6 ms·
Elastic Tab Stops (2017)
- teo_zero 3y agoNo plugin for Vim?!
- eviks 3y agoAwesome idea, some decades-old MS Word niceties would be a big improvement in formatting, unfortunately no popular editors (even the new modern ones) seem to be properly engineered to allow implementing it
- rusk 3y agoI’d love to have a little blue squiggly intellisense underline every time code lense thinks I should have done it differently.
- TeMPOraL 3y agoHuh, this might actually not be that difficult to make nowadays - modify a copilot plugin to prompt LLM for "grammar check" instead of completions, run it in the background like error checker, and use that output to add the blue squiggly lines to parts of code the LLM has an opinion on.
- kragen 3y agoi keep coming back to gravgaard's idea, though i think the minimum width of a tab should be 0 spaces and not 1; it plausibly permits adding not just proportional fonts (as gravgaard points out) but also multiple font sizes to plain text without losing all ability to do layout i think you should be able to nest multiple lines within such a 'table cell' by enclosing it between form feed and vertical tab, which are both conventionally considered whitespace, and are therefore allowed already in the grammars of conventional free-form languages like c, java, js, and scheme. nesting tables within table cells permits almost infinitely flexible layouts, as we all remember from the days before css; and, although the layout algorithm is not as trivial as emulating a teletype, it's fairly simple, linear time, and very fast (as long as you don't try to add word wrap or something) (you probably also want rowspan and colspan; these should be indicated by putting carriage return and backspace, respectively, in the cells spanned into, like \^ in tbl) a 'terminal emulator' using such a format would probably need an alternative to character-cell cursor addressing; probably the best alternative is to have multiple cursors, with one escape sequence to move cursor X to the active cursor (forgetting its previous position) and another escape sequence to exchange the active cursor with cursor X there's no need for escape sequences to look like line noise either further details are in nestable.md in git clone http://canonical.org/~kragen/sw/pavnotes2.git
- eviks 3y agoWhy do you think it can't shrink below 1? That's exactly what's happening in currently rudimentary implementations like in Sublime Text, where width can be smaller if needed for alignment The "spec" also doesn't seem to mandate a minimum
- kragen 3y agothe illustrations on gravgaard's page show a minimum of one space between columns, even in places where that seriously compromises the desired formatting, such as int someDemoCode( int fred, int wilma) i think it would be better to represent that, where actually desired, by 00000000: 696e 7420 736f 6d65 4465 6d6f 436f 6465 int someDemoCode 00000010: 2820 0969 6e74 2066 7265 642c 0a09 696e ( .int fred,..in 00000020: 7420 7769 6c6d 6129 0a t wilma). . (note the explicit space following the left paren) and render 00000030: 696e 7420 736f 6d65 4465 6d6f 436f 6465 int someDemoCode 00000040: 2809 696e 7420 6672 6564 2c0a 0969 6e74 (.int fred,..int 00000050: 2077 696c 6d61 290a wilma). as the more acceptable int someDemoCode(int fred, int wilma) which i think differs from gravgaard's intended semantics
- eviks 3y agoI see. Yeah, in this case I'd also prefer no space betwen ( and int But then in your design how would you Tab to actually add whitespace, not just vertically align? Would then 2nd tab have a width of 1 space?
- kragen 3y agoyou wouldn't use the tab ('horizontal tabulation') character to add space, but rather to separate table columns; you would use the space character to add space https://en.wikipedia.org/wiki/Tab_key https://en.wikipedia.org/wiki/Tab_key > The word tab derives from the word tabulate, which means "to arrange data in a tabular, or table, form."
- smasher164 3y agoA great idea hindered by the lack of adoption in tools.
- rusk 3y agoAnd everybody throughout the lifecycle of the code using such tools
- corbezzoli 3y agoI don't find this useful. The alternative is simple: - do not indent code that way - do not align comments on the side Before int someDemoCode( int fred, int wilma) ×(); /* comment */ print("hello again!\n"); /* comment */ makeThisFunctionNameShorte(); /* comment */ After int someDemoCode( int fred, int wilma ) ×(); /* nobody */ print("hello again!\n"); /* needs */ makeThisFunctionNameShorte(); /* aligned comments */ This kind of control over indentation and alignment borders on OCD. You should be using a code formatter anyway, so indentation is auto-fixed.
- rerdavies 3y agoOn the other hand int animateIndenting( int startingIndent, /// Starting indent, in spaces int endingIndent, /// Ending indent, in spaces int animationTimeMs /// Animation time in milliseconds ) { ... } is tempting. It's an interesting idea. Whether it's a good idea. It's hard to be completely objective when, for a brief time in the 80s, I spent one third of all my coding time maintaining elaborately baroquely indented Pascal comments. (Not my coding standard. It was fashionable at the time). That the formatter doesn't replace tabs with space... quaintly optimistic. A great shame, since requiring that people use editors with this feature for all eternity, or have ridiculously random indentation of comments is a non-starter.
- rusk 3y agoThe key difference you are outlining here is form vs function. The latter example is perfectly reasonable because you are adding actual “content” and restructuring around that. I don’t think any reasonable person could object to that - coding guidelines bedamned. GP’s example is just finicky window dressing based on indulging a personal aesthetic based on what the author things “looks good” on a particular day, with a particular font on a particular screen. What we should be striving for in code style is the lowest common denominator most bare bones strucure that can be read, understood and modified with the most rudimentary of tools. EDIT > What happened to "code is primarily to be read, occasionally to be executed"? Exactly this. Code should be readable for all. It goes through all sorts of other actors and tooling, not just your painstakingly configured IDE. >> What we should be striving for in code style is the lowest common denominator most bare bones strucure that can be read, understood and modified with the most rudimentary of tools. > as if, when designing a building, everyone involved - architects, plumbers, electricians, HVAC engineers … All the above have to abide by building codes, use standardised parts and tools and most have to conform to certified standards which their work is then also validated against. We have many, many coding standards most of which discourage tabs and fancy formatting but developers get special exemption because “ma creativiteh” > plaintext code directly is an idea that needs to die. Yes let’s throw out some things that work perfectly well to accommodate a few malcontent crybabies. At the end of the day our laws and most of our written communication depends heavily on plaintext and that’s not gona change any time soon just because a few people don’t want to learn how to use it properly.
- sebstefan 3y agoA number of space users simply never learned or cared to use the tab key to indent. Their choice doesn't really come from a value proposition This won't do much to sway these programmers
- rerdavies 3y agoHuh? We space users all use the tab key. We just make sure our editor replaces them with spaces as we type because of decades of bitter experience with how mixed tabs and spaces behave over time. The more interesting question is why tab users haven't noticed that we use mandatory auto-code-formatting these days, to make sure all your tabs are belong to us. ;-P
- sebstefan 3y agoWe live in a diverse world!
- TeMPOraL 3y ago> The more interesting question is why tab users haven't noticed that we use mandatory auto-code-formatting these days, to make sure all your tabs are belong to us. I'm guessing they're using an equivalent of `M-x tabify` running automatically after opening a file. Excerpt from documentation on `tabify` in Emacs: Convert multiple spaces in region to tabs when possible. A group of spaces is partially replaced by tabs when this can be done without changing the column they end at. If called interactively with prefix ARG, convert for the entire buffer. Personally, I'm a "space user", and I only have `delete-trailing-whitespace` run on save (`before-save-hook`); at work, we have a pre-commit hook that untabifies committed changes (and then another to run language-specific autoformatter).
- Etherlord87 3y ago> We space users all use the tab key. Not all. I've seen people hit spaces repeatedly…
- rustybolt 3y agoYeah, great idea, let's adopt it. Then in three years from now juniors can add "tab management" to their "to learn" list and get into flamewars which "tab management" tool or plugin is the best.
- IshKebab 3y agoefgaxchsgfggbcv ,
- sasaf5 3y ago"Use only spaces, and indent 2 spaces at a time. We use spaces for indentation. Do not use tabs in your code. You should set your editor to emit spaces when you hit the tab key." https://google.github.io/styleguide/cppguide.html#Spaces_vs._Tabs https://google.github.io/styleguide/cppguide.html#Spaces_vs....
- gaazoh 3y agoNot everything Google does is gospel, it feels kind of weird that you post these without further context. Although most coding guidelines seem to have converged towards spaces over tabs (see [1], [2],[3], your source, and many more), it also causes accessibility issues, especially for visually impaired people. Some people require larger fonts, making space-indented lines go offscreen quicker. Some people require braille displays, which have a limited line length. A tab takes a single character on these, vs multiple (usually 4) for space-indented code. Some people require bigger indents to be able to process them better. Not even considering disabilities, some people prefer 2 spaces, some 4, and some whatever pleases them. Working with tabs allows everyone to work on the same codebase with their own preference. By definition this is a subjective matter, and trying to enforce a preference across a whole codebase or programming language is needlessly opinionated. Plus, the 2 first example use case in the article can't be solved either with spaces or standard tab stops. --- [1] https://peps.python.org/pep-0008/#tabs-or-spaces https://peps.python.org/pep-0008/#tabs-or-spaces > Spaces are the preferred indentation method [2] https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions#style-guidelines https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals... > Use four spaces for indentation. Don't use tabs [3] https://www.oracle.com/technetwork/java/codeconventions-150003.pdf https://www.oracle.com/technetwork/java/codeconventions-1500... > Four spaces should be used as the unit of indentation. The exact construction of the indentation > (spaces vs. tabs) is unspecified. Tabs must be set exactly every 8 spaces (not 4). While leaving tabs vs. spaces "unspecified", specifying stabstops of 8 spaces actively discourages tabs
- sasaf5 3y agoThanks for all the additional info! I should have added that my preference is for the definition of a unified gospel throughout the codebase/organization, Google's just being the one we ended up picking. >Working with tabs allows everyone to work on the same codebase with their own preference. This is where the problem starts. As someone who has to integrate code from a dozen devs, it seems that everyone has a sligthly different usage of tabs (TFA adding one more). If we can ever set everyone on the same page with tabs, I am fine with it. It's just that in production it always seems to cause problems. Spaces are easier to specify. For the case of disability support, I'd risk to guess that different usages of tabs would end up derailing accessibility software just as much as it derails integration. But I'd prefer deferring this opinion to someone who has experience with it.
- IshKebab 3y agoI always thought this was a great idea, but most developers don't even understand normal tabs so this never really stood a chance.
- pmontra 3y agoI've been using proportional fonts in emacs since many years ago, I can't remember how many. When I find code aligned with spaces to a horizontal position I keep it there. If I have to modify it I realign everything. Example a = 1 ab = 2 abc = 3 becomes a = 1 change = 2 abc = 3 Nobody ever said a word about it. In Elixir projects we've been using the language code formatter for years and it forces a coding style like mine by default.
- rusk 3y agoOne of my pet peeves is when I go to the trouble of lining up my indents, usually for some good reason like improving clarity or readability and some busybody comes along and flattens it all for no good reason other than pandering to their own personal aesthetic.
- gaazoh 3y agoOne of my pet peeves is when I go to the trouble of flattening indents, usually for some good reason like improving clarity or readability and some busybody comes along and indents it all for no good reason other than pandering to their own personal aesthetic. Honestly, I use spaces because virtually all tooling and coding conventions that exist prefer spaces over tabs, but I don't understand how it came that spaces won over tabs in the programming world. So much energy wasted on counting spaces in text documents, it's absurd.
- rusk 3y agoPlease engage with the substance of my comment rather than just further iterating the argument that’s in your head. It is equally frustrating whether tabs or spaces. Who on earth is counting spaces?
- pmontra 3y agoI press tab in emacs and it inserts or removes the right amount of spaces to indent the line. I press newline and it creates a new line with the correct space based indentation. If I'm in Python I can press tab multiple times to cycle through indentation levels or do it manually with space and the deletion keys.
- deleted 3y ago[deleted]
- Xophmeister 3y agoThis is something we've discussed[1] in the development of Topiary, deferring the process to the formatter. It's not a priority issue for us right now, but given the lack of universal editor support for elastic tab stops, having the formatter do this seems like a reasonable solution. [1]: https://github.com/tweag/topiary/issues/170 https://github.com/tweag/topiary/issues/170
- TeMPOraL 3y ago> Rather than saying that a tab character places the text that follows it at the next Nth column, we should say that a tab character is a delimiter between table cells in a manner more reminiscent of how they're used in tab separated value (TSV) files. When used for text or code I call this format "Tab Separated Columns". Seen in this light, we can see that space aligned files are analogous to the old fixed width data files, and we all know the advantages that delimited files have over those. If we're lifting abstraction one level up - from dumb plaintext to delimited records - maybe it's time to revive the ASCII control characters that were specifically meant for this? I'm talking about ASCII 28 to ASCII 31 - file, group, unit and record separators.
- kragen 3y agomy variant proposal in https://news.ycombinator.com/item?id=37938960 https://news.ycombinator.com/item?id=37938960 provides for arbitrarily deeply nested structures instead of a pick-like static four levels, and does so while maintaining compatibility with historical definitions of "whitespace" for the purpose of things like parsing c; i'm curious to hear what you think, though i know you're not such a fan of backwards compatibility
- fanf2 3y agoDunno where the year in the title comes from. I first saw this web page in 2006 https://dotat.at/:/C8PC9.html https://dotat.at/:/C8PC9.html
- snoopen 3y agoMaybe I'm being naive, but doesn't this add unnecessary noise to diffs, making it harder to see subtle changes?
- kragen 3y agoit does not; the idea is not to insert extra space characters into files, but to display tab characters as a quantity of whitespace sufficient to visually align columns vertically
- PlunderBunny 3y agoMy memory might be incorrect, but I recall using a version of MacPascal in the early 90s, that gave you absolutely no control whatsoever over indentation - pressing tab or space outside of a quoted string did nothing at all. The editor indented automatically according to the code you typed and some (presumably) hard coded rules. It was the most liberating thing I had ever encountered in the act of coding, and I still yearn for it.