On 08/11/2011 21:21, Lex Trotman wrote:
On Wed, Nov 9, 2011 at 3:40 AM, Nick Treleaven nick.treleaven@btinternet.com wrote:
On 04/11/2011 00:21, Lex Trotman wrote:
- long functions cause bugs
Rubbish, wrong functions cause bugs no matter how long, and being unable to see the whole logic leads to wrong design.
Long simple functions are Ok. Obscuring the logic is obviously bad. Sub-functions should be near the function that uses it if the sub-function is only used once.
- too many variables in one place cause bugs
Thats what declarations in inner blocks are for :)
That helps a bit, but the more things you have to keep track of the more likely you'll forget to initialize a variable that needs it or forget to free memory or other bugs.
I'm sure there are statisics to back this up, it's well known in code analysis/reliability circles.
And there are also statistics that say the opposite, that breaking it up too far over complicates things and causes unreliability.
Agree, I should have included some numbers in my points. It depends on context, but I would say a function longer than 15 lines may be too long. More than about 7 variables can get hard to keep track of everything.