News for hackers. Stuff that matters.
Re:Controversial Programming Opinions (2012) by 908B64B197 on Friday December 04, 2020 @02:36PM (#25306679)
> Relatedly, the 80 column "rule" is as stupid in code as it would be in prose. Use your aesthetic sense.

Horizontal scrolling is almost always a bad experience for the user. But 80 is way too restrictive. I'd say no more than half a standard monitor wide is the character limit. What's a standard monitor depends on what's used by the devs writing the code of course.

> Source code should liberally use Unicode symbols.

Give it a few years. But make sure there's a good normalization (there are several ways to print the same glyph on the screen that are different bytes in memory)

Re:Controversial Programming Opinions (2012) by josephg on Friday December 04, 2020 @03:46PM (#25307678)
At google (at least when I was there) they have a hard rule of 120 character lines or something. (I think it varies by language).

I thought the rule was ridiculous - until I realised one of my colleagues had set his computer up with 3 tmux sessions side by side, each perfectly fitting a 120 column code window. He never had to scroll sideways, and he was very productive with his setup. The fact he knew exactly how wide to make his terminals made his workflow much better.

I don’t follow that rule on my own projects, beyond keeping line lengths “reasonable”. But that rule might be on to something.

Re:Controversial Programming Opinions (2012) by elektronaut on Friday December 04, 2020 @09:51PM (#25311240)
This is why I’ve come around on the 80 character rule after switching to Emacs, fitting four buffers side by side on my 27” monitor just works.

120 characters/3 columns is great for more verbose languages, but I find it a bit too wide for a vertical split on a 15” laptop monitor.

Re:Controversial Programming Opinions (2012) by moron4hire on Friday December 04, 2020 @10:34PM (#25311474)
I just enable word wrap in my editor
Re:Controversial Programming Opinions (2012) by pc86 on Friday December 04, 2020 @04:03PM (#25307936)
I don't think the fact that it worked for one guy (or more accurately, that he adjusted his workflow according to this rule) makes it a good rule by definition.
Re:Controversial Programming Opinions (2012) by Brian_K_White on Friday December 04, 2020 @05:19PM (#25308994)
It's not that they contorted their workflow to satisfy some arbitrary rules, it's that the fact of the dependable consistent rule made it possible for them to formulate an efficient dependable consistent workflow at all.
Re:Controversial Programming Opinions (2012) by spideymans on Friday December 04, 2020 @02:49PM (#25306855)
The 80 column “rule” also discourages the use of descriptive naming, which IMO is far more important to readability than short lines.

Also 80 columns is near impossible to adhere to for more verbose language.

Re:Controversial Programming Opinions (2012) by bjourne on Saturday December 05, 2020 @01:40AM (#25312373)
Descriptive naming usually isn't.

    E=m*c^2 or 
    objectEnergyInJoule = massOfObjectInKilograms * speedOfLightInVacuum^2 ?
Re:Controversial Programming Opinions (2012) by DangitBobby on Saturday December 05, 2020 @02:24AM (#25312584)
Now imagine that you're not looking at a famous equation and you tell me which one you would rather have to sus out the intention of.

    a = b/c

or

    numApples = numBananas/apple BananaConversionRate
Re:Controversial Programming Opinions (2012) by bjourne on Saturday December 05, 2020 @04:57AM (#25313222)
The first one, no question about it.
Re:Controversial Programming Opinions (2012) by kazinator on Saturday December 05, 2020 @12:12PM (#25316176)
Yes. We would want the descriptive names for identifiers which have broad scope, but short names for the local variables that work with them.

I would rather give a function the descriptive name in such a way that the parameters can then be given trivial, mnemonic names.

Strawmannish example:

   incrementAccountBalance(a, n)
   {
      ...
   }
The descriptive function name gives away what a and n are, so it is unhelpful to make this:

   incrementAccountBalance(account, amountToIncrementBy)
Reasonable middle ground:

   incrementAccountBalance(acct, delta)
Re:Controversial Programming Opinions (2012) by spideymans on Saturday December 05, 2020 @08:52PM (#25320269)
With incrementAccountBalance(a, n), it's impossible to tell exactly what each argument is from the function signature alone. Of course I could assume that a = account and n = amount to increment by, but that's nothing more than an assumption, which only invites inevitable bugs. Alternatively I could look at the function body, and try to figure out what's going on, but that's time wasted that could be spent more productively.

Further, non-descriptive naming often assumes that the programmer reading and modifying the code has domain-specific knowledge. That might be true of mid level or senior engineers have have been with a particular company for years, but the new grad coming into a financial services company (a field he has no training or familiarity with) will have no idea what "a" or "b" means. I was in that position, and the descriptive naming absolutely would have helped me to learn and become productive with the codebase faster.

I'd say that your reasonable middle ground would be the best practice.

Re:Controversial Programming Opinions (2012) by DangitBobby on Saturday December 05, 2020 @10:15PM (#25320699)
Opposite of my choice of which I also have no question.
Re:Controversial Programming Opinions (2012) by skrtskrt on Friday December 04, 2020 @03:48PM (#25307717)
For both Python and Go I use descriptive (often long) names and ~90-char line limit, and use linebreaks liberally to reconcile the two
Re:Controversial Programming Opinions (2012) by Viliam1234 on Sunday December 06, 2020 @05:24PM (#25327198)
> Also 80 columns is near impossible to adhere to for more verbose language.

Not if you use Unicode (and Chinese language).

Re:Controversial Programming Opinions (2012) by layer8 on Friday December 04, 2020 @04:29PM (#25308313)
I settled on 100 characters as the sweet spot, with an exception for trailing punctuation being allowed to go beyond (because you don’t want to wrap a line just because of some trailing punctuation).
Re:Controversial Programming Opinions (2012) by iandinwoodie on Saturday December 05, 2020 @12:01AM (#25311916)
I remember hitting the punctuation dilemma with my self-imposed character limit. Putting the punctuation on the next line, looking at it displeased, moving it back, questioning the purpose of rules if they're not followed; racking my brain over the world's least consequential conundrum. Ultimately I decided to adhere to my limit, but to treat punctuation and the word that precedes it as a single unit to be wrapped together.
Re:Controversial Programming Opinions (2012) by lostmsu on Friday December 04, 2020 @05:15PM (#25308956)
Also sometimes comments.
Re:Controversial Programming Opinions (2012) by layer8 on Friday December 04, 2020 @08:03PM (#25310554)
Nah, comments are important and should be in the main field of view. :)
Re:Controversial Programming Opinions (2012) by selfhoster11 on Friday December 04, 2020 @04:59PM (#25308718)
Horizontal scrolling can be avoided with line-wrapping. It's not always a good way to deal with the problem, but it's useful for some edge cases.
Re:Controversial Programming Opinions (2012) by lolinder on Friday December 04, 2020 @11:04PM (#25311638)
Line wrapping is often difficult to read as well. If programmers wrap the line themselves, they can break it up logically, rather than letting the computer break lines wherever it's convenient. Further, they can respect the indentation level of the line, whereas most line wraps I've seen wrap starting all the way to the left.
Re:Controversial Programming Opinions (2012) by xigoi on Saturday December 05, 2020 @05:45AM (#25313477)
Vim has a setting to make line wraps start at the same indent as the line.
Re:Controversial Programming Opinions (2012) by egypturnash on Friday December 04, 2020 @11:03PM (#25311634)
Word wrap. Turn on word wrap.
Re:Controversial Programming Opinions (2012) by lolinder on Friday December 04, 2020 @11:07PM (#25311651)
In every editor I've tried it on, word wrap wraps the lines all the way to the left, instead of respecting indentation levels. This makes for very difficult grokking of control flow, both in languages with significant whitespace and C-style languages. If programmers simply wrap their own lines, they can respect the white space conventions of their language and make it much easier for other developers to read later.
Re:Controversial Programming Opinions (2012) by hollerith on Friday December 04, 2020 @11:26PM (#25311743)
VS Code respects the indentation level (provided editor.wordWrap has some value other than "off" and editor.wrappingIndent has some value other than "none"). In other words, if a line needs to be split into 2 "virtual" lines to fit in the window, VS Code inserts a "virtual copy" of the line's initial whitespace before the second virtual line. By "virtual copy", I mean that the copy of the whitespace is never inserted into the file, but is added during the rendering of the contents of the file into the window.

Emacs on the other hand, has the problem you describe, and probably always will because of how hard xdisp.c is to modify and because the maintainers of Emacs probably do not consider the problem important enough to justify a big change to xdisp.c.

I was never a vim user, but my cursory investigation led me to conclude that vim, too, has the problem you describe.

Re:Controversial Programming Opinions (2012) by metaphor on Friday December 04, 2020 @11:59PM (#25311898)
The parent assumes that word wrap, a feature we take for granted today, is even a thing in the editors/terminals of legacy systems that this 80-character rule likely targets.
Re:Controversial Programming Opinions (2012) by kazinator on Saturday December 05, 2020 @06:58AM (#25313905)
> I'd say no more than half a standard monitor wide is the character limit.

So if "monitor wide" is 80 characters, like a DEC VT-100 terminal, or WYSE-50 or whatever, then we have a 40 column rule.