2 ms·
I completely disagree with the article. The right hand side is far better. Not perfect; there are definitely a couple of things to improve, but it's better than
by mcv 3y ago
I completely disagree with the article. The right hand side is far better. Not perfect; there are definitely a couple of things to improve, but it's better than just a big long meandering god function like on the left. It feels like the author is arguing to go back to the coding style of the 1980s.
Big advantage of the right-hand style: the various steps are laid out in a simple 5-line function. You immediately see what making a pizza involves. Want to know more about it (like whether baking involves the creation of a completely new oven), you can zoom in on the details, but you never have to look at details that are irrelevant to you, unlike on the left side, where you have to dig through a page of code to figure out which part is relevant to you.
Mind you, there are a lot of ways in which the right hand style could go wrong: if you don't separate your concerns, and have global or member variables manipulated by different functions in ways that are not immediately obvious, then superficially clean code could be hiding some terrible spaghetti. But at least the right-hand style punishes you for that and encourages you to do better (in fact, I'm currently refactoring a bit of code that did exactly that). The left hand side would allow terribly messy code with complex interactions between different parts of the code without making it obvious that those interactions are there, and will make it more intimidating to refactor them. Small functions are easier to test and easier to refactor.
- lucumo 3y agoI agree. The right hand side also makes it very easy to zoom in on the problem details. If the pizza is not properly boxed, I don't want to worry about whether the salami was sliced the right way. I can skip over that, and immediately zoom in on the boxing process. Pretending that a comment header is the same as a function is a bit silly. We can navigate to functions, not to comments.