I know it was his argument not yours, but any worthwhile text compression algorithm should recognize 4/8/16 whatever number of spaces (or the byte sequence that represents it) as a common, repeated sequence in source code and compress that difference away, no problem.
Asmor ยท 59 points ยท Posted at 23:09:23 on June 20, 2016 ยท (Permalink)
That's why I have my editor set to use the Fibbonacci sequence as tab stops.
[deleted] ยท 2 points ยท Posted at 09:23:50 on June 21, 2016 ยท (Permalink)
Fibonacci
Still lol'd
Asmor ยท 6 points ยท Posted at 12:44:25 on June 21, 2016 ยท (Permalink)
See, you'd make a good code reviewer!
(why yes, I have sent tickets back for typos in comments before)
I know what UTF-16 is; in what language would you encode your source in UTF-16?
[deleted] ยท 439 points ยท Posted at 12:11:17 on June 20, 2016 ยท (Permalink)
Behold, the most potent digital holy war in the history of computer science. More bitter than Java/C#, and twice as pointerless.
Personally, I favor tabs since that's what tabs are for. It's not like tabs are some semi-proprietary Microsoft technology, they predate computers and have had a dedicated key since typewriters.
To that end, I have CodeMaid for VisualStudio configured to convert everything to tabs and save as soon as I open a file. I won't argue with my coworkers about which position is superior, but I've picked a side and plan to enforce it.
Philosophically, I prefer tabs for the exact same reason as you stated. That's literally their purpose. Levels of tabbing indicate the amount of logical indentation in the code.
But I use spaces regardless because from what I can tell, basically every official channel does. It's PEP, it's the style recommended by Google in Java, it's what my university recommends/requires on the occasions they demand a particular style. From my perspective, the argument is done. The wrong side won it, but it's over, except for Internet debates of the same callibre as vim vs emacs or ghif vs jif.
Oracle requires spaces in their standards, so Sun now must recommend spaces.
Fenor ยท 1 points ยท Posted at 07:54:39 on June 22, 2016 ยท (Permalink)
well the original sun coding standard where with tabs. now Oracle reccomended spaced because the indentation of queries need to use spaces for a sql-like indentation (wich is setting the space after select from, where vertically)
then they bought Sun. i don't think that the coding standard for java has changed from tabs to space. but finding the oracle documentation suck for both the database and java (unless these are api with the old standard)
it suck so much that when i need to search thing related to oracle or java i always add to the research string -docs.oracle.com (not -oracle.com because the asktom on oracle.com actually make a good job)
Oh I was just making a joke because I have a friend who works for Oracle and told me that their standard is spaces only. I have no knowledge of it other than that.
The tab character was originally there so you didn't have to press space four times. Now we can tell the tab button to press space four times for us and the tab character should be laid to rest.
Consistency and beauty above legacy and tradition, please.
Zagorath ยท 98 points ยท Posted at 20:02:27 on June 20, 2016 ยท (Permalink)*
Beauty is exactly why tabs are better. A single tab represents a single level of logical indentation. That's a beautiful, elegant solution, like refactoring your code to pull out something that logically should be its own function into its own function, rather than bluntly throwing it the middle of another one.
EDIT: I just thought of an even better analogy. It's like pressing the "Heading" button in Word and adjusting the space below paragraphs, or \section in LaTeX, rather than just manually increasing the font size and entering blank lines. Sure, it accomplishes the same basic task, but one is far more beautiful. Pressing space a bunch of times (or having the editor do it for you) is exactly like pressing enter a bunch of times to get the right amount of whitespace above your next line.
My problem with 4 spaces vs 1 indent is deletion. I have to hit the backspace key 4 times with spaces, as opposed to once with indents. Not to mention that it is also easy to accidentally delete just 1 of the 4 spaces in an indent, therefore ruining the alignment of the code.
Yes. People keep saying "configure your editor to insert 4 spaces per tab", but always seem to forget everything else about editing space-indented code. If I accidentally hit a character-inserting key that I didn't want to while editing text, then I want backspace to undo the insertion correctly.
Are there any editors that get this correct? I personally use vim for a number of reasons, but it definitely can't be configured into handling <TAB> and <BACKSPACE> correctly when indenting with spaces.
cmpsb ยท 26 points ยท Posted at 20:06:16 on June 20, 2016 ยท (Permalink)
Sublime Text does with both backspace and shift+tab. Notepad++, Visual Studio and Kate have shift+tab too.
I don't have Sublime Text and am on Linux so I can't test Notepad++ and Visual Studio, but Kate does not seem to handle it correctly. Depending on the setting, either pressing <TAB> then <BACKSPACE> leaves extra spaces or pressing <TAB> then <BACKSPACE> deletes too much.
I personally use vim for a number of reasons, but it definitely can't be configured into handling <TAB> and <BACKSPACE> correctly when indenting with spaces.
I use expandtab sw=4 ts=4 when editing code indented using groups of 4 spaces, but if I accidentally press <TAB> when I shouldn't have then <BACKSPACE> won't correctly erase all of the inserted spaces.
I use expandtab sw=4 ts=4 sts=4 smarttab and I haven't seen that problem in literally years.
Edit: Hell, I just did sw=0 sts=0 ts=4 autoindent and it still behaves correctly... Looks like smarttab is the one. :set nosmarttab and it starts deleting single spaces.
You have to leave insert/append mode to use undo. If I'm in insert/append mode and accidentally hit 1 key that inserts a character that I don't want then I hit backspace to undo that action.
qspec02 ยท 3 points ยท Posted at 21:02:40 on June 20, 2016 ยท (Permalink)
What do you want it to do? I'd have to double check my vimrc, but I am fairly certain that vim can correctly backspace 4 spaces inserted with tab.
I want both of the following to be true when editing code:
In insert (or append) mode, pressing <TAB> then <BACKSPACE> should be a no-op
In insert (or append) mode, pressing <SPACE> then <BACKSPACE> should be a no-op
With noexpandtab, I can get both behaviors pretty easily (by default). With expandtab (and an indentation width wider than 1), I cannot get both behaviors simultaneously. In particular, I see no way to get behavior 1 when expandtab is enabled and my indentation width is greater than 1.
emnoor ยท 1 points ยท Posted at 23:18:47 on June 20, 2016 ยท (Permalink)
If you have ts, sts and sw set, vim should do both 0 and 1 correctly.
To what values? Assume that my desired indentation width is 4 spaces. A number of people have made suggestions, but none have made both 1 and 2 work correctly (are those 0-indexed for you?).
All ordered lists on this subreddit are automatically converted to be 0-indexed, by the subreddit CSS. If you're on mobile or have CSS turned off, it will display incorrectly.
emnoor ยท 3 points ยท Posted at 23:15:28 on June 20, 2016 ยท (Permalink)
It can be. My vim backspces correctly to 4 spaces when indented and 1 space in other places. There are my indent settings:
set tabstop=8
set softtabstop=4
set shiftwidth=4
set expandtab
This is one of the reasons I'm an Emacs user. I can highlight the whole buffer and hit Tab once to automatically indent a whole file in accordance with whatever style guide is applicable to my current language, and I can do so with spaces.
A tab doesn't insert four spaces, it moves to the next tab stop. This makes things much more consistent (particularly if you're pure evil and don't use a monospace font) and leads to better looking code that's easier to configure to your preferences. If you want a tab to equal 50 spaces, then you can set your editor to that!
jaxklax ยท 9 points ยท Posted at 23:08:50 on June 20, 2016 ยท (Permalink)
particularly if you're pure evil and don't use a monospace font
Its a mess, some people even do 3 spaces. This is why tabs are better, spacies can't even agree on number of spaces. With a tab the ones reading the code can set indentation width dependent on a balance of readability and screen width. That said I use whatever is more prevalent in the language I'm writing in. I don't claim to be special enough to embark on a tab vs space crusade, consistency is more important than both.
You misunderstand my point. The original intended purpose of the tab was not to serve as indentation exactly but to save typists from pressing space four times.
Also, a space is always a character in width, whereas a tab is utterly lawless and inconsistent.
Edit: missed a space
ZHaDoom ยท 19 points ยท Posted at 19:35:52 on June 20, 2016 ยท (Permalink)
Edit: missed a space
Wouldn't have happened if you used tabs.
[deleted] ยท 54 points ยท Posted at 16:54:58 on June 20, 2016 ยท (Permalink)
In your editor, you can usually configure the tab to be any number of spaces you want. I like 4. Some editors default to 2, and it bugs me so it's the first thing I change.
Tabs: Freedom to change how they look to you
Spaces: Step one is replacing all the 2-space indents with 2-spaces
This is why Tabs are the Master Race, and you filthy spacies must be exterminated.
And now I've spoken to you, I can confirm that idiot Tab users are too dumb to realise a single button can be used so we don't have to press space four times.
You keep hold of your legacy character. After it dies, you can drink its rotten juices and pass into the next life with it, knowing you did something stupid.
KJ6BWB ยท 1 points ยท Posted at 22:37:42 on June 20, 2016 ยท (Permalink)
The amount of times I've hit a variable undefined error and scratched my head for literally minutes before realising that in other people's code, "colour" doesn't usually have a 'u'.
[deleted] ยท 0 points ยท Posted at 20:32:08 on June 20, 2016 ยท (Permalink)
In addition, I know of at least one (Drupal) has in it's official documentation to indent with 2 spaces. So if your editor is set to convert spaces to tabs - you're already breaking the API.
2 spaces is obscene, though not nearly so obscene as 3 or 5. Drupal isn't exactly known for being a particularly intelligent, pure, insightful, or respected platform. It gets the job done, but fuck their official docs.
[deleted] ยท 0 points ยท Posted at 21:50:15 on June 20, 2016 ยท (Permalink)
Chaos and anarchy! If you don't like the docs, then don't use the software. That is what breeds spaghetti code.
It's interesting to hear that drupal is not pure madness.
[deleted] ยท 1 points ยท Posted at 22:54:17 on June 20, 2016 ยท (Permalink)
[deleted]
[deleted] ยท 2 points ยท Posted at 22:58:12 on June 20, 2016 ยท (Permalink)
As long as you're a spacie, you'll never understand why none of that makes sense or why tabs are superior.
Tarmen ยท 1 points ยท Posted at 21:02:28 on June 22, 2016 ยท (Permalink)
%s/ \{4}\|^I/ /
set shiftwidth=2 expandtab
retab
YuvalZ ยท 0 points ยท Posted at 19:38:35 on June 20, 2016 ยท (Permalink)
Consistency in more important than freedom.
Having every thing look alike is better then every one choosing how it looks like, even of its only for their own eyes.
Wizhi ยท 3 points ยท Posted at 20:08:26 on June 20, 2016 ยท (Permalink)
Having every thing look alike is better then every one choosing how it looks like, even of its only for their own eyes.
So color-scheme enforcement is a thing now?
I'm kidding, but really though as long as everyone agrees that "this is indented N levels", why should it be enforced whether 1 level of indention is x or y spaces wide?
YuvalZ ยท 1 points ยท Posted at 20:28:58 on June 20, 2016 ยท (Permalink)
When I rule, Monokai will be the only color-scheme >:)
as long as everyone agrees
That's exactly the point, if N levels of indent is always 4N characters long, you will always know at glance of much a line is indented, no matter what editor you use (maybe the font matters a little). That's readability right there, and readability counts.
Wizhi ยท 1 points ยท Posted at 20:44:53 on June 20, 2016 ยท (Permalink)
When I rule, Monokai will be the only color-scheme >:)
Are you arguing for tabs or spaces? Each one brings consistency in a different manner
Using tabs means that different files can look consistent to the same programmer
Using spaces means that one files appears consistently for different programmers
It's more important to me that everyone else's code has a consistent look than that my code looks the same on everyone else's machine as it does on mine.
This is really confusing to talk about :(
YuvalZ ยท 1 points ยท Posted at 20:16:49 on June 20, 2016 ยท (Permalink)
I'm arguing for spaces :)
To be honest, when I used to think about this argument it never accrued to me that anyone ever use any number of spaces other than 4, anything else just seems too terrible to think about. So the way I saw it, using spaces means that everything looks the same to everyone always.
But if people out there in the world are using a number that is wrong and not 4, then that's a good argument for using tabs, to prevent the horribleness of non 4 spaces indentation.
I use width 8 indentation, but I indent with tabs so that people like you don't hate me ;)
There's other arguments for using tabs over spaces:
First, using tabs for indentation and spaces for alignment makes the syntax reflect the semantics of the whitespace. If you do it correctly then automatic tools will have an easier time figuring out what whitespace represents indentation and what whitespace represents alignment.
Second, it's harder (slower) to edit space-based code. Usually you configure <TAB> to insert more than one space, but then <BACKSPACE> doesn't function as an undo the way it does for every other character-inserting key on the keyboard.
The backspace issue is by far my biggest issue with spaces
YuvalZ ยท 1 points ยท Posted at 20:52:18 on June 20, 2016 ยท (Permalink)
I guess each solution solves some problems and creates a few more, just like programming.
The main reason for me for using spaces is that I usually code in python, where its a convention to use 4 spaces. Probably to prevent argument like this one.
I don't agree so much with your first argument. The fact that your file will have a combination of tabs and spaces just seems wrong to me. All your aliments will be ruined on someone else's machine where the width of tab is different. But if you use spaces it will stay clean.
About your second argument, Sublime will automatically delete the 4 spaces with a single backspace. I don't know how it works on every editor, so I guess its a valid point.
I don't agree so much with your first argument. The fact that your file will have a combination of tabs and spaces just seems wrong to me. All your aliments will be ruined on someone else's machine where the width of tab is different. But if you use spaces it will stay clean.
I don't see how your argument justifies spaces. If I like a 2 space indent and you like a 4 space indent we can both use tabs and both get our way. It's fine to say don't mix the two but spaces aren't superior.
YuvalZ ยท 1 points ยท Posted at 21:34:09 on June 20, 2016 ยท (Permalink)
If we both agree that if you use tabs, then you should use only tabs, then spaces gives you more control of how your code will look like. For example, If I have a function with a lot of arguments, and I want all the arguments to be on a different line while having the same aliment as the first arg. With spaces you can do it, with tabs, you can't.
And I don't necessarily think that spaces are superior, I think that spaces with a consistent length (like 4) are superior.
Ummm... tabs for indentation, spaces for alignment. I line up function arguments all the time and haven't had issues with changing tab sizes in a while.
I guess each solution solves some problems and creates a few more, just like programming.
True, and I clearly value some of the tradeoffs over others.
All your aliments will be ruined on someone else's machine where the width of tab is different.
No, that's why you align with spaces. If you do it correctly, then changing tab sizes should "just work". I have a Rust project where I edit it with 8-wide tabs but have configured GitHub to display it using 4-wide tabs because the Rust community using 4-wide indentation. It works perfectly fine.
About your second argument, Sublime will automatically delete the 4 spaces with a single backspace.
I use the command line extensively so I don't see myself using Sublime anytime soon, but if I insert 3 spaces then press backspace will it only delete the last space?
YuvalZ ยท 1 points ยท Posted at 21:16:57 on June 20, 2016 ยท (Permalink)
I'm writing from my phone, so i'm not sure, but if I remember correctly Sublime will delete as many spaces as necessary to snap to the "grid". So if you have 3 spaces it will delete all of them, but if you have 6 then it will only delete 2.
That's what I would expect based on other editors, and is a problem because you don't always want that behavior.
If I accidentally add an extra space anywhere in my code except the indentation, then backspace should only remove 1 character.
YuvalZ ยท 1 points ยท Posted at 21:41:48 on June 20, 2016 ยท (Permalink)
I think we're going into argument that are starting to become irrelevant in comparison to the "main arguments".
You can talk forever about all the little nuances of what is better. But eventually the I'm used to x spaces/tabs is probably the best one.
I'm discussing editor configuration because although I prefer to edit tab-indented code, I'm occasionally (soon to be frequently) forced to edit space-indented code and would like it to be as painless as possible.
_cortex ยท 1 points ยท Posted at 20:21:44 on June 20, 2016 ยท (Permalink)
Some languages' style guides ask for 2, some older developers ask for 8 and to never nest more than 3 or 4 blocks deep.
PBI325 ยท 1 points ยท Posted at 18:44:25 on June 20, 2016 ยท (Permalink)
The original intended purpose of the tab was not to serve as indentation exactly but to save typists from pressing space four times.
And it still does, so what's your point? It literally takes a measurable amount of time to have to type out spaces and remember how many to do where and whatnot. Makes brain hurt, *grunt*
what is your argument for spaces? you just said "consistency and beauty" without giving any reasons for why and how it might have those traits
Genion1 ยท 2 points ยท Posted at 16:11:43 on June 21, 2016 ยท (Permalink)
"consistency and beauty" when you want to align multiple lines independent of indentation level. E.g. a list of numbers of varying magnitudes or function arguments that span multiple lines.
Fenor ยท 2 points ยท Posted at 12:40:10 on June 21, 2016 ยท (Permalink)
Says your grandpa.
psydave ยท 1 points ยท Posted at 20:09:29 on June 20, 2016 ยท (Permalink)
You can tab once to insert 4 spaces, but why backspace 4 times?
Consistency and beauty? Hah. My tab indented code probably looks prettier than yours. (I focus a lot on readability, more than most other programmers.)
I don't need a backspace to fix indentation level, my <TAB> key doesn't insert tab-or-spaces-or-poop-emoji-whatever either, it just INDENTS CODE to the right position the way I configured it (no '\t's), so I don't f****** care.
I'd say yes. Vim won that battle years ago, so it's less interesting these days. There are still quite a few people left who don't realise that tabs are inferior to spaces.
[deleted] ยท 5 points ยท Posted at 22:58:09 on June 20, 2016 ยท (Permalink)*
Oh come on, I'm trying to start a high-quality flame war over here. The proper reaction is:
LIES! BURN THE HERETIC!
But mostly because getting a whole team to use tabs one certain way is a nightmare (some use tabs for indentation / spaces for alignment, others litter tabs throughout the lines for alignment because now their tab key is not configured to insert four spaces) and there are no real downsides to using spaces in any modern editor. As long as you're not using Microsoft Notepad, your tab key still indents and your backspace key still de-indents, but your code doesn't turn into a mess.
Also, when using tabs, people are less strict about staying within our 100-column limit (because they were using 2- or 1-width tabs) which is pretty awful when trying to use a side-by-side diff-tool.
Back when I just started programming I preferred tabs, but now that I've experienced tabs in the workplace, my aversion of spaces has been completely cured.
Tabs are clearer for automatic tools. If you want to run some sort of code analyzer and your code is indented with spaces, the analyzer has to guess what level of indentation each line has. In particular, this makes it more difficult to reformat space-indented code into tab-indented code than the other way around. In other words, converting from tab indentation to space indentation is lossy.
Editors don't handle spaces as well. If my editor is configured to use tabs and I hit tab then backspace, it will erase the tab I just entered -- which is consistent with what happens if I hit any other character-inserting key followed by backspace. This makes backspace function as an undo for accidentally inserted characters, and gives the editor predictable behavior, which means I can interact with it much more quickly. If I use space-based indentation (assuming a width greater than 1) then I lose that property and editing becomes more difficult (slower).
No fighting over indentation width (unless a width is enforced for the purpose of setting a column limit).
Source files are smaller. This is an insignificant difference for almost everyone.
Reasons to use spaces for indentation:
If working in a group project, people are less likely to commit atrocities unnoticed with a space-based style guide than a tab-based style guide
If the style guide does not define a specific tab width then you cannot enforce a particular column limit (you mentioned this). You can fix this by enforcing a specific tab width, but you lose viewing flexibility for your developers.
You don't have to think about indentation versus alignment as much
I wouldn't say that there are no real downsides to using spaces in modern editors, only tradeoffs.
But in an attempt to keep some sort of flame war going, let's nitpick the reasons for tabs apart!
Tabs are clearer for automatic tools. If you want to run some sort of code analyzer and your code is indented with spaces, the analyzer has to guess what level of indentation each line has.
The problem is that, by nature of at least some people in a team not being very careful, there will be tabs littered through the code used for alignment. Any code analyser that assumes every tab is an indent will give faulty results in any code that doesn't go through very thorough code review and we all know no one actually does that. You could fix your analyser to take the littered tabs into account, but at that point it should also handle spaces flawlessly, so that's not a reason to use tabs any more.
Editors don't handle spaces as well. If my editor is configured to use tabs and I hit tab then backspace, it will erase the tab I just entered -- which is consistent with what happens if I hit any other character-inserting key followed by backspace. This makes backspace function as an undo for accidentally inserted characters, and gives the editor predictable behavior, which means I can interact with it much more quickly. If I use space-based indentation (assuming a width greater than 1) then I lose that property and editing becomes more difficult (slower).
Use a better editor! Refer to any of the vim vs emacs crusading threads for more details.
Use a better editor! Refer to any of the vim vs emacs crusading threads for more details.
I currently use vim, and would probably put in the effort to learn how to use emacs if I knew it would solve that problem. The issue is that I need someone to prove to me that emacs would handle space-based indentation better, and I don't know anyone who can show me how to configure emacs. A couple of people here on Reddit have tried to help, but posting links to emacs documentation is insufficient -- it has quite the learning curve.
Tabs are a quick way to get there, but some editors like to make them really big. Which is kind of annoying. So it's convenient to have your editor set up to replace them with spaces.
Edit: I never realized the amount of butthurt I was walking into.
G3Kappa ยท 67 points ยท Posted at 13:48:55 on June 20, 2016 ยท (Permalink)
Or have your editor set up to have a tab width of 4 spaces instead of 8?
I mean, it's your editor. You can do whatever you want.
โ Well it ain't a free shop, is it? So fuck off!
Slak44 ยท 11 points ยท Posted at 14:00:59 on June 20, 2016 ยท (Permalink)
it's your editor
You can't always view files using your preferred editor, and sometimes you must view them on a foreign computer. Spaces will be consistent, while tabs are likely different.
Companies that manage their own code repositories, code review tools, browser-based UIs for viewing deployed code, and so on, and when not all of them use the same method of rendering tabs or monospaced fonts.
Slak44 ยท 3 points ยท Posted at 14:17:18 on June 20, 2016 ยท (Permalink)
I don't do it often enough to call it a deciding factor, but it sure is useful when I have to.
gokjib ยท 12 points ยท Posted at 16:28:46 on June 20, 2016 ยท (Permalink)
Well the philosophy that I enjoy using is based on "write once, run anywhere". This means including all of the libraries with the code, including project files with the code, and generally making the code the easiest possible to work with and run.
This includes formatting, and with formatting comes spacing. The least finicky of the two, between spaces and tabs, is spaces. They always take up one character space. They are predictable. From my editor, to anyone elses editor, it will all display pretty much the same.
Even if they happen to be using notepad for some reason. They won't be forced to deal with 8-character tabs.
All this being said, I still use the tab key. I don't pound on the space key like some sort of caveman.
From my editor, to anyone elses editor, it will all display pretty much the same
Why do you want your code to display the same for everyone else? Your preferences shouldn't take precedence over the preferences of the people trying to read and/or edit your code.
Even if they happen to be using notepad for some reason. They won't be forced to deal with 8-character tabs.
By choosing to use spaces, you are forcing everyone to use your preferred indentation width. At least by using tabs you are giving everyone with a decent (non-Notepad) editor a choice.
[deleted] ยท 3 points ยท Posted at 19:45:44 on June 20, 2016 ยท (Permalink)
By choosing to use spaces, you are forcing everyone to use your preferred indentation width.
But I already force them to use my preferred variable names, line breaks, vertical whitespace (i.e. empty lines), etc. For better or worse, source code is not generally stored as an AST.
If you have a decent editor, and you don't like it, then format the document. You are capable of doing so if you have an editor that is made for programming.
Unfortunately Reddit's markup doesn't allow me to show you.
It's so evil Reddit won't even let me do it.
lx45803 ยท 9 points ยท Posted at 17:59:22 on June 20, 2016 ยท (Permalink)
0 leading spaces
1 leading spaces
2 leading spaces
3 leading spaces
Just throw 4 spaces in front of every line.
[deleted] ยท 10 points ยท Posted at 18:49:45 on June 20, 2016 ยท (Permalink)
Just throw 4 spaces in front of every line.
Like...like a tab?
(Yes, I know it focus on the next element in the browser here, but still)
[deleted] ยท 6 points ยท Posted at 18:58:03 on June 20, 2016 ยท (Permalink)
A tab is 8 spaces.
[deleted] ยท 1 points ยท Posted at 19:10:29 on June 20, 2016 ยท (Permalink)
Damn. I had no idea. I can't remember a time I used tab and it actually moved the cursor 8 spaces. Do any IDEs or text editors use that as a default or is that a legacy definition of some sort?
[deleted] ยท 3 points ยท Posted at 19:23:03 on June 20, 2016 ยท (Permalink)
IIRC 4 spaces is the Windows standard, 8 spaces is the Unix standard. I know for a fact that in Python and Haskell, it's 8 spaces.
[deleted] ยท 2 points ยท Posted at 19:30:51 on June 20, 2016 ยท (Permalink)
Okay, that makes sense.
I use tabs for C++, Java, and web dev stuff, but hadn't realized I use 2 spaces in Python instead of tab until you mentioned it. Never fiddled with Haskell.
Auxx ยท 24 points ยท Posted at 17:32:15 on June 20, 2016 ยท (Permalink)
That's the reason to use tabs - everyone in a team can set their editor to their liking and have indentation at 2, 3, 4 or whatever spaces they want! Buy the source code will be the same. Tabs forever!
...literally every editor I've ever used has that option. You might want to use something that is not Microsoft Notepad.
Well shit. I read it on mobile and with my font it looked like an n. Whoops.
However
It is possible. In vim, you can change the visual character that shows up as the final char in a tab. You can edit a font (in something like FontForge) to include a whitespace character of width 0.14 and use tabs of width 4. BAM, tab with width ฯ!
That said, spaces4lyfe. If you set softtabstop=4, this method also works with spaces.
Yes it is, for many people. Some style guides say to use 2 spaces, like Ruby's. 2 spaces is obviously at a different indent level vs no spaces in front of a line. I don't know how you wouldn't be able to see it.
Sometimes I'm forced to if I have to make a fix and I only have command line compilers to work with. However, that's usually on Linux, and I just use nano at that point. Which is pretty good about tabs.
levir ยท 1 points ยท Posted at 21:17:07 on June 20, 2016 ยท (Permalink)
When a person wanted to type a table (of numbers or text) on a typewriter, there was a lot of time-consuming and repetitive use of the space bar and backspace key. To simplify this, a horizontal bar was placed in the mechanism with a moveable lever stop for every position across the page, called a tab stop.
So, there is no need for a separate tab symbol anymore, in modern editors you can insert as many spaces as you want by pressing one key.
[deleted] ยท 15 points ยท Posted at 16:30:23 on June 20, 2016 ยท (Permalink)
Why use an IDE or editor that can't fix that problem? Switching to tabs is just admitting defeat
psydave ยท 2 points ยท Posted at 00:17:50 on June 21, 2016 ยท (Permalink)
It's not defeat if it was never a goal to begin with.
And... if you're developing on Windows for .Net, your only real choice is Visual Studio. There's probably some extension somewhere which does that, but why fight it?
You know what's good about tabs? You can define what a tab is... How big it is and even better it takes the same size in the file no matter what. Why is this a discussion?
I have CodeMaid for VisualStudio configured to convert everything to tabs and save as soon as I open a file. I won't argue with my coworkers about which position is superior, but I've picked a side and plan to enforce it.
I applaud your dedication, however, unless you are the one making decisions for the whole team, I think it's best to discuss things like this, and settle on a solution. Flip flopping from tabs to spaces can make for some real bitchy merges.
Fenor ยท 1 points ยท Posted at 08:47:36 on June 21, 2016 ยท (Permalink)
ok but how do you compare this digital holywar to the Vim/emacs?
[deleted] ยท 1 points ยท Posted at 12:42:22 on June 22, 2016 ยท (Permalink)
Or your team could could just agree on a fucking style and enforce it on check-in to SCM.
[deleted] ยท 0 points ยท Posted at 12:44:55 on June 22, 2016 ยท (Permalink)
This was a really funny moment in the Apple WWDC Platforms state of the Union presentation. Had to laugh when he said "You know, it doesn't matter once it's compiled"
Cathercy ยท 136 points ยท Posted at 14:24:01 on June 20, 2016 ยท (Permalink)
This. That's why I make all of my code a big one-liner.
You know, I've been avoiding watching the latest season of that. I thought I'd be okay waiting for it be over so I could binge watch it. "It's not Game of Thrones, after all, there's nothing in the way of spoilers that could be a problem", I said. I don't think I can count the number of times I've been proven wrong about thatโฆ
Title-text: Of course, factions immediately sprang up in favor of '~*~sTaR tReK iNtO dArKnEsS~*~', 'xX_StAr TrEk InTo DaRkNess_Xx', and 'Star Trek lnto Darkness' (that's a lowercase 'L').
No, two spaces. I don't actually stand by that, but I once worked on a project where that was enforced. Everything looked do weird, the angles were all wrong.
That makes perfect sense though. Consider a grid. There are vertical lines at x=0, x=1, x=2, etc. If you want to reference the first cell in that grid, you need to be at x=0.5 so that you land inside the cell.
Just getting people to indent their code where I work would be a win as far as I'm concerned. We have a stupid IDE that doesn't have the capability to automatically indent.
There are some developers at my work who do the same thing, and if I say "tab," some of them will actually go off on a rant about it. I'm trying to be efficient here, dammit. I don't care if you want to use spaces instead of tabs, but "tab" has half the syllables of "indent" a quarter the syllables of "hit space four times."
That's how I code sometimes for this package too. Notepad++ is awesome. You know, I'm really not sure what the mindset is. I think part of their thinking is "get it done as soon and quick as possible" which is why they don't mess with indenting. Single line If statements, not using loops, etc. I have explained the advantage of using the correct, efficient methodology but then they get angry. I've gotten better at my approach but not everyone is receptive even if I'm being incredibly polite and not insulting or accusatory. And I really like my coworkers, nice people! Just not everyone started in the industry as a programmer.
Seriously? Tabs vs spaces is important enough to you to entirely avoid a language where they made a design decision to remove the problem, just because you feel they made the wrong choice?
Jetlogs ยท 34 points ยท Posted at 11:47:46 on June 20, 2016 ยท (Permalink)
[deleted] ยท 7 points ยท Posted at 18:25:29 on June 20, 2016 ยท (Permalink)
Tabs are only used for expressing the indentation level. One tab per โblockโ
And when I format my code like this and explain the above to people, I'm the bad guy.
Assume the spaces below are actually 4-space SmartTabs. I don't know how to express a tab on Reddit.
public partial class Default : Page {
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack)
DoSomething(); }
private void DoSomething() {
blahblah(); } }
Indentation expresses nesting depth. One tab per level. Frankly, I wish I could do this:
public partial class Default : Page
protected void Page_Load(object sender, EventArgs e)
try
DoSomething();
catch
DoSomethingElse();
We already have the idea of curly brackets being optional for single-statement ifs, loops, etc. Why not take it to its logical conclusion and make it optional for all things containing only one sub-thing?
ralpo08 ยท 25 points ยท Posted at 21:09:57 on June 20, 2016 ยท (Permalink)
nemec ยท 0 points ยท Posted at 23:56:22 on June 20, 2016 ยท (Permalink)
Smart tabs already insert spaces in place of tabs, which is not only allowed by PEP8 but encouraged (as you noted). The only thing they disallow is the mixing of the spaces.
You mean in the style guide, or the interpreter itself? I've never had issues with "smart tabs" with CPython -- but I'm not contributing to the Python community itself.
The interpreter itself. Python 3 programs wont run if you have mixed tabs and spaces. In Python 2 they run normally unless a command line option is given
I just tested with CPython 3.5.1, and it runs tab-indented code perfectly fine. What's disallowed is mixing tabs and spaces for indentation, but the last thing you said was tabs for indentation and spaces for alignment, which works fine.
[deleted] ยท 3 points ยท Posted at 19:09:03 on June 20, 2016 ยท (Permalink)
[deleted]
[deleted] ยท 1 points ยท Posted at 20:46:44 on June 20, 2016 ยท (Permalink)
I'm not trying to make my code pretty. I'm trying to remove as much of it as I can without sacrificing too much readability. :)
mr___ ยท 0 points ยท Posted at 18:36:59 on June 20, 2016 ยท (Permalink)
You should really try F#
EDIT: Tabs are a syntax error in F#, because indentation level is significant and tab has no defined amount of indent. Very smart people made that choice, and it's the right one.
What?! That makes no sense, with tabs each tab means exactly one level of indentation. How it displays is not important, only the semantics are important, and the semantics of tabs are well-defined.
Using spaces to indent makes the compiler/interpreter have to guess what indentation level a given number of spaces means, and making that guess requires the context of the surrounding code. It's a much more difficult problem than just counting tabs.
I don't see why the F# developers would have done that.
mr___ ยท 0 points ยท Posted at 18:59:34 on June 20, 2016 ยท (Permalink)*
Because spaces are not forbidden, and tabs have no defined number of spaces.
We care about code "reading" right, same as with python. It has nothing to do with your editor. If the compiler assumes 8 spaces per tab, and you assumed 2 or 3 or 4 or 6, then your "apparently" correct code, isn't. Because what might look un-indented to you, looks indented to the compiler.
Try actually using such a language before you knock it. F# is one of the most beautiful and expressive languages around.
You stated that tabs are syntax errors in F#. I know that they are not a syntax error in Python because most of the Python I write is tab indented and I've never gotten such an error on my own machine. I did get that error once, but that was when I pasted tab-indented code into an unfamiliar Python editor that was configured for space-based indentation and it didn't know what to do with it.
So what I'm getting here is either that F# somehow depends on the number of spaces in an indent (which is dumb) or that it doesn't allow mixing tabs with spaces (which is sensible) and you are just unable to articulate it or to see that it's irrelevant.
mr___ ยท 2 points ยท Posted at 11:54:57 on June 21, 2016 ยท (Permalink)
It does depend on the number of spaces in an indent. It is a layout sensitive language
\u0009 is the tab character and it is not any space characters
\u0020 is the space character and it is a space character
\u0009 !== \u0020
So the compiler should not have to assume anything about how many spaces a tab character is and it would make it way easier to use as a distinct indentation as apposed to spaces where you must have exactly 4 spaces or exactly 2 spaces or exactly n spaces for the compiler to understand where indentations are actually happening.
A tab character is always exactly one indentation it is never some number of spaces unless your editor has replaced your tab key with a macro that creates spaces in which case that is an issue with spaces not tabs.
IRBMe ยท 2 points ยท Posted at 21:20:38 on June 20, 2016 ยท (Permalink)
tabs have no defined number of spaces.
That's... because tabs are't some number of spaces? They're tabs. One tab character = one level of indentation. You seem to be thinking of the tab width, which is purely a rendering option which determines how much horizontal space should be allocated when a tab character is rendered. If you're not rendering the code, the tab width doesn't have any relevance.
mr___ ยท 1 points ยท Posted at 11:52:30 on June 21, 2016 ยท (Permalink)
It does in layout sensitive languages, where the code must "look" the same to both you and the compiler.
IRBMe ยท 2 points ยท Posted at 12:00:28 on June 21, 2016 ยท (Permalink)*
It does in layout sensitive languages
The compiler only cares about the character stream. Given the following, where --> represents a tab and . represents a space:
a
-->b....c
-->-->d
The compiler would see the following character stream:
0x09 is a tab character, 0x20 is a space character and 0x0a is a new line character.
The tab width controls how the 0x09 values in the character stream are rendered as pixels, which is of no relevance to a compiler.
You might be confusing the fact that your editor of choice might insert some number of space characters for you when you press the tab key, with an actual tab character. If your editor inserts, say, 4 spaces when you press the tab key then the character stream will contain 0x20,0x20,0x20,0x20, but that is not a tab character. A tab character is a single 0x09.
In short, the setting that controls how a tab character should be rendered is not the same as the setting that controls how many spaces your editor might choose to insert when you press the tab key, if indeed you have it configured to do so.
mr___ ยท -1 points ยท Posted at 16:59:17 on June 21, 2016 ยท (Permalink)
IRBMe ยท 2 points ยท Posted at 17:08:53 on June 21, 2016 ยท (Permalink)
I'm aware of how indentation works in certain languages but don't see how it relates to my point. Do you understand that a tab stop is a single character?
mr___ ยท 1 points ยท Posted at 20:47:16 on June 21, 2016 ยท (Permalink)
Do you understand what I am saying about layout-based languages? It IS important that you and the compiler agree how far from the left margin a statement is, in columns. That's hard to do when everyone chooses a tab size arbitrarily AND spaces are allowed. Tabs are not the only things that lead lines, or set column indent counts.
IRBMe ยท 1 points ยท Posted at 20:58:09 on June 21, 2016 ยท (Permalink)*
Do you understand what I am saying about layout-based languages?
Yes, completely. I have used several myself.
It IS important that you and the compiler agree how far from the left margin a statement is, in columns.
Indeed, and both I and the compiler can agree that 1 tab character = 1 indentation level, 2 tab characters = 2 indentation levels, 3 tab characters = 3 indentation levels and so on.
That's hard to do when everyone chooses a tab size arbitrarily
A tab is always a single character. Do you understand this? There is no such thing as a "tab size" in a stream of characters; there are spaces, and there are horizontal tabs, but the idea of a tab character of a certain size is an incoherent concept. I'm going to repeat this again, because it seems to be the root of your misunderstanding. Inside a text file, there is no such thing as a tab size. Tab characters do not have a size other than the number of bits used to encode the character, the same as any other. It only makes sense to assign a width to a horizontal tab when you wish to render the tab. The tab width is the setting that tells the text renderer how far over the following character should be rendered whenever it encounters a horizontal tab character - i.e. the ASCII code 0x09.
Again, tab width is a setting that controls how tab characters are rendered, and how characters are rendered on the display is completely irrelevant to a compiler. If I create a file containing the following content: 0x09,'a' i.e. a tab character followed by the character, "a", then I can open this file in one editor in which the tab width is set to the equivalent of 2 spaces, another editor in which it's set to 4 and another in which it's set to 8. In all 3 editors, the 'a' character would be rendered in a different position, and yet the contents of the file have not changed. A compiler reading the file will see the exact same two characters, no matter what editor I happen to view the file in, and no matter what the tab width is set to in any of these editors. The compiler will always see a tab character - that is, a character of ASCII code 0x09 - followed by an 'a' character - that is, a character of ASCII code 0x61. Do you understand this?
Your argument is like saying that you and the compiler must agree on the font, or the color scheme. The font and the color scheme are rendering properties that affect how the character stream is displayedjust like the tab width. There is no such thing as the font of a character in an ASCII text stream just as there is no such thing as the width of a tab character in an ASCII text steam. It is a rendering option like the font.
Tabs are not the only things that lead lines, or set column indent counts.
If you're mixing the type of whitespace that you use for indentation then that's problematic, of course, but has absolutely nothing to do with the tab width of a tab character.
mr___ ยท 1 points ยท Posted at 21:09:18 on June 21, 2016 ยท (Permalink)
So when the compiler sees a line leading with a tab then 4 spaces, then the next line 12 spaces, should it group the two lines into a block?
IRBMe ยท 1 points ยท Posted at 21:17:58 on June 21, 2016 ยท (Permalink)
So when the compiler sees a line leading with a tab then 4 spaces, then the next line 12 spaces, should it group the two lines into a block?
Firstly, what does this have to do with the tab width? Absolutely nothing; it's completely unrelated and entirely irrelevant.
Secondly, to answer your question, that depends entirely on the specification of the language or the implementation of the compiler, so if you want to know the answer then you should read the documentation.
"Indentation is rejected as inconsistent if a source file mixes tabs and spaces in a way that makes the meaning dependent on the worth of a tab in spaces; a TabError is raised in that case."
mr___ ยท 1 points ยท Posted at 21:31:58 on June 21, 2016 ยท (Permalink)
You started out saying tab width isn't, or should not be, relevant to the compiler. You agree now that it is and the language spec has to carefully define the width of a tab or reject them?
Of course I know that a tab is a single code point........
If you use a tab character to indent a code block, then every other instance of this level of indentation in the same code block must be a tab character.
If you use some number of spaces to indent a code block, then every other instance of this level of indentation in the same code block must be the same number of spaces.
Width of a tab character is irrelevant. The number of them is all that is relevant.
Why is this so hard all of a sudden?
IRBMe ยท 1 points ยท Posted at 21:45:31 on June 21, 2016 ยท (Permalink)*
You started out saying tab width isn't, or should not be, relevant to the compiler.
Correct. It isn't, and I've explained why as clearly and in as much detail as I possibly can, so I'm at a complete and utter loss as to why you still don't understand it.
You agree now that it is and the language spec has to carefully define the width of a tab or reject them?
No. You still do not seem to understand what "tab width" means despite my attempts to explain it to you, and you seem to be confusing tabs with spaces.
You do understand that if your editor is configured to enter, say, 4 spaces when you press the tab key, that your file now contains only spaces and no tab characters, right? You understand that the tab key and a tab character are two different things? You understand that pressing the tab key may cause spaces and not tabs to be inserted if your editor is configured to do so, right?
The only way I can make sense of your comments is if your editor is set to insert some number of spaces when you press the tab key and you're confusing the tab key for a tab character. In that case, of course the number of spaces that are inserted when you press your tab key makes a difference because that number of spaces are hard-coded into the file. However, this is completely different from inserting a tab character.
Of course I know that a tab is a single code point
Okay, let's try to clear this up once and for all.
Here is a screenshot of a text file inside my text editor. You can see that the first character is a tab, the second character is the letter a, and the final character is a line feed, right? My editor has a tab width of 4.
Here is a screenshot of the same file in a hex editor, clearly showing the tab character (0x09), the 'a' (0x61) and the line feed (0x0a).
Now I have set the tab width in my text editor to 8. As can be seen in this screenshot, the tab is now wider looking.
After setting my tab width to 8 and saving the file, what do you think I will see now when I open it in the hex editor? Show me the hexadecimal values that you would expect to see.
I wanted this, but so many people screw it up and use the tab key for alignment that we forced everyone to use spaces in our company. Once it's consistent people have better things to worry about than tabs vs spaces...
This is the unfortunate truth. It's so much nicer to work with tab-indented code than with space-indented code, but most large projects and organizations choose a space-indented style because so many programmers are incapable of correctly indenting their code with tabs :'(
is harder for a human to quickly read and parse than this:
if ((some() == COMPLETELY) && // this is a comment
(contrived() == example) || // that can explain
(to_illustrate() != a_point())) // some stuff
{
...
}
In the latter example, a long and complex expression is broken up across multiple lines such that each line contains a smaller sub-expression that is easier to understand, and each of the components of each sub-expression are aligned so as to highlight the similarities and differences between them. Note also the addition of the comments that can now be used to provide some explanation of each sub-expression.
Another example:
result = some_function(FIRST_THING, "a string", an_object, true, false, &x);
Could be improved as follows:
result = some_function(
/* which_thing: */ FIRST_THING,
/* description: */ "a string",
/* the_thing: */ an_object, // a little note about this object
/* is_a_foo: */ true,
/* is_a_bar: */ false,
/* output_thing: */ &x);
(Of course, using proper named parameters would be better if the language supported it)
Both of these examples are, of course, contrived and we should not actually write code like that, but they serve as demonstrations of how breaking code up across multiple lines and adding alignment can improve readability without having anything to do with editor width.
It is really, truly language-dependent. I use 2 spaces for Haskell. I use 2 spaces for my own projects in JavaScript, but I write in a style that makes that work. If I am choosing for a larger group, then I pick tabs, or 4 spaces if everyone likes spaces.
I'm still trying to pick a style for Pony and Premake. Both of them are completely whitespace agnostic, so indentation only (barely) matters for readability.
Normally, I'd just go 4 spaces, but then the rest of the community has settled on 2 or 3.
Tabs/Spaces debate aside, I feel sorry for you being stuck in an email client that doesn't have conversation indentation (oh, sorry, I mean threading...)
Are all those replies directly to you? To somebody who replied to you? In one long string? In multiple branches? How on earth do you know at a glance how to follow the threads of conversation?
Habits die hard. If I hit a key I didn't mean to and it inserted a character I don't want, I instinctively press backspace to remove it. Changing that to Shift-Tab if I accidentally press tab increases my cognitive load (because it becomes an exception to the backspace-as-insertion-undo rule) and the chance that I forget what I had intended to type.
I use Atom. One of the add-ons lets you convert between tabs and spaces. My general rule is tabs for files only I look at; spaces for when I'm sharing the code. Different text editors view tabs differently, so covering to spaces makes sure that others will see the code in the same format I saw it in, no matter what they use to edit. For example, I convert to spaces before turning in CS assignments.
That depends on what you mean by better. I use tabs when I'm coding because it's easier, and it also keeps the file size smaller. That being said, file size of the source doesn't matter in the compiled version, so it's really up to programmer preference. Spaces are always better when sharing code, though, if you want to make sure the formatting is consistent on all editors.
Spaces are always better when sharing code, though, if you want to make sure the formatting is consistent on all editors.
But why would you want that? Using tabs allows the reader to set how wide they'd like indentation to be. By choosing to use spaces to "make sure the formatting is consistent", you are intentionally forcing the reader to view the code in the way that you are comfortable with, not the way that they are comfortable with.
To give you an example, I use an indentation width of 8. Let's assume that you like an indentation width of 4. If I send you my tab-indented code and you open it in your editor, you will see an indentation width of 4, which is comfortable for you. If I first convert my code to use spaces, then you will see code with an indentation width of 8, which is not to your liking. Wouldn't you rather I send you code that you can view as you like, not as I like?
Great question! Personally, I like the size of the tab - one space per indent doesn't provide enough contrast for me. So I can place multiple "spaces" with just one press of the tab button.
Furthermore, I like to align comments in their own "column" to the right when declaring variables. Tabs let me align those comments without having to count the number of spaces or press space until I reach the Comment Column.
That's how everyone uses spaces. No one (good) is using single space indentation. Everyone sets up the tab key to insert 2 or 4 spaces. And god, no one is actually pressing the space bar 4 times. Spaces instead of tabs are the exact same thing except the tab character width is less standardized. Switch to spaces ffs.
I firmly believe that the technically correct indentation method is to use tabs, for a number of reasons. Therefore I will always prefer to use tabs over spaces for indentation, and will want others to do the same as well.
This eternal holy war needs to die.
Until it is as convenient (comfortable, fast, etc...) to edit space-indented code as it is to edit tab-indented code, I will have a strong preference for writing tab-indented code. It seems to me that you have no interest in changing your position in this debate, so until one of us changes our minds this war will go on.
If someone gives vim good support for editing space-indented code, or makes another editor that is popular and efficient as vim, then I will probably stop arguing for tab-based indentation. I don't want to do that, however, because it's a difficult problem. If you want to give vim better support for editing space-indented code, then go ahead, and let me know when it's implemented.
Okay, I've installed emacs, but it looks like it will take a while to learn how to use it. Do you have any quick guide for how to configure emacs to edit space-indented code? I want to give it a quick try to see if it's worth spending the time to learn.
So you just clone the git repository into your ~/.emacs.d directory?
Pressing <TAB> where? <TAB> in emacs programming modes does indentation, so you should open/create a source file first
It doesn't do anything when I'm editing a source file, regardless of the language of the file.
I realize that it takes a while to learn a good editor. I only know how to use vim because some coworkers forced me to use it several years ago. I want to make sure that emacs is an improvement over vim before I spend the time to learn to use it.
Would you mind answering a question for me? Is it possible to configure emacs (or spacemacs) so that all of the following are true?
Pressing <TAB> inserts some specified number of spaces (or it inserts spaces until the next multiple of the indent size)
Pressing <TAB> then <BACKSPACE> in that order is a no-op
Pressing <SPACE> then <BACKSPACE> in that order is a no-op
Vim can do 1 and 3 (in any combination) easily, but is unable to do 2 if <TAB> inserts more than 1 space. If emacs can't be configured to do all of 1, 2, and 3 at the same time then I don't think it's worth investing my time to learn emacs.
No, TAB just does indentation, the rest depends on your settings
In emacs you can always press 'F1','k','Key_or_combination' and it shows things Key does:
E.g. for <Backspace> in C-mode
DEL (translated from <backspace>) runs the command
c-electric-backspace
Delete the preceding character or whitespace.
If c-hungry-delete-key' is non-nil (indicated by "/h" on the mode
line) then all preceding whitespace is consumed. If however a prefix
argument is supplied, orc-hungry-delete-key' is nil, or point is
inside a literal then the function in the variable
`c-backspace-function' is called.
the last function itself is
c-backspace-function is a variable defined in `cc-vars.el'.
Its value is backward-delete-char-untabify
Documentation: *Function called by `c-electric-backspace' when deleting backwards.
Do you really want to do all your indentations manually?
Yes, and for multiple reasons:
No autoformatter can always correctly guess what I want.
The less the editor does for me, the easier it is to predict. When I fail to correctly guess how an editor is going to behave I have to notice the difference, figure out what happened, correct it, then continue typing. This breaks my "flow" when I am coding. I'd rather just control indentation manually. The exception is that if I insert a newline after an indented line and/or aligned line then I want the indentation and alignment to carry over to the next line.
For me, using an editor is all about cognitive load and predictability. When I am programming, I first figure out what code I want to insert. Once I've written the code in my head, I then try to type it as quickly as possible, and any errors (unpredicted editor behaviors) may cause me to "lose my train of thought" and forget what I intended to write. While I don't manually re-indent every line, I want my editors to behave in a relatively simple manner so that I can easily (subconsciously) predict their behavior.
I've been using vim's copyindent for a while now, and I am used to how it works. Switching to any other behavior would require a lot of retraining (months or years), and may not bring any improvement.
I don't know about emacs, but vim's "smart" formatter is horrible anyway, and I typically have to go back and fix the code. Because of this need to correct the automatically formatted code anyway, I still need the ability to manually edit indentation and alignment efficiently anyway.
No autoformatter can always correctly guess what I want.
Maybe it depends on language too, but I can't remember any problem with emacs autoformatter (I write mostly in lisp-like languages though, but AFAIK C worked well too), even while refactoring bigger pieces - just press C-M-\ (or M-x indent-region) and it's done.
So you just clone the git repository into your ~/.emacs.d directory?
yes
Luvax ยท 2 points ยท Posted at 21:48:51 on June 20, 2016 ยท (Permalink)*
thers will see the code in the same format I saw it in
Never understood that. Why does your code has to look the same for everyone? What's wrong if I want to use only 2 characters per "tab" when working with your code.
For example, I convert to spaces before turning in CS assignments.
You're well on your way to using tabs and tabs only, padawan. Embrace the Light Tab Side of the Force; do not be ashamed of it, for it will serve you well in the coming times of darkness imposed by the Sith Spaces Order.
Nothing mad about it. I used tabs for years and years until finally switching to spaces (IDE turns tabs into spaces, I don't manually press spacebar, that would be mad).
It just makes more sense when working in teams (especially teams that include newer developers) and to maintain consistency/readability.
I hate that spaces take up more place, but you minify everything anyway.
[deleted] ยท 2 points ยท Posted at 11:43:55 on June 21, 2016 ยท (Permalink)
I asked my boss this question and he said we use python, and that I'm retarded.
Gabe_b ยท 4 points ยท Posted at 19:59:28 on June 20, 2016 ยท (Permalink)
Who gives a shit. Unless it's in a YAML file. Then tabs will ruin your whole day.
[deleted] ยท 1 points ยท Posted at 21:49:24 on June 20, 2016 ยท (Permalink)
So I use a Lisp, Clojure specifically. I've been using a two neat Emacs plugins: agressive-indent and paredit. Syntax you say, tabs or space you say? I don't actually care. It fixes it for me. It does this consistently and perfectly. I don't care anymore. I'm FREEEE
Looks like there are a lot of space haters in here. My reason for using spaces is that I know how wide 80 characters is. If I use tabs, I may exceed the width of 80 characters which can result in funny looking git commits and terminal wraparound, not to mention if the code ever needs to be printed for some reason.
pnpbios ยท 1 points ยท Posted at 22:47:40 on June 20, 2016 ยท (Permalink)
Spaces and tabs are different things. if they were html tags they would be able to be styled differently. IMHO multiple spaces would be collapse to one (unless after a period when it should be more for readability if we are talking prose). Tabs would be based on context. E.e. Cummings would hate me.
I'm curious to see the attachment of the 301 email. If it's a meme that would be me in the dev team.
TinynDP ยท 1 points ยท Posted at 15:34:43 on June 21, 2016 ยท (Permalink)
Automated checkin pre-hook?
myrrlyn ยท 1 points ยท Posted at 20:46:00 on June 22, 2016 ยท (Permalink)
ctrl-f editorconfig => phrase not found
Sweet JESUS people what is wrong with you all.
Get your local editorconfig plugin
Use your tab key to spawn \t characters like a civilized human being.
Use editorconfig to make \t be as wide or narrow you want, on a per-language basis, so literally everyone is happy.
Commit your editorconfig in your project to make everyone see code your way.
Don't set root=true in your project editorconfigs; set that in your project folder editorconfig so that the editorconfig of projects you cloned written by people who are wrong, are overriden by Your Local Truth
We all stop talking about this forever and ever. It's a solved problem, like vim vs emacs. It's 2016, people, use a real editor like Atom ;)
ProcessWire. It's a great CMS but they've decided to make up their own styleguide. But they've added Composer support so it's also taking some good steps.
Why? Because I like to think I respect my code reviewers eyes.
Looking over tabs based content in pull requests gives all kinds of wacky radical formatting...
That said, I used to be tabs when I was a young vigilante single force to be reckoned with army. Two things happened: 1 I used to bounce around editors across multiple systems all the time, and tabs got really annoying to setup to look consistent, and 2 now I work in teams, and all our code needs to co-mingle. Spaces has proven to be very nice to work with. So that's my default now.
When you discover HTML minifiers, your head's gonna explode.
Luvax ยท 1 points ยท Posted at 21:41:03 on June 20, 2016 ยท (Permalink)
Tabs can be anything, 2 spaces, 1 space, 3 spaces or even 8. It's up to you. Tabs are a form of seperating code from it's presentation like in good software design. The only "good" argument I know in favor of tabs is that "they look the same anywhere" which is of course true, but if the indentation of you code is important than your code is shit.
Modern compilers handle this pretty cleanly now, but there was a time long ago (70s-90s), when it actually mattered because the compilers handled tabs and spaces differently and tabs in the code sometimes meant that your program wouldn't compile. It also made a difference in that tabs would cause your code alignment to be skewed, since the editor had a different length for a tab character.
That's okay, you shouldn't be interchanging tabs and spaces for indentation. If you stick to only tabs for indentation then CPython is perfectly happy.
In that case you need to fix it to be consistent. In any other language I'd just tell you to make your IDE (since you just said that you use one) auto-format the code, but that's tricky in a language that doesn't use braces. I think that that's a downside of Python.
True, but CPython is perfectly happy if you indent using tabs.
If I'm working on a personal project (where I'm the only developer/maintainer), then I don't care about language standards, I'm going to use the style that's best for me.
How is the alignment skewed? Does it really matter whether all indentations have a width of e.g. 4 spaces or 8 spaces? I mean, code indented with the same amount of tabs won't just magically have different indentation levels...
(Of course you shouldn't mix tabs and spaces, but who does that?)
Saved comment
Targren ยท 870 points ยท Posted at 12:30:19 on June 20, 2016 ยท (Permalink)
Found the guy using spaces.
*ducks and runs*
Asmor ยท 164 points ยท Posted at 19:49:34 on June 20, 2016 ยท (Permalink)
Look, I wrote the compression algorithm, I think I know a little something about file sizes!
Vider7CC ยท 27 points ยท Posted at 20:22:54 on June 20, 2016 ยท (Permalink)
Heh.. reference.. heh
aceysmith ยท 12 points ยท Posted at 21:28:31 on June 20, 2016 ยท (Permalink)
I know it was his argument not yours, but any worthwhile text compression algorithm should recognize 4/8/16 whatever number of spaces (or the byte sequence that represents it) as a common, repeated sequence in source code and compress that difference away, no problem.
Asmor ยท 59 points ยท Posted at 23:09:23 on June 20, 2016 ยท (Permalink)
That's why I have my editor set to use the Fibbonacci sequence as tab stops.
[deleted] ยท 2 points ยท Posted at 09:23:50 on June 21, 2016 ยท (Permalink)
Still lol'd
Asmor ยท 6 points ยท Posted at 12:44:25 on June 21, 2016 ยท (Permalink)
See, you'd make a good code reviewer!
(why yes, I have sent tickets back for typos in comments before)
gospelwut ยท 27 points ยท Posted at 19:52:44 on June 20, 2016 ยท (Permalink)
Found the guy not using compression.
Baegus ยท 68 points ยท Posted at 20:17:48 on June 20, 2016 ยท (Permalink)
Found the guy not using Pied Piper.
DaylightDarkle ยท 30 points ยท Posted at 20:47:08 on June 20, 2016 ยท (Permalink)
Found the guy using Nucleus
parlez-vous ยท 39 points ยท Posted at 21:10:17 on June 20, 2016 ยท (Permalink)
Found the guy who fucks
Stop_Sign ยท 23 points ยท Posted at 01:39:01 on June 21, 2016 ยท (Permalink)
Found the guy from /r/all
[deleted] ยท -2 points ยท Posted at 04:45:05 on June 21, 2016 ยท (Permalink)
This guy fucks
markswam ยท 1 points ยท Posted at 12:20:56 on June 21, 2016 ยท (Permalink)
Found the guy using Nano.
sixstringartist ยท 21 points ยท Posted at 21:44:41 on June 20, 2016 ยท (Permalink)
more like the dude responding to an argument with memes.
pweifan ยท 23 points ยท Posted at 15:26:33 on June 20, 2016 ยท (Permalink)
Exactly the point I came here to make. Nicely done, sir!
osowhimsy ยท 1 points ยท Posted at 21:28:50 on June 20, 2016 ยท (Permalink)
Can you explain this please?
naseweis520 ยท 4 points ยท Posted at 21:57:22 on June 20, 2016 ยท (Permalink)
FlyingPiranhas ยท 5 points ยท Posted at 22:29:05 on June 20, 2016 ยท (Permalink)
Who codes in a 2-byte encoding?!
Inityx ยท 1 points ยท Posted at 00:20:22 on June 21, 2016 ยท (Permalink)
https://en.wikipedia.org/wiki/UTF-16
FlyingPiranhas ยท 4 points ยท Posted at 00:25:29 on June 21, 2016 ยท (Permalink)
I know what UTF-16 is; in what language would you encode your source in UTF-16?
[deleted] ยท 439 points ยท Posted at 12:11:17 on June 20, 2016 ยท (Permalink)
Behold, the most potent digital holy war in the history of computer science. More bitter than Java/C#, and twice as pointerless.
Personally, I favor tabs since that's what tabs are for. It's not like tabs are some semi-proprietary Microsoft technology, they predate computers and have had a dedicated key since typewriters.
To that end, I have CodeMaid for VisualStudio configured to convert everything to tabs and save as soon as I open a file. I won't argue with my coworkers about which position is superior, but I've picked a side and plan to enforce it.
Coffeinated ยท 245 points ยท Posted at 16:15:24 on June 20, 2016 ยท (Permalink)
Pointerless, ehehe.
[deleted] ยท 41 points ยท Posted at 16:32:03 on June 20, 2016 ยท (Permalink)
I hoped someone would catch that.
LastStar007 ยท 56 points ยท Posted at 18:16:23 on June 20, 2016 ยท (Permalink)
We get it, you dereference
terryaki510 ยท 40 points ยท Posted at 20:02:28 on June 20, 2016 ยท (Permalink)
I got dereference
OriginalToe ยท 11 points ยท Posted at 20:13:57 on June 20, 2016 ยท (Permalink)
Try {
theLabyrinthMaker ยท 42 points ยท Posted at 20:43:29 on June 20, 2016 ยท (Permalink)
}
Sorry, it was bothering me.
Bob_Droll ยท 11 points ยท Posted at 21:20:48 on June 20, 2016 ยท (Permalink)
Is nobody going to catch the fucking exceptions?
jfb1337 ยท 14 points ยท Posted at 21:28:19 on June 20, 2016 ยท (Permalink)
eagle999 ยท 9 points ยท Posted at 21:54:12 on June 20, 2016 ยท (Permalink)
FTFY
[deleted] ยท 5 points ยท Posted at 13:31:55 on June 21, 2016 ยท (Permalink)
[deleted] ยท 3 points ยท Posted at 04:39:54 on June 21, 2016 ยท (Permalink)
This thread has enough flame wars... now tell me, emacs or vim?
JimblesSpaghetti ยท 1 points ยท Posted at 20:21:36 on July 16, 2016 ยท (Permalink)
Textadept
[deleted] ยท 2 points ยท Posted at 04:47:44 on June 21, 2016 ยท (Permalink)
FTFY
lerhond ยท 5 points ยท Posted at 21:52:16 on June 20, 2016 ยท (Permalink)*
There is a (bot for that unless it's banned on this subreddit.
Edit: Ok, it runs only on this subreddit. Well...
parenthesis-bot ยท 6 points ยท Posted at 21:54:32 on June 20, 2016 ยท (Permalink)
)
This is an autogenerated response. source | /u/HugoNikanor
TheBali ยท 2 points ยท Posted at 12:08:51 on June 22, 2016 ยท (Permalink)
Does it works ( for ( multiple ( parenthesis? )
edit: it works, twice.
parenthesis-bot ยท 2 points ยท Posted at 12:08:54 on June 22, 2016 ยท (Permalink)
))
This is an autogenerated response. source | /u/HugoNikanor
parenthesis-bot ยท 1 points ยท Posted at 12:08:58 on June 22, 2016 ยท (Permalink)
))
This is an autogenerated response. source | /u/HugoNikanor
ralpo08 ยท 5 points ยท Posted at 21:03:34 on June 20, 2016 ยท (Permalink)
The indentation is still off, tho
okawei ยท 1 points ยท Posted at 21:16:47 on June 20, 2016 ยท (Permalink)
Nah, indentation looks fine to me: https://www.dropbox.com/s/7bhsx4k8i664ev1/Screenshot%202016-06-20%2017.16.36.png?dl=0
OvergrownGnome ยท 1 points ยท Posted at 22:26:21 on June 20, 2016 ยท (Permalink)
Should be even with the try.
okawei ยท 1 points ยท Posted at 22:29:04 on June 20, 2016 ยท (Permalink)
....Damn it....
Mugen593 ยท 1 points ยท Posted at 01:13:22 on June 21, 2016 ยท (Permalink)
Well I mean they did try.
ribo ยท 101 points ยท Posted at 19:40:33 on June 20, 2016 ยท (Permalink)
http://i.imgur.com/Jq1T5AY.jpg
You are an evil person.
psydave ยท 15 points ยท Posted at 20:10:28 on June 20, 2016 ยท (Permalink)
You just have to configure your diff tools to ignore whitespace...
Matosawitko ยท 17 points ยท Posted at 20:46:35 on June 20, 2016 ยท (Permalink)
git blame, on the other hand...frebib ยท 25 points ยท Posted at 21:00:31 on June 20, 2016 ยท (Permalink)
https://github.com/jayphelps/git-blame-someone-else
drevyek ยท 4 points ยท Posted at 21:26:09 on June 20, 2016 ยท (Permalink)
yup.
Zagorath ยท 20 points ยท Posted at 20:02:53 on June 20, 2016 ยท (Permalink)
Philosophically, I prefer tabs for the exact same reason as you stated. That's literally their purpose. Levels of tabbing indicate the amount of logical indentation in the code.
But I use spaces regardless because from what I can tell, basically every official channel does. It's PEP, it's the style recommended by Google in Java, it's what my university recommends/requires on the occasions they demand a particular style. From my perspective, the argument is done. The wrong side won it, but it's over, except for Internet debates of the same callibre as vim vs emacs or ghif vs jif.
AhrisFifthTail ยท 3 points ยท Posted at 19:14:40 on June 22, 2016 ยท (Permalink)
I'll tab til I die. Friggin' Spacies....
Fenor ยท 3 points ยท Posted at 08:49:01 on June 21, 2016 ยท (Permalink)
well if i recall correctly Sun raccomended tabs and not spaces.
just_comments ยท 1 points ยท Posted at 00:09:23 on June 22, 2016 ยท (Permalink)
Oracle requires spaces in their standards, so Sun now must recommend spaces.
Fenor ยท 1 points ยท Posted at 07:54:39 on June 22, 2016 ยท (Permalink)
well the original sun coding standard where with tabs. now Oracle reccomended spaced because the indentation of queries need to use spaces for a sql-like indentation (wich is setting the space after select from, where vertically)
then they bought Sun. i don't think that the coding standard for java has changed from tabs to space. but finding the oracle documentation suck for both the database and java (unless these are api with the old standard)
it suck so much that when i need to search thing related to oracle or java i always add to the research string -docs.oracle.com (not -oracle.com because the asktom on oracle.com actually make a good job)
just_comments ยท 1 points ยท Posted at 08:01:26 on June 22, 2016 ยท (Permalink)
Oh I was just making a joke because I have a friend who works for Oracle and told me that their standard is spaces only. I have no knowledge of it other than that.
bumblebritches57 ยท 1 points ยท Posted at 03:26:55 on June 22, 2016 ยท (Permalink)
You should be able to set your IDE to convert from/to whichever format you want on save... I know Xcode does for sure.
mellow_gecko ยท 116 points ยท Posted at 16:36:33 on June 20, 2016 ยท (Permalink)
The tab character was originally there so you didn't have to press space four times. Now we can tell the tab button to press space four times for us and the tab character should be laid to rest.
Consistency and beauty above legacy and tradition, please.
Zagorath ยท 98 points ยท Posted at 20:02:27 on June 20, 2016 ยท (Permalink)*
Beauty is exactly why tabs are better. A single tab represents a single level of logical indentation. That's a beautiful, elegant solution, like refactoring your code to pull out something that logically should be its own function into its own function, rather than bluntly throwing it the middle of another one.
EDIT: I just thought of an even better analogy. It's like pressing the "Heading" button in Word and adjusting the space below paragraphs, or \section in LaTeX, rather than just manually increasing the font size and entering blank lines. Sure, it accomplishes the same basic task, but one is far more beautiful. Pressing space a bunch of times (or having the editor do it for you) is exactly like pressing enter a bunch of times to get the right amount of whitespace above your next line.
int__0x80 ยท 4 points ยท Posted at 17:42:01 on June 25, 2016 ยท (Permalink)
I...I think you've just converted me
RunasSudo ยท 2 points ยท Posted at 22:01:04 on June 20, 2016 ยท (Permalink)
Hear, hear!
Zagorath ยท 2 points ยท Posted at 03:49:03 on June 21, 2016 ยท (Permalink)
Fancy seeing you here.
RunasSudo ยท 3 points ยท Posted at 06:30:16 on June 21, 2016 ยท (Permalink)
I come prepared.
Zagorath ยท 1 points ยท Posted at 07:01:03 on June 21, 2016 ยท (Permalink)
Hahaha I wish I could say the same, but no RES on mobile.
ROFLicious ยท 26 points ยท Posted at 19:51:31 on June 20, 2016 ยท (Permalink)
My problem with 4 spaces vs 1 indent is deletion. I have to hit the backspace key 4 times with spaces, as opposed to once with indents. Not to mention that it is also easy to accidentally delete just 1 of the 4 spaces in an indent, therefore ruining the alignment of the code.
FlyingPiranhas ยท 17 points ยท Posted at 19:59:24 on June 20, 2016 ยท (Permalink)
Yes. People keep saying "configure your editor to insert 4 spaces per tab", but always seem to forget everything else about editing space-indented code. If I accidentally hit a character-inserting key that I didn't want to while editing text, then I want backspace to undo the insertion correctly.
Are there any editors that get this correct? I personally use vim for a number of reasons, but it definitely can't be configured into handling <TAB> and <BACKSPACE> correctly when indenting with spaces.
cmpsb ยท 26 points ยท Posted at 20:06:16 on June 20, 2016 ยท (Permalink)
Sublime Text does with both backspace and shift+tab. Notepad++, Visual Studio and Kate have shift+tab too.
FlyingPiranhas ยท 3 points ยท Posted at 20:18:45 on June 20, 2016 ยท (Permalink)
I don't have Sublime Text and am on Linux so I can't test Notepad++ and Visual Studio, but Kate does not seem to handle it correctly. Depending on the setting, either pressing <TAB> then <BACKSPACE> leaves extra spaces or pressing <TAB> then <BACKSPACE> deletes too much.
monster860 ยท 1 points ยท Posted at 01:38:43 on June 21, 2016 ยท (Permalink)
So does atom!
greyfade ยท 17 points ยท Posted at 20:48:35 on June 20, 2016 ยท (Permalink)
Set your
shiftwidthlike a civilized vimmer.FlyingPiranhas ยท 1 points ยท Posted at 20:53:34 on June 20, 2016 ยท (Permalink)
I use
expandtab sw=4 ts=4when editing code indented using groups of 4 spaces, but if I accidentally press <TAB> when I shouldn't have then <BACKSPACE> won't correctly erase all of the inserted spaces.greyfade ยท 8 points ยท Posted at 21:35:33 on June 20, 2016 ยท (Permalink)
I use
expandtab sw=4 ts=4 sts=4 smarttaband I haven't seen that problem in literally years.Edit: Hell, I just did
sw=0 sts=0 ts=4 autoindentand it still behaves correctly... Looks likesmarttabis the one.:set nosmarttaband it starts deleting single spaces.ckcollab ยท 1 points ยท Posted at 21:09:55 on June 20, 2016 ยท (Permalink)
Undo?
FlyingPiranhas ยท 1 points ยท Posted at 21:19:25 on June 20, 2016 ยท (Permalink)
You have to leave insert/append mode to use undo. If I'm in insert/append mode and accidentally hit 1 key that inserts a character that I don't want then I hit backspace to undo that action.
qspec02 ยท 3 points ยท Posted at 21:02:40 on June 20, 2016 ยท (Permalink)
What do you want it to do? I'd have to double check my vimrc, but I am fairly certain that vim can correctly backspace 4 spaces inserted with tab.
FlyingPiranhas ยท 1 points ยท Posted at 21:06:08 on June 20, 2016 ยท (Permalink)
I want both of the following to be true when editing code:
With
noexpandtab, I can get both behaviors pretty easily (by default). Withexpandtab(and an indentation width wider than 1), I cannot get both behaviors simultaneously. In particular, I see no way to get behavior 1 whenexpandtabis enabled and my indentation width is greater than 1.emnoor ยท 1 points ยท Posted at 23:18:47 on June 20, 2016 ยท (Permalink)
If you have ts, sts and sw set, vim should do both 0 and 1 correctly.
FlyingPiranhas ยท 1 points ยท Posted at 23:25:51 on June 20, 2016 ยท (Permalink)
To what values? Assume that my desired indentation width is 4 spaces. A number of people have made suggestions, but none have made both 1 and 2 work correctly (are those 0-indexed for you?).
Zagorath ยท 1 points ยท Posted at 19:59:26 on June 22, 2016 ยท (Permalink)
All ordered lists on this subreddit are automatically converted to be 0-indexed, by the subreddit CSS. If you're on mobile or have CSS turned off, it will display incorrectly.
emnoor ยท 3 points ยท Posted at 23:15:28 on June 20, 2016 ยท (Permalink)
It can be. My vim backspces correctly to 4 spaces when indented and 1 space in other places. There are my indent settings:
iPhritzy ยท 1 points ยท Posted at 03:08:29 on June 21, 2016 ยท (Permalink)
There is also a visual studio plugin called tab sanity. Work likes spaces and that plugin keeps me from pulling my hair out.
kendalltristan ยท 1 points ยท Posted at 03:14:00 on June 21, 2016 ยท (Permalink)
Atom handles it really well. In fact if not for me explicitly specifying spaces in the preferences, I'd have no idea I was using them.
Avambo ยท 4 points ยท Posted at 22:30:16 on June 20, 2016 ยท (Permalink)
I use Atom and it deletes 4 spaces the same way as one tab.
muffsponge ยท 2 points ยท Posted at 20:02:27 on June 20, 2016 ยท (Permalink)
I have the same issue with visual studio. Ctrl+backspace, tab, tab.. is what I end up doing.
northrupthebandgeek ยท 2 points ยท Posted at 20:45:40 on June 20, 2016 ยท (Permalink)
This is one of the reasons I'm an Emacs user. I can highlight the whole buffer and hit Tab once to automatically indent a whole file in accordance with whatever style guide is applicable to my current language, and I can do so with spaces.
Backspace is only for
viheathens.scottpid ยท 3 points ยท Posted at 17:49:09 on June 21, 2016 ยท (Permalink)
How do you know someone uses emacs?
They'll tell you.
ROFLicious ยท 2 points ยท Posted at 19:39:59 on June 21, 2016 ยท (Permalink)
No need to start another flame war, we are already in the midst of one you madman
northrupthebandgeek ยท 2 points ยท Posted at 22:24:08 on June 21, 2016 ยท (Permalink)
Some men just want to watch the world burn.
Foofin ยท 1 points ยท Posted at 23:30:44 on June 20, 2016 ยท (Permalink)
You can just use shift+tab (tabs from right to left) instead of backspace.
ROFLicious ยท 2 points ยท Posted at 19:38:25 on June 21, 2016 ยท (Permalink)
so two buttons instead of one? And it doesn't fix the accidental deletion of 1 space out of the 4 when I am fixing my code.
mellow_gecko ยท 1 points ยท Posted at 01:13:26 on June 21, 2016 ยท (Permalink)*
Depends on your editor, I guess. I never have those issues with vim. Well, I did until I learnt not to use it like notepad.
RedPandaIsBestPanda ยท 1 points ยท Posted at 14:20:32 on June 21, 2016 ยท (Permalink)
Use an IDE that supports shift-tabbing back?
ROFLicious ยท 2 points ยท Posted at 19:37:29 on June 21, 2016 ยท (Permalink)
But why use shift+tab, when I can just backspace?
mqduck ยท 1 points ยท Posted at 04:20:12 on June 22, 2016 ยท (Permalink)
Qt Creator (my personal favorite C/C++ IDE) handles it well also.
lazyklimm ยท 0 points ยท Posted at 20:56:55 on June 20, 2016 ยท (Permalink)
Do you still indent your code manually? It's 2016, man, why just don't let editor do all that boring stuff?
ROFLicious ยท 1 points ยท Posted at 19:39:19 on June 21, 2016 ยท (Permalink)
I'm pretty anal
demize95 ยท 8 points ยท Posted at 21:43:15 on June 20, 2016 ยท (Permalink)
A tab doesn't insert four spaces, it moves to the next tab stop. This makes things much more consistent (particularly if you're pure evil and don't use a monospace font) and leads to better looking code that's easier to configure to your preferences. If you want a tab to equal 50 spaces, then you can set your editor to that!
jaxklax ยท 9 points ยท Posted at 23:08:50 on June 20, 2016 ยท (Permalink)
covers ears LALALALALA!
a_fools_gold ยท 17 points ยท Posted at 18:31:44 on June 20, 2016 ยท (Permalink)
Heretic!
exscape ยท 3 points ยท Posted at 19:38:20 on June 20, 2016 ยท (Permalink)
Isn't 1 tab = 8 spaces the more oldschool value?
worldDev ยท 6 points ยท Posted at 22:56:46 on June 20, 2016 ยท (Permalink)
Its a mess, some people even do 3 spaces. This is why tabs are better, spacies can't even agree on number of spaces. With a tab the ones reading the code can set indentation width dependent on a balance of readability and screen width. That said I use whatever is more prevalent in the language I'm writing in. I don't claim to be special enough to embark on a tab vs space crusade, consistency is more important than both.
laserBlade ยท 2 points ยท Posted at 02:16:35 on June 21, 2016 ยท (Permalink)
I mean, 3 spaces should piss off everybody about equally, so...
oldark ยท 1 points ยท Posted at 16:19:33 on June 22, 2016 ยท (Permalink)
Can confirm, company standard is 3 spaces.
ZHaDoom ยท 2 points ยท Posted at 20:20:00 on June 20, 2016 ยท (Permalink)
nope. You moved your carriage to the next tab stop. Which was setup various ways depending on the manufacture.
[deleted] ยท 27 points ยท Posted at 16:40:09 on June 20, 2016 ยท (Permalink)
Tabs and spaces look the same, being whitespace, and it'd be consistent if everyone would use tab of its intended purpose.
social__assassin ยท 21 points ยท Posted at 19:05:08 on June 20, 2016 ยท (Permalink)
Not to a computer
thrilldigger ยท 3 points ยท Posted at 20:46:30 on June 20, 2016 ยท (Permalink)
And? Are you a computer? If any of my coworkers were computers, maybe that argument would have some value.
mellow_gecko ยท 41 points ยท Posted at 16:42:48 on June 20, 2016 ยท (Permalink)*
You misunderstand my point. The original intended purpose of the tab was not to serve as indentation exactly but to save typists from pressing space four times.
Also, a space is always a character in width, whereas a tab is utterly lawless and inconsistent.
Edit: missed a space
ZHaDoom ยท 19 points ยท Posted at 19:35:52 on June 20, 2016 ยท (Permalink)
Wouldn't have happened if you used tabs.
[deleted] ยท 54 points ยท Posted at 16:54:58 on June 20, 2016 ยท (Permalink)
In your editor, you can usually configure the tab to be any number of spaces you want. I like 4. Some editors default to 2, and it bugs me so it's the first thing I change.
Tabs: Freedom to change how they look to you
Spaces: Step one is replacing all the 2-space indents with 2-spaces
This is why Tabs are the Master Race, and you filthy spacies must be exterminated.
mellow_gecko ยท 16 points ยท Posted at 17:06:56 on June 20, 2016 ยท (Permalink)
Freedom to change the appearance of someone else's art without even producing anything new from it?
Filthy, illogical tab talk right there.
Would you change the indentation of a poem?
No. Unless you were too dumb to understand its importance or had no respect for the artist.
The only conclusion is that tab users see themselves as lower even than poets. Which is pretty fucking dire.
Poetry sucks.
[deleted] ยท 37 points ยท Posted at 17:19:14 on June 20, 2016 ยท (Permalink)
In a heartbeat, spacie. The Tabs are all about freedom.
mellow_gecko ยท 12 points ยท Posted at 17:26:32 on June 20, 2016 ยท (Permalink)
So is graffiti.
[deleted] ยท 16 points ยท Posted at 17:36:23 on June 20, 2016 ยท (Permalink)
Heck yeah. Dumb spacie wouldn't understand real art. You lack the brain power from pressing the space bar so many times.
mellow_gecko ยท 10 points ยท Posted at 17:40:31 on June 20, 2016 ยท (Permalink)
And now I've spoken to you, I can confirm that idiot Tab users are too dumb to realise a single button can be used so we don't have to press space four times.
You keep hold of your legacy character. After it dies, you can drink its rotten juices and pass into the next life with it, knowing you did something stupid.
KJ6BWB ยท 1 points ยท Posted at 22:37:42 on June 20, 2016 ยท (Permalink)
You misspelled "realize".
mellow_gecko ยท 2 points ยท Posted at 01:16:16 on June 21, 2016 ยท (Permalink)
The amount of times I've hit a variable undefined error and scratched my head for literally minutes before realising that in other people's code, "colour" doesn't usually have a 'u'.
[deleted] ยท 0 points ยท Posted at 20:32:08 on June 20, 2016 ยท (Permalink)
In addition, I know of at least one (Drupal) has in it's official documentation to indent with 2 spaces. So if your editor is set to convert spaces to tabs - you're already breaking the API.
thrilldigger ยท 2 points ยท Posted at 20:48:12 on June 20, 2016 ยท (Permalink)
2 spaces is obscene, though not nearly so obscene as 3 or 5. Drupal isn't exactly known for being a particularly intelligent, pure, insightful, or respected platform. It gets the job done, but fuck their official docs.
[deleted] ยท 0 points ยท Posted at 21:50:15 on June 20, 2016 ยท (Permalink)
Chaos and anarchy! If you don't like the docs, then don't use the software. That is what breeds spaghetti code.
hexasquid ยท 1 points ยท Posted at 20:47:43 on June 20, 2016 ยท (Permalink)
It's interesting to hear that drupal is not pure madness.
[deleted] ยท 1 points ยท Posted at 22:54:17 on June 20, 2016 ยท (Permalink)
[deleted]
[deleted] ยท 2 points ยท Posted at 22:58:12 on June 20, 2016 ยท (Permalink)
As long as you're a spacie, you'll never understand why none of that makes sense or why tabs are superior.
Tarmen ยท 1 points ยท Posted at 21:02:28 on June 22, 2016 ยท (Permalink)
YuvalZ ยท 0 points ยท Posted at 19:38:35 on June 20, 2016 ยท (Permalink)
Consistency in more important than freedom. Having every thing look alike is better then every one choosing how it looks like, even of its only for their own eyes.
Wizhi ยท 3 points ยท Posted at 20:08:26 on June 20, 2016 ยท (Permalink)
So color-scheme enforcement is a thing now?
I'm kidding, but really though as long as everyone agrees that "this is indented N levels", why should it be enforced whether 1 level of indention is x or y spaces wide?
YuvalZ ยท 1 points ยท Posted at 20:28:58 on June 20, 2016 ยท (Permalink)
When I rule, Monokai will be the only color-scheme >:)
That's exactly the point, if N levels of indent is always 4N characters long, you will always know at glance of much a line is indented, no matter what editor you use (maybe the font matters a little). That's readability right there, and readability counts.
Wizhi ยท 1 points ยท Posted at 20:44:53 on June 20, 2016 ยท (Permalink)
Now see, this I can get behind!
hexasquid ยท 1 points ยท Posted at 20:50:13 on June 20, 2016 ยท (Permalink)
I can't even.
Solarized is what you mean.
FlyingPiranhas ยท 4 points ยท Posted at 19:56:05 on June 20, 2016 ยท (Permalink)
Are you arguing for tabs or spaces? Each one brings consistency in a different manner
It's more important to me that everyone else's code has a consistent look than that my code looks the same on everyone else's machine as it does on mine.
This is really confusing to talk about :(
YuvalZ ยท 1 points ยท Posted at 20:16:49 on June 20, 2016 ยท (Permalink)
I'm arguing for spaces :) To be honest, when I used to think about this argument it never accrued to me that anyone ever use any number of spaces other than 4, anything else just seems too terrible to think about. So the way I saw it, using spaces means that everything looks the same to everyone always.
But if people out there in the world are using a number that is wrong and not 4, then that's a good argument for using tabs, to prevent the horribleness of non 4 spaces indentation.
FlyingPiranhas ยท 4 points ยท Posted at 20:23:25 on June 20, 2016 ยท (Permalink)
I use width 8 indentation, but I indent with tabs so that people like you don't hate me ;)
There's other arguments for using tabs over spaces:
First, using tabs for indentation and spaces for alignment makes the syntax reflect the semantics of the whitespace. If you do it correctly then automatic tools will have an easier time figuring out what whitespace represents indentation and what whitespace represents alignment.
Second, it's harder (slower) to edit space-based code. Usually you configure <TAB> to insert more than one space, but then <BACKSPACE> doesn't function as an undo the way it does for every other character-inserting key on the keyboard.
batmanasb ยท 3 points ยท Posted at 21:01:25 on June 20, 2016 ยท (Permalink)
The backspace issue is by far my biggest issue with spaces
YuvalZ ยท 1 points ยท Posted at 20:52:18 on June 20, 2016 ยท (Permalink)
I guess each solution solves some problems and creates a few more, just like programming.
The main reason for me for using spaces is that I usually code in python, where its a convention to use 4 spaces. Probably to prevent argument like this one.
I don't agree so much with your first argument. The fact that your file will have a combination of tabs and spaces just seems wrong to me. All your aliments will be ruined on someone else's machine where the width of tab is different. But if you use spaces it will stay clean.
About your second argument, Sublime will automatically delete the 4 spaces with a single backspace. I don't know how it works on every editor, so I guess its a valid point.
darkpaladin ยท 3 points ยท Posted at 21:12:25 on June 20, 2016 ยท (Permalink)
I don't see how your argument justifies spaces. If I like a 2 space indent and you like a 4 space indent we can both use tabs and both get our way. It's fine to say don't mix the two but spaces aren't superior.
YuvalZ ยท 1 points ยท Posted at 21:34:09 on June 20, 2016 ยท (Permalink)
If we both agree that if you use tabs, then you should use only tabs, then spaces gives you more control of how your code will look like. For example, If I have a function with a lot of arguments, and I want all the arguments to be on a different line while having the same aliment as the first arg. With spaces you can do it, with tabs, you can't.
And I don't necessarily think that spaces are superior, I think that spaces with a consistent length (like 4) are superior.
FlyingPiranhas ยท 1 points ยท Posted at 15:46:33 on June 21, 2016 ยท (Permalink)
Ummm... tabs for indentation, spaces for alignment. I line up function arguments all the time and haven't had issues with changing tab sizes in a while.
FlyingPiranhas ยท 2 points ยท Posted at 20:57:13 on June 20, 2016 ยท (Permalink)
True, and I clearly value some of the tradeoffs over others.
No, that's why you align with spaces. If you do it correctly, then changing tab sizes should "just work". I have a Rust project where I edit it with 8-wide tabs but have configured GitHub to display it using 4-wide tabs because the Rust community using 4-wide indentation. It works perfectly fine.
I use the command line extensively so I don't see myself using Sublime anytime soon, but if I insert 3 spaces then press backspace will it only delete the last space?
YuvalZ ยท 1 points ยท Posted at 21:16:57 on June 20, 2016 ยท (Permalink)
I'm writing from my phone, so i'm not sure, but if I remember correctly Sublime will delete as many spaces as necessary to snap to the "grid". So if you have 3 spaces it will delete all of them, but if you have 6 then it will only delete 2.
FlyingPiranhas ยท 1 points ยท Posted at 21:20:31 on June 20, 2016 ยท (Permalink)
That's what I would expect based on other editors, and is a problem because you don't always want that behavior.
If I accidentally add an extra space anywhere in my code except the indentation, then backspace should only remove 1 character.
YuvalZ ยท 1 points ยท Posted at 21:41:48 on June 20, 2016 ยท (Permalink)
I think we're going into argument that are starting to become irrelevant in comparison to the "main arguments". You can talk forever about all the little nuances of what is better. But eventually the I'm used to x spaces/tabs is probably the best one.
FlyingPiranhas ยท 1 points ยท Posted at 21:44:33 on June 20, 2016 ยท (Permalink)
I'm discussing editor configuration because although I prefer to edit tab-indented code, I'm occasionally (soon to be frequently) forced to edit space-indented code and would like it to be as painless as possible.
_cortex ยท 1 points ยท Posted at 20:21:44 on June 20, 2016 ยท (Permalink)
Some languages' style guides ask for 2, some older developers ask for 8 and to never nest more than 3 or 4 blocks deep.
parenthesis-bot ยท 0 points ยท Posted at 19:58:07 on June 20, 2016 ยท (Permalink)
:)
This is an autogenerated response. source | /u/HugoNikanor
PBI325 ยท 1 points ยท Posted at 18:44:25 on June 20, 2016 ยท (Permalink)
And it still does, so what's your point? It literally takes a measurable amount of time to have to type out spaces and remember how many to do where and whatnot. Makes brain hurt, *grunt*
mellow_gecko ยท 2 points ยท Posted at 18:44:55 on June 20, 2016 ยท (Permalink)
You poor thing...
levir ยท 0 points ยท Posted at 21:12:45 on June 20, 2016 ยท (Permalink)
Technically not true.
ADSRelease ยท 2 points ยท Posted at 22:24:41 on June 20, 2016 ยท (Permalink)
what is your argument for spaces? you just said "consistency and beauty" without giving any reasons for why and how it might have those traits
Genion1 ยท 2 points ยท Posted at 16:11:43 on June 21, 2016 ยท (Permalink)
"consistency and beauty" when you want to align multiple lines independent of indentation level. E.g. a list of numbers of varying magnitudes or function arguments that span multiple lines.
ADSRelease ยท 3 points ยท Posted at 16:27:00 on June 21, 2016 ยท (Permalink)
Sure but we're talking about indentation
Genion1 ยท 0 points ยท Posted at 09:29:30 on June 22, 2016 ยท (Permalink)
Yeah but most people using tabs also align with tabs.
ADSRelease ยท 1 points ยท Posted at 10:36:33 on June 26, 2016 ยท (Permalink)
The conversation most people are having revolves around what fills the space between the line start and the first element of text only
bumblebritches57 ยท 2 points ยท Posted at 03:27:47 on June 22, 2016 ยท (Permalink)
Tabs are better for teams where everyone has different opinions on how many spaces to indent.
Fenor ยท 1 points ยท Posted at 08:49:29 on June 21, 2016 ยท (Permalink)
consistency and beauty is the tab key. not the space key
mellow_gecko ยท -2 points ยท Posted at 11:26:13 on June 21, 2016 ยท (Permalink)
Says your grandma.
Fenor ยท 2 points ยท Posted at 11:34:24 on June 21, 2016 ยท (Permalink)
because even her is smart enought to recognize that tabs are superior
mellow_gecko ยท -2 points ยท Posted at 12:23:43 on June 21, 2016 ยท (Permalink)
Says your grandma.
Fenor ยท 2 points ยท Posted at 12:40:10 on June 21, 2016 ยท (Permalink)
Says your grandpa.
psydave ยท 1 points ยท Posted at 20:09:29 on June 20, 2016 ยท (Permalink)
You can tab once to insert 4 spaces, but why backspace 4 times?
Consistency and beauty? Hah. My tab indented code probably looks prettier than yours. (I focus a lot on readability, more than most other programmers.)
lazyklimm ยท -2 points ยท Posted at 20:53:33 on June 20, 2016 ยท (Permalink)
I don't need a backspace to fix indentation level, my <TAB> key doesn't insert tab-or-spaces-or-poop-emoji-whatever either, it just INDENTS CODE to the right position the way I configured it (no '\t's), so I don't f****** care.
gospelwut ยท 5 points ยท Posted at 19:53:23 on June 20, 2016 ยท (Permalink)
Are you sure it's holier than vim/emacs?
TropicalAudio ยท 2 points ยท Posted at 21:22:34 on June 20, 2016 ยท (Permalink)
I'd say yes. Vim won that battle years ago, so it's less interesting these days. There are still quite a few people left who don't realise that tabs are inferior to spaces.
[deleted] ยท 5 points ยท Posted at 22:58:09 on June 20, 2016 ยท (Permalink)*
[deleted]
TropicalAudio ยท 3 points ยท Posted at 23:30:50 on June 20, 2016 ยท (Permalink)
Oh come on, I'm trying to start a high-quality flame war over here. The proper reaction is:
But mostly because getting a whole team to use tabs one certain way is a nightmare (some use tabs for indentation / spaces for alignment, others litter tabs throughout the lines for alignment because now their tab key is not configured to insert four spaces) and there are no real downsides to using spaces in any modern editor. As long as you're not using Microsoft Notepad, your tab key still indents and your backspace key still de-indents, but your code doesn't turn into a mess.
Also, when using tabs, people are less strict about staying within our 100-column limit (because they were using 2- or 1-width tabs) which is pretty awful when trying to use a side-by-side diff-tool.
Back when I just started programming I preferred tabs, but now that I've experienced tabs in the workplace, my aversion of spaces has been completely cured.
FlyingPiranhas ยท 1 points ยท Posted at 16:02:27 on June 21, 2016 ยท (Permalink)
Reasons to use tabs for indentation:
Reasons to use spaces for indentation:
I wouldn't say that there are no real downsides to using spaces in modern editors, only tradeoffs.
TropicalAudio ยท 1 points ยท Posted at 16:17:42 on June 21, 2016 ยท (Permalink)
But in an attempt to keep some sort of flame war going, let's nitpick the reasons for tabs apart!
The problem is that, by nature of at least some people in a team not being very careful, there will be tabs littered through the code used for alignment. Any code analyser that assumes every tab is an indent will give faulty results in any code that doesn't go through very thorough code review and we all know no one actually does that. You could fix your analyser to take the littered tabs into account, but at that point it should also handle spaces flawlessly, so that's not a reason to use tabs any more.
Use a better editor! Refer to any of the vim vs emacs crusading threads for more details.
FlyingPiranhas ยท 1 points ยท Posted at 19:04:37 on June 21, 2016 ยท (Permalink)
I currently use vim, and would probably put in the effort to learn how to use emacs if I knew it would solve that problem. The issue is that I need someone to prove to me that emacs would handle space-based indentation better, and I don't know anyone who can show me how to configure emacs. A couple of people here on Reddit have tried to help, but posting links to emacs documentation is insufficient -- it has quite the learning curve.
TropicalAudio ยท 1 points ยท Posted at 07:09:21 on June 22, 2016 ยท (Permalink)
set softtabstop=4should fix most of your problems.ELFAHBEHT_SOOP ยท 21 points ยท Posted at 13:00:20 on June 20, 2016 ยท (Permalink)*
I prefer tabs replaced by 2 or 4 spaces.
Tabs are a quick way to get there, but some editors like to make them really big. Which is kind of annoying. So it's convenient to have your editor set up to replace them with spaces.
Edit: I never realized the amount of butthurt I was walking into.
G3Kappa ยท 67 points ยท Posted at 13:48:55 on June 20, 2016 ยท (Permalink)
Or have your editor set up to have a tab width of 4 spaces instead of 8?
I mean, it's your editor. You can do whatever you want.
lazyklimm ยท 5 points ยท Posted at 17:12:44 on June 20, 2016 ยท (Permalink)
โ It's a free country, ain't it?
โ Well it ain't a free shop, is it? So fuck off!
Slak44 ยท 11 points ยท Posted at 14:00:59 on June 20, 2016 ยท (Permalink)
You can't always view files using your preferred editor, and sometimes you must view them on a foreign computer. Spaces will be consistent, while tabs are likely different.
Cathercy ยท 37 points ยท Posted at 14:08:34 on June 20, 2016 ยท (Permalink)
What work are you doing that you often need to view code on a foreign computer? Often enough that it is the deciding factor on tabs vs spaces?
MagicallyVermicious ยท 4 points ยท Posted at 20:08:27 on June 20, 2016 ยท (Permalink)
Companies that manage their own code repositories, code review tools, browser-based UIs for viewing deployed code, and so on, and when not all of them use the same method of rendering tabs or monospaced fonts.
Slak44 ยท 3 points ยท Posted at 14:17:18 on June 20, 2016 ยท (Permalink)
I don't do it often enough to call it a deciding factor, but it sure is useful when I have to.
gokjib ยท 12 points ยท Posted at 16:28:46 on June 20, 2016 ยท (Permalink)
Then what is the deciding factor?
notsooriginal ยท 4 points ยท Posted at 18:29:00 on June 20, 2016 ยท (Permalink)
The right to have an opinion and never change your mind, regardless of logic. /s
ELFAHBEHT_SOOP ยท 1 points ยท Posted at 18:35:15 on June 20, 2016 ยท (Permalink)
Well the philosophy that I enjoy using is based on "write once, run anywhere". This means including all of the libraries with the code, including project files with the code, and generally making the code the easiest possible to work with and run.
This includes formatting, and with formatting comes spacing. The least finicky of the two, between spaces and tabs, is spaces. They always take up one character space. They are predictable. From my editor, to anyone elses editor, it will all display pretty much the same.
Even if they happen to be using notepad for some reason. They won't be forced to deal with 8-character tabs.
All this being said, I still use the tab key. I don't pound on the space key like some sort of caveman.
FlyingPiranhas ยท 5 points ยท Posted at 18:43:07 on June 20, 2016 ยท (Permalink)
Why do you want your code to display the same for everyone else? Your preferences shouldn't take precedence over the preferences of the people trying to read and/or edit your code.
By choosing to use spaces, you are forcing everyone to use your preferred indentation width. At least by using tabs you are giving everyone with a decent (non-Notepad) editor a choice.
[deleted] ยท 3 points ยท Posted at 19:45:44 on June 20, 2016 ยท (Permalink)
But I already force them to use my preferred variable names, line breaks, vertical whitespace (i.e. empty lines), etc. For better or worse, source code is not generally stored as an AST.
ELFAHBEHT_SOOP ยท 0 points ยท Posted at 18:50:02 on June 20, 2016 ยท (Permalink)
If you have a decent editor, and you don't like it, then format the document. You are capable of doing so if you have an editor that is made for programming.
FlyingPiranhas ยท 3 points ยท Posted at 19:04:53 on June 20, 2016 ยท (Permalink)
That doesn't work if the code is in a shared repository and we will both be working on it.
ELFAHBEHT_SOOP ยท 1 points ยท Posted at 21:56:43 on June 20, 2016 ยท (Permalink)
Yeah, hopefully we have a code standard by that time. Conflicting formats wouldn't be a problem at that point.
Wizhi ยท 2 points ยท Posted at 20:14:35 on June 20, 2016 ยท (Permalink)
Why should the document change, every time someone wants to view it? Wouldn't it be more optimal to just change how it's displayed?
That's kind of what modern editors do with tabs.
ELFAHBEHT_SOOP ยท 1 points ยท Posted at 21:59:32 on June 20, 2016 ยท (Permalink)
This is in the context of an open source project that people download and modify. Not making revisions that go back into the main branch
anotherdonald ยท 14 points ยท Posted at 13:50:11 on June 20, 2016 ยท (Permalink)
You evil person.
ELFAHBEHT_SOOP ยท 12 points ยท Posted at 14:37:51 on June 20, 2016 ยท (Permalink)
Actually, that's dumb. 2 spaces isn't enough to see a significant difference.
4 spaces seems pretty good, but 3 spaces seems just right. I don't know many people that use 3 spaces though. It usually seems to either be 2 or 4.
mellow_gecko ยท 17 points ยท Posted at 16:35:04 on June 20, 2016 ยท (Permalink)
3 might be the magic number but in this instance it would be evil.
ELFAHBEHT_SOOP ยท 2 points ยท Posted at 16:39:46 on June 20, 2016 ยท (Permalink)
Why?
mellow_gecko ยท 9 points ยท Posted at 16:44:16 on June 20, 2016 ยท (Permalink)
Unfortunately Reddit's markup doesn't allow me to show you.
It's so evil Reddit won't even let me do it.
lx45803 ยท 9 points ยท Posted at 17:59:22 on June 20, 2016 ยท (Permalink)
Just throw 4 spaces in front of every line.
[deleted] ยท 10 points ยท Posted at 18:49:45 on June 20, 2016 ยท (Permalink)
Like...like a tab?
(Yes, I know it focus on the next element in the browser here, but still)
[deleted] ยท 6 points ยท Posted at 18:58:03 on June 20, 2016 ยท (Permalink)
A tab is 8 spaces.
[deleted] ยท 1 points ยท Posted at 19:10:29 on June 20, 2016 ยท (Permalink)
Damn. I had no idea. I can't remember a time I used tab and it actually moved the cursor 8 spaces. Do any IDEs or text editors use that as a default or is that a legacy definition of some sort?
[deleted] ยท 3 points ยท Posted at 19:23:03 on June 20, 2016 ยท (Permalink)
IIRC 4 spaces is the Windows standard, 8 spaces is the Unix standard. I know for a fact that in Python and Haskell, it's 8 spaces.
[deleted] ยท 2 points ยท Posted at 19:30:51 on June 20, 2016 ยท (Permalink)
Okay, that makes sense.
I use tabs for C++, Java, and web dev stuff, but hadn't realized I use 2 spaces in Python instead of tab until you mentioned it. Never fiddled with Haskell.
Thanks for informing me!
FlyingPiranhas ยท 1 points ยท Posted at 19:14:34 on June 20, 2016 ยท (Permalink)
Almost every command line tool I'm familiar with defaults to a tab width of 8, including editors.
[deleted] ยท 0 points ยท Posted at 21:13:50 on June 20, 2016 ยท (Permalink)
Thatms way too many, I prefer 2 spaces
flukus ยท 0 points ยท Posted at 22:05:20 on June 20, 2016 ยท (Permalink)
A tab is however many spaces you want it to be.
mellow_gecko ยท 3 points ยท Posted at 18:10:37 on June 20, 2016 ยท (Permalink)
Nice
Auxx ยท 24 points ยท Posted at 17:32:15 on June 20, 2016 ยท (Permalink)
That's the reason to use tabs - everyone in a team can set their editor to their liking and have indentation at 2, 3, 4 or whatever spaces they want! Buy the source code will be the same. Tabs forever!
northrupthebandgeek ยท 3 points ยท Posted at 20:53:59 on June 20, 2016 ยท (Permalink)
As a spacie, I'll gladly convert to tabs if there's an editor that lets me set the tab width to ฯ.
TropicalAudio ยท 3 points ยท Posted at 21:20:10 on June 20, 2016 ยท (Permalink)*
...literally every editor I've ever used has that option. You might want to use something that is not Microsoft Notepad.Well shit. I read it on mobile and with my font it looked like an n. Whoops.
However
It is possible. In vim, you can change the visual character that shows up as the final char in a tab. You can edit a font (in something like FontForge) to include a whitespace character of width 0.14 and use tabs of width 4. BAM, tab with width ฯ!
That said, spaces4lyfe. If you set softtabstop=4, this method also works with spaces.
winthrowe ยท 1 points ยท Posted at 22:22:18 on June 20, 2016 ยท (Permalink)
I've never seen an editor with that option. It always seems restricted to integers.
HomemadeBananas ยท 4 points ยท Posted at 20:14:48 on June 20, 2016 ยท (Permalink)
Yes it is, for many people. Some style guides say to use 2 spaces, like Ruby's. 2 spaces is obviously at a different indent level vs no spaces in front of a line. I don't know how you wouldn't be able to see it.
ELFAHBEHT_SOOP ยท 1 points ยท Posted at 21:58:24 on June 20, 2016 ยท (Permalink)
You can, but it doesn't seem like enough space for me. Just personal preference.
typhoon_2099 ยท 2 points ยท Posted at 17:06:42 on June 20, 2016 ยท (Permalink)
It works fine when I use it for SCSS files.
YourLocalFax ยท 1 points ยท Posted at 22:31:29 on June 20, 2016 ยท (Permalink)
I prefer 3,but i use 4 most often and I don't know why.
[deleted] ยท 1 points ยท Posted at 17:07:26 on June 20, 2016 ยท (Permalink)
I use tabs as 3 spaces
qspec02 ยท 0 points ยท Posted at 21:04:51 on June 20, 2016 ยท (Permalink)
I like 2 spaces for my html. 8 for C, and 4 for just about everything else.
Goheeca ยท 3 points ยท Posted at 17:18:57 on June 20, 2016 ยท (Permalink)
Yeah, doubled tabs are truly evil.
[deleted] ยท 3 points ยท Posted at 13:49:56 on June 20, 2016 ยท (Permalink)
We should share a repo and let our editors duke it out.
[deleted] ยท 2 points ยท Posted at 18:35:39 on June 20, 2016 ยท (Permalink)
[deleted]
ELFAHBEHT_SOOP ยท 1 points ยท Posted at 18:43:40 on June 20, 2016 ยท (Permalink)
Sometimes I'm forced to if I have to make a fix and I only have command line compilers to work with. However, that's usually on Linux, and I just use nano at that point. Which is pretty good about tabs.
levir ยท 1 points ยท Posted at 21:17:07 on June 20, 2016 ยท (Permalink)
mhm
nano --tabsize 4 filedicaparly ยท 2 points ยท Posted at 22:26:04 on June 20, 2016 ยท (Permalink)
Id venture to say the Vi/Emacs war is almost as bad
jmachee ยท 3 points ยท Posted at 20:18:40 on June 20, 2016 ยท (Permalink)
I counter with:
"Pronounce 'GIF'."
nemec ยท 5 points ยท Posted at 23:40:51 on June 20, 2016 ยท (Permalink)
GIraFfe
jmachee ยท 1 points ยท Posted at 02:09:08 on June 21, 2016 ยท (Permalink)
http://i.imgur.com/sWkqx13.gifv
bumblebritches57 ยท 1 points ยท Posted at 03:30:54 on June 22, 2016 ยท (Permalink)
Disgusting.
[deleted] ยท 0 points ยท Posted at 03:44:56 on June 21, 2016 ยท (Permalink)
GIt Fucked. HARD G MASTER RACE
lazyklimm ยท 1 points ยท Posted at 16:27:39 on June 20, 2016 ยท (Permalink)
thats it
So, there is no need for a separate tab symbol anymore, in modern editors you can insert as many spaces as you want by pressing one key.
[deleted] ยท 15 points ยท Posted at 16:30:23 on June 20, 2016 ยท (Permalink)
So why not use the tab key?
marishtar ยท 2 points ยท Posted at 19:34:18 on June 20, 2016 ยท (Permalink)
We do. Pretty much every IDE has the option to decide whether or not to put tabs or spaces when tab is pressed.
mellow_gecko ยท 2 points ยท Posted at 16:37:55 on June 20, 2016 ยท (Permalink)
What, redefine the tab character to mean an arbitrary number of spaces?
Hmm...
That's either utter idiocy or genius. I honestly can't tell which.
[deleted] ยท 11 points ยท Posted at 16:39:13 on June 20, 2016 ยท (Permalink)
Well, what other key would you reassign to increase line indent?
If you're not using the tab key to produce tab characters, might as well assign it to 4 spaces.
lazyklimm ยท 3 points ยท Posted at 16:45:25 on June 20, 2016 ยท (Permalink)
exactly
mellow_gecko ยท 4 points ยท Posted at 16:45:38 on June 20, 2016 ยท (Permalink)
Oh, I thought you meant redefine '\t' as ' '*x
Obviously the tab key itself is there so you don't have to press space four times.
[deleted] ยท 3 points ยท Posted at 16:52:04 on June 20, 2016 ยท (Permalink)
Exactly, except some people prefer spaces.
mellow_gecko ยท 8 points ยท Posted at 16:55:40 on June 20, 2016 ยท (Permalink)
Hahahahaha. Fuck you.
The '\t' character is legacy and the button is there to print ' '*4.
[deleted] ยท 3 points ยท Posted at 16:59:03 on June 20, 2016 ยท (Permalink)
Sounds like spacie logic to me.
Tab Master Race.
mellow_gecko ยท 1 points ยท Posted at 17:02:19 on June 20, 2016 ยท (Permalink)
At least I'm not keeping something alive that wants to die.
I'm a nice person.
But you know why you have that crushing sense of guilt just before you sleep each night.
[deleted] ยท 2 points ยท Posted at 17:22:45 on June 20, 2016 ยท (Permalink)
No spacie is a nice person. You'd stab a Tab in the back first chance you get. Ruining my nice repositiories with your trashy spaces.
mellow_gecko ยท 1 points ยท Posted at 17:25:08 on June 20, 2016 ยท (Permalink)
Dude, I have a script to convert all my nicely spaced work to tabs before committing to shitty tab-dominated repositories like yours.
Because I'm nice unlike you who assumes the worst of everyone because you're stuck in ASCII land.
Seriously that shit is dead. Let it die.
[deleted] ยท 2 points ยท Posted at 17:37:25 on June 20, 2016 ยท (Permalink)
Tab exists in Unicode also.
mellow_gecko ยท 0 points ยท Posted at 17:42:40 on June 20, 2016 ยท (Permalink)
Only for the sake of backwards compatibility with legacy shit.
I'm impressed that we appear to be arguing twice simultaneously in two different threads.
But I guess, nonetheless, a filthy tabster will never be a truly worthy intellectual rival. Shame. We almost had a thing.
lazyklimm ยท 1 points ยท Posted at 16:44:25 on June 20, 2016 ยท (Permalink)
Oh man, what year are you living in?
mellow_gecko ยท 2 points ยท Posted at 16:50:04 on June 20, 2016 ยท (Permalink)
2016 but I had to check. Why do you ask?
lazyklimm ยท 5 points ยท Posted at 16:57:16 on June 20, 2016 ยท (Permalink)
Because here in 2016 most modern editors have such option
mellow_gecko ยท 3 points ยท Posted at 17:00:18 on June 20, 2016 ยท (Permalink)
...
Modern editors can't change the accepted ASCII/UTF-8 definition of '\t'
Modern editors can only replace those dumb characters with the spaces that should be there.
lazyklimm ยท 6 points ยท Posted at 17:10:17 on June 20, 2016 ยท (Permalink)
oh, fuck '\t', I meant the Tab key.
flukus ยท 1 points ยท Posted at 22:07:44 on June 20, 2016 ยท (Permalink)
No, they don't replace the tabs with spaces.
lazyklimm ยท 1 points ยท Posted at 16:39:23 on June 20, 2016 ยท (Permalink)*
There's no reason to not use the tab key, I use it myself to make proper indentation (with space symbols) in emacs all the time :)
P.S. $0.02 from JWZ
psydave ยท 2 points ยท Posted at 20:08:05 on June 20, 2016 ยท (Permalink)
OMG thank you. It just never made sense to me to do it any other way. Why tab once and backspace 4 (or more?) times?
jrh3k5 ยท 8 points ยท Posted at 21:22:07 on June 20, 2016 ยท (Permalink)
Most IDEs are smart enough to not require you to backspace through each of the space characters when it senses that it's an indentation.
the_noodle ยท 0 points ยท Posted at 23:44:03 on June 20, 2016 ยท (Permalink)
Why use an IDE or editor that can't fix that problem? Switching to tabs is just admitting defeat
psydave ยท 2 points ยท Posted at 00:17:50 on June 21, 2016 ยท (Permalink)
It's not defeat if it was never a goal to begin with.
And... if you're developing on Windows for .Net, your only real choice is Visual Studio. There's probably some extension somewhere which does that, but why fight it?
RainbowCatastrophe ยท 3 points ยท Posted at 18:27:02 on June 20, 2016 ยท (Permalink)
You're reckoning to start another holy war mentioning that monstrosity... long live vim
[deleted] ยท 1 points ยท Posted at 18:18:55 on June 20, 2016 ยท (Permalink)
ctrl-K, D does that too, and without a plugin.
Kinglink ยท 1 points ยท Posted at 20:37:44 on June 20, 2016 ยท (Permalink)
You know what's good about tabs? You can define what a tab is... How big it is and even better it takes the same size in the file no matter what. Why is this a discussion?
svtguy88 ยท 1 points ยท Posted at 21:51:19 on June 20, 2016 ยท (Permalink)
เฒ _เฒ
I applaud your dedication, however, unless you are the one making decisions for the whole team, I think it's best to discuss things like this, and settle on a solution. Flip flopping from tabs to spaces can make for some real bitchy merges.
Fenor ยท 1 points ยท Posted at 08:47:36 on June 21, 2016 ยท (Permalink)
ok but how do you compare this digital holywar to the Vim/emacs?
[deleted] ยท 1 points ยท Posted at 12:42:22 on June 22, 2016 ยท (Permalink)
Or your team could could just agree on a fucking style and enforce it on check-in to SCM.
[deleted] ยท 0 points ยท Posted at 12:44:55 on June 22, 2016 ยท (Permalink)
I refuse to negotiate with spacie scum.
windowsphoneguy ยท 52 points ยท Posted at 12:01:03 on June 20, 2016 ยท (Permalink)
This was a really funny moment in the Apple WWDC Platforms state of the Union presentation. Had to laugh when he said "You know, it doesn't matter once it's compiled"
Cathercy ยท 136 points ยท Posted at 14:24:01 on June 20, 2016 ยท (Permalink)
This. That's why I make all of my code a big one-liner.
Furyful_Fawful ยท 53 points ยท Posted at 16:06:37 on June 20, 2016 ยท (Permalink)
Python developers hate him!
ThatSwedishBastard ยท 62 points ยท Posted at 17:33:42 on June 20, 2016 ยท (Permalink)
PythonAll developers hate him!northrupthebandgeek ยท 11 points ยท Posted at 20:57:28 on June 20, 2016 ยท (Permalink)
Except Perl hackers, of course.
mikbob ยท 1 points ยท Posted at 12:36:27 on July 9, 2016 ยท (Permalink)
FTFY
Wacov ยท 5 points ยท Posted at 19:41:40 on June 20, 2016 ยท (Permalink)
I just can't interpret this absurd approach
bumblebritches57 ยท 1 points ยท Posted at 03:31:44 on June 22, 2016 ยท (Permalink)
and that's part of the reason I don't use python
PBI325 ยท 8 points ยท Posted at 18:48:47 on June 20, 2016 ยท (Permalink)
This was also the argument killer on the June 12th episode of Silicon Valley.
Zagorath ยท 5 points ยท Posted at 20:10:49 on June 20, 2016 ยท (Permalink)
You know, I've been avoiding watching the latest season of that. I thought I'd be okay waiting for it be over so I could binge watch it. "It's not Game of Thrones, after all, there's nothing in the way of spoilers that could be a problem", I said. I don't think I can count the number of times I've been proven wrong about thatโฆ
break_main ยท 23 points ยท Posted at 10:56:52 on June 20, 2016 ยท (Permalink)
so what did you guys decide?
HeWhoCouldBeNamed ยท 53 points ยท Posted at 11:03:11 on June 20, 2016 ยท (Permalink)
Double spaces, of course.
abeaba ยท 149 points ยท Posted at 14:52:43 on June 20, 2016 ยท (Permalink)*
2 spaces + 1 tab to satisfy everyone ยฏ\_(ใ)_/ยฏ
Bonus points if each line is different from the previous one:
[deleted] ยท 69 points ยท Posted at 17:11:14 on June 20, 2016 ยท (Permalink)
dude stop
Ferdi265 ยท 32 points ยท Posted at 19:55:05 on June 20, 2016 ยท (Permalink)
Encode morse-messages in your whitespace with tabwidth=1 where tab is long while space is short.
thrilldigger ยท 23 points ยท Posted at 20:53:29 on June 20, 2016 ยท (Permalink)
Just program in whitespace, ya fuckin' casual.
Treyzania ยท 3 points ยท Posted at 20:54:23 on June 20, 2016 ยท (Permalink)
เฒ _เฒ
just_comments ยท 1 points ยท Posted at 00:10:34 on June 22, 2016 ยท (Permalink)
https://xkcd.com/1167/
xkcd_transcriber ยท 1 points ยท Posted at 00:10:57 on June 22, 2016 ยท (Permalink)
Image
Mobile
Title: Star Trek into Darkness
Title-text: Of course, factions immediately sprang up in favor of '~*~sTaR tReK iNtO dArKnEsS~*~', 'xX_StAr TrEk InTo DaRkNess_Xx', and 'Star Trek lnto Darkness' (that's a lowercase 'L').
Comic Explanation
Stats: This comic has been referenced 20 times, representing 0.0173% of referenced xkcds.
xkcd.com | xkcdย sub | Problems/Bugs? | Statistics | Stopย Replying | Delete
thecatdidthatnotme ยท 11 points ยท Posted at 11:23:34 on June 20, 2016 ยท (Permalink)
Huhumm You mean 4 spaces, don't you?
Don_Equis ยท 16 points ยท Posted at 11:40:37 on June 20, 2016 ยท (Permalink)
I use double tabs.
Edit: but I'm open to use 4 1-space tabs.
_LePancakeMan ยท 1 points ยท Posted at 14:30:24 on June 20, 2016 ยท (Permalink)
but are you also open to using a 2-tab tab?
HeWhoCouldBeNamed ยท 3 points ยท Posted at 11:48:00 on June 20, 2016 ยท (Permalink)
No, two spaces. I don't actually stand by that, but I once worked on a project where that was enforced. Everything looked do weird, the angles were all wrong.
UnchainedMundane ยท 3 points ยท Posted at 15:29:59 on June 20, 2016 ยท (Permalink)
Well, I think we can reach a compromise.
The new company standard will be 3 spaces.
thecatdidthatnotme ยท 6 points ยท Posted at 15:57:18 on June 20, 2016 ยท (Permalink)
Just like 0.5-based indexing!
UnchainedMundane ยท 6 points ยท Posted at 16:23:21 on June 20, 2016 ยท (Permalink)
That makes perfect sense though. Consider a grid. There are vertical lines at x=0, x=1, x=2, etc. If you want to reference the first cell in that grid, you need to be at x=0.5 so that you land inside the cell.
the_noodle ยท 2 points ยท Posted at 23:46:26 on June 20, 2016 ยท (Permalink)
See: python split notation
the_noodle ยท 0 points ยท Posted at 23:46:10 on June 20, 2016 ยท (Permalink)
That's basically what python splits do though
BoxOfSnoo ยท 3 points ยท Posted at 14:54:47 on June 20, 2016 ยท (Permalink)
Only after punctuation.
HeWhoCouldBeNamed ยท 2 points ยท Posted at 19:35:34 on June 20, 2016 ยท (Permalink)
Of course:
[deleted] ยท 6 points ยท Posted at 21:11:44 on June 20, 2016 ยท (Permalink)
1 Tab + 4x ZERO_WIDTH_SPACE should make everyone happy
[deleted] ยท 22 points ยท Posted at 18:02:13 on June 20, 2016 ยท (Permalink)*
[deleted]
ToKe86 ยท 36 points ยท Posted at 23:27:37 on June 20, 2016 ยท (Permalink)
LobsterThief ยท 11 points ยท Posted at 03:03:36 on June 21, 2016 ยท (Permalink)
Man, this is refreshingly readable. Especially the justify-aligned nature of it -- spaces to the end of the line. Simply beautiful.
ToKe86 ยท 8 points ยท Posted at 14:32:29 on June 21, 2016 ยท (Permalink)
Plus you never have to worry about forgetting a semicolon; it's always there!
HomerSPC ยท 2 points ยท Posted at 03:10:00 on June 21, 2016 ยท (Permalink)
He's a mad man.
flukus ยท 2 points ยท Posted at 08:14:44 on June 21, 2016 ยท (Permalink)
That's a lot more readable than I would have expected.
iamprasad88 ยท 1 points ยท Posted at 09:40:05 on June 26, 2016 ยท (Permalink)
I'm going to set this as a listchar to try it out. Thanks.
cmbarnett87 ยท 16 points ยท Posted at 17:29:26 on June 20, 2016 ยท (Permalink)
Just getting people to indent their code where I work would be a win as far as I'm concerned. We have a stupid IDE that doesn't have the capability to automatically indent.
groundxaero ยท 21 points ยท Posted at 19:06:07 on June 20, 2016 ยท (Permalink)
That must be a god damned nightmare factory, I pity you.
cmbarnett87 ยท 5 points ยท Posted at 19:13:20 on June 20, 2016 ยท (Permalink)
Ya, when I'm trying to help troubleshoot and I'm telling them what to type I can tell some people are annoyed when I say "tab"...
markswam ยท 1 points ยท Posted at 12:35:52 on June 21, 2016 ยท (Permalink)
There are some developers at my work who do the same thing, and if I say "tab," some of them will actually go off on a rant about it. I'm trying to be efficient here, dammit. I don't care if you want to use spaces instead of tabs, but "tab" has half the syllables of "indent" a quarter the syllables of "hit space four times."
wwwwvwwvwvww ยท 11 points ยท Posted at 23:27:05 on June 20, 2016 ยท (Permalink)
Oh god. Nothing makes me more frustrated than looking at poorly indented code. It's worse when you get to the bottom of the file and see this:
[deleted] ยท 1 points ยท Posted at 15:09:54 on June 21, 2016 ยท (Permalink)
Never try Lisp
lazyklimm ยท 3 points ยท Posted at 19:38:23 on June 20, 2016 ยท (Permalink)
why use it then?
cmbarnett87 ยท 3 points ยท Posted at 19:46:05 on June 20, 2016 ยท (Permalink)
It's niche marketing research software.
flukus ยท 1 points ยท Posted at 08:13:52 on June 21, 2016 ยท (Permalink)
Why not use $editor instead of the IDE?
DraslinHDF ยท 1 points ยท Posted at 21:16:56 on June 20, 2016 ยท (Permalink)
Yep, the IDE I work in also has a feature set from 1972. Bleh!
[deleted] ยท 1 points ยท Posted at 03:34:51 on June 23, 2016 ยท (Permalink)
I used to code js in notepad++, every tab fucking accounted for.
How does that not infuriate them? No tabs is so much harder to read
cmbarnett87 ยท 2 points ยท Posted at 12:40:09 on June 23, 2016 ยท (Permalink)
That's how I code sometimes for this package too. Notepad++ is awesome. You know, I'm really not sure what the mindset is. I think part of their thinking is "get it done as soon and quick as possible" which is why they don't mess with indenting. Single line If statements, not using loops, etc. I have explained the advantage of using the correct, efficient methodology but then they get angry. I've gotten better at my approach but not everyone is receptive even if I'm being incredibly polite and not insulting or accusatory. And I really like my coworkers, nice people! Just not everyone started in the industry as a programmer.
Shamaenei ยท 22 points ยท Posted at 17:16:31 on June 20, 2016 ยท (Permalink)
Use Go. They only know tabs.
eighthCoffee ยท 8 points ยท Posted at 20:02:33 on June 20, 2016 ยท (Permalink)*
.
flukus ยท 1 points ยท Posted at 08:11:38 on June 21, 2016 ยท (Permalink)
You've got my attention. Where do they stand on brace alignment?
Shamaenei ยท 2 points ยท Posted at 08:50:28 on June 21, 2016 ยท (Permalink)
I would say mandatory braces with same line start and end on the same tab level as the method started. See also https://golang.org/doc/faq#semicolons
flukus ยท 1 points ยท Posted at 08:52:37 on June 21, 2016 ยท (Permalink)
OK, it's on my "to research" list now.
[deleted] ยท 2 points ยท Posted at 20:20:35 on June 20, 2016 ยท (Permalink)*
[deleted]
porthos3 ยท 2 points ยท Posted at 20:55:16 on June 20, 2016 ยท (Permalink)
Seriously? Tabs vs spaces is important enough to you to entirely avoid a language where they made a design decision to remove the problem, just because you feel they made the wrong choice?
Jetlogs ยท 34 points ยท Posted at 11:47:46 on June 20, 2016 ยท (Permalink)
why not both? :)
KinOfMany ยท 38 points ยท Posted at 13:40:04 on June 20, 2016 ยท (Permalink)
You monster.
3kr ยท 92 points ยท Posted at 14:16:59 on June 20, 2016 ยท (Permalink)
Why not Zoidberg?
HellGate94 ยท 21 points ยท Posted at 16:02:51 on June 20, 2016 ยท (Permalink)
now i need to know what char this is
Tinfoilpain ยท 48 points ยท Posted at 16:20:08 on June 20, 2016 ยท (Permalink)
It's Zoidberg from the show Futurama.
HellGate94 ยท 11 points ยท Posted at 16:24:38 on June 20, 2016 ยท (Permalink)
thats obvious. but what utf 8 char(s) is he using
Tinfoilpain ยท 23 points ยท Posted at 16:36:42 on June 20, 2016 ยท (Permalink)
http://i.imgur.com/pEnis.jpg
Impstrong ยท 42 points ยท Posted at 18:36:57 on June 20, 2016 ยท (Permalink)
The URL on that one is interesting.
DropTableAccounts ยท 12 points ยท Posted at 19:20:14 on June 20, 2016 ยท (Permalink)
actually that's just what it looks like, in markdown it's probably something like "[http://i.imgur.com/pEnis.jpg](http://thatsthejoke.com/thatsthejoke.png)"
derpherp128 ยท 1 points ยท Posted at 19:52:40 on June 20, 2016 ยท (Permalink)
http://i.imgur.com/pEnis.jpg
The_Dragonn_29 ยท 7 points ยท Posted at 22:19:27 on June 20, 2016 ยท (Permalink)
Fun fact: That link is actually a really nice photo.
krokodil2000 ยท 5 points ยท Posted at 20:29:22 on June 20, 2016 ยท (Permalink)
0xZ01DB3R6
clockwork_coder ยท 11 points ยท Posted at 16:41:09 on June 20, 2016 ยท (Permalink)
whoosh
flukus ยท 1 points ยท Posted at 08:01:48 on June 21, 2016 ยท (Permalink)
The zoidberg one.
caagr98 ยท 5 points ยท Posted at 16:42:49 on June 20, 2016 ยท (Permalink)
Sadly, you can't
set listchars=tab:$zoidberg:(parenthesis-bot ยท 18 points ยท Posted at 16:43:27 on June 20, 2016 ยท (Permalink)
:)
This is an autogenerated response. source | /u/HugoNikanor
argv_minus_one ยท 10 points ยท Posted at 16:22:09 on June 20, 2016 ยท (Permalink)
Tabs for indentation. Spaces for alignment. It is the true way.
Gelezinis__Vilkas ยท 1 points ยท Posted at 21:00:02 on June 22, 2016 ยท (Permalink)
In one line
snarfy ยท 71 points ยท Posted at 13:53:07 on June 20, 2016 ยท (Permalink)
This is a solved problem
[deleted] ยท 7 points ยท Posted at 18:25:29 on June 20, 2016 ยท (Permalink)
And when I format my code like this and explain the above to people, I'm the bad guy.
Assume the spaces below are actually 4-space SmartTabs. I don't know how to express a tab on Reddit.
Indentation expresses nesting depth. One tab per level. Frankly, I wish I could do this:
We already have the idea of curly brackets being optional for single-statement ifs, loops, etc. Why not take it to its logical conclusion and make it optional for all things containing only one sub-thing?
ralpo08 ยท 25 points ยท Posted at 21:09:57 on June 20, 2016 ยท (Permalink)
Switch to Python
MrMetalfreak94 ยท -2 points ยท Posted at 21:53:39 on June 20, 2016 ยท (Permalink)*
Only that Python already decided to be on the space side of the war. They even disallow the use of Smart Tabs :/
parenthesis-bot ยท 3 points ยท Posted at 21:54:31 on June 20, 2016 ยท (Permalink)
)
This is an autogenerated response. source | /u/HugoNikanor
nemec ยท 0 points ยท Posted at 23:56:22 on June 20, 2016 ยท (Permalink)
Smart tabs already insert spaces in place of tabs, which is not only allowed by PEP8 but encouraged (as you noted). The only thing they disallow is the mixing of the spaces.
MrMetalfreak94 ยท 2 points ยท Posted at 00:25:59 on June 21, 2016 ยท (Permalink)
That's what I meant. Using tabs for indentation and spaces for alignment is forbidden in Python 3 and discouraged in Python 2
FlyingPiranhas ยท 1 points ยท Posted at 19:21:12 on June 21, 2016 ยท (Permalink)
You mean in the style guide, or the interpreter itself? I've never had issues with "smart tabs" with CPython -- but I'm not contributing to the Python community itself.
MrMetalfreak94 ยท 2 points ยท Posted at 19:39:40 on June 21, 2016 ยท (Permalink)
The interpreter itself. Python 3 programs wont run if you have mixed tabs and spaces. In Python 2 they run normally unless a command line option is given
FlyingPiranhas ยท 1 points ยท Posted at 19:44:17 on June 21, 2016 ยท (Permalink)
I just tested with CPython 3.5.1, and it runs tab-indented code perfectly fine. What's disallowed is mixing tabs and spaces for indentation, but the last thing you said was tabs for indentation and spaces for alignment, which works fine.
[deleted] ยท 3 points ยท Posted at 19:09:03 on June 20, 2016 ยท (Permalink)
[deleted]
[deleted] ยท 1 points ยท Posted at 20:46:44 on June 20, 2016 ยท (Permalink)
I'm not trying to make my code pretty. I'm trying to remove as much of it as I can without sacrificing too much readability. :)
ckcollab ยท 3 points ยท Posted at 21:14:28 on June 20, 2016 ยท (Permalink)
Welcome to Python!
mr___ ยท 0 points ยท Posted at 18:36:59 on June 20, 2016 ยท (Permalink)
You should really try F#
EDIT: Tabs are a syntax error in F#, because indentation level is significant and tab has no defined amount of indent. Very smart people made that choice, and it's the right one.
FlyingPiranhas ยท 16 points ยท Posted at 18:48:38 on June 20, 2016 ยท (Permalink)
What?! That makes no sense, with tabs each tab means exactly one level of indentation. How it displays is not important, only the semantics are important, and the semantics of tabs are well-defined.
Using spaces to indent makes the compiler/interpreter have to guess what indentation level a given number of spaces means, and making that guess requires the context of the surrounding code. It's a much more difficult problem than just counting tabs.
I don't see why the F# developers would have done that.
mr___ ยท 0 points ยท Posted at 18:59:34 on June 20, 2016 ยท (Permalink)*
Because spaces are not forbidden, and tabs have no defined number of spaces.
We care about code "reading" right, same as with python. It has nothing to do with your editor. If the compiler assumes 8 spaces per tab, and you assumed 2 or 3 or 4 or 6, then your "apparently" correct code, isn't. Because what might look un-indented to you, looks indented to the compiler.
Try actually using such a language before you knock it. F# is one of the most beautiful and expressive languages around.
FlyingPiranhas ยท 9 points ยท Posted at 19:07:19 on June 20, 2016 ยท (Permalink)
What is different about F# from Python that makes this an issue for F# and not an issue for Python?
mr___ ยท 2 points ยท Posted at 21:17:50 on June 21, 2016 ยท (Permalink)
It is an issue in python, and python will raise TabError if it detects you mixed them
FlyingPiranhas ยท 1 points ยท Posted at 22:01:24 on June 21, 2016 ยท (Permalink)
You stated that tabs are syntax errors in F#. I know that they are not a syntax error in Python because most of the Python I write is tab indented and I've never gotten such an error on my own machine. I did get that error once, but that was when I pasted tab-indented code into an unfamiliar Python editor that was configured for space-based indentation and it didn't know what to do with it.
AraneusAdoro ยท 6 points ยท Posted at 19:22:49 on June 20, 2016 ยท (Permalink)
So what I'm getting here is either that F# somehow depends on the number of spaces in an indent (which is dumb) or that it doesn't allow mixing tabs with spaces (which is sensible) and you are just unable to articulate it or to see that it's irrelevant.
mr___ ยท 2 points ยท Posted at 11:54:57 on June 21, 2016 ยท (Permalink)
It does depend on the number of spaces in an indent. It is a layout sensitive language
AraneusAdoro ยท 2 points ยท Posted at 12:05:06 on June 21, 2016 ยท (Permalink)
How sensitive, on a scale of 1 to 10 where 1 is Python and 10 is Befunge?
BadleyHairless ยท 3 points ยท Posted at 20:51:26 on June 20, 2016 ยท (Permalink)
That does not make any sense.
\u0009is the tab character and it is not any space characters\u0020is the space character and it is a space character\u0009!==\u0020So the compiler should not have to assume anything about how many spaces a tab character is and it would make it way easier to use as a distinct indentation as apposed to spaces where you must have exactly 4 spaces or exactly 2 spaces or exactly n spaces for the compiler to understand where indentations are actually happening.
A tab character is always exactly one indentation it is never some number of spaces unless your editor has replaced your tab key with a macro that creates spaces in which case that is an issue with spaces not tabs.
IRBMe ยท 2 points ยท Posted at 21:20:38 on June 20, 2016 ยท (Permalink)
That's... because tabs are't some number of spaces? They're tabs. One tab character = one level of indentation. You seem to be thinking of the tab width, which is purely a rendering option which determines how much horizontal space should be allocated when a tab character is rendered. If you're not rendering the code, the tab width doesn't have any relevance.
mr___ ยท 1 points ยท Posted at 11:52:30 on June 21, 2016 ยท (Permalink)
It does in layout sensitive languages, where the code must "look" the same to both you and the compiler.
IRBMe ยท 2 points ยท Posted at 12:00:28 on June 21, 2016 ยท (Permalink)*
The compiler only cares about the character stream. Given the following, where
-->represents a tab and.represents a space:The compiler would see the following character stream:
0x09 is a tab character, 0x20 is a space character and 0x0a is a new line character.
The tab width controls how the 0x09 values in the character stream are rendered as pixels, which is of no relevance to a compiler.
You might be confusing the fact that your editor of choice might insert some number of space characters for you when you press the tab key, with an actual tab character. If your editor inserts, say, 4 spaces when you press the tab key then the character stream will contain
0x20,0x20,0x20,0x20, but that is not a tab character. A tab character is a single 0x09.In short, the setting that controls how a tab character should be rendered is not the same as the setting that controls how many spaces your editor might choose to insert when you press the tab key, if indeed you have it configured to do so.
mr___ ยท -1 points ยท Posted at 16:59:17 on June 21, 2016 ยท (Permalink)
https://en.m.wikipedia.org/wiki/Off-side_rule
IRBMe ยท 2 points ยท Posted at 17:08:53 on June 21, 2016 ยท (Permalink)
I'm aware of how indentation works in certain languages but don't see how it relates to my point. Do you understand that a tab stop is a single character?
mr___ ยท 1 points ยท Posted at 20:47:16 on June 21, 2016 ยท (Permalink)
Do you understand what I am saying about layout-based languages? It IS important that you and the compiler agree how far from the left margin a statement is, in columns. That's hard to do when everyone chooses a tab size arbitrarily AND spaces are allowed. Tabs are not the only things that lead lines, or set column indent counts.
IRBMe ยท 1 points ยท Posted at 20:58:09 on June 21, 2016 ยท (Permalink)*
Yes, completely. I have used several myself.
Indeed, and both I and the compiler can agree that 1 tab character = 1 indentation level, 2 tab characters = 2 indentation levels, 3 tab characters = 3 indentation levels and so on.
A tab is always a single character. Do you understand this? There is no such thing as a "tab size" in a stream of characters; there are spaces, and there are horizontal tabs, but the idea of a tab character of a certain size is an incoherent concept. I'm going to repeat this again, because it seems to be the root of your misunderstanding. Inside a text file, there is no such thing as a tab size. Tab characters do not have a size other than the number of bits used to encode the character, the same as any other. It only makes sense to assign a width to a horizontal tab when you wish to render the tab. The tab width is the setting that tells the text renderer how far over the following character should be rendered whenever it encounters a horizontal tab character - i.e. the ASCII code 0x09.
Again, tab width is a setting that controls how tab characters are rendered, and how characters are rendered on the display is completely irrelevant to a compiler. If I create a file containing the following content:
0x09,'a'i.e. a tab character followed by the character, "a", then I can open this file in one editor in which the tab width is set to the equivalent of 2 spaces, another editor in which it's set to 4 and another in which it's set to 8. In all 3 editors, the 'a' character would be rendered in a different position, and yet the contents of the file have not changed. A compiler reading the file will see the exact same two characters, no matter what editor I happen to view the file in, and no matter what the tab width is set to in any of these editors. The compiler will always see a tab character - that is, a character of ASCII code 0x09 - followed by an 'a' character - that is, a character of ASCII code 0x61. Do you understand this?Your argument is like saying that you and the compiler must agree on the font, or the color scheme. The font and the color scheme are rendering properties that affect how the character stream is displayed just like the tab width. There is no such thing as the font of a character in an ASCII text stream just as there is no such thing as the width of a tab character in an ASCII text steam. It is a rendering option like the font.
If you're mixing the type of whitespace that you use for indentation then that's problematic, of course, but has absolutely nothing to do with the tab width of a tab character.
mr___ ยท 1 points ยท Posted at 21:09:18 on June 21, 2016 ยท (Permalink)
So when the compiler sees a line leading with a tab then 4 spaces, then the next line 12 spaces, should it group the two lines into a block?
IRBMe ยท 1 points ยท Posted at 21:17:58 on June 21, 2016 ยท (Permalink)
Firstly, what does this have to do with the tab width? Absolutely nothing; it's completely unrelated and entirely irrelevant.
Secondly, to answer your question, that depends entirely on the specification of the language or the implementation of the compiler, so if you want to know the answer then you should read the documentation.
According to the Python 3 language reference:
"Indentation is rejected as inconsistent if a source file mixes tabs and spaces in a way that makes the meaning dependent on the worth of a tab in spaces; a TabError is raised in that case."
mr___ ยท 1 points ยท Posted at 21:31:58 on June 21, 2016 ยท (Permalink)
You started out saying tab width isn't, or should not be, relevant to the compiler. You agree now that it is and the language spec has to carefully define the width of a tab or reject them?
Of course I know that a tab is a single code point........
AraneusAdoro ยท 2 points ยท Posted at 21:50:14 on June 21, 2016 ยท (Permalink)
Oh for crying out loud.
If you use a tab character to indent a code block, then every other instance of this level of indentation in the same code block must be a tab character.
If you use some number of spaces to indent a code block, then every other instance of this level of indentation in the same code block must be the same number of spaces.
Width of a tab character is irrelevant. The number of them is all that is relevant.
Why is this so hard all of a sudden?
IRBMe ยท 1 points ยท Posted at 21:45:31 on June 21, 2016 ยท (Permalink)*
Correct. It isn't, and I've explained why as clearly and in as much detail as I possibly can, so I'm at a complete and utter loss as to why you still don't understand it.
No. You still do not seem to understand what "tab width" means despite my attempts to explain it to you, and you seem to be confusing tabs with spaces.
You do understand that if your editor is configured to enter, say, 4 spaces when you press the tab key, that your file now contains only spaces and no tab characters, right? You understand that the tab key and a tab character are two different things? You understand that pressing the tab key may cause spaces and not tabs to be inserted if your editor is configured to do so, right?
The only way I can make sense of your comments is if your editor is set to insert some number of spaces when you press the tab key and you're confusing the tab key for a tab character. In that case, of course the number of spaces that are inserted when you press your tab key makes a difference because that number of spaces are hard-coded into the file. However, this is completely different from inserting a tab character.
Okay, let's try to clear this up once and for all.
Here is a screenshot of a text file inside my text editor. You can see that the first character is a tab, the second character is the letter a, and the final character is a line feed, right? My editor has a tab width of 4.
Here is a screenshot of the same file in a hex editor, clearly showing the tab character (0x09), the 'a' (0x61) and the line feed (0x0a).
Now I have set the tab width in my text editor to 8. As can be seen in this screenshot, the tab is now wider looking.
After setting my tab width to 8 and saving the file, what do you think I will see now when I open it in the hex editor? Show me the hexadecimal values that you would expect to see.
AraneusAdoro ยท 2 points ยท Posted at 21:09:12 on June 21, 2016 ยท (Permalink)
https://docs.python.org/3/reference/lexical_analysis.html#indentation
levir ยท 2 points ยท Posted at 21:22:23 on June 20, 2016 ยท (Permalink)
Outlaw spaces, enforce tabs. Problem solved.
Right?
[deleted] ยท -1 points ยท Posted at 19:58:59 on June 20, 2016 ยท (Permalink)
[removed]
generic_lurker ยท 7 points ยท Posted at 18:37:16 on June 20, 2016 ยท (Permalink)
This looks like the correct answer, and I'll be using this method from now on. Thanks!
Creshal ยท 66 points ยท Posted at 14:28:37 on June 20, 2016 ยท (Permalink)
Tabs for indentation, spaces for alignment.
eresonance ยท 31 points ยท Posted at 16:56:05 on June 20, 2016 ยท (Permalink)
I wanted this, but so many people screw it up and use the tab key for alignment that we forced everyone to use spaces in our company. Once it's consistent people have better things to worry about than tabs vs spaces...
FlyingPiranhas ยท 18 points ยท Posted at 18:31:39 on June 20, 2016 ยท (Permalink)
This is the unfortunate truth. It's so much nicer to work with tab-indented code than with space-indented code, but most large projects and organizations choose a space-indented style because so many programmers are incapable of correctly indenting their code with tabs :'(
parenthesis-bot ยท -20 points ยท Posted at 18:32:02 on June 20, 2016 ยท (Permalink)
)
This is an autogenerated response. source | /u/HugoNikanor
Asmor ยท 5 points ยท Posted at 19:52:04 on June 20, 2016 ยท (Permalink)
That's what code review is for.
You don't have to send tickets back for dumb reasons like that very many times before they get the hint.
Of course, it also requires you have diligent code reviewers who aren't afraid to be pedantic and hurt feelings.
eresonance ยท 3 points ยท Posted at 23:13:48 on June 20, 2016 ยท (Permalink)
Requires larger teams that actually have time to do code reviews :(
parenthesis-bot ยท 5 points ยท Posted at 23:15:27 on June 20, 2016 ยท (Permalink)
:)
This is an autogenerated response. source | /u/HugoNikanor
Asmor ยท 7 points ยท Posted at 23:25:14 on June 20, 2016 ยท (Permalink)
Little passive-aggressive there, bot.
LobsterThief ยท 0 points ยท Posted at 03:23:49 on June 21, 2016 ยท (Permalink)
:)
lazyklimm ยท 3 points ยท Posted at 19:40:56 on June 20, 2016 ยท (Permalink)
tab key != tab symbol
flukus ยท 2 points ยท Posted at 07:53:20 on June 21, 2016 ยท (Permalink)
Have a syntax checker as part of the check-in/build process.
FinFihlman ยท 2 points ยท Posted at 20:00:57 on June 20, 2016 ยท (Permalink)
If we weren't fucking stuck in the middle ages where people use 80 characters width we wouldn't fucking have the problem of alignment.
We have two eyes. Our field of view is wiiiiiiiiiiiiiiiiiiiiiiide.
IRBMe ยท 8 points ยท Posted at 21:40:30 on June 20, 2016 ยท (Permalink)
I would argue that this:
is harder for a human to quickly read and parse than this:
In the latter example, a long and complex expression is broken up across multiple lines such that each line contains a smaller sub-expression that is easier to understand, and each of the components of each sub-expression are aligned so as to highlight the similarities and differences between them. Note also the addition of the comments that can now be used to provide some explanation of each sub-expression.
Another example:
Could be improved as follows:
(Of course, using proper named parameters would be better if the language supported it)
Both of these examples are, of course, contrived and we should not actually write code like that, but they serve as demonstrations of how breaking code up across multiple lines and adding alignment can improve readability without having anything to do with editor width.
lazyklimm ยท 1 points ยท Posted at 19:40:16 on June 20, 2016 ยท (Permalink)
You make Occam sad
Cheesemacher ยท -1 points ยท Posted at 17:14:35 on June 20, 2016 ยท (Permalink)
Of course then you have to use an editor that shows what the empty space is made of.
Creshal ยท 9 points ยท Posted at 17:20:11 on June 20, 2016 ยท (Permalink)
Soโฆ anything not notepad?
flukus ยท 3 points ยท Posted at 22:09:09 on June 20, 2016 ยท (Permalink)
I think notepad has this feature too.
flarn2006 ยท 9 points ยท Posted at 19:23:14 on June 20, 2016 ยท (Permalink)
What's wrong with poop emoji?
anotherdonald ยท 5 points ยท Posted at 13:49:52 on June 20, 2016 ยท (Permalink)
I guess it turned into a "text or HTML" war.
UnchainedMundane ยท 10 points ยท Posted at 15:30:26 on June 20, 2016 ยท (Permalink)
Judging by those file sizes, all of them are HTML mail.
[deleted] ยท 3 points ยท Posted at 22:55:23 on June 20, 2016 ยท (Permalink)*
[deleted]
Garnet638 ยท 1 points ยท Posted at 06:00:47 on June 21, 2016 ยท (Permalink)
Well then I'd love to see what's in the 301kb email. Probably those signatures with the shitload of images and quotes in colored comic sans
flukus ยท 3 points ยท Posted at 22:15:13 on June 20, 2016 ยท (Permalink)
When are spaces people going to stop forcing their alignment preferences on everyone else?
PersianMG ยท 1 points ยท Posted at 12:25:26 on July 17, 2016 ยท (Permalink)
When we die.
lazersmoke ยท 8 points ยท Posted at 16:45:34 on June 20, 2016 ยท (Permalink)
It is really, truly language-dependent. I use 2 spaces for Haskell. I use 2 spaces for my own projects in JavaScript, but I write in a style that makes that work. If I am choosing for a larger group, then I pick tabs, or 4 spaces if everyone likes spaces.
brendanrivers ยท 5 points ยท Posted at 17:59:18 on June 20, 2016 ยท (Permalink)
why on earth would you ever bend your strict and uncompromised rules to fit the needs of someone else on your team? go back to JS scrublord!
/s
greyfade ยท 1 points ยท Posted at 19:22:01 on June 21, 2016 ยท (Permalink)
I'm still trying to pick a style for Pony and Premake. Both of them are completely whitespace agnostic, so indentation only (barely) matters for readability.
Normally, I'd just go 4 spaces, but then the rest of the community has settled on 2 or 3.
JeremyR22 ยท 3 points ยท Posted at 23:33:30 on June 20, 2016 ยท (Permalink)
Tabs/Spaces debate aside, I feel sorry for you being stuck in an email client that doesn't have conversation
indentation(oh, sorry, I mean threading...)Are all those replies directly to you? To somebody who replied to you? In one long string? In multiple branches? How on earth do you know at a glance how to follow the threads of conversation?
nelmaven ยท 15 points ยท Posted at 17:16:00 on June 20, 2016 ยท (Permalink)
flukus ยท 7 points ยท Posted at 22:11:59 on June 20, 2016 ยท (Permalink)
That doesn't solve the problem though, I want my indentation to be 2 spaces, my co-workers want it to be 4. Tabs make everyone happy.
corgi92 ยท 13 points ยท Posted at 20:11:11 on June 20, 2016 ยท (Permalink)
Now press backspace, I dare you.
[deleted] ยท 17 points ยท Posted at 20:26:05 on June 20, 2016 ยท (Permalink)
Easy, just configure your backspace to delete 4 characters!
Kinglink ยท 16 points ยท Posted at 20:40:18 on June 20, 2016 ยท (Permalink)
Some people just like to watch the world burn.
LobsterThief ยท 1 points ยท Posted at 03:05:29 on June 21, 2016 ยท (Permalink)
Usually I just use SHIFT-TAB (in Sublime).
FlyingPiranhas ยท 0 points ยท Posted at 21:14:06 on June 20, 2016 ยท (Permalink)
Now add 2 spaces in some code and try to delete just the last space.
Configuring backspace to remove more than 1 characters makes it hard to deal with alignment and everything that isn't indentation.
[deleted] ยท 13 points ยท Posted at 20:38:41 on June 20, 2016 ยท (Permalink)
[deleted]
TropicalAudio ยท 2 points ยท Posted at 21:36:43 on June 20, 2016 ยท (Permalink)
It's pretty damn useful.
FlyingPiranhas ยท 1 points ยท Posted at 21:14:24 on June 20, 2016 ยท (Permalink)
But then it doesn't properly delete non-indentation spaces.
greyfade ยท 4 points ยท Posted at 21:33:14 on June 20, 2016 ยท (Permalink)*
Set your
smarttablike a civilized person and it will.I can't even find a way to make Vim not backspace over theshiftwidth.FlyingPiranhas ยท 1 points ยท Posted at 21:42:53 on June 20, 2016 ยท (Permalink)*
That combination doesn't work for me. After using your exact sequence of commands, pressing space, space, backspace still removes both spaces.
EDIT: I think you changed your post while I was reading it. Your updated post may in fact work -- I'll edit this once I've tested it more thoroughly.
EDIT 2: It still doesn't work quite correctly, but it's better than what I was using previously. Thank you very much!
[deleted] ยท 1 points ยท Posted at 22:42:44 on June 20, 2016 ยท (Permalink)
[deleted]
FlyingPiranhas ยท 1 points ยท Posted at 22:45:56 on June 20, 2016 ยท (Permalink)
That doesn't handle non-indentation spaces very well (deleting an unpredictable number at a time and inserting 8 at a time).
I'm currently using
set expandtab smarttab sw=0 ts=4Thanks for trying to help, though. I appreciate it.
the_noodle ยท 1 points ยท Posted at 23:49:49 on June 20, 2016 ยท (Permalink)
That's what shift width is there for, it should delete to the last multiple.
noisypixy ยท 1 points ยท Posted at 20:19:27 on June 24, 2016 ยท (Permalink)
Ctrl+Dnelmaven ยท 9 points ยท Posted at 21:21:26 on June 20, 2016 ยท (Permalink)
Sublime Text, backspace removes one indentation level. No problem at all.
FlyingPiranhas ยท 1 points ยท Posted at 21:30:56 on June 20, 2016 ยท (Permalink)
But Sublime doesn't behave well if you're trying to delete a single space character (unless it just happens to be 1 past the indentation grid).
[deleted] ยท 2 points ยท Posted at 22:34:08 on June 20, 2016 ยท (Permalink)
[deleted]
FlyingPiranhas ยท 1 points ยท Posted at 22:42:20 on June 20, 2016 ยท (Permalink)
Anytime you accidentally add an extra space that's not immediately after your indentation.
Boom_Rang ยท 2 points ยท Posted at 20:39:25 on June 20, 2016 ยท (Permalink)
Some IDEs support Shift-Tab to remove a level of indentation regardless of whether you're using tabs or spaces
FlyingPiranhas ยท 1 points ยท Posted at 21:16:14 on June 20, 2016 ยท (Permalink)
Habits die hard. If I hit a key I didn't mean to and it inserted a character I don't want, I instinctively press backspace to remove it. Changing that to Shift-Tab if I accidentally press tab increases my cognitive load (because it becomes an exception to the backspace-as-insertion-undo rule) and the chance that I forget what I had intended to type.
DJDarkViper ยท 1 points ยท Posted at 22:10:45 on June 20, 2016 ยท (Permalink)
douchehat ยท 5 points ยท Posted at 17:02:57 on June 20, 2016 ยท (Permalink)
I use Atom. One of the add-ons lets you convert between tabs and spaces. My general rule is tabs for files only I look at; spaces for when I'm sharing the code. Different text editors view tabs differently, so covering to spaces makes sure that others will see the code in the same format I saw it in, no matter what they use to edit. For example, I convert to spaces before turning in CS assignments.
typhoon_2099 ยท 10 points ยท Posted at 17:11:05 on June 20, 2016 ยท (Permalink)
I have Atom set up to use Comic Sans MS, would tabs be better than spaces for most situations?
levir ยท 1 points ยท Posted at 21:26:18 on June 20, 2016 ยท (Permalink)
Yes.
douchehat ยท 1 points ยท Posted at 17:19:06 on June 20, 2016 ยท (Permalink)
That depends on what you mean by better. I use tabs when I'm coding because it's easier, and it also keeps the file size smaller. That being said, file size of the source doesn't matter in the compiled version, so it's really up to programmer preference. Spaces are always better when sharing code, though, if you want to make sure the formatting is consistent on all editors.
It doesn't really matter. You do you.
FlyingPiranhas ยท 4 points ยท Posted at 18:27:59 on June 20, 2016 ยท (Permalink)
But why would you want that? Using tabs allows the reader to set how wide they'd like indentation to be. By choosing to use spaces to "make sure the formatting is consistent", you are intentionally forcing the reader to view the code in the way that you are comfortable with, not the way that they are comfortable with.
To give you an example, I use an indentation width of 8. Let's assume that you like an indentation width of 4. If I send you my tab-indented code and you open it in your editor, you will see an indentation width of 4, which is comfortable for you. If I first convert my code to use spaces, then you will see code with an indentation width of 8, which is not to your liking. Wouldn't you rather I send you code that you can view as you like, not as I like?
the_noodle ยท 2 points ยท Posted at 00:04:00 on June 21, 2016 ยท (Permalink)
You could also refactor all variables to game of thrones characters if that helps you follow the code.
It's your job to do that yourself in your editor, though, not everyone else's job to write code differently to accommodate these idiosyncracies.
lazyklimm ยท 6 points ยท Posted at 17:13:50 on June 20, 2016 ยท (Permalink)
Why not use spaces all the way then?
douchehat ยท 1 points ยท Posted at 18:12:41 on June 20, 2016 ยท (Permalink)
Great question! Personally, I like the size of the tab - one space per indent doesn't provide enough contrast for me. So I can place multiple "spaces" with just one press of the tab button.
Furthermore, I like to align comments in their own "column" to the right when declaring variables. Tabs let me align those comments without having to count the number of spaces or press space until I reach the Comment Column.
tl;dr It's convenient.
lazyklimm ยท 3 points ยท Posted at 20:45:16 on June 20, 2016 ยท (Permalink)
but what if variable names are longer than tabsize ? :)
douchehat ยท 1 points ยท Posted at 21:04:00 on June 20, 2016 ยท (Permalink)
That's the fun part! Add more tabs accordingly!
lazyklimm ยท 1 points ยท Posted at 21:14:24 on June 20, 2016 ยท (Permalink)
To every line? No, thanks, I'm ok with unaligned comments.
DarthNihilus ยท 2 points ยท Posted at 18:33:17 on June 20, 2016 ยท (Permalink)
?????
That's how everyone uses spaces. No one (good) is using single space indentation. Everyone sets up the tab key to insert 2 or 4 spaces. And god, no one is actually pressing the space bar 4 times. Spaces instead of tabs are the exact same thing except the tab character width is less standardized. Switch to spaces ffs.
This eternal holy war needs to die.
FlyingPiranhas ยท 3 points ยท Posted at 18:58:11 on June 20, 2016 ยท (Permalink)
I firmly believe that the technically correct indentation method is to use tabs, for a number of reasons. Therefore I will always prefer to use tabs over spaces for indentation, and will want others to do the same as well.
Until it is as convenient (comfortable, fast, etc...) to edit space-indented code as it is to edit tab-indented code, I will have a strong preference for writing tab-indented code. It seems to me that you have no interest in changing your position in this debate, so until one of us changes our minds this war will go on.
If someone gives vim good support for editing space-indented code, or makes another editor that is popular and efficient as vim, then I will probably stop arguing for tab-based indentation. I don't want to do that, however, because it's a difficult problem. If you want to give vim better support for editing space-indented code, then go ahead, and let me know when it's implemented.
lazyklimm ยท 2 points ยท Posted at 18:59:59 on June 20, 2016 ยท (Permalink)
emacs
FlyingPiranhas ยท 1 points ยท Posted at 19:21:34 on June 20, 2016 ยท (Permalink)
Okay, I've installed emacs, but it looks like it will take a while to learn how to use it. Do you have any quick guide for how to configure emacs to edit space-indented code? I want to give it a quick try to see if it's worth spending the time to learn.
lazyklimm ยท 2 points ยท Posted at 19:34:54 on June 20, 2016 ยท (Permalink)
install spacemacs, AFAIK it is a ex-vim-userfriendly addon that makes transition much easier
smth like that https://www.jwz.org/doc/tabs-vs-spaces.html ?
FlyingPiranhas ยท 1 points ยท Posted at 19:52:51 on June 20, 2016 ยท (Permalink)
I don't see that in my distro's repositories.
That seems to be aimed at people who already know how to use emacs. I put this into my emacs file:
but pressing <TAB> does nothing. Do I need something else?
lazyklimm ยท 1 points ยท Posted at 20:03:00 on June 20, 2016 ยท (Permalink)
http://spacemacs.org/,
Pressing <TAB> where? <TAB> in emacs programming modes does indentation, so you should open/create a source file first
FlyingPiranhas ยท 1 points ยท Posted at 20:13:27 on June 20, 2016 ยท (Permalink)
So you just clone the git repository into your ~/.emacs.d directory?
It doesn't do anything when I'm editing a source file, regardless of the language of the file.
I realize that it takes a while to learn a good editor. I only know how to use vim because some coworkers forced me to use it several years ago. I want to make sure that emacs is an improvement over vim before I spend the time to learn to use it.
Would you mind answering a question for me? Is it possible to configure emacs (or spacemacs) so that all of the following are true?
Vim can do 1 and 3 (in any combination) easily, but is unable to do 2 if <TAB> inserts more than 1 space. If emacs can't be configured to do all of 1, 2, and 3 at the same time then I don't think it's worth investing my time to learn emacs.
lazyklimm ยท 1 points ยท Posted at 20:35:09 on June 20, 2016 ยท (Permalink)*
No, TAB just does indentation, the rest depends on your settings
In emacs you can always press 'F1','k','Key_or_combination' and it shows things Key does:
E.g. for <Backspace> in C-mode
the last function itself is
lazyklimm ยท 1 points ยท Posted at 20:38:19 on June 20, 2016 ยท (Permalink)
I think it can be configured that way, but why? Do you really want to do all your indentations manually?
FlyingPiranhas ยท 1 points ยท Posted at 20:51:24 on June 20, 2016 ยท (Permalink)
Yes, and for multiple reasons:
For me, using an editor is all about cognitive load and predictability. When I am programming, I first figure out what code I want to insert. Once I've written the code in my head, I then try to type it as quickly as possible, and any errors (unpredicted editor behaviors) may cause me to "lose my train of thought" and forget what I intended to write. While I don't manually re-indent every line, I want my editors to behave in a relatively simple manner so that I can easily (subconsciously) predict their behavior.
I've been using vim's copyindent for a while now, and I am used to how it works. Switching to any other behavior would require a lot of retraining (months or years), and may not bring any improvement.
I don't know about emacs, but vim's "smart" formatter is horrible anyway, and I typically have to go back and fix the code. Because of this need to correct the automatically formatted code anyway, I still need the ability to manually edit indentation and alignment efficiently anyway.
lazyklimm ยท 1 points ยท Posted at 21:12:11 on June 20, 2016 ยท (Permalink)
Maybe it depends on language too, but I can't remember any problem with emacs autoformatter (I write mostly in lisp-like languages though, but AFAIK C worked well too), even while refactoring bigger pieces - just press C-M-\ (or M-x indent-region) and it's done.
lazyklimm ยท 1 points ยท Posted at 20:43:27 on June 20, 2016 ยท (Permalink)
yes
Luvax ยท 2 points ยท Posted at 21:48:51 on June 20, 2016 ยท (Permalink)*
Never understood that. Why does your code has to look the same for everyone? What's wrong if I want to use only 2 characters per "tab" when working with your code.
thrilldigger ยท 1 points ยท Posted at 21:05:28 on June 20, 2016 ยท (Permalink)
You're well on your way to using tabs and tabs only, padawan. Embrace the
LightTab Side of the Force; do not be ashamed of it, for it will serve you well in the coming times of darkness imposed by theSithSpaces Order.BigHowski ยท 2 points ยท Posted at 22:18:50 on June 20, 2016 ยท (Permalink)
What mad man uses spaces?
LobsterThief ยท 2 points ยท Posted at 03:06:18 on June 21, 2016 ยท (Permalink)
This mad man does, and many mad men before me.
Skullclownlol ยท 2 points ยท Posted at 08:12:43 on June 23, 2016 ยท (Permalink)
Nothing mad about it. I used tabs for years and years until finally switching to spaces (IDE turns tabs into spaces, I don't manually press spacebar, that would be mad).
It just makes more sense when working in teams (especially teams that include newer developers) and to maintain consistency/readability.
I hate that spaces take up more place, but you minify everything anyway.
[deleted] ยท 2 points ยท Posted at 11:43:55 on June 21, 2016 ยท (Permalink)
I asked my boss this question and he said we use python, and that I'm retarded.
Gabe_b ยท 4 points ยท Posted at 19:59:28 on June 20, 2016 ยท (Permalink)
Who gives a shit. Unless it's in a YAML file. Then tabs will ruin your whole day.
luizpericolo ยท 1 points ยท Posted at 21:48:29 on June 20, 2016 ยท (Permalink)
Kudos! You managed to spread the flamewar here.
This is why we can't have nice things...
[deleted] ยท 1 points ยท Posted at 21:49:24 on June 20, 2016 ยท (Permalink)
So I use a Lisp, Clojure specifically. I've been using a two neat Emacs plugins: agressive-indent and paredit. Syntax you say, tabs or space you say? I don't actually care. It fixes it for me. It does this consistently and perfectly. I don't care anymore. I'm FREEEE
Secondsemblance ยท 1 points ยท Posted at 22:05:02 on June 20, 2016 ยท (Permalink)
Looks like there are a lot of space haters in here. My reason for using spaces is that I know how wide 80 characters is. If I use tabs, I may exceed the width of 80 characters which can result in funny looking git commits and terminal wraparound, not to mention if the code ever needs to be printed for some reason.
pnpbios ยท 1 points ยท Posted at 22:47:40 on June 20, 2016 ยท (Permalink)
If you write make files, you use tabs.
opa_zorro ยท 1 points ยท Posted at 23:28:26 on June 20, 2016 ยท (Permalink)
Spaces and tabs are different things. if they were html tags they would be able to be styled differently. IMHO multiple spaces would be collapse to one (unless after a period when it should be more for readability if we are talking prose). Tabs would be based on context. E.e. Cummings would hate me.
monster860 ยท 1 points ยท Posted at 01:35:54 on June 21, 2016 ยท (Permalink)
Soooo. Which one is it?
[deleted] ยท 1 points ยท Posted at 02:55:13 on June 21, 2016 ยท (Permalink)
My vimrc replaces tabs with spaces.
JoseJimeniz ยท 1 points ยท Posted at 03:54:12 on June 21, 2016 ยท (Permalink)
Bedlam DL3
Java_Beans ยท 1 points ยท Posted at 05:40:32 on June 21, 2016 ยท (Permalink)
I'm curious to see the attachment of the 301 email. If it's a meme that would be me in the dev team.
TinynDP ยท 1 points ยท Posted at 15:34:43 on June 21, 2016 ยท (Permalink)
Automated checkin pre-hook?
myrrlyn ยท 1 points ยท Posted at 20:46:00 on June 22, 2016 ยท (Permalink)
ctrl-f editorconfig=> phrase not foundSweet JESUS people what is wrong with you all.
\tcharacters like a civilized human being.\tbe as wide or narrow you want, on a per-language basis, so literally everyone is happy.root=truein your project editorconfigs; set that in your project folder editorconfig so that the editorconfig of projects you cloned written by people who are wrong, are overriden by Your Local Truth_LePancakeMan ยท 1 points ยท Posted at 14:32:58 on June 20, 2016 ยท (Permalink)
hey OP, what language are you using? Are there no standards in your language?
typhoon_2099 ยท 1 points ยท Posted at 17:09:37 on June 20, 2016 ยท (Permalink)
The CMS I use at work has decided to write up their own style guide and it flies in the face of PSR-1/2. It infuriates me.
_LePancakeMan ยท 1 points ยท Posted at 18:29:02 on June 20, 2016 ยท (Permalink)
ouch. which one is it? My CMS (TYPO3) just switched to PSR
typhoon_2099 ยท 1 points ยท Posted at 18:30:28 on June 20, 2016 ยท (Permalink)
ProcessWire. It's a great CMS but they've decided to make up their own styleguide. But they've added Composer support so it's also taking some good steps.
_LePancakeMan ยท 1 points ยท Posted at 18:34:10 on June 20, 2016 ยท (Permalink)
good to see that other CMS are coming along as well as TYPO3 is (they also went all it with composer recently).
I don't know a lot about processWire, but the number one thing holding back TYPO3 is it's past - there sadly is a lot of prejudice against it
DJDarkViper ยท 1 points ยท Posted at 22:32:22 on June 20, 2016 ยท (Permalink)
Spaces.
Why? Because I like to think I respect my code reviewers eyes.
Looking over tabs based content in pull requests gives all kinds of wacky radical formatting...
That said, I used to be tabs when I was a young vigilante single force to be reckoned with army. Two things happened: 1 I used to bounce around editors across multiple systems all the time, and tabs got really annoying to setup to look consistent, and 2 now I work in teams, and all our code needs to co-mingle. Spaces has proven to be very nice to work with. So that's my default now.
thatbloke83 ยท 1 points ยท Posted at 18:02:06 on June 20, 2016 ยท (Permalink)
Tabs
[deleted] ยท 1 points ยท Posted at 19:07:16 on June 20, 2016 ยท (Permalink)
Spaces. Zero-width spaces.
Muhahahaha!
lazyklimm ยท 1 points ยท Posted at 19:37:28 on June 20, 2016 ยท (Permalink)
Negative-width spaces
[deleted] ยท 1 points ยท Posted at 19:29:46 on June 20, 2016 ยท (Permalink)
https://www.youtube.com/watch?v=SsoOG6ZeyUI
lazyklimm ยท 2 points ยท Posted at 19:37:07 on June 20, 2016 ยท (Permalink)*
'Tabs vs Spaces' holywar isn't about keys, it's all about symbols: ' ' vs '\t'.
// btw, tab guy detected
youtubefactsbot ยท 4 points ยท Posted at 19:30:03 on June 20, 2016 ยท (Permalink)
bot info
[deleted] ยท 1 points ยท Posted at 21:02:30 on June 20, 2016 ยท (Permalink)
[deleted]
rbemrose ยท 3 points ยท Posted at 21:52:09 on June 20, 2016 ยท (Permalink)
When you discover HTML minifiers, your head's gonna explode.
Luvax ยท 1 points ยท Posted at 21:41:03 on June 20, 2016 ยท (Permalink)
Tabs can be anything, 2 spaces, 1 space, 3 spaces or even 8. It's up to you. Tabs are a form of seperating code from it's presentation like in good software design. The only "good" argument I know in favor of tabs is that "they look the same anywhere" which is of course true, but if the indentation of you code is important than your code is shit.
Lrd_Herobrine ยท 0 points ยท Posted at 15:08:38 on June 20, 2016 ยท (Permalink)
So? What are the results?
HolyGarbage ยท 0 points ยท Posted at 15:22:02 on June 20, 2016 ยท (Permalink)
Some men just wants to watch the workplace burn.
GooseTheGeek ยท 0 points ยท Posted at 19:56:47 on June 20, 2016 ยท (Permalink)
I thought this was /r/SiliconValleyHBO for a minute here
DJDarkViper ยท 1 points ยท Posted at 21:29:27 on June 20, 2016 ยท (Permalink)
same...
w00tboodle ยท -2 points ยท Posted at 12:33:04 on June 20, 2016 ยท (Permalink)
Modern compilers handle this pretty cleanly now, but there was a time long ago (70s-90s), when it actually mattered because the compilers handled tabs and spaces differently and tabs in the code sometimes meant that your program wouldn't compile. It also made a difference in that tabs would cause your code alignment to be skewed, since the editor had a different length for a tab character.
Hullu2000 ยท 5 points ยท Posted at 15:04:23 on June 20, 2016 ยท (Permalink)
Python still only accepts tabs or spaces but not both
[deleted] ยท 2 points ยท Posted at 19:01:26 on June 20, 2016 ยท (Permalink)
Not necessarily.
That runs.
Hullu2000 ยท 1 points ยท Posted at 19:58:15 on June 20, 2016 ยท (Permalink)
But they don't work interchangeably like in this example
FlyingPiranhas ยท 1 points ยท Posted at 20:14:09 on June 20, 2016 ยท (Permalink)
That's okay, you shouldn't be interchanging tabs and spaces for indentation. If you stick to only tabs for indentation then CPython is perfectly happy.
Hullu2000 ยท 1 points ยท Posted at 20:39:04 on June 20, 2016 ยท (Permalink)
I ocasionally end up using them interchangeably because I use tabs but some code I copy paste uses spaces and my IDE can't seem to be able to decide.
Hullu2000 ยท 1 points ยท Posted at 20:39:16 on June 20, 2016 ยท (Permalink)
I ocasionally end up using them interchangeably because I use tabs but some code I copy paste uses spaces and my IDE can't seem to be able to decide.
FlyingPiranhas ยท 1 points ยท Posted at 20:58:47 on June 20, 2016 ยท (Permalink)
In that case you need to fix it to be consistent. In any other language I'd just tell you to make your IDE (since you just said that you use one) auto-format the code, but that's tricky in a language that doesn't use braces. I think that that's a downside of Python.
Hullu2000 ยท 1 points ยท Posted at 06:16:33 on June 21, 2016 ยท (Permalink)
I use autoformating in C/C++ but it gets messy when I start disagreing with it.
FlyingPiranhas ยท 1 points ยท Posted at 07:27:54 on June 21, 2016 ยท (Permalink)
I always follow up manually when I run an autoformatter, they usually get a few things wrong the first time.
Also, I never configure my editor to format as I type; that never seems to work well.
KarlKastor ยท 5 points ยท Posted at 15:39:49 on June 20, 2016 ยท (Permalink)
Four spaces are specified in PEP.
FlyingPiranhas ยท 1 points ยท Posted at 15:56:21 on June 20, 2016 ยท (Permalink)
True, but CPython is perfectly happy if you indent using tabs.
If I'm working on a personal project (where I'm the only developer/maintainer), then I don't care about language standards, I'm going to use the style that's best for me.
argv_minus_one ยท -8 points ยท Posted at 16:23:35 on June 20, 2016 ยท (Permalink)
Another fine reason not to use Python for anything. As if there weren't enough reasons already.
lazyklimm ยท -6 points ยท Posted at 17:00:12 on June 20, 2016 ยท (Permalink)
Python sucks, but 4 spaces rule from PEP8 is one of the best things it has
argv_minus_one ยท -1 points ยท Posted at 18:04:12 on June 20, 2016 ยท (Permalink)
Not even. Tabs or you're doing it wrong. It's only because of tabs that I can have my preferred 2-space indent without offending anyone else.
DropTableAccounts ยท 3 points ยท Posted at 19:26:35 on June 20, 2016 ยท (Permalink)
How is the alignment skewed? Does it really matter whether all indentations have a width of e.g. 4 spaces or 8 spaces? I mean, code indented with the same amount of tabs won't just magically have different indentation levels...
(Of course you shouldn't mix tabs and spaces, but who does that?)
UnchainedMundane ยท 2 points ยท Posted at 15:31:16 on June 20, 2016 ยท (Permalink)
That still happens. When it does, you know that the author was abusing tabs.
I wish people would turn on whitespace highlighting in their editors.
argv_minus_one ยท 2 points ยท Posted at 16:24:28 on June 20, 2016 ยท (Permalink)
Do you have an example of this?
mr___ ยท 2 points ยท Posted at 18:53:44 on June 20, 2016 ยท (Permalink)
Modern compilers like for F# and Scala prohibit tabs.
northrupthebandgeek ยท -1 points ยท Posted at 21:00:48 on June 20, 2016 ยท (Permalink)
Spaces for indentation, tabs for alignment.
[deleted] ยท -1 points ยท Posted at 22:53:54 on June 20, 2016 ยท (Permalink)
[deleted]
flukus ยท 0 points ยท Posted at 08:22:37 on June 21, 2016 ยท (Permalink)
Then we'd be arguing over 2 spaces or 4 instead of whether or not to use the option that makes both groups happy.