News for hackers. Stuff that matters.
Re:Almost monospaced: the perfect fonts for writing by pmontra on Monday November 07, 2022 @02:50AM (#33502533)
I've been using proportional fonts in programming for about ten years. I stopped doing things like

  abc = 1
  d   = 2
which add very little readability value IMHO.

Things like

  func(arg1,
       arg2,
       arg3)
usually don't align well because func( has a different width than the five spaces in the lines below. However

1) my text editor (emacs) aligns those lines for me (probably any programmer's editor does) so at least I don't have to do precision work

2) I ended up writing code like

  func(
    arg1,
    arg2,
    arg3
  )
especially with named arguments (arg=value). That aligns even with proportional fonts and all arguments immediately stand out.

If the arguments are few (two or three) and there are no named arguments I don't break them on multiple lines.

The result is that no coworker ever complained about my code.

Languages with a formatter (Elixir) solve the problem once and for all and align well with both kinds of fonts.

Re:Almost monospaced: the perfect fonts for writing by amadvance on Monday November 07, 2022 @03:31AM (#33502900)
I do something similar also with if() and others:

  if (condition...
      && condition...
      && condition...
  ) {
Re:Almost monospaced: the perfect fonts for writing by tuyiown on Monday November 07, 2022 @07:23AM (#33504906)
Same here but pushed it to force same column condition statement:

    if ((
      condition1
    ) && (
      condition2
    ) && (
      ...
    )) {
Re:Almost monospaced: the perfect fonts for writing by Izkata on Monday November 07, 2022 @02:13PM (#33510783)
But that loses the table-like structure and makes it harder to read.
Re:Almost monospaced: the perfect fonts for writing by anilakar on Monday November 07, 2022 @03:22AM (#33502811)
Formatting your code in an unintuitive way because of the font is a code smell to me.
Re:Almost monospaced: the perfect fonts for writing by pmontra on Monday November 07, 2022 @03:25AM (#33502845)
Honest question: which one is unintuitive?
Re:Almost monospaced: the perfect fonts for writing by alpaca128 on Monday November 07, 2022 @05:17AM (#33503926)
Why? The purpose of code is to be readable to humans.

At the same time I get your point and also the argument about Git diffs (which also should be readable). So maybe the ideal situation would be a separation of code and its formatting, so that we have more options than tabs and also no need for crutches like tabs. Like a better, more flexible code formatter that lets you display and edit code in the editor using one style but then saves the file in a standard format that's consistent across the whole project.

Re:Almost monospaced: the perfect fonts for writing by nkrisc on Monday November 07, 2022 @05:41AM (#33504154)
Viewing the examples generally, the second one better communicates hierarchy at the cost of an extra line. The arguments are all grouped together visually and without distraction, while in the first example the first argument gets muddled with the function name. Why? To save a line break?
Re:Almost monospaced: the perfect fonts for writing by kazinator on Monday November 07, 2022 @12:27PM (#33508992)
The canonical notation is like this:

  func(arg1, arg2, arg3)
the first example splits it across multiple lines in a way which maximally preserves the other apects of the notation.
Re:Almost monospaced: the perfect fonts for writing by nkrisc on Monday November 07, 2022 @09:46PM (#33515361)
> the first example splits it across multiple lines in a way which maximally preserves the other aspects of the notation.

Once you’re splitting it across lines I don’t think that is a desirable attribute. Better to use a format that suits multiple lines than attempt to match as closely as possible to a format intended for one line. Like those “flying cars” that try to look like the “canonical” car.

From my perspective this is a UI problem (though not a serious one).

Re:Almost monospaced: the perfect fonts for writing by seanmcdirmid on Monday November 07, 2022 @06:58AM (#33504721)
That’s what many auto formatter do anyways, even ones setup for fixed width fonts.