6 ms·
Slight rant about a mistake I see every times this is mentioned: > a user needs to easily differentiate between 1, I, |, and l along with 0 and O. Most of the
by SuchAnonMuchWow 5y ago
Slight rant about a mistake I see every times this is mentioned:
> a user needs to easily differentiate between 1, I, |, and l along with 0 and O.
Most of the times, a font present those characters side by side, to show their differences and to illustrate the fact that they can be easily differentiated.
But what we need is not differentiate between them, but identify precisely every single one of them when presented without the other as a comparison point.
Almost every font presented in the article makes that mistake: for example, 0 is almost always the exact same shape and size compared to O, except for a dot or a slash across the 0. This allows you to recognize a 0 at first glance, but not a O. The same issue is also present in a lot of the presented fonts with l that can be mistaken for a 1.
- Stratoscope 5y agoThis is one of the things I appreciate about using a proportional font for coding. Nothing stops you from having a big fat O and a little skinny 0, just like you see right here in your comment and mine with HN's Verdana font. You don't have to have every character stuffed into the same fixed size box.
- username90 5y agoI can't imagine trying to code without being able to align characters on different rows...
- Stratoscope 5y agoShow me an example where you need to do that, and maybe I can suggest an alternative. Or I will say "yup, you got me there!" ;-)
- ChrisMarshallNY 5y agoAlmost all my code is heavily aligned, and I rely on monospace. I’m pretty anal about that kind of thing. My cloc score is generally about 50% comment-to-code. But I’m an outlier. Most folks have almost no comments at all in their code. I guess I could use tabs, instead of spaces, but I’m not interested in doing that.
- deleted 5y ago[deleted]
- 411111111111111 5y agoI find it interesting how controversial the code comments situation has become. When I started in this industry, comments were extremely rare and people were consistently pushing to add comments everywhere. Some time later, the pushback came and people started saying that code shouldn't need comments, and if you feel the need to add one... You should rewrite it instead so the code is self explanatory. Neither side seems to have stopped repeating their points though and there is always a chance to trigger opinionated people into endless discussions just by mentioning comments
- ChrisMarshallNY 5y agoI don't bother trying to convince people to see things my way. All I can say, is that I almost never get questions about my code. I write about my approach here: https://littlegreenviper.com/miscellany/leaving-a-legacy/ https://littlegreenviper.com/miscellany/leaving-a-legacy/ It's a long screed, so no one reads it.
- RobertKerans 5y agoIt was a good screed, not tedious! It made a lot of sense, thank you.
- dec0dedab0de 5y agoOne big thing that has changed in regard to comments is that variables and functions can have longer names now. In most modern languages it is considered bad practice to have single letter variables, or even abbreviated ones, except in very well known cases. So the rule of thumb for languages like python or ruby is that if you need comments to understand what your code is doing, then you messed up somewhere. Make it easier to read, keep your functions small, and add docstrings. Save your comments for why you're doing something. But if you're using a less readable language like c, then by all means, comment everything along the way. I just read a comment I wrote a few years ago that said "I don't know why I have to do it the long way, but it's the only thing that works consistently" over a bit of seemingly verbose code that I would have tried to simplify if I didn't remind myself of that previous struggle.
- sharikous 5y agoWhen you hardcode a lookup table to be able to align data is very useful (and also esthetically pleasant), at least from my point of view. I would not leave my monospace font
- ziml77 5y agoPrinting a table to the console or log file. A very simple example from just this weekend for me is that I wanted to see how C++ was laying out an object in memory. I assigned the pointers to one and two character variables. When I printed out the variable name followed by the address, I actually had to go back and add an extra space before the single character variable names so the addresses would align. That made it much easier to see the differences between the various pointers into the object.
- Stratoscope 5y agoFunny you mention log files with extra spaces. At my current job, I deal with an API called the RTO, and I wanted to log the requests to that API and the matching responses. Of course the words "request" and "response" are not the same length. But I thought it would look nice to line things up for a request and its matching response, so I just added an extra space after "request:", like this: RTO request: {...} RTO response: {...} When testing locally in a terminal, this looked great. Everything lined up and was pretty. What I didn't realize was that most people view these logs in New Relic, which does use a monospaced font but does not prevent collapsing of adjacent spaces. So the logs look like this: RTO request: {...} RTO response: {...} Obviously not the end of the world! But it did happen that the first part of the {...} stuff should match between the request and the response, so it made it easier to understand (if it worked) to line them up. I am tempted to change the messages to this, which I think will work around this problem: RTO request : {...} RTO response: {...} Sometimes you can't win for losing!
- danuker 5y ago> does use a monospaced font but does not prevent collapsing of adjacent spaces. Whoever implemented this in "New Relic" did not think at all about preserving information, which seems critical in a log file.
- iudqnolq 5y agoIt may be lost at display time. The default behavior of a browser is to collapse adjacent white space so something like <p> Hello <span>World</span> doesn't render with a huge number of spaces.
- branko_d 5y agoSELECT CAST(CASE WHEN DENY_ADMIN_FILTERS > 0 THEN 0 WHEN ALLOW_ADMIN_FILTERS > 0 THEN 1 END AS bit) CAN_ADMIN_FILTERS, CAST(CASE WHEN DENY_ADMIN_ACL > 0 THEN 0 WHEN ALLOW_ADMIN_ACL > 0 THEN 1 END AS bit) CAN_ADMIN_ACL, CAST(CASE WHEN DENY_ADMIN_RML > 0 THEN 0 WHEN ALLOW_ADMIN_RML > 0 THEN 1 END AS bit) CAN_ADMIN_RML, CAST(CASE WHEN DENY_ADMIN_WORKFLOW > 0 THEN 0 WHEN ALLOW_ADMIN_WORKFLOW > 0 THEN 1 END AS bit) CAN_ADMIN_WORKFLOW, CAST(CASE WHEN DENY_SET_STATE > 0 THEN 0 WHEN ALLOW_SET_STATE > 0 THEN 1 END AS bit) CAN_SET_STATE, CAST(CASE WHEN DENY_SHARE > 0 THEN 0 WHEN ALLOW_SHARE > 0 THEN 1 END AS bit) CAN_SHARE, CAST(CASE WHEN DENY_LINK_PARENTS > 0 THEN 0 WHEN ALLOW_LINK_PARENTS > 0 THEN 1 END AS bit) CAN_LINK_PARENTS, CAST(CASE WHEN DENY_UNLINK_PARENTS > 0 THEN 0 WHEN ALLOW_UNLINK_PARENTS > 0 THEN 1 END AS bit) CAN_UNLINK_PARENTS, CAST(CASE WHEN DENY_LINK_CHILDREN > 0 THEN 0 WHEN ALLOW_LINK_CHILDREN > 0 THEN 1 END AS bit) CAN_LINK_CHILDREN, CAST(CASE WHEN DENY_UNLINK_CHILDREN > 0 THEN 0 WHEN ALLOW_UNLINK_CHILDREN > 0 THEN 1 END AS bit) CAN_UNLINK_CHILDREN, CAST(CASE WHEN DENY_WRITE > 0 THEN 0 WHEN ALLOW_WRITE > 0 THEN 1 END AS bit) CAN_WRITE, CAST(CASE WHEN DENY_SEE > 0 THEN 0 WHEN ALLOW_SEE > 0 THEN 1 END AS bit) CAN_SEE, CAST(CASE WHEN DENY_READ > 0 THEN 0 WHEN ALLOW_READ > 0 THEN 1 END AS bit) CAN_READ, CAST(CASE WHEN DENY_READ_END > 0 THEN 0 WHEN ALLOW_READ_END > 0 THEN 1 END AS bit) CAN_READ_END FROM private_data_iviews.SECURITY_PRECACHE_ACL_INCLUSIVE WITH (NOEXPAND) WHERE @acl_id IS NOT NULL AND @acl_id = ACL_ID AND @user_id = USER_ID
- pc86 5y agoThis seems like a good example of when not to arbitrarily align characters. Large horizontal gaps can very easily result in moving up or down a line and not realizing it.
- branko_d 5y agoHow is that? Are you talking about word wrapping? Also, what's the alternative here? Sure, I could indent everything and make it much more vertical, but that would make things even less readable.
- klyrs 5y agoNeed? No. Prefer? Yes. foo(True, True) foo(False, True) foo(False, False) foo(True, False) Add a few more parameters, put some arithmetic in there that isn't clearly an unrolled double for-loop. Maintaining repetitive code of that form is easier when the arguments are well aligned. And if you're using an editor with a block-select feature, then this changes from an aesthetic preference into a game-changer when you, say, add or remove an argument to foo.
- teddyh 5y agoThere is an elegant solution: https://nickgravgaard.com/elastic-tabstops/ https://nickgravgaard.com/elastic-tabstops/
- Groxx 5y agoWhile I do very much like that article, and I think it's a viable contender for The One True Way™... They don't solve it. Those spaces to manually-align things are still potentially skewed because it's not fixed-space.
- kibwen 5y agoI don't have anything against proportional fonts for coding in, but the font has to actually be designed for coding, regardless of if it's proportional or monospace. That doesn't just mean having distinguishable 1/l/| and 0/O etc, it also means that the more obscure symbols/punctuation can't just be an afterthought and should compose nicely with regular characters and with each other: (foo) and [foo] and {foo} and <foo> should all look pleasant, things like += and <= and -> should not be misaligned, etc.
- wodenokoto 5y agoDo you have examples of where that doesn’t happen?
- SuchAnonMuchWow 5y agoI found ubuntu mono to be one of the best in term of identifying those characters, with l and 1 being immediately identifiable, but O is only slightly larger than 0 so it can still be mistaken for a 0 if you are not careful (0 has a dot so it can not be mistaken with O). I don't know of any monospace font where O can easily be identified as such and not mistaken with 0. edit: see a sample here: https://fonts.google.com/specimen/Ubuntu+Mono?category=Monospace&preview.text=i1lI%7C%20oO0&preview.text_type=custom https://fonts.google.com/specimen/Ubuntu+Mono?category=Monos... Every character is easily identifiable by itself, except for O. I'm also curious if anyone has a monospace with better identifiably for O and 0.
- dec0dedab0de 5y agoI use andale mono it has a dot in the middle of zero. There are plenty of others that have dots and slashes. I wouldn't use a font that didn't. https://en.wikipedia.org/wiki/Andalé_Mono https://en.wikipedia.org/wiki/Andalé_Mono edit: I also use monaco which has slashes in zero https://en.wikipedia.org/wiki/Monaco_(typeface) https://en.wikipedia.org/wiki/Monaco_(typeface)
- SuchAnonMuchWow 5y agoThe point is not that 0 must be easily identifiable, but also O: If you see a O without 0 as a comparison, can you identify it as such ? In every monospaced font I know, there is a way to identify 0 (the dot or the slash), but not O which could be easily mistaken for a 0.
- dec0dedab0de 5y agoWouldn't it be the one without the dot or the slash? it's honestly never been a problem for me. What has been a problem is the difference between an oval and a circle when zero is not marked.
- Abishek_Muthian 5y agoIdentifying 0 and O might be trivial for most of us, But it's a major problem for some. One of the first problem posted on my problem validation platform was 'Identifying letter O from 0 and vice versa '[1], within couple of days a browser plugin to address the problem was developed by someone else and posted. It's now my poster for a problem to push down the point that no problem is small. [1] https://needgap.com/problems/12-identifying-letter-o-from-0-and-vice-versa-typography-web https://needgap.com/problems/12-identifying-letter-o-from-0-...