5 ms·
If you want more syntax weirdness: tab characters are illegal.
by swiley 7y ago
If you want more syntax weirdness: tab characters are illegal.
- dnautics 7y agoIt's linted out iirc. Is it really strange to mandate that code look explicit and have no ambiguous whitespace?
- simias 7y agoI don't mind opinionated coding style (my Rust integration scripts all enforce that stock "rust clippy" doesn't return any error) and I do think that using tabs for indentation simply doesn't work in practice regardless of how great they are in theory because hardly anybody uses them correctly (including the vast majority of code editors by default). It might be strange to back it straight into the compiler but I don't mind it. That being said it does make it even weirder to allow braceless ifs IMO, but that's bikeshedding.
- clarry 7y ago> I do think that using tabs for indentation simply doesn't work in practice It has worked just fine for decades for projects with millions of lines of code. It might not work for babby's first patch and how do I configure an IDE??
- simias 7y agoDepends of your definition of "fine". The linux kernel works fine indenting with tabs but it mandates 8-space tabs and a lot of code ends up looking borderline unreadable if you use anything else, meaning that the only thing they get by using tabs is slightly smaller file sizes. Besides if you want to enforce the 80column limit you have to standardize a tab width anyway. It's simply not worth it IMO. The pros are simply too small and inconsequential to justify not using spaces on new projects. Although now that automatic code formaters are becoming ubiquitous it really doesn't matter what you use in your editor I suppose.
- chungus_khan 7y ago> including the vast majority of code editors by default Which ones exactly? Not really a problem I've encountered often except when someone tries to mix both spaces and tabs, and in general editors are built with the existence of this very common character in mind. People tend to hit the tab key to indent anyway, and one tab char meaning one level of indent is perfectly intuitive and allows users to individually configure how large they want their indents to be.
- woodrowbarlow 7y agothe problem i encounter is when you try to break a long line into multiple lines. if you want to use tabs and align the continuation, you should be mixing spaces and tabs. for example ('-' is tab, '.' is space): --function_with_lots_of_arguments(arg1, arg2, arg3, --................................arg4, arg5, arg6); it can be done, but a lot of editors get it wrong and it requires paying attention to the whitespace. of course, another style would be to just indent the continuation twice, without aligning it. (i personally prefer to align continuations.)
- Mawr 7y agoSome food for thought: https://youtu.be/ZsHMHukIlJY?t=633 https://youtu.be/ZsHMHukIlJY?t=633 For example, this is the best way to define functions with argument lists long enough not to fit on a single line: fn doThing( argument1, argument2, argument3, ) { <code> } Visually clear, doesn't have any spaces/tabs issues, produces minimal diffs when adding/removing/renaming arguments.
- Stratoscope 7y agoVery interesting talk! Thanks for the reference. More food for thought: The style in your example is more consistent with the way nearly every programmer formats code that has more than one statement. For example: if( shouldDoThings ) { doOneThing(); doAnotherThing(); doLastThing(); } Why do we want to format statements that way, but function calls and expressions a different way? No one would write this: if (shouldDoThings) {doOneThing(); doAnotherThing(); doLastThing();} I have a theory about that but will have to save it for another day. Somewhat related, the Rust coding style guidelines used to follow a heavily column-aligned style, but changed to indentation-only a year or two ago. I posted an example from the Servo source code with the old and new formats here: https://news.ycombinator.com/item?id=18962177 https://news.ycombinator.com/item?id=18962177
- deleted 7y ago[deleted]
- BubRoss 7y agoEven weirder than that, it intentionally fails on \r\n newline, so windows text files straight up don't work by default.
- loeg 7y agoGood! Even Windows Notepad, the extreme example of "not a code editor editor," supports \n newlines now: https://devblogs.microsoft.com/commandline/extended-eol-in-notepad/ https://devblogs.microsoft.com/commandline/extended-eol-in-n...
- BubRoss 7y agoWhy is it good to force all your users to figure out how to set their text editors to do something different and unnecessary just because you refuse to do what essentially every other non toy language has always been able to do? How is a decision like that not a giant red flag of user hostility and bad judgement?
- loeg 7y agoIs your metaphor about Windows since XP or about Zig?
- BubRoss 7y agoThis isn't a metaphor. Zig has gone to more effort to make itself break for windows users than it would have taken to make it work and not cause problems. Zig says it wants to replace C and it puts out builds that purposely break by default.
- wtetzner 7y agoI'm assuming it's only illegal as whitespace? In other words, they're allowed in string literals, right?
- rhodysurf 7y agoCorrect
- cgh 7y agoReally? I might have to take a look at this language then. Making tabs illegal whitespace might very well be a proxy for other good design decisions.
- Bekwnn 7y agoBecause the language is attempting to have a standardized formatter. I'm all for it, personally.
- loeg 7y agoHonestly, I like tabs for indent in C, but still support this language choice by Zig. It's hard to do tabs wrong if you don't allow tabs at all. Python3 went part of the way to disallowing tabs completely, but instead only disallowed mixed tabs and spaces. (And in Python, it's a bigger problem as the indentation level is significant to the syntax.)
- flukus 7y agoUgh, I was planning to learn zig at one point but things like this mean I'm going to pass. This doesn't even seem to be in the documentation that I could find. Throw in their plans to add a package manager and it's own make system and it seems to be getting further and further from the C replacement I was interested in.