Hacker News new | ask | show | jobs
by Kevguy 4053 days ago
I definitely _have_ gone "wtf" when dealing with some long functions. A 380 line switch/case comes to mind. I have also had to deal with the 5 level deep inheritance that was equally difficult in its own way. Figuring out where to balance between length and depth is one of the more difficult parts of programming in my opinion.

After many years maintaining my and other people's code, I do tend toward shorter methods. On the other hand, splitting up a method into several methods just to keep under a hard line limit causes more problems than it solves.

1 comments

Sure, of course I prefer shorter code. But I'd much rather read a hundred straightforward lines than wrap my head around yet another abstraction (of which there are thousands in any non trivial codebase).

I must disagree on the switch statement. A main loop with an rather large switch statement is a perfectly normal way to write a trivial interpreter. C provides a nice way of doing it, and as long as you declare your constants properly it's all perfectly readable. A lot of excellent code bases are structured that way. (Awk comes to mind, IIRC, and it's very easy to read and extend.)