Consider this Metaphor
. When it comes to code length, I think we should consider the following:
The Cat in The Hat (50 pp.)
and
Lord of The Rings (1,178 pp.)
There is nothing wrong with Lord of the Rings
. It's a fabulous book. The Cat in the Hat
is also a great book. Both can be understood by a 5 year olds, but only one is better suited due to content.
To my point, writing code should make sense to a 5 year old whenever we can. Cyclomatic Complexity
is an important concept that may developers should consider as they generate code. Utilizing and creating libraries to enhance functionality and code reusability as much as possible. This way our code can speak more volumes than what we see written.
Most of us are not writing assembly code. But the root of our code is assembly. Searching through 10000 lines assembly is harder than 10000 lines of python, if it is done correctly.
But some work requires writing 500 to 1000 lines. Our goal with code should be to write 300 lines of clean code.
As developers, we want to write "Lord of The Rings". Until we get a bug and wish we were writing "Cat in the Hat". Don't make coding a measure of ego. Just make things work in a simple fashion.
Developers don't want to document code, (I love documented code personally, I'm not that selfish). So don't write code that only you can understand/read. Write Cat in the Hat
code.
We all know you are J.R.R. Tolken (in your head). Remember you will have nothing to prove with bug free code.
Another reason for the Metaphor.
Don't overkill the reader spread the wealth. If you work with a group of people and all of them have to change that same a large file, you are will probably putting yourself into git
merge hell.
Everyone loves rebasing.
-> Said no one ever!
TL;DR
Focus on readability. Spread your code and helper over multiple lines and files as much as you can. Don't throw 8 or 9 classes in a single file, It makes the code hard to read and harder to maintain. If you have a large condition code or loop, consider changing them to Lambdas if the language supports it. Utilities functions should be considered a great avenue to increase code readability. Avoid heavy nesting.