No. [0]
485 karma · joined April 8, 2015
No. [0]
It's relatively rare to refactor a single line of code into its own function, unless it's really hard to read, e.g. some nasty regex.
> even if they're supposedly so self contained you don't need to look at them individually - that's rarely true in practice
If a long function is broken up into smaller functions only for the sake of having smaller functions, then you end up with functions that don't really make sense on their own and, sure, the bigger function is better. But if the broken up functions are named well enough like in the example above, then it shouldn't be necessary to see how it's implemented, unless you're tracking down a bug. After all, it's very rare to look at e.g. how a library function is implemented, and for some libraries/languages it's not even possible.
> When faced with a file with dozens of tiny functions, it's much harder to get a top level understanding than if it has a smaller number of longer functions.
Most languages have facilities to help with that, e.g. function visibility. Your smaller number of large functions can remain the public API for your module while the "dozens" of tiny functions can be private. In either case, long files are harder to take in no matter how many functions they're composed of.
This. Your code shouldn't be documenting what it will do in the future: it should be clear what it's doing right now. Otherwise some other engineer maybe from another team will come upon it, misread it, and bugs ensue. Trying to save yourself time in the future ends up wasting time for others, and likely for yourself as well.
Lo and Behold, Reveries of the Connected World - Werner Herzog. Film about the internet.
The Thin Blue Line - Erol Morris. Film about a murder of a police officer that comes to a different conclusion than the court did about who the murderer is and led to the release of an innocent man and the incarceration of the guilty one.
The Civil War - Ken Burns. There's a reason it's a classic!
Good Intentions - Walter Williams. Film about how economic policies that sound good often have the reverse effects that they intend to have.
While a senior engineer just asking you to rewrite it without further details is bad, it's good practice to follow the "make it work, make it right, (optional) make it fast" approach. The "make it right" part is where you make your code readable after you've ensured that it works and before you submit it for review. If you find later that you need to make it fast, it is expected that readability will have to be traded for performance.
> Saying yes as often as possible is, famously, the first rule of improv, vital to maintaining energy, imagination, and humor. It is also, I have long thought, a sure sign that you’re falling in love, not to mention crucial to sustaining that love over the long haul. And, while sometimes impractical, dangerous, or just plain dumb, saying yes to as much stuff as possible is, over all, a pretty good strategy for getting through life.