Live data from Hacker News

Line length in programming

ck.kennt-wayne.de

71–74 of 74 posts

Re: Line length in programming

#71
post #59
post #37

Earlier quoted context omitted.

That is a straw man. No one actually thinks 80 character displays are the reason to use 80 characters. I think 80-100 is fine. More than 100 and you probably need to refactor the line some, because you probably have too much logic on a single line (or you need to choose names that aren't hugely long).

The beauty of expressive languages like Python is that you can fit a lot of logic into one line with list comprehensions and the likes. When it isn't obvious what it is doing straight away, add a comment.

This is almost always a bad idea. I've extracted many a python line into 2-4 lines to make it a hell of a lot more clear. Packing logic into a line is not a good thing. It may be fun and a challenge, but it makes for fragile code that is easy to get wrong and/or misunderstand.

Re: Line length in programming

#72
post #69
post #37

Earlier quoted context omitted.

That is a straw man. No one actually thinks 80 character displays are the reason to use 80 characters. I think 80-100 is fine. More than 100 and you probably need to refactor the line some, because you probably have too much logic on a single line (or you need to choose names that aren't hugely long).

>> No one actually thinks 80 character displays are the reason to use 80 characters. Err, yeah they do, I have been given exactly that reason on a few occasions, generally by older engineers who had experience with old-school machines that had precisely those screen dimensions. I don't disagree with your main point, but it's really not a straw man.

Well, for most people it's a straw man. I've worked with some greybeards, and they are smart enough to know that they can resize the terminal on their modern laptop :)

Re: Line length in programming

#73
post #71
post #59

Earlier quoted context omitted.

The beauty of expressive languages like Python is that you can fit a lot of logic into one line with list comprehensions and the likes. When it isn't obvious what it is doing straight away, add a comment.

This is almost always a bad idea. I've extracted many a python line into 2-4 lines to make it a hell of a lot more clear. Packing logic into a line is not a good thing. It may be fun and a challenge, but it makes for fragile code that is easy to get wrong and/or misunderstand.

I often use list comprehensions where I would have previously used a for loop. It means you have less variables and are less likely to have side effects. I wouldn't say it is always a bad idea.

Re: Line length in programming

#74
post #64

Earlier quoted context omitted.

I just had a quick look at that grammar article. I imagine when people are describing something technical / scientific / difficult to comprehend, it will take more words.

And what is more technical than code? It's literally logic that will be followed extremely, anally literally. No scientific language gets close to being that literal - normally, you are always going to keep the author's view/point in mind as you read. If you were to accidentally remove a random "not" from scientific writing (as happens), we can usually realize what the author meant. (With rare exceptions, if we are p…

Code rarely has the ambiguities that spoken languages do.
Post reply on HN