Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'd like to get your opinions on this...

I think programmers nowadays are a bit overly obsessed on getting lines of code down

Its certainly possible to write something in one line when you could use 6 if you use the more obscure and "fancy" tools available in the language you are using. One thing that randomly springs to mind is linq in .net Reasons why more lines might be better.

1. The longer more explicit code might end up shorter and more performant after it is compiled (like in the oldskool performance increasing trick of unrolling loops)

2.When you come back to your fancy code later you may have forgotten about that particular fancy trick and now you dont understand your code.

3. Other people are less likely to understand your code.

4. By using more specialised features in a langauge your code is now less transportable to other langauges.

Personally I think the obsession with fewer lines quickly becomes counter-productive and the main reason it is done is in order to show-off your knowledge of these fancy things.

Note: I'm not talking about the guy in the article btw. Just talking a about a general trend I've noticed in modern programming.



> 1. The longer more explicit code might end up shorter and more performant after it is compiled (like in the oldskool performance increasing trick of unrolling loops)

Or it might be less performant. If you actually care about this, you should have an automated test running regularly that will tell you one way or the other. But most of the time it's not worth worrying about such things.

> 2.When you come back to your fancy code later you may have forgotten about that particular fancy trick and now you dont understand your code. > 3. Other people are less likely to understand your code.

Or using fancy tricks more frequently can help you remember them. I think you should use every feature available in the language - developers need to be able to understand the language so that they can read third-party library code. Or else have an automated system that flags usage of particular features.

> 4. By using more specialised features in a langauge your code is now less transportable to other langauges.

Who cares? Seriously, how likely is this to actually come up? If you've chosen language X you presumably had a good reason for doing so; you should write language X, not try and write language Y in language X.

Fewest lines of code is not the perfect metric, but I think it hits the sweet spot: it's very simple to calculate, and captures a good proportion of the difference between good code and bad code.


I haven't seen much of this myself, although I can imagine it happening.

From what I've seen, bloated code tends to be code that is copied (either literally or in style) from somewhere else, which doesn't fit the task at hand. So you have functions that have lots of options, but only ever get called once with one set of parameters. The fix is to rewrite everything so that the abstractions are taylored to the task at hand.

What you are describing is a kind of excessive elegance. But this is fairly independent of the problem I described (and the article is describing).

I'll also say that there is a limit to bloat, and LOC is often a good guide to functionality. E.g. if I'm interesting in re-implementing something, I'll first look at the weight of the code. If I thought something would be a half hour job and the code is 5000 lines, I'll probably re-evaluate. Sometimes I've pondered reimplementing certain libraries, only to find they weigh in at a million lines of code.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: