[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Tabs or Spaces, /g/?
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 130
Thread images: 7
File: tabs-vs-spaces.png (74 KB, 717x325) Image search: [Google]
tabs-vs-spaces.png
74 KB, 717x325
Tabs or Spaces, /g/?
>>
>>51427864
Tabs.
>>
Spaces. 3 of them. Use a monospace font
>>
Tabs if your editor isn't shitty.
>>
Spaces. 4 of them.
I thought it was generally agreed that tabs are bad programming practice?
>>
blank characters
>>
Spaces, tabs always end up in messed up indentations.
>>
>>51427864
spaces
tab fags can gtfo
>>
4 tabs
>>
Tabs, so everyone can set them to whatever width they want and everyone can be happy.

>>51427970
>I fuck up indentation and somehow this is the tabs' fault
>>
sometimes I use 2 spaces and 1 tab together to mess with co-workers
>>
tabs. easiest.
>>
>>51427901
>Spaces. 3 of them.
>>>/trash/
>>
>>51427864
Tabs.
>>
Spaces. I don't like tabs.
>>
>>51427864
Tabs.
Or if my IDE is smart enough to use backspace as unindent, 4 spaces. But mainly tabs.
>>
>>51427864
Spaces at an even count. Tabs translate very poorly between editors, spaces are consistent enough that you don't need to worry so much about the editor settings.
>>
>>51427864
Who even uses tabs if their editor doesn't convert them into spaces?
>>
tabs for indentation

spaces for alignment

fags
>>
>>51428186
people whose editors don't convert them to spaces
>>
>>51427864
Also who uses 2 spaces for indentation?
It practically means you are going to write hadouken code all the time.
>>
>>51427864
>not returns
>>
File: Tab_can[1].jpg (158 KB, 475x653) Image search: [Google]
Tab_can[1].jpg
158 KB, 475x653
>>
>>51428191
this desu senpai
>>
>>51428160

So you actually bother typing multiple spaces over and over and over, just so you can switch back and forth between IDE's? Jezus christ man.
>>
vim makes my tab button enter 4 spaces :3
>>
>>51427864
Tabs for indentation, spaces for alignment.

Then you can convert your tabs into any number of spaces and things will still line up, regardless of the tab size preference of the reader.
>>
>>51427864
tabs tabs tabs

tabs are intended for tabulation/indentation
spaces aren't
>>
Come on people, this has been a solved problem for an awfully long time. You indent with tabs, and physically align with spaces. This way, everyone can read your code at whatever indentation size they like, and nothing breaks.

Indenting with spaces is just a rude dick move, as it unnecessarily forces people to read your code in your preferred indentation size instead of theirs. If you use spaces to indent, stay the fuck away from projects that involve multiple people.
>>
>>51428160
>Tabs translate very poorly between editors
No they don't.
Tabs translate to a certain number of columns.
This can change based on what the user has set.
This is a GOOD THING, because it allows everyone to view it how they want to view it.
>>
Tabs, as in pressing the tab key.

>>51427950
It's generally agreed that certain depreciated text editors are still used by a few chromosome enhanced individuals.
>>
>>51428438
Not him but IDE can make the tab key make a certain number of spaces instead.
>>
File: msc96.jpg (454 KB, 660x1000) Image search: [Google]
msc96.jpg
454 KB, 660x1000
Tabs, or 4 spaces if you have editor problems.
>>
>>51427864
Tabs, everything else shouldn't be considered a thing.
>>
File: 1445359089519.jpg (44 KB, 622x833) Image search: [Google]
1445359089519.jpg
44 KB, 622x833
>>51427864
8 spaces. Takes a while to get used to, but when you do, you can never go back.
>>
>>51427864
Tabs, but what do I know? I'm only just learning how to properly use java...
>>
>the year MMXV AD
>not having an IDE that will understand and convert between them so when some faggot who actually uses tabs opens your code in it, your 4 spaces will become a single tab
>>
>>51431291
Converting to spaces is lossy. You can't trivially (without parsing) change indentation size, without messing up alignment.

That's why the superior strategy is tabs for indentation, spaces for alignment. Tab size can be configured while maintaining alignment, and tabs can be substituted for any number of spaces with simple replacement for rendering unambiguously.
>>
>>51427864
I literally don't give a shit anymore. I personally use spaces, but ultimately anyone who receives code from someone else can just run it through a reformatter in their editor and use whatever formatting they want. This is a trivial thing to waste time thinking about.
>>
>>51428062
>Tabs, so everyone can set them to whatever width they want and everyone can be happy.
The code formatters that are built in to every worthwhile IDE allow people to set them to whatever width they want regardless of tabs or spaces. It's seriously just a keyboard shortcut away to apply whatever formatting you configure ahead of time.

>I fuck up indentation and somehow this is the tabs' fault
He was probably referring specifically to what happens when someone attaches comments at the end of various lines of code and has it formatted so that the comments line up perfectly. If you transfer the code to another computer where they have the tabs set to a different width, it causes the comments to no longer be lined up perfectly like they were before. Additionally, this problem can also be seen with code elements which a person attempts to apply any kind of "pretty" formatting to using tab characters.
>>
I think I use both but I'm not a programmer

just for stuff like my fstab where I want it to line up with the line above
>>
>>51428438
>being this retarded
Nobody actually does what you just described. Every modern IDE and programmer's text editor has the ability to automatically insert the configured number of spaces when you hit the tab key.
>>
>>51427864
only a skiddie would ask this question, the answer is always tabs.

OP a stupid fag.
>>
>>51428571
>This is a GOOD THING, because it allows everyone to view it how they want to view it.
Formatters do a far better job of accomplishing this and they don't give a fuck whether it's tab's or spaces.
>>
>>51427864
Spaces are fixed, there will always be someone who hates the number of spaces you use.
Tabs have a width set in your IDE.

Tabs are superior.

>people still use spaces
>>
>>51432148
You can also set the number of spaces for indentation in your IDE. They are both configurable and are both trivial to override with your own preferences. Why are you still arguing for either side?
>>
There is absolutely no reason to use spaces.

1. Any proper editor will allow you to set the width of how a tab appears. So if you like the look of 4 spaces, you can set a tab to look like 4 spaces. People can now view the code how they want, and they don't have to go through an additional step of reformatting code.
2. A tab is meant for indentation, by using spaces you are breaking conventions.

Spaces cause the most issues. We have to build editors to deal with the issues that spaces cost, where if every one just used tabs we'd be much better off.

Only time spaces should be used is when aligning something.
>>
>>51432227
>Only time spaces should be used is when aligning something.
mixing tabs and spaces?
you don't deserve to live.
>>
>>51432227
>1. Any proper editor will allow you to set the width of how a tab appears. So if you like the look of 4 spaces, you can set a tab to look like 4 spaces. People can now view the code how they want, and they don't have to go through an additional step of reformatting code.
The exact same thing is true about spaces. Any decent editor lets you configure either tabs or spaces and set how wide either should be.
Someone could literally use the exact same argument on the other side
>>
>>51432263
In that case, spaces would take up more storage space.

There's no reason to use spaces, especially when it breaks conventions.
>>
>>51432293
You're fucking autistic if you care about an extra 1 byte (or 3 extra if you use 4 spaces instead of 2 master race) of data per indentation.

It literally makes no practical difference whether a person uses tabs or spaces. Whenever I import code into my own environment I reformat it 100% anyways using the formatter built in to my IDE. It's trivial to do and the code always turns out the way I want it (taking into consideration much more than just tabs/spaces).
>>
>>51432334
I don't care about that, I'm just listing off reasons as to why tabs are better.

Tabs have more advantages than spaces. While good editors will allow you to work with both of them equally as well, there are still more benefits to using tabs.

Why should I use spaces over tabs?
>>
>>51432372
Because then you don't have to fiddle with the settings of every text editor you use to get the indentation level you want. If I open one of my project files on some random text editor that is not on a machine owned by me or is in a text editor I have not configured yet, I would prefer that it look passable without me having to much about with settings first. I can't remember which editor it was, but I opened one of my project files in some text editor once and it was set to 8 character width and somehow fucked the formatting of all my end of line comments. That is the day I switched to spaces and never looked bad. I have had 0 problems as a result of my change.
>>
Spaces for indentation

Tabs for word separation.
>>
>>51427864
tabs that create spaces.
>>
>>51428438
>Not setting expandtab in your vimrc
This has been a thing since forever.
>>
>>51427864
Depends on what coding standards were set by the team or company. You don't want to be that one jackass that tries to force your coding standards into a group effort.
>>
>>51427864
Depends.
>>
>spaces
you need all the changes in formatting, macros etc.
>tabs
It just werks.. Less wasted space, equally customizable in length.
>>
Spaces. I don't even know what the point of tabs are. They seem like some leftover from the 60s. If you're so autistic about your preferred indentation, you can just as well have your editor display spaces at the beginning of the line differently.
>>
>>51427864
Both. Tabs for indentation, spaces for alignment.
>>
>>51433472
>I don't even know what the point of tabs are.
It's a special indentation character where the editor can decide its length, literally made for indentation.
>>
>open browser
>search absolutely anything into it
>find a sentence and highlight the space between a word
>Ctrl c/Ctrl v
>>
>>51433584
I once had to do this when my spacebar was broken and I needed to send something. Just typing CtrlV every time I needed a space.
>>
>>51431348
This.
Tabs.
>>
I use tabs and then convert to spaces, because tabs do not display correctly when I copy & paste code fragments into word, even with a monospace font
>>
>>51427864
b-both
>>
>>51433584
very useful t bh
>>
>>51428062
>Tabs, so everyone can set them to whatever width they want and everyone can be happy.
Are you saying that your editor doesn't automatically reformat and reindent the files you open up and save them back with their original indentation? Are you living in the 1990s?
>>
>there are dipshits who actually use spaces
>>
>>51428540
Tabs are intended for tabulation, not indentation.

Tabulation: to arrange into a table

I bet you code in Excel spreadsheets, you lowlife.
>>
>>51432293
>In that case, spaces would take up more storage space.
>Worrying about bytes that don't even add up to half a blu-ray movie over the course of all human history.
Do you also code in assembly?
>>
>>51432671
kek
>>
>>51436210
a real programmer uses a magnetised needle and a steady hand!
>>
Some of you retards need to read this, very carefully:
https://www.jwz.org/doc/tabs-vs-spaces.html
>>
>>51431547
>someone attaches comments at the end of various lines of code and has it formatted so that the comments line up perfectly

I hate this shit so much; I don't know whay "indent with tabs, align with spaces" is so difficult for some people. Also, these bullshit aligned comments ALWAYS look like shit. Just put them in a block before your lines of code, or before the related line. I like tabs personally, but I can see encouraging spaces over tabs if only to discourage obnoxious shit like this, where every time you change a line of code you need to do extra work to keep the god damn comments lined up.
>>
Just look at the fucking icon on the tab button, you must have downs syndrome if you think spaces are better for indentation
>>
>>51427864
I've honestly never seen an experienced programmer recommend tabs
>>
>>51436354
I've honestly never seen an experienced programmer recommend anything but tabs.
>>
>>51436210
What kind of fucking casual are you?
>>
>>51432254
The real issue is that people shouldn't care about aligning things. It doesn't make anything easier to read, and just adds extra pointless whitespace.

My policy:
If I reach the end of some self-imposed column, I break the line wherever I start the continuation at one extra level of indention. If the continuation extends for multiple lines, then each subsequent line doesn't get indented any more than the first did.
// Fuck this shit
myExtraLongFunctionCall(var1,
7,
extraLongVar2,
extraLongVar3,
extaLongVar4,
asdf);

// The superior way that won't get fucked up when someone tries to use tabs
myExtraLongFunctionCall(var1, 7, extraLongVar2, extraLongVar3,
extraLongVar4asdf);
>>
These threads are fun because you get to see multiple classes of idiots in action.

Idiot #1: Thinks that indenting with spaces means hitting the space bar multiple times. He isn't using an editor that indents code automatically.

Idiot #2: Doesn't know what auto formatters are. Thinks that using tabs lets other people adjust indentation width when anyone can take an arbitrary file, run it through a formatter (automatically), and have their preferred indentation width regardless of whether the file was originally indented with tabs, spaces, or bananas.

Idiot #3: Doesn't know that all projects/companies have a style guide and thus there is no point in arguing over indentation style since you must follow the guide period.

Idiot #3.5: Isn't using a text editor that can automatically format code that follows the project style guide with their own preferred indentation style and then automatically save the code using the project's required style, thus rendering any and all complaints moot.
>>
>>51436270
It's literally not even relevant to the issue. All it says is "some editors don't insert tab characters unless you tell them to (lol emacs, it's really the only one) therefore nobody should insert the tab character even though the tab character is correctly interpreted by any editor".
>>
>>51436417
>"We here at google have recently introduced a new programming language with a big emphasis on parser simplicity--leading to superior compiler accuracy and code readability!"
>>
>>51436425
Absolutely_disgusting.jpg
You're outright the worst in the entire thread and if I didn't know better I'd think you're b8ing.
>>
>>51436427
You forgot:
idiot #4: doesn't know how auto-formatters work and think that they can magically detect indentation policy without being told what it is
idiot #5: so retarded he doesn't understand that most people don't work alone on programming projects and therefore modifying a source file for muh spess purposes adds humongous wastes of time and trashes commit logs completely
idiot #6: thinks that blindly following the most retarded guideline is the way forward instead of selecting the optimal strategy
>>
>>51436243
There's a reason why people minify js.
>>
>>51431348
Exactly.
>>
>>51436460
I know that it's such a common practice that many people clearly must disagree, but I'd argue either in favor of automated code formatting tools or using spaces, if only to reduce the amount of hideous shit like pic related, from the linux kernel (I know it's not the best example because His Holiness linus mandated 8-character tabs, but that's another issue in itself)
>>
>>51432263
>reformatting lets you not reformat
Toppest kek, spacefag.
>>
>>51436519
Because they don't know about gzipped HTTP and/or they decided it's a good idea to deliver a 10MB application via their website.
>>
>>51436540
>ASM (thus without indentation) is a good argument for using spaces over tabs!
2000/10 imad.
>>
>>51436178
Oh yes, this sounds awesome for working on collaborative projects, right?
>>
>>51436602
It's great, because it keeps the autist who insists on Fibonacci sequence indentation happy, and all the code in the repository uses consistent 4-width spaces indentation.
>>
I used to prefer tabs, but now I use 4 spaces everywhere I can.

1. Fuck you and your ability to set the tabs however you want. The code should look exactly the same on every screen. Fuck ambiguity.
2. You can align things in columns when you need it, without going "oh boy mixing tabs with spaces" (inb4 that autotab gif that uses one tab to separate table cells - well fuck it, I've never seen it outside that gif). Compare
{Snow, 0x0404},
{Thunderstorm, 0x1010},
{Hurricane, 0x5855},
(10+ more items)

with
{Snow,         0x0404},
{Thunderstorm, 0x1010},
{Hurricane, 0x5855},
(10+ more items)

Say what you want, the second one is always more readable (otherwise humans wouldn't have invented tables).
3. You can use half tabs (see Google's code guidelines where they tell you to indent "public:" etc. with one space. Even if it is shit suggestion, you have more freedom in your own decisions alright.)
4. Automatic code linters (you do use them right?) that guard max line size will just work, without every intern asking you "hey how much characters does the tab count for when validating my code?" (also see point 1)

I'd say tabs are okay for Ruby and maybe Python where each line usually takes 20 characters tops, because most of my arguments boil down to what happens once you need to wrap your code often (== at least one time per file).

(For the record, I write code in C++, C, C#, Python, Ruby and PHP.)
>>
>>51436574
You're missing the point; the problem with tabs isn't indentation; I honestly think that's a pretty good use of them. The real issue comes from two things:
>people thinking they need to "align" things like comments rather than putting them on their own line
>people carrying out said alignment using tabs

And that assembly snippet is a great example of exactly why that looks awful.
>>
>>51436630
And to follow up, aligning things can be fine, as in >>51436628 where it makes *code* easier to undertand. Just, if you do so, you should be using spaces otherwise differing tab settings WILL make things look like shit.
>>
>>51436628
>>>/tumblr/
>>
File: 349.png (14 KB, 800x600) Image search: [Google]
349.png
14 KB, 800x600
Tabs converted to spaces.

The number of them either 2 or 4, depending on the language I'm writing in.
I like 2 more, personally.
>>
>>51436628
friendly protip: listing out the programming languages you use makes you look like an amateur
>>
Tabs
>>
>>51436689
I listed them to show what I was referring to. For example, I can't have opinion on indenting lisp, since I don't use it (and judging from its syntax, I don't want to).
>>
>>51436746
You can't have an opinion on indenting lisp because lisp is indented automatically (with spaces). There is no argument unless you're an autist
>>
>>51436210
that's why i said
>tabulation/indentation
it's not exactly the same thing, but they're similar concepts. properly indented code has a table-link structure, with the lines as rows and different levels of indentation as columns.
>>
>>51427864
I'm for tabs.

Down with filthy fucking spacers.
>>
>>51436855
table-like*

also, tabs are superior for aligning things with varying width to the same column.
$array =
[
'foo' => 1,
'foobar' => 2,
'niggerstonguemyanus' => 3,
];
>>
>>51436628
>You can align things in columns when you need it

No, fuck that. It's stupid.

If you can't read it because it's not aligned in columns there's something wrong with your brain anyway.
>>
>>51436911
Fuckoff, fizzbuzztard.
>>
Neither, only newlines


int main(void) {


printf("Come at me bro");


}

>>
>>51436930
I'm sorry your brain doesn't work properly.
>>
>>51436942
I hear they have job openings at microsoft!
>>
>>51436974
I'm sorry you think fizzbuzz is the height of programming expertise.
>>
>>51437013
I don't think it is, just like I don't think aligning things into columns accomplishes jack dick other than wasting time.
>>
>>51436906
>also, tabs are superior for aligning things with varying width to the same column
See the pic on >>51436540. This is *exactly* why tabs shouldn't be used for alignment. because different editors have different settings. It only works if you either mandate that everyone use your same tab settings, which is a fucking obnoxious thing to do. Sure, people can change editor settings, but then what if you need to work on a different project in the same language where some jackass assumed yet another different tab width? Don't do this shit with tabs. If it's that important to align your columns, then hold down the space bar for a little longer.
>>
>>51437036
Whaaaat? You manage to graduate from fizzbuzz to hello world??? Congratulations, timmy!
>>
>>51437068
> In my special education class,
hello world
is harder than
fizzbuzz
.
> My teacher lets me spend extra time aligning things into columns because she knows I'm autistic and won't accomplish anything with the time wasted anyway.
>>
>>51437115
That's too bad, timmy. Maybe you'll become normal one day, don't despair now :)
>>
>>51437115
>Implying companies aren't hiring autistic "coders" like crazy.
>>
Tabs, Kek of then
>>
>>51428233
>being this retarded
>>
>>51431348
I don't really know what problem you're describing but I can tell you from years working in an office where everyone is always checking in files with fucked up formatting from their personal tweak of the editor settings, that it's perfectly able to adapt.
>>
In thought a tab is just a "\t", which can be interpreted as much indention as the user sets it to.
So it is vastly superior to spaces, because each space takes a byte and you can't change the indention with the click of a button in the menus.
>>
>>51438563
yea, a tab is a single byte
>>
>>51438563
>because each space takes a byte
Yes, and this will totally matter when you send your 100000-file particle physics simulator as an e-mail attachment.

>you can't change the indention with the click of a button in the menus
Yes you can idiot
>>
>>51438580
So why are we arguing about tabs vs spaces if any sane person would just use tabs and adjust the indention in his editor as he pleases?
>>
>>51438587
Well, it would be 4 times as big for each line.
This adds up fast.
>>
>>51427864
Spaces. COBOL programmer here.
>>
Spaces. One kind of semi-manual whitespace is already too much, let's not make it any more complicated.
>>
>>51438590
>...if any sane person...
there's your answer
>>
>>51438507
>I'm a professional hello world developer and
Filtered.
Thread replies: 130
Thread images: 7

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.