News for hackers. Stuff that matters.
Re:When monospace fonts aren't: The Unicode character width ... by mzs on Saturday September 12, 2015 @03:05AM (#10207510)
I always put whitespace after a keyword (like while) so that I can use regexps to find only function calls.

What about this?

  int c[] = {
       3,   6,   9,
      12,  15,  18,
  ...
     300, 303, 306
  };
or

  int v =
    ((r << 24) & 0xff000000) |
    ((g << 16) &   0xff0000) |
    ((b <<  8) &     0xff00) |
    ( a        &       0xff) ;
Re:When monospace fonts aren't: The Unicode character width ... by Stratoscope on Saturday September 12, 2015 @03:46AM (#10207563)
Those are nice - especially the second one, which is a great illustration of how you can use thoughtful alignment in a monospaced font to make the logic in a piece of code really stand out.

It's very different from the examples of column alignment I was critiquing in my earlier message, where there's an equally good or better way to format the code using indentation only.

All in all, I still prefer the visual appearance and compact nature of proportional fonts, especially my current favorite, Trebuchet MS - and they do just fine for almost all the code I write. But for all my criticism of column alignment, I have to admit I do miss it in cases like your second example where it brings clarity.

My dream editor would have a way to allow the use of both proportional fonts where they work well and monospaced fonts where they are better, all within the same file. Perhaps a special commenting convention that would let you switch back and forth.

One of the editors I use, Komodo, has a bit of this. When you create a custom visual theme, you can specify both a proportional font and a monospaced font, and either toggle the entire file back and forth with a hotkey or select one font or the other as part of syntax highlighting - similar to the way many editors let you select bold or italic for particular syntax elements. For example you can select a monospaced font for comments so you can do ASCII art there, while using a proportional font for other code.

Thanks for sharing those examples!

Re:When monospace fonts aren't: The Unicode character width ... by mzs on Saturday September 12, 2015 @11:32AM (#10208343)
First I just want to thank you for the very pleasant reply. More often than not people online tend to get very religious and downright mean about things like convention like this, so thank you the dialog here has been refreshing.

You might be interested in literate programming:

https://en.wikipedia.org/wiki/Literate_programming#Tools

It's not exactly what you are after, but I think is more fundamentally what you are after - ways to make it easier to understand what code is doing. You can have the best of both worlds too here with something like noweb and two windows.

One other thing I ran into is a code base that had incredibly long lines (more than 132 often). So I started using ndiff to help me there. It's a python script that puts + and - under the lines where the differences are as well. I also wrote a little script to html it with different colors. It was pretty awful until I made it monospace too sadly.

Cheers!

Re:When monospace fonts aren't: The Unicode character width ... by thaumasiotes on Sunday September 13, 2015 @03:19AM (#10210614)

    int v =
      ((r << 24) & 0xff000000) |
      ((g << 16) &   0xff0000) |
      ((b <<  8) &     0xff00) |
      ( a        &       0xff) ;
Is there a reason you're doing the shift before the mask? I find this much less intuitive than the equivalent

    int v =
      ((r & 0xff) << 24) |
      ((g & 0xff) << 16) |
      ((b & 0xff) <<  8) |
      ( a & 0xff) ;
Re:When monospace fonts aren't: The Unicode character width ... by mzs on Sunday September 13, 2015 @11:47PM (#10213566)
Cause I was trying to exaggerate the effect of space to within reason somewhat?

Cause it was like 1AM here when I wrote it?

Take your pick ;)

Yeah I'd totally write the bottom way I think, or I hope, cheers.