One of my favourite quotes from Ken Thompson (who apparently knows a bit about computers) is:I tend to break up a subprogram when there are too many local variables. Another clue is [too many] levels of indentation. I rarely look at length.
It's not an absolute truth, but he does give two pretty good indicators.
The length of a function isn't important - what you're trying to do in that length is... :-)
This kind of quote used to make me disappointed that I never went to university to do computer science. I imagined that such quotes would be thrown out by a teacher, followed by the magic word "Discuss".
Of course, I eventually met some CS students, who disabused me of this romantic notion. ;-)
Yeah, that would be a neat class, but I never had a class like that. It's not so much the teachers wouldn't be open to that, but that the students wouldn't be capable of following up with a discussion. It would be dumb anyway -- speculating on design practices that apply to something none of the students have ever done: working with code at different stages of the code life cycle. At best the students could rephrase other bits of wisdom heard but never experienced, which does not a discussion make. This describes a large portion of the discussions I had in college classes. Discussion sucked. But then I wasn't a very satisfied student in general.
Number of variables, lines or nested levels is just a sign to take more careful look. Should code be changed or not it depends on context. I can spot bad code from 5 meters, it's much harder to tell if code is done right. Some things are complex and require complex algorithms. On another side, if piece of code does not fit in my screen, it probably will be too complex to fit in my brain in first reads.# Ģirts
"This kind of quote used to make me disappointed that I never went to university to do computer science. I imagined that such quotes would be thrown out by a teacher, followed by the magic word "Discuss"."
My experience is that only a small part in CS is about programming.