Hacker News new | ask | show | jobs
by goddstream 1785 days ago
Interesting, but it made me wonder - are there any programming languages that you can use with a proportional font? Python would not be on the list...
5 comments

I read and write all my Python code (and all my code in every language) in a proportional font.

You may be thinking of Python's "significant whitespace". But all that does is indicate nested blocks.

This works exactly the same in a proportional or monospaced font. The only thing Python cares about is how many spaces or tabs you have at the beginning of a line, and that you don't mix the two.

There are coding styles that don't look as good in a proportional font, such as this kind of "column alignment" or "hanging indent":

  def function_with_a_long_name(first_param_with_a_long_name,
                                second_param_with_a_long_name,
                                third_param_with_a_long_name):
      pass
But you don't have to code like that!

The most popular Python code formatter, Black, only uses indentation and no column alignment. Here is how it formats that code:

  def function_with_a_long_name(
      first_param_with_a_long_name,
      second_param_with_a_long_name,
      third_param_with_a_long_name,
  ):
      pass
This indentation-based coding style is just as easy to read and write in a proportional font as it is in monospaced.

https://black.readthedocs.io/en/stable/

The latter is a better style anyway. It takes more lines, but it doesn't require realignment when renaming. Not to mention that getting the variable indent alignment can require fighting the editor. One common feature is to delete spaces back to the previous tab stop. When not aligning things, that feature is handy and exactly what I want the editor to do. But for realignment, it's a big pain. Removing a single leading space might require hitting delete and then pressing space 3 times. You might even need to do that when adding spaces because it's easy too overshoot by a single character and have to move backwards to correct it.
Smalltalk is traditionally done in a proportional font. Short methods, and an editor that only does one method at a time, help that work out.
Technically, you can use any language, including Python. Python cares about the number of whitespace characters, not the sizing of them. Any other languages will have the same issue of your columns / pretty formatting not lining up exactly, but won't cause any issues.

If I had to pick one to use with a proportional font, I guess it would be Perl. The aesthetics would at least fit it well.

I'd love for all IDEs to support notebook style computing where comment blocks just turn into proportional font prose, perhaps with optional markdown rich text. Tables, lists, etc. look way better as proper HTML instead of ASCII art intermingled with code.
> comment blocks just turn into proportional font

that would be horrific! Don't you ever use comments to pin-point to specific parts of a source line?

I’ve used Input Sans[1] with Python in the past and it works pretty well except if you use white space for formatting or ascii art as opposed to just indenting.

It works because the spaces are nice and wide unlike in a typical proportional font.

I don’t use it anymore mostly because I wanted something with a little more character but it’s worth a try.

[1]: https://djr.com/input/