Hacker News new | past | comments | ask | show | jobs | submit login

> And they're absolutely right. But it begs the first-principals question-- why code using a monospace font? Today, every major editor that isn't terminal-based supports proportional width fonts beautifully.

There was a whole "coding font" family designed around the idea that we should be using proportional fonts for this, and it makes a great case...

https://input.djr.com/info/

...except that just about every time I've tried this, I've quickly run into places where trying to use a proportional font creates visual fails. Here's a simple one:

    /**
     * Render a given template
     *
     * @param string $_template
     * @param array $_args
     * @return string
     */
Put that in a non-proportional font, and the asterisks on the first line probably won't line up with the rest. Now think of someone doing visual alignment of assignment operators in a block of code like you often see in Ruby, or any code following the indentation standard where you line up parameters in a multi-line function header with the character after the open parenthesis like you often see in Python. Speaking of parentheses, can you imagine what will happen with proportional fonts and Lisp indentation? It'd drive the hardiest Emacs user to drink in short order.

Proportional fonts in editors are a good idea whose time probably just hasn't yet come. We'd need (a) to have editors that support "elastic" or variable tabs to keep things aligned in a truly sane fashion, (b) to re-teach a generation or two of programmers that indenting with the tab character is good, actually, and (c) to develop a few new conventions for what makes code look neat and pretty.




I do find it hilarious that using tabs with non static tab stops basically solved this problem. Anyone that ever typed, on a typewriter, almost certainly used controlled tabs to line up data. I recall tables were easily done by just seeing the tabs correctly then proceeding in standard way.

That said, I don't see my lisp coffee caring that much. Let expressions benefit from lining up. Most other code, though? Not sure it matters that much.


FWIW, Verdana aligns those asterisks just fine. I do think deleting those asterisks makes documentation better and I personally write documentation without asterisks. Why they are there at all? It's just noise.


It's a documentation standard that is used by various tools, if you're utilizing those tools you don't really have an option.


https://docs.oracle.com/javase/1.5.0/docs/tooldocs/windows/j... - this standard? It clearly states you have options. Doxygen does the same.


You may be right on the main point, but I have a quarrel with one of your arguments.

> Put that in a non-proportional font, and the asterisks on the first line probably won't line up with the rest.

So lose the redundant asterisks. They serve no purpose. They make the comment both harder to read and harder to write.


That's a "DocBlock", in this case for PHP, although it comes from JavaDoc and I suspect there are some other languages using the same format. It's a standard convention that API documentation can be automatically generated from, and in many editors the comment block itself can be at least partially automatically generated. (e.g., in Visual Code, if I just type "/*" on a line before a function header and hit TAB, the editor's going to fill in a lot of those details.)

At any rate, while you might be technically correct, in practice, "PHP and Java coders should abandon this long-held convention used by hundreds of thousands of programmers and decades' worth of tooling in order to avoid unsightly alignment issues when using proportional fonts in editors" may be a hard sell. :)


Sacrificing legibility of code for a flawed tradition is a wrong tradeoff.


Less a tradition and more of a standard. It's more or less complaining that the way HTML escapes < > is ugly so you're going to substitute your own variant. There's nothing technically stopping you, but if you want your code to be parseable by web browsers you unfortunately need to adhere to standards.


> Put that in a [proportional] font, and the asterisks on the first line probably won't line up with the rest.

You quickly learn not to care about that. So what if the asterisks in the first boilerplate line don't line up with the ones below? And which of those two asterisks should have lined up with the others?

It just doesn't matter. Everything in the meat of the comment still lines up just fine in a proportional font, just as it does in monospace.

> Now think of someone doing visual alignment of assignment operators in a block of code like you often see in Ruby

I gave up that coding style many years ago, even before I switched to proportional fonts. You end up doing stuff like this (making up a contrived example, and not in any particular programming language here):

  name                  = user.name
  age                   = user.age
  driver_license_number = dl_database(user).dl_number
Sure, it looks nice to see the "= user.etc" lined up, but does it actually help the readability and maintainability of the code? I used to think so, but I don't any more.

Maybe it is because I am getting older and all that sideways visual scanning is not as pleasant as it used to be. Maybe it is because of the unnecessary commit diffs that this style produces.

Once I stopped doing this, I realized that the code would look fine in any font, mono or proportional.

> or any code following the indentation standard where you line up parameters in a multi-line function header with the character after the open parenthesis like you often see in Python.

It's worth noting that Black, by far the most popular Python formatter, eschews column alignment in favor of a purely indentation-based format. Python code formatted with Black is just as readable in a proportional font as in monospaced.

Here is a more extreme example from Rust, whose rustfmt tool used to rely heavily on the kind of column alignment you're talking about:

    let mut rewrites = try_opt!(subexpr_list.iter()
                                            .rev()
                                            .map(|e| {
                                                rewrite_chain_expr(e,
                                                                   total_span,
                                                                   context,
                                                                   max_width,
                                                                   indent)
                                            })
                                            .collect::<Option<Vec<_>>>());
The Rust team later saw the disadvantages of this kind of column alignment and switched to an indentation-based format fairly similar to Black:

    let mut rewrites = try_opt!(
        subexpr_list
            .iter()
            .rev()
            .map( |e| {
                rewrite_chain_expr( e, total_span, context, max_width, indent )
            })
            .collect::<Option<Vec<_>>>()
    );
(That may not be the exact rustfmt style, but it's pretty close, and it illustrates the benefit of simple indentation vs. column alignment.)

> re-teach a generation or two of programmers that indenting with the tab character is good, actually

Bless you for that! This is another advantage of indentation-only formatting. It stops mattering whether you use tabs or spaces! The code will be just as readable in any font, monospaced or proportional, and it won't matter at all if one dev prefers to render tabs as two spaces and another likes four.

The key to all of this is to abandon the kind of column alignment that monospaced fonts make so tempting.

I do agree with your point about Lisp. Monospaced fonts are so heavily ingrained in that culture that I couldn't begin to imagine how to change it.


Textmate 2 had some support for proportional width and different heights and styles in its early days. Don’t know how it panned out since I’ve since stopped using it.




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

Search: