17 ms·
Tabs are better for two reasons: - accessibility[0] - customization - not everyone wants the same tab-width [0] https://www.reddit.com/r/javascript/comments/
by FredFS456 5y ago
Tabs are better for two reasons:
- accessibility[0]
- customization - not everyone wants the same tab-width
[0] https://www.reddit.com/r/javascript/comments/c8drjo/nobody_talks_about_the_real_reason_to_use_tabs/ https://www.reddit.com/r/javascript/comments/c8drjo/nobody_t...
- greggman3 5y agomajor tech companies disagree with you tabs don't work for customization code // comment code code // comment If there are tabs between the code and the comments they won't align if you customize their length. If you use spaces there then you're just hypocritical. There are just as many arguments pro tabs as there are con tabs Many could be solved with smart tools. Have your editor reformat the text to your preference. Have it put it back to the project's preference when you check it in.
- Seb-C 5y agoBut 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 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.
- markrages 5y agoA decent editor supports smart tabs