News for hackers. Stuff that matters.
Re:Five Rules for Writing Good Code by city41 on Saturday November 28, 2009 @06:44PM (#965670)
Refactoring large methods into a collection of small aptly named ones has its drawbacks too. When reading the code the reader has to keep a mental stack going maintaining what each sub function means/does. Sometimes this is worse than keeping it inline. There is definitely a good balance to be had between the two approaches.
Re:Five Rules for Writing Good Code by aerique on Saturday November 28, 2009 @07:28PM (#965716)
You shouldn't need to keep a mental stack since as you say the small functions are aptly named. You just check once whether the function really does what it suggests and then you don't have to throw it on your stack the next time.
Re:Five Rules for Writing Good Code by InclinedPlane on Saturday November 28, 2009 @07:50PM (#965731)
Exactly. Naming and proper design is very important. Tracking state changes through numerous "DoStuff" and "HandleThings" methods definitely represents additional intellectual overhead.
Re:Five Rules for Writing Good Code by inffcs00 on Sunday November 29, 2009 @05:30AM (#966208)
I think that if you follow the "One level of abstraction per function" tip from the "Clean Code" book, and you do a proper naming of your functions this problem disappears.
Re:Five Rules for Writing Good Code by j_baker on Sunday November 29, 2009 @10:31AM (#966396)
I actually have a blog post about this general subject: http://jasonmbaker.com/the-devils-in-the-details

In extracting code into a method, you're intentionally obscuring what it does. Most of the time this is a good thing because you want to only focus on the details of the routine you're in. Thus, if you follow the "make your method do one thing" rule, you should be ok.

If your methods have no cohesion to them, then you will have problems breaking them down. But then again, I would argue that that's the least of your problems.

Re:Five Rules for Writing Good Code by zb on Saturday November 28, 2009 @10:16PM (#965855)
A better title for the article might have been "Five Heuristics for Writing Good Code".