4 ms·
Also people forget that quote is from the 70s. Almost 50 years go. Programming used to be very different from what it is now. "Premature optimization" wasn't "
by preommr 3y ago
Also people forget that quote is from the 70s. Almost 50 years go.
Programming used to be very different from what it is now. "Premature optimization" wasn't "hey just use this popular lib cause it scales", it was "let's use some impossible to understand bit fiddling algorithm that only works on this piece of hardware".
- bluGill 3y agoIn any compiled language your optimizer will do all those weird things for you, and will even handle all the different generations of CPUs for you. Compilers never give you a better algorithm if you write the wrong one. Almost all languages have a standard library that has all the normal algorithems you would want, and where something wierd is better they have that done for you.
- eesmith 3y agoCompilers can and do replace some (simple) algorithms with a better one. At https://stackoverflow.com/questions/74417624/how-does-clang-generate-non-looping-code-for-sum-of-squares https://stackoverflow.com/questions/74417624/how-does-clang-... is someone asking why the compiler replaced: int a = 0; while (n--) a += (n * n); an O(n) algorithm, with the O(1) equivalent of: a = n * (n-1) / 2 + n
- zimpenfish 3y agoI think your `n * (n-1) / 2 + n` should be `n(n+1)(2n+1)/6` according to the SO article. `n * (n-1) / 2 + n` would be the sum of numbers, not sum of squares.
- eesmith 3y agoThank you for the correction!
- ska 3y ago> Programming used to be very different from what it is now Programming has definitely evolved. This maxim seems to be exactly as applicable then as it is now though, and as misunderstood.
- deleted 3y ago[deleted]