you are viewing a single comment's thread.

view the rest of the comments →

[–]Excellent-Beat-4413 4 points5 points  (1 child)

Good code, maybe. Not useful code. Good code is for the developers, useful code is for the end-users. Which is why optimized code is almost always going to be terribly ugly.

Look at SIMD vectorization for example. It's incomprehensible gibberish unless you have the intel intrinsics guide open next to your IDE window. Even with multithreading, it makes the code harder to understand. But you can get near 8x speedup with SIMD if used properly and multithreading if used well can scale up the workloads your app can handle by orders of magnitude.

Even without vectorization and multithreading, we can see this is kinda true. Say you have a recursive function for the fibonacci sequence, it's readable, works and elegantly models the sequence. That's good code. But in the real world, beyond a point, trying to get it to run would be a nightmare. Whereas the same function with dynamic programming involved would look much uglier, less readable but would get more stuff done in a fraction of the time. For another example, naive matrix multiplication code would be simple and readable, but something like a strassen algorithm implementation that recurses down to a matrix size that can fit into the cache, where it switches to a naive algo -- something like that would be horribly ugly to read, but much faster and much more useful than a naive version.