7 ms·
> Picking a programming font is like picking a religion. No matter what you pick someone will say you're wrong. Most people will agree at least that monospaced
by Stratoscope 9y ago
> Picking a programming font is like picking a religion. No matter what you pick someone will say you're wrong. Most people will agree at least that monospaced fonts are ideal for reading code and that both of you who use proportionally spaces fonts are destined for hell, or at the very least, purgatory.
I guess I'm destined for hell or purgatory then.
Hanselman is not alone. I had the CEO of one company look over my shoulder and ask, "Mike, I don't understand how you can program in a proportional font. How can that possibly work?"
He wasn't interested in the answer, he just wanted to make a point to me and our teammates that what I was doing was weird and wrong.
I would hope for people to have more intellectual curiosity than this. One of the best ways to learn is to let your assumptions be challenged: talk with people who do something differently from you and find out why they do it.
It's been said that a programmer should learn a new programming language every year or so, and especially learn a new kind of language that will teach you different ways to think about code.
Similarly, I think every programmer should try coding in a proportional font, at least for a while. It may show you new ways to think about how you format your code, as it did for me when I got curious many years ago and tried it.
For example, it cured the bad habit I had of lining up too many things in columns, like this:
myFunctionThatDoesStuff(someArgument,
andThisCalculatedOne(anArgumentThatMeansSomething,
anotherWordyName));
Obviously that won't work in a proportional font, so it forced me to try this instead:
myFunctionThatDoesStuff(
someArgument,
andThisCalculatedOne(
anArgumentThatMeansSomething,
anotherWordyName
)
);
This indentation-only style has many advantages, and of course it works just fine in a monospaced font too. In fact the Rust/Servo team recently switched to it from their former column-aligned style.
- Osiris 9y agoI use the proportional font "Input", which is designed for programming. I really enjoy it. The only annoyance is matching indentation in certain scenarios.
- seanmcdirmid 9y agoDitto for me. Going proportional made me consider using saner formatting policies rather than fancy ones. I've also narrowed my code column width by writing more vertically and less horizontally to make scanning easier on my eyes while also allowing for more side by side buffers.
- mathgenius 9y ago> For example, it cured the bad habit I had of lining too many things up in columns I don't like this style either, but it's a style not a "bad habit."
- Stratoscope 9y ago> I don't like this style either, but it's a style not a "bad habit." Point well taken. But this was just a personal observation. If other people use column alignment, it would certainly be presumptuous of me to call it a "bad habit"! For me, though, it was just that. I had no real reason for it other than having always done that way, and it was really starting to get in the way. So I was glad to be done with it.
- marcosdumay 9y agoIt's a decision with a lot of downsides. Each one not very significative, like polluting diffs, that add into a mild nuisance.
- Avshalom 9y agonah, it's a bad habit. It means constant readjustment and unnecessarily bloated diffs every time you change a function or variable name. or the lovely foo := a; bar := b; then a day later foo := a; bar := b; foobar := cd; which also points to the problem that it lends itself to premature constant readjustment because a day later you have to move every thing again because as it turns out you really needed foobarlist as well. and each time you end up with a diff reporting that foo and bar (and then foobar) have changed too. It's making busy work for yourself and ruining the usefulness of code review tools. ALSO alignment vs indentation is the whole reason we have to have the spaces vs tabs argument.
- Stratoscope 9y ago> alignment vs indentation is the whole reason we have to have the spaces vs tabs argument. Indeed, that is one of the things I like about the indentation-only style. Unlike column alignment, you can use either spaces or tabs for indentation and the formatting still comes out fine.
- fiatjaf 9y agoWhy did you format the code snippets in your comment in a monospace font? Also, I'm curious. I want to see how the code looks like. I want to know what are the downsides of monospace and the benefits of proportional. The one you cited isn't too much of a deal, since it is just a habit you can create using monospace still.
- Stratoscope 9y ago> Why did you format the code snippets in your comment in a monospace font? Because I don't know of a way to get HN to format text in a proportional font without losing the line breaks. Believe me, I've tried. :-) > Also, I'm curious. I want to see how the code looks like. I am glad you are curious about it! > I want to know what are the downsides of monospace and the benefits of proportional. The one you cited isn't too much of a deal, since it is just a habit you can create using monospace still. Indeed, and now that you mention it, I'm not entirely sure which happened first. I may have switched to the second style with indentation instead of column alignment before I started using a proportional font, just because I was tired of the excessive line lengths and always having to fiddle with the spaces. Regarding the downsides and benefits, will it sound like a cop-out if I say it's just something you have to try for yourself? Part of my preference for proportional fonts isn't even tied to any rational reasons. I spend much of my day looking at code, and I just find proportional fonts easier to read, more beautiful and pleasant to look at. But beauty, of course, is in the eye of the beholder.
- 9y ago
- scottLobster 9y agoTo each their own. Personally I dislike nested function calls in general and would use intermediate variables with descriptive names. var calculatedOne = andthisCalculatedOne(anArgumentThatMeansSomething, anotherWordyName); myFunctionThatDoesStuff(someArgument, calculatedOne); Edit: That "anotherWordyName" is supposed to be column justified, HN really needs <code> tags instead of this indentation nonsense. The extra vertical space is easily worth the increase in readability IMO. I've never touched proportional formatted code beyond a day or two when I was forced to by my environment, and all I encountered was more annoyances in getting my code to align properly. I'm glad you found some benefit, but I'd argue those benefits could be achieved any number of other ways.
- Stratoscope 9y ago> Personally I dislike nested function calls in general and would use intermediate variables with descriptive names. Oh, I agree completely that step-by-step is often more readable than deep nesting. OTOH, your example is a good illustration of the problems with column indentation. If it hadn't been HN's goofy code formatting that messed you up, it would have been some code refactoring that changed the length of one of those variable or function names.
- deleted 9y ago[deleted]
- shanselman 9y agoGreat answer, thanks for that insight! (I was just joshing!)
- Stratoscope 9y ago> I was just joshing! I know, and I apologize for hinting that you of all people may have lacked intellectual curiosity! That comment was really directed toward the former CEO of mine... :-) Actually I'm glad you put in that little joshing swipe against us proportionalites, as it gave me an excuse to have some fun exploring the topic.
- sixothree 9y agoI would probably want to hit you with a baseball bat if I had to spend any time reading your code with my monospaced font. At least for the type of code that I work in that lends itself to code alignment.
- Stratoscope 9y ago> I would probably want to hit you with a baseball bat if I had to spend any time reading your code with my monospaced font. Well, that's a good way to get a head start on the "hell or purgatory" thing, isn't it! :-) I'm not saying every kind of code is suited for a proportional font. If you use ASCII art, or if you are writing out two-dimensional matrices or the like, a monospaced font will serve you better. The kind of casual and unnecessary column alignment in my first example is what I was talking about. The second (indented) example is perfectly readable in either a monospaced or proportional font. So if you run across it you hopefully won't need your baseball bat.
- sixothree 9y agoOk. So do you use tabs or spaces? Do any reasonable editors support tabs of this sort?
- Pxtl 9y agoAgree on indentation-only-style. Alignment is just a painful mess to maintain every time I encounter it.
- ctrl-j 9y agoUse a decent code editor? Jetbrains editors have it built in (change some settings and then ctrl+alt+l does it for you.) Sublime, VSCode, Atom, etc.. all have prettify plugins. Aligned code is easy to read code. Aligning code is a pain in the ass. A good code editor once again saves the day (and man hours!)
- ghusbands 9y agoIt's odd to claim that editors that don't support this aren't decent.
- geon 9y agoThere is another example of when mono spacing is useful; multiple calls to the same function with diffrent arguments. But that's basically hardcoded tabular data, and should really be solved by an editor with proper tab-stops. Not by abusing the monospaceivity and spaces for alignment.
- Chris_Newton 9y agoBut that's basically hardcoded tabular data, and should really be solved by an editor with proper tab-stops. Not by abusing the monospaceivity and spaces for alignment. That’s the crux of the issue for me. I can think of many ways I’d like to present code in my idealised programming language(s) that would use significantly more advanced layout and typography than today’s typical environments. However, I wouldn’t actually want to use any of them unless my programming tools all supported them properly. That means the editor, but also the source control and diff tools, the code review and bug tracking systems, and so on. In the absence of any standard conventions for how to represent that extra metadata in an underlying format as robust and flexible as plain text, it’s hard to see this ever happening, though I imagine it would be fun to try.
- deleted 9y ago[deleted]
- mattnewton 9y agoSublime-text-style multiple cursor text manipulation would break here. And your code would look different than everyone else's machine. How would you display a guideline to make sure you were under a characters-per-line style? What advantages are there? I could never see it working for me. I want a program to format my code with resonable defaults and be done with it.
- tobr 9y agoHow would multiple cursors be affected by this? I use a proportional typeface and multiple cursors for all sorts of things, I can't really see how these concepts are even related. As you say, use automatic formatting and you don't need to worry about line-length. (Otoh, having a mandatory max line length makes about as much sense as having a max identifier length or a max lines per file.)
- bastijn 9y agoMax column length (line length) does make sense in one case. It simplifies side-by-side comparison. We have a max 100 column rule which is perfect for our merge and review tooling :). It was raised from 80 few years back and probably raises again to 120 as everybody has all their monitors 1920x1080 now. The idea is everybody should see the entire line in one go without wrapping enabled. A second reason is that it prevents nesting as a side effect. You are forced to make methods and don't go into nested if/for. Much easier to check for our (custom) linter than verifying for/if nested loop depth. Oh, Turning on word wrap is evil...
- mattnewton 9y agoYou can't drag a cursor down vertically and know what will happen, something I do surprisingly often because it is very powerful. Line length guide lines makes sense for me as a visual indicator of what will wrap when I hit the max lines per file. They are also nice ways to gauge when you are nesting too deep or making overly complicated expressions. Max line length allows you to do nice things with window management and diff tool layout and not spend forever moving around to see the text. I am a convert after thinking it didn't matter. Now it being 80 characters is arbitrary but so would almost any other number be.
- dri_ft 9y agoI feel like proportional fonts make sense for me when coding in lisps. Not sure why.
- jorams 9y agoI really wonder why, because alignment is one of the core things in lisp code style. Take this trivial snippet: (let ((foo 1) (bar 2)) (print foo) (print bar)) The (print ...) statements should just be indented two spaces, so you don't need a monospaced font for that, but the bindings should be aligned... "(let (" in a proportional font generally won't have the same width as 6 spaces. How do you deal with this?
- Koshkin 9y agoOn the one hand, I agree that the time of typewriters and their fonts is (or should be) long gone. On the other hand, something keeps telling me that program code is not (and should not be) exactly a piece of literature, and there may be some advantages to being able to see code as a two-dimensional object rather than linear text.
- jcranberry 9y agoBlock selection and anything having to do with IO formatting are very good reasons why monospaced fonts are still useful. That being said the idea that a programmer being resistant to changing their font style is indicative of general intellectual laziness is one of the most laughable things I've ever heard. I'd be more convinced if someone told me that refusing to change syntax highlighting themes implied you're a bad programmer.
- Stratoscope 9y ago> ...the idea that a programmer being resistant to changing their font style is indicative of general intellectual laziness is one of the most laughable things I've ever heard. Let me just mention that this isn't what I said at all. I don't blame you for misunderstanding, I must not have explained my thoughts clearly. I didn't say anything about intellectual "laziness", and I certainly didn't mean that someone who didn't want to change their coding font was intellectually lazy. I was talking about intellectual curiosity, specifically with reference to my former CEO who questioned the sanity of anyone who would code in a proportional font. Instead of wondering why someone would make such a non-mainstream decision and being even slightly interested in their reasons for it, he simply dismissed it out of hand as the bad habit of a weirdo. That's the lack of intellectual curiosity I was talking about.
- deleted 9y ago[deleted]
- jcranberry 9y agoIronically, I'd disagree and say that your CEO was being intellectually lazy by explaining your preference for proportional font by the absurd declaration that anyone who does it is simply sophomoric or inexplicable. However, I would not take this kind of instance of intellectual laziness to be indicative of a more general complacency when it comes to ideas, tools, or self-development more generally. By contrast I think intellectual curiosity is a great thing when present and lamentable when not, but I don't think it's a prerequisite to be a good professional in almost any field, including programming related ones.
- matt4077 9y agoAt least you still get people complaining about you. It means they care for your soul. Try using a tab-size of 3 spaces.
- deleted 9y ago[deleted]
- beefsack 9y agoI've been interested to try programming using proportional fonts for a while, but really like ligatures and don't want to do away with them (I'm using Hasklig at the moment.) Does anyone have a recommendation? I'm having trouble finding anything at the moment.
- TranquilMarmot 9y agoI used to have a coworker who was REALLY slow at reading code. For the longest time, I couldn't figure out why, but eventually he told me he was dyslexic. I mentioned that I had hear of some fonts that were specifically made for people with dyslexia, so he downloaded one and tried it out. There was an almost immediate improvement in his output of code, and it was always interesting to go read over his shoulder and see things not-monospaced. Personally, I only stick to monospaced fonts, but I wouldn't be totally opposed to trying something else. I even tried dotsies for a while (http://dotsies.org/ http://dotsies.org/) but could never get used to it and it slowed me down too much.
- Too 9y agoWhat about code that naturally represents tables, like this? rotationMatrix = [[ cos(x), -sin(x), 0], [ sin(x), cos(x), 0], [ 0, 0, 1]]
- Stratoscope 9y agoYup, that's a great example of where a monospaced font helps. I don't claim that proportional fonts are ideal for every kind of code, only that it's an educational experience to try them out, even if just for a while. Your example is interesting because it combines two different kinds of alignment. One of them I find unhelpful - pushing everything to the right to match the length of the variable name. The other is the useful alignment within the matrix. So personally I would make this minor change: rotationMatrix = [ [ cos(x), -sin(x), 0 ], [ sin(x), cos(x), 0 ], [ 0, 0, 1 ] ] Now you have the nice matrix layout without having to realign the code if you ever rename rotationMatrix.
- qrbLPHiKpiux 9y agoThis is such a nice display of art and it is what I mostly judge a coders ability by.
- tigershark 9y agoI never used a proportional font while coding in my life and I always used the second way of indenting. If this is the only advantage of the proportional fonts I guess that the mis-alignment disadvantage far, far outweighs it.