3 ms·
But nobody defends using tabs for aligning code. The debate is about indentation only. Tabs are not suited to aligning code, but ideal for indentation.
by Seb-C 5y ago
But nobody defends using tabs for aligning code. The debate is about indentation only.
Tabs are not suited to aligning code, but ideal for indentation.
- greggman3 5y agoThey aren't really. You have to give up certain common styles. Example function(arg1, arg2, arg3, arg4, arg5, arg6) { code } The line with arg4 on it can't be indented by tabs alone but it's a common coding standard.
- markrages 5y agoThat's alignment, not indentation. Alignment should always be done by spaces.
- greggman3 5y agoThe people above claimed tabs let you customize. I'm only pointing out as soon as you add alignment that positive goes out the window.
- Dylan16807 5y agoIt doesn't go out the window if you can convince people to do it properly. I think you might be misunderstanding the alignment comment. The idea is that the lines starting with "function" and "arg4" have the same number of tabs, and then the "arg4" line has nine spaces after the tabs.
- Seb-C 5y agoExactly. The right way in this example would be like this (where '>' is a tab and '_' is a space). (For a better readability and ease of edition, I however prefer to actually indent arguments (each on it's line) rather than the suggested alignment, as I show in the second function) class Something { >const obj = { >>somePropName: 1, >>xyz_________: 2, >}; >function foo(arg1, arg2, arg3, >_____________arg4, arg5, arg6) { >>code >} > >function bar( >>arg1, >>arg2, >>arg3, >) { >>code >} }
- greggman3 5y agoGreat, so lots of mixed invisible characters in the same line. Yea, that's never caused any problems, cough makefiles, cough python, ... Fortunately all the projects I work on do the proper thing and use spaces ;) React (FB) says they use spaces: https://github.com/airbnb/javascript#whitespace https://github.com/airbnb/javascript#whitespace (react links to the airbnb style guide) Google: is usually spaces, https://google.github.io/styleguide/jsguide.html#formatting-block-indentation https://google.github.io/styleguide/jsguide.html#formatting-... Apple: https://llvm.org/docs/CodingStandards.html#whitespace https://llvm.org/docs/CodingStandards.html#whitespace, https://webkit.org/code-style-guidelines/#indentation-4-spaces https://webkit.org/code-style-guidelines/#indentation-4-spac..., Swift (load xcode, see it inserts spaces in default code projects and with reformatting in xcode, ...) Mozilla: https://firefox-source-docs.mozilla.org/code-quality/coding-style/coding_style_cpp.html#header-files https://firefox-source-docs.mozilla.org/code-quality/coding-..., rustfmt defaults to spaces: https://rust-lang.github.io/rustfmt/?version=v1.4.38&search=#hard_tabs https://rust-lang.github.io/rustfmt/?version=v1.4.38&search=... Python: https://www.python.org/dev/peps/pep-0008/#tabs-or-spaces https://www.python.org/dev/peps/pep-0008/#tabs-or-spaces PS: I know some projects use tabs (go, linux) for example. I don't work on those :P
- Dylan16807 5y ago> Great, so lots of mixed invisible characters in the same line. Yea, that's never caused any problems, cough makefiles, cough python, ... Of all the ways you could object, I feel like listing makefiles and python might make the least sense. Makefiles require tabs and python has zero problems using tabs for indentation and spaces for alignment. In fact, python will make it harder to accidentally indent a line wrong than almost any other language. I'd just say people are more likely to screw up, or something like that. > PS: I know some projects use tabs (go, linux) for example. I don't work on those :P Linux requires 8 space indentations so it's the worst of all worlds.
- Dylan16807 5y agoHonestly I don't care much if that particular kind of alignment works or not. As long as you never use tabs after other characters, things will work well enough.