Does a good program almost always has less number of lines of code?

or is reuseability, robustness, clearness of code, efficiency, etc more important?
Last edited on
These are all attributes of a properly developed program. However, number of lines of code shouldn't matter. Some times it's a better idea to have that extra 100 lines of code that clearly spell out what the programs doing rather than have those 10 lines that are extremely complicated.
I'll expand, but on a C++ function/method level rather than a whole program level.

Reusability:
Number of lines of code and reusability are not directly linked, but I would argue that there is often (but not
always) a correlation. For a function to be reusable, typically it can only do one thing. For example, I'd bet
you'll find more uses of a function that finds the minimum element in an array of integers than a function that
first asks the user to enter via keyboard an array of integers and then finds the minimum element. Obviously
in this case the second function is simply a superset of the first and therefore will contain more code.

Robustness:
If by robustness you mean "bullet-proof" or "doesn't crash", I would argue that more code is necessary for
robustness (more code is needed to handle more error cases). If by robustness you mean "feature rich", I
would again argue that more code is necessary for more features.

Clarity:
I would agree with Return 0. But clarity, it should be said, is in the eyes of the beholder. This, for example,
is clear to me:

 
std::for_each( v.begin(), v.end(), std::cout << "The contents of the vector are:\n" << boost::lambda::_1 << '\n' );


But for those who aren't familiar with boost::lambda or std::for_each might be puzzled over what this does. For
them, this longer version might be clearer:

1
2
3
std::cout << "The contents of the vector are:" << std::endl;
for( size_t i = 0; i < v.size(); ++i )
    std::cout << v[ i ] << std::endl;


Efficiency:
There is no correlation between lines of code and efficiency. This is unbelievably slow for large vectors and is
only one line of code:

1
2
3
void some_func( std::vector< std::string > v ) {
   // Do stuff
}


Anywhere this function is called, we push a copy of the actual parameter onto the stack which results in
copying all of the contained strings.
Topic archived. No new replies allowed.