Saturday, October 29, 2016

Good Coding Taste

Brian Barto:

But it wasn’t the line count that mattered. It was that if-statement. It’s gone. No longer needed. The code has been refactored so that, regardless of the object’s position in the list, the same process is applied to remove it.

[…]

To the best of my ability to discern, the crux of the “good taste” requirement is the elimination of edge cases, which tend to reveal themselves as conditional statements. The fewer conditions you test for, the better your code “tastes”.

It’s an interesting example because the “bad” version has more state and branching, but some programmers would find the “good” version harder to understand, due to the indirection and attendant C syntax.

3 Comments RSS · Twitter


My biggest problem with his article is that his own code he claims is in "good taste" would be slower than code that has a for loop for the top row (that the compiler would easily optimize), a for loop for the bottom row (again easily optimized), and a for loop for the sides. His code is jumping all over the place in memory.


@David Yeah, performance-sensitive code probably has higher priorities than this sort of taste.


While I don’t disagree with his conclusion per se, it seems that his example is about standard computer science (time complexity) rather than “good taste”, as doing GRID_SIZE×GRID_SIZE iterations to initialize 4×GRID_SIZE values is not something you let slide because it is more readable.

Leave a Comment