Ask HN: Is removing as many LOC as possible really that big of a priority?
I'm a student, working at my first job in the industry. We don't use a rubber duck here but I've been noticing companies using the "Rubber Duck Challenge" as incentive to remove as many LOC as possible. Is this practical?
Surely you'd want to remove only when necessary, I understand trying to refactor a legacy codebase to something more manageable, but usually (unless it's terribly written) removing lines by condensing things down only leads to harder legibility.
Can anyone who's used this method or has (more) experience in the industry throw their 2¢ in?
10 comments
[ 2.5 ms ] story [ 32.9 ms ] threadYou're right, but that's not always true. In any sufficiently large project, there are thousands of LoC that can be removed by changing libraries, writing DRYer code, etc.
However, turning it into a competition probably isn't going to stay within the lines of "good" lowering of LoC.
And, in some cases, increasing LoC can make the code better. For example, breaking up a huge method into several, well-named methods will slightly increase LoC, but also increase readability.
make it work
make it right
make it fast
Getting to the point where you can remove LOC takes mastery.
LZW compression tries to remove as many bytes as possible from text, but it does not help readability. I know, you wouldn't LZW compress the source and then try to compile it. You can move in that direction, though, if you try to shorten the source too much.
Remove needless duplication. Remove lines where it improves clarity or structure. Absolute shortest source code is not a worthwhile goal.
So, I think better design is the goal, and fewer LOC is a natural side effect. I personally find that essential for evolving a large project. Some managers are ok with ever-increasing tech debt, which I associate with increasing job dissatisfaction.
Sometimes, the most readable solution is quite long. Other times, it's short and compact. But, if it's always readable, chances are high that it is not only well designed, but it will be easy to maintain.
This for me is a bad idea. I always have it in the back of my mind about reducing a modules footprint but as someone else mentioned on here. There's an art to it. Sometimes it's a bodge, followed by another fix in another part of the code base a month later which then frees you to delete.
Quite often it's like that actually. Patience is key.
I'd also like to add +1 for duplicating code. I see lot of devs just unwilling to dupe code at the cost of readability and speed of development.
Perhaps that code could be refactored down the line or more often the act of making it "neat" gives up 1 or more niceties that made you write it like that in the first place.