Neither tabs or spaces are good. The correct way is to leave no whitespace in the code at all. It’s unnecessary and adds to processing time.
Everyone should aim for 1LOC per commit
“Error: syntax error on line 1”
…shit
Great, no scrolling through thousands of lines to find the right one!
Scrolling to a line number seems inefficient.
My program, written in the whitespace language, ruined.
CURSE YOU PERRY THE PLATYPUS!
Now next time I read anything about why any Python libraries are named what they are named, I’m going to hear Dr Doofenschmirtz voice. Thank you for that.
The argument for having tabs adjust depending on your ide sounds better than it is in practice. Someone formatting code to look nice with width 4 will look horrendous for someone who uses width 8.
Spaces makes it uniform and captures the exact style the original dev intended
If you have your tab width set on 8, that is on you. You will also set your IDE to insert 8 spaces when you press TAB and I will cry when I have to give you a code review.
When I indent my code, I am indicating that I am in a nested block. I don’t care if, on your screen, that indent is 2, 3, or 4 characters.
Anarchist: tab with set to 1
That’s fine, when I view it I will get my preferred tab width. This situation is only anarchist with spaces, with tabs they are just a masochist.
If the original dev intended to make their code less accessible and their project less inclusive in favor of eye candy, they should rethink their priorities.
Tabs let you define how big you want each indent to be
…except when they don’t. Many common environments have a hardcoded tab size of 8, which is insanely big for using it for indentation.
Because other people might have restricted environment which might not suit their preference is not a good reason to level it down IMO.
Also, I think 9 is the best size for indent (matter of preference), do you think I should switch to space so everyone can enjoy this wonderful view I have ?
It’s not just “might”. Termux is pretty much the only good choice for programming on Android.
I think 9 is the best size for indent (matter of preference), do you think I should switch to space
I think you should switch to an exorcist.
What’s your point ? You can use vim on termux and set the tabsize to whatever you want for example.
Also
:exorcise
is only a quickpluginstall
away, anyway. /sYes, but if you use something like
cat
,head
,less
, etc. to view code, or the Python REPL, you’re still going to see the default tab size.You can set the tabstop with
less -x*n*
. But ok I see what you mean. I still stand by my point though. If termux doesn’t support setting tabstops and it’s an issue, then it’s a bug in termux, not a reason to level down your formatting standard.
Ah, the best kind of indent. A tab and a space.
Or just set tabsize to 9, that’s the point :)
Where’s the fun in that?
Why would you ever need 9 other than trolling people on the internet?
Straight on point!
This is the biggest problem with tabs. Too many tools don’t let you adjust the size (or make it very difficult). This is the only reason I usually prefer spaces (only very slightly).
My dream solution is elastic tabstops and I’ve posted about it here before a few months ago. The problem with wanting elastic tabstops is that it seriously compounds the issue of “editors don’t properly support it”
As an embedded software developer that does linux kernel drivers I’ve come to love the tab size 8 indentation level.
I’m paraphrasing: “if your indentation level gets too deep, it’s time to rethink/refactor your function.”
And with tab 8 you’ll notice it rather quick if your function does too much/unrelated stuff.
A function should be short and do one thing only, if possible. It also makes unit testing easier if that’s a requirement.
When you’re operating on such a low level of abstraction, it’s no wonder you don’t need deep nesting.
Oh, I’ve done my fair share of C++ and Python as well. But you got to agree with me that when you are on your fourth indented “if case” it’s time to step back and think about what you are trying to achieve. I mean it’s probably going to work, but probably also very hard to maintain that type of code.
How would you implement, for example, Gaussian elimination with at most 3 levels of nesting?
Abstraction.
The solution for all levels of nesting.
Be specific. Which exact part would you abstract away and how?
There a many ways to implement abstractions, but it’s highly dependent on the language in question. You could simply refactor each level of nesting into its own function, with all dependents provided as parameters instead of scoped variables. You could then flatMap to avoid a bunch of nested looping, favoring a linear approach that’s often easier to reason about. You could go all out and refactor all your conditional statements away, in favor of the Either monad. You’d then have a number of functions, each doing one thing (including no nesting), and a main function gluing it all together, linearly. That is a pattern you can always apply; there’s nothing controversial about it, and on a similar note there’s nothing particularly challenging about Gaussian elimination.
What environment are you using that has a hardcoded tab size? I haven’t seen this since typewriters.
Some projects just use tabs as a compressed form of 8 spaces. But that is a sin. Use tab to mean “one indent level” and align with spaces if you need to. (the occasional ASCII art diagram)
What environment are you using that has a hardcoded tab size?
- Termux
- SourceHut
- “View page source” in the browser
Termux
I think running
tabs -N
(whereN
is you preferred tab size) in the terminal should work. This is what I use in my zshrc on desktop.SourceHut
Yup, they seem to be pretty opinionated here. If you look at the source there is just an inlined style with a single rule
pre { tab-size: 8 }
. I guess that is what you get when you use opinionated tools. The user’s browser isn’t right, my preference is right!“View page source” in the browser
On Firefox this uses my default tab size of 4. But I guess changing this default isn’t user-friendly.
You can’t count it as good when it is unconfigurable when it happens to use your preference when the whole selling point of tabs is that they’re configurable.
I don’t understand what you are trying to say. I agree that SourceHut forcing their preference isn’t good. The other two are configurable and I have configured them to my preference on my machines.
You made it sound like Firefox wasn’t configurable, my bad. I thought you were saying you didn’t care that it wasn’t configurable because you liked the width they chose.
Oh no. It is configurable, although it requires editing
userContent.css
. So barely configurable. I think it defaults to 8 but I reduce it to 4.
Github uses 8 as a default. It’s configurable though.
What environment are you using that has a hardcoded tab size?
Microsoft Windows’ Notepad. I have sometimes used that when on a public computer.
I wish every language had a gofmt, this is such a non-debate (tabs are indentation, spaces are alignment)
rustfmt
Yesterday, I shared some spicy takes. A few were particularly controversial—most notably, that I correct Gif the correct way (with a soft G)
And I stopped reading there.
Years ago there was no way to share IDE settings between developers.
You ended up with some developers choosing a tab width of 2 spaces, some choosing 4 spaces and as there was no linting enforcement some people using 2-4 spaces depending on their IDE settings.
This resulted in an unreadable mess as stuff was idented to all sorts of random levels.
It doesn’t matter if you use tabs or spaces as long as only one type is consistently used within a project.
Spaces tends to win because inevitably there are times you need to use spaces and so its difficult to ensure a project only uses tabs for identation.
IDE’s support converting tabs into spaces based on tab width and code formatting will ensure correct indentation. You can now have centralised IDE settings so everyone gets the same setup.
Honestly 99% of people don’t care about formatting (they only care when consistency isn’t enforced and code is hard to read), there is always one person who wants a 60 charracter line width or only tabs or double new lined parathensis. Who then sucks up huge amounts of the team time arguing their thing is a must while they code in emacs, unlike the rest of the team using an actual ide.
deleted by creator
inevitably there are times you need to use spaces
When? You indent with tabs then add any spaces you want for precise alignment. When would you need to use spaces to indent?
Do not mix tabs and spaces.
Its impossible to automate checking that tabs were only used for indentation and spacing for precise alignment. So you then take on a burden of manually checking
You end up with the issue where someone didn’t realise and space idented or anouther person used tabs for precise alignment and people forget to check the whitespace characters in review and it ends up going inconsistent and becoming a huge pile of technical debt to fix.
Use only one, you can automate enforcement and ensure the code renders consistency.
I think calling one way better than the other is flawed. The reason the title is saying that tabs are objectively better is because they are used in addition to where spaces are used elsewhere. You could make the same argument in favor spaces due to keeping things simpler.
The argument of having variable indent size for tabs so viewers can decide how big they are is imho legitimate but also not the goal as it’s addressing something that teams generally agree on. There is max characters per line, brace placement, general code style and rules. Yes we can eject the indentation from the rules that are agreed on but once again simplicity over complexity has an equal say.
In the end it doesn’t matter that much, a good programmer will be able to work in either setting, the Editor will do most of the work anyways.
With all that said, spaces all the way!
Wrong.
Another accessibility reason for tabs: when using a braille display, each space takes up one character cell, so indenting with four spaces eats up four cells. Indenting three times with four spaces each eats up 12 characters already. Tabs only take one character cell each, so three indents = three character cells used.
The fact that there (I assume?) isn’t a braille oriented text editor that can handle space-based indentation in a smarter way is a bit depressing. Maybe the solution should be better tools based around accessibility rather than convincing everyone to switch to tabs, which is a project that will just never succeed.
So your fix is “convince all the people that want/need the better handling to use a specific editor?” - perhaps it’s a smaller number of people, but do you not see the irony there?
I honestly don’t care about tabs vs. spaces, but if there’s a low cost change in my setup that makes it easier on others, why not?
My spontaneous reaction is that making some sort of braille oriented setting for some or hopefully most editors used by people with braille displays (I have no idea if using a “normal” editor even makes sense if you’re using a braille display) is the most pragmatic solution to their screens being taking up by spaces.
First of all, convincing everyone to use tabs is a monumental task. Convincing people with braille displays to use more convenient tools on the other hand seems pretty easy, why wouldn’t you want to use more convenient tools?
Secondly, there is a large amount of code written with spaces today, so even if people switch with tabs in the future you might still want to be able to read legacy code.
Thirdly, I don’t think that the choice of tabs vs. spaces is completely arbitrary because of alignment. Using tabs for indentation and space for alignment leads to a lot more micro management of whitespace compared to just using spaces. I would guess that alignment isn’t very braille friendly anyway, but it does make the code more readable for other people. Having a good braille editor affordance might be closer to letting us have our cake and eat it too.
Of course, I don’t know what this would look like exactly, and maybe there’s some sort of obstacle that I’m overlooking, I do want to be clear that this is just of the top of my head as someone who has never used a braille display.
rather than convincing everyone to switch to tabs, which is a project that will just never succeed.
Few years back, Coraline Ada Ehmke went on a one person crusade opening a pull request on every major Github repository to adopt a code of conduct for the project, detailing the complex rules of how the humans in that microcosm of a project should interact with one another. Today, it’s the norm.
Arguing that it’s invincible to convince people at large to adopt tabs over spaces with good arguments is a ridiculous statement. All you are doing is making up excuses for not having to care.
I thought it was a non-issue that tooling should take care of anyway until stackoverflow published this:
https://stackoverflow.blog/2017/06/15/developers-use-spaces-make-money-use-tabs/
Spaces all the way
I consider tabs for indentation a failed concept.
The idea is good, but it evidently failed. Most guidelines and newer Tools recommend or require or use spaces for indent. They have their reasons too.
The prevalence of spaces makes it hard to make a contrary argument for tabs. By now, I don’t think it’s worth even if it had reasonable advantages.
Editors/IDEs that parse syntax can adjust space indent too. A mixture for indent and alignment is not obvious for everyone (I always display whitespace in my editors and am deliberate and consistent, but many people and editor defaults won’t be). Some defaults of four or eight space-width tab display is atrociously wasteful and inaccessible.
Spaces are a good enough baseline. It works well enough. And most importantly it works consistently. That’s why it won in prevalence and use.
If I could only get everyone who works on the thing I work on to use a whitespace visualizer, it would be enough. We can fight about tabs or spaces after we get rid of all the unnecessary trailing ones.
It works well enough
is an argument that works for you because you have somewhat healthy eyesight (not counting common glasses).
It “won” because the majority of healthy people has no problem marginalizing minorities with disabilities.
That’s all well and good if everyone uses editors you can configure to a certain standard all the time. Then tabs all the way.
Unfortunately that’s not reality for everyone.
Everyone should use a better editor.
Honestly, what fucking editor are you using that doesn’t allow you to configure tab length? Wordpad?
I’m hopping between shells using whatever is installed.
Vim has it, even Nano has it. It’s one setting away, set it once and forget it. If you use throwaway containers it would be hassle but I don’t understand why you would need to view code inside the container in that case.
Tabs let you define how big you want each indent to be, and spaces do not.
Spaces can too: Simply use more or less of them, to taste.
I have ADHD. Two spaces per indent makes it damn near impossible for me to scan code.
Then use four, or six, or eight, or 20. Hell, most code I’ve seen uses four spaces per indent anyway.
[Re: braille]
Surely there’s an editor out there that will automatically display indent spaces as a tab character. Or failing that it seems like it would be rather trivial create a program to convert n spaces to tabs, and vice versa.
You are missing the point. Lots of code has multiple authors. There is offer no space indention that works for all authors. With tabs each author or reader can use the width that works for them.
automatically display indent spaces as a tab character
You can’t really do this reliably. The problem is that spaces may be used in other places for alignment where the width shouldn’t be dynamic. If you do a simple
s/ /\t/g
you will have funny results where code was aligned carefully using spaces. (The reverse does work though if you want to go from tabs to spaces, because tabs contain more information.)You could potentially do a good job with a full parser for the language in question to determine the indent level and separate indent from alignment. But I’d rather not rely on this for no reason. Sometimes I don’t have a full parser available for every language I want to edit.
Spaces do not allow the viewer of code to choose how wide the indents are, this is dictated by the developer.
Most IDEs allow users to customise how many spaces to display tab indents as. Doing so the other way around may cause issues with languages based on whitespaces such as python.
laughs in lisp
Nah, I’ll keep on sticking with spaces or whatever the language’s formatter uses. Ain’t no way am I mixing tabs and spaces, will just stick with spaces.
I used to be a tabs guy, somepoint over time, especially when I realized some of the edge cases I have in formatting only remain consistent when using spaces, I switched.
Looks like you missed the point. This is about indentation, not formatting.
Use tabs to indent your lines, but if you want to align a parameter with the parenthesis on the line above or something like that, you add spaces after the indentation tabs.
That way if someone wants to they can configure their tab length to 20 spaces and the indentation will remain consistent and the code will remain aligned.
My point was that it’s pretty much impossible to indent with tabs in lisp. It’ll be harder to read and scan for everyone else who has a different tab with. How you indent and what you want to indent to is very different compared to a c-style language.
Tabs for indentation/increased scope, spaces for alignment. The best answer.