r/AskComputerScience • u/YounisMo • Jan 07 '26
Optimality in computing
So this question is gonna be mouthful but I have geniune curiousity I'm questioning every fundamental concept of computing we know and use everyday like cpu architecture, the use of binary and bytes, the use of ram and all the components that make a up a computer, a phone or whatever Are all these fundamentals optimal? If we could start over and erase all out history and don't care about backward compatibility at all How would an optimal computer look like? Would we use for example ternary instead of binary? Are we mathematically sure that all the fundamentals of computing are optimal or are we just using them because of market, history, compatibility constraints and if not what would be the mathematically and physically and economically optimal computer look like (theoretically of course)
View all comments
Show parent comment
1
u/flatfinger Jan 07 '26
FORTRAN and C were designed around different philosophies, which are more or less suitable for different tasks. Consider the following two C functions:
A FORTRAN compiler given code equivalent to the former (but reversing the subscripts because FORTRAN uses column-major arrays) would be expected to identify that the segments of the array processed by each complete run of the inner loop would all be contiguous, and thus convert it into code which uses a single loop. Classic C, by contrast, was designed around the idea that a programmer who needed the level of performance that would result from using a single loop would write the code to use a single loop. Note that the
syntax arr[3][n]in classic C doesn't mean "access item n of row 3" but "take the address of arr plus three times its stride, displace that bysizeof(arr[0][0])timesibytes, and access whatever is at the resulting address. The fact that for values of i from -15 to -1 that would access the same storage asarr[3-i/3][i%3]wasn't an implementation detail, but rather a consequence of the fact that for eachiin that range, the address computations used by both expressions would yield the same address.In FORTRAN, a compiler would be entitled to assume that an access to
ARR(I,J)would access somethign in columnIof rowJof the array (FORTRAN is column-major), and could consequently assume that an access to e.g. ARR(I,J) and an access to ARR(I+1,K) couldn't access the same storage, even if it knew nothing aboutJandK.In order to accommodate people who wanted C to be suitable for use as a FORTRAN replacement, the C Standard seeks to characterize as Undefined Behavior any situaton where the kinds of assumptions that would be appropriate in FORTRAN fails to hold, thus allowing compilers to assume that programs will only do the kinds of things that would be valid in FORTRAN, ignoring the fact that much of C's reputation for speed had come from the fact that programmers could compute addresses for things in a variety of ways that would be hard for compilers to reason about, but that compilers wouldn't expected to try to reason about.