9 ms·
> even in languages where a [...] } was needed, the indentation always predicted where it would have gone anyway. > if I were to design a [...] language, it wo
by conaclos 4y ago
> even in languages where a [...] } was needed, the indentation always predicted where it would have gone anyway.
> if I were to design a [...] language, it would push me toward indentation-sensitivity.
> That’s a notable shift from my prior perspective, where
> I felt that whitespace-insensitivity was preferrable to indentation-sensitivity.
I'm starting to have the same change of perspective for a different reason: widespread use of formatters.
One of the drawbacks of white-space sensitivity is the accidental mixing of distinct white-spaces (e.g., tabs and spaces). Using a formatter eliminates this problem because all white-spaces are normalized.
- quickthrower2 4y agoAbsolutely. After all in language whitespace doesn’t matter so much!
- pharmakom 4y agoSimple solution is to ban tabs from source-code using the compiler
- vitro 4y agoYou can set tab display width for whatever width you prefer, you cannot do the same for space. From accessibility point of view, tabs are more usable for people with sight problems.
- zokier 4y agoIf you have standardized indentation width, then the only difference is how the indentation is stored in the file. You can present either option in arbitrary way to the user. Doing n spaces to m character cells is as simple transformation as 1 tab to m character cells.
- mananaysiempre 4y agoNo, it isn’t[1], not in most formatting styles, if we’re speaking about the usage where the user can adjust the tab width and have the formatting not fall apart. (Note this excludes e.g. Vim or Visual Studioconfigured to use tabs, so that may be a part of the confusion.) The reason is that alignment still needs to be done with spaces: TAB if (foo) { TAB TAB bar(spam, TAB TAB ....eggs); TAB } [1] https://www.emacswiki.org/emacs/SmartTabs https://www.emacswiki.org/emacs/SmartTabs
- jeltz 4y agoNone of what you wrote contradicts the comment you replied to.
- mananaysiempre 4y agoAh whoops, now I’m not sure. Either that comment was saying that with a standardized indentation width, having an option to adjust the indentation width does not matter, which is trivially true and not contradicted by mine but strange to say as a reply to a comment pointing out that option; or it was (implicitly?) saying that with a standardized indentation width in the storage format, you could recover the tabs from the spaces and adjust the result, which is contradicted by my comment: you can’t automatically distinguish indentation spaces and alignment spaces without at least language-syntax smarts, and while the former should be adjusted the latter mustn’t be.
- still_grokking 4y agoNever heard of such feature. Could you tell how to set this up in say VSCode or IntelliJ? AFAIK it works only one way: You can format tabs with an arbitrary number of spaces. But you can't render spaces with anything else than spaces. How should this even work? You would need semantic code analysis to make it happen…
- pharmakom 4y agoThis is an important concern. However, an IDE that understands the source code will be able to render the indentations in a customizable way.
- bb88 4y agoI feel like we're reliving the episode from Silicon Valley where Richard Hendricks broke up with his GF over tabs vs. spaces. In 2023, it is technologically possible for the IDE repo to use tab characters and the git repo to use spaces, or vice versa. Also, in 2023, I don't care anymore.
- pharmakom 4y agoIndeed. Source code is just a human readable storage format. The editor can render whatever is best for readability.
- Octoth0rpe 4y agoI'm not sure I'd be comfortable with an IDE that chooses to render 4 spaces as 2 spaces, etc.
- pharmakom 4y agoSo dont configure it that way? Invisible character display also helps
- still_grokking 4y agoAnyway, until someone links some definitive source that this is indeed implemented I assume that the claim is made up. You would need semantic code analysis just to render whitespace. That's nuts.
- dropofwill 4y agoI've used vim's conceal feature to do something like this before to read some ridiculous code that had 16 space indentations. You can use this for all sorts of fun things like making lambda: render as λ. That doesn't use any code analysis, it's just dumb rendering, not sure why you would need anything else?
- peoplefromibiza 4y agos/^spaces|^tabs/whatever_width_you_want/g that's what every editor does when you set indentation width to N spaces or TAB width to X
- conaclos 4y agoTabs vs Spaces is an endless debate. A compiler should accept any of them. For consistency, it could reject code that mix tabs and white-sapces.
- tomxor 4y ago> One of the drawbacks of white-space sensitivity is the accidental mixing of distinct white-spaces (e.g., tabs and spaces) I discovered something really surprising regarding whitespace awareness of others, TL;DR that many juniors fundamentally misunderstand "tabs vs spaces", thinking that "tab" means the tab key rather than the tab character. As a follow up to migrating a bunch of repos and discovering every possible combination of "wrong" indentation... I asked what people's preferences were, my assumption that the cause of this mess was different people working on the same repo with differing preferences. Only to find that this was not the case at all, they were mostly from the same individual. And those individuals had a severe misunderstanding of what "tab" vs "spaces" meant. Essentially many people are either not aware of the tab character or not aware that the tab key does not necessarily insert a tab character due to auto indent features. So those people interpret "using tabs" as "using the tab keyboard key", getting confused at why anyone would be using the space bar. I then realised that the source of this misunderstanding comes from auto-indent defaults in modern text editors. The automatic, per-line indentation type detection, combined with automatic space insertion and automatic navigation over spaces when using cursor keys makes tabs and spaces indistinguishable unless you either turn these features off or render invisibles. This becomes a problem when chunks of code are pasted from somewhere else with different indentation styles, since they act as seeds of an indentation type that start to propagate and compete with adjacent line indentations. The worst combinations are competing space-based indentation levels, e.g 2 vs 4 spaces, when these are adjacent the automatic indentation behaviour cannot figure out which is correct since 2*2 = 1*4, 4*4 = 2*8 etc etc. This can make it impossible to set e.g a closing bracket onto the correct indent level. Rather than realise the auto indent is insufficient, It seems that novices will just submit to the editor - thinking it is somehow broken. So rather than enforce a tab/space/indentation level style guide: I said I didn't care what they preferred, so long as they turned on invisibles and made sure their code is self-consistent by manually selecting an indentation style/level. i.e I've ended up mandating specific text editor settings rather than a style guide.
- wodenokoto 4y agoDouble space, quadruple space and tabs all being legal choices was a bigger mistake in Python than the concept of indentations itself.
- dmitriid 4y ago> I'm starting to have the same change of perspective for a different reason: widespread use of formatters. Formatters will no save you from the many, many, many cases where indentation is simply ambiguous. Edit: that is, if you go towards only indentation like Python and YAML
- still_grokking 4y agoAnd because the syntax is ambiguous things like Python or YAML can't be parsed, right?
- dmitriid 4y agoIt can be parsed but you cannot reliably format it. IDEA with its powerful formatters frequently struggles to properly format either of them, resulting in invalid code.
- still_grokking 4y ago> It can be parsed […] So it's not ambiguous. > IDEA with its powerful formatters frequently struggles to properly format either of them, resulting in invalid code. IDEA (by now) does very stupid things while trying hard to be smart. Also it's full of bugs. I stopped to use it because of all those annoyances.
- dmitriid 4y ago> So it's not ambiguous. It is. you can parse something given how it's indented. Doesn't mean that the resulting code is actually correct (from the logic point of view). And you cannot properly format it because the logic is ambiguous. Both of these are valid code. One (or both of them) are incorrect if x > 0: function1() function2() function3() if x > 0: function1() function2() function3() No formatter will be able to guess which one is correct. It will do a best effort approximation. But good luck figuring out how to format a YAML file: db: mysqldatabase: hostname: localhost port: 3012 username: root password: root Oh oops. Valid file. Can be parsed. Invalid indentation > IDEA (by now) does very stupid things while trying hard to be smart. This is beside the point.
- nordsieck 4y ago> Using a formatter eliminates this problem because all white-spaces are normalized. That's only true most of the time, not all of the time. If you ever want to output source code programmatically, then indentation becomes a big pain all over again.
- WJW 4y agoCan you expand on this? Prepending spaces (or tabs) to strings is one of the most basic operations there is, so that can't be where the difficulty is. Keeping track of what the current indentation level should be also seems like something that any tool which outputs source code already does.
- nordsieck 4y agoThere is a whole range of programs that fit in between "output a single block string of text" and "yer a compiler, Harry!". And maybe the right answer is to import a compiler's worth of tooling to output a bit of code. But to me that seems like needless overhead, since meaningful whitespace isn't really a positive to begin with.
- MadcapJake 4y ago> Keeping track of what the current indentation level should be also seems like something that any tool which outputs source code already does. The challenge you are refuting is about building said tools. Just because existing tools have pushed through this challenge doesn't mean it's not both tech debt for those existing tools and a challenge for any new tool in the space. I think the best argument imo is that whitespace has to be properly maintained per line which adds computational cost and statefulness.
- TylerE 4y agoHow hard is it really? Instead of write(“{“) it’s indent += 1 and write(“ “*indent) and the start of each line. Decrement where you’d have a }
- still_grokking 4y ago
- schneems 4y agoI’m the creator of syntax suggest, the syntax error detection library that ships with Ruby 3.2 I’ve switched my perspectives on whitespace significance. It makes for shorter source code but comes with a signal to noise problem. If there’s a mistake in the indentation it’s harder to determine intent. Versus if you expect well formatted and indented code (I love auto formatters like cargo fmt), and syntax to declare intent, then your tools can make better guesses and suggestions than if you only have one signal. The other problem I’ve found working with Python is I often want to copy code and paste into my REPL but it’s usually inside of another context so I get an indentation error. While I like significant whitespace, I LOVE tooling that understands my intent and helps me fix it. I’ll trade slightly more verbosity if it means better tooling. Though obviously I’m quite biased.
- pilaf 4y agoThank you for your hard work making my favorite programming language even better. I completely agree with all your points on significant whitespace for programming languages. Where I think it makes a lot more sense though is for structured static data. My quality of live would be worsened without the likes of Haml, Sass and YAML.
- schneems 4y agoThanks for the note! I enjoy using slim in my views though prefer scss to sass. I think for many of those tools either misindentations raise an error (like failing a yaml schema validation) or result in incorrect but observable behavior (content isn’t in a div as expected). It really comes down to how the tool is supposed to be used and how failures are handled. In general I think that’s the difference between a good experience and a great one: when we can have beautiful failures that help us learn.
- still_grokking 4y ago> I completely agree with all your points on significant whitespace for programming languages. Where I think it makes a lot more sense though is for structured static data. This makes no sense. If the arguments against significant whitespace are valid for executable code they're also valid for markup. If it's fine to use significant whitespace for markup / data literals even the perceived drawbacks apply than it would be equally fine for executable code.
- dszoboszlay 4y agoBased on my quite limited experience with Python the big drawback of indentation sensitivity is copy pasting will only work when your editor has great language support. If I copy a block of code from indentation level X and paste it to indentation level Y when I have explicit end-of-block tokens the worst thing that could happen is that I end up with badly indented code that I have to clean up manually. On the other hand, if indentation matters, and my editor messes up things, I am very likely to get code that looks good, probably compiles too, but does nothing like the original. I have to read through every line carefully and think about where the blocks were meant to end. In the end I'm still not convinced that significant indentation would worth the trouble.
- llimllib 4y agoI've been writing python for 20 years, and I truly cannot think of an instance where pasting code was an issue. I use vim mostly without any plugins, not any fancy editor.
- wink 4y agoI've written a lot of python in my life (but most of the time not as my main day-to-day language) so whenever I had to try something small in a REPL I do paste. I guess it would work to highlight a piece of code and run it externally with a shortcut, but I've never set that up, so I did indeed run into this problem more often whenever I was just taking up Python again (for example I find [x for x in ....] kinda horrible and have at times fat-fingered if it's twice nested)
- tomrod 4y agoUse ipython's magic function, %paste. If you need to make minor edits, %cpaste. If you're exploring, consider using a notebook.
- matsemann 4y agoI've only used python a few years professionally, but seen it multiple times. With other languages I paste in code between some brackets, run the autoformatter and it looks as I want. With python I paste in some code, run the autoformatter, only to see because of spacing issues half the lines I pasted didn't get properly parsed to be inside the for loop or whatever. Also makes it hard to copy a snippet to run inside a REPL or whatever. In general just a huge amount of pain, and the "good thing" about how it forces well formatted code I've never seen as an issue with autoformatters and linters in othet languages.
- duped 4y ago> the accidental mixing of distinct white-spaces (e.g., tabs and spaces). Using a formatter eliminates this problem because all white-spaces are normalized. I've found an easier solution is to forbid tabs outside string literals. You can't do the same with spaces.
- ummonk 4y agoFunny, I have the opposite opinion for the same reason as you - I'd rather just use an auto-formatter in a non-whitespace sensitive language and have the option to mark certain sections as needing custom indentation for readability. E.g. I've had situations where I'm calling into an API to programmatically build a nested GUI in Python, and the inability to indent my API calls to represent the structure of the nested UI was seriously frustrating. Also, trying to copy-paste code in Python while getting the indentation right is an exercise in severe frustration.