Author Topic: Programming Megathread  (Read 106417 times)

Why does it matter? You pick on everyone when they do something just slightly different.
we're having a debate about wether tabs or spaces are better
in a debate you generally pick on other people's opinions

Code: [Select]
#This is a code in Python what tells you the min of 3 numbers

def min(a,b):
    return a if a < b else b

def min1(a,b,c):
     return min(a,b) if min(a,b) < c else c

print("min(5,1) = %d" % min(5,1))
print("min1(5,1,2) = %d" % min1(5,1,2))

output:
min(5,1) = 1
min1(5,1,2) = 1

but then why hit the spacebar four times when you can just hit tab once
you hit tab once, using any decent text editor which, when the settings are changed, will automatically insert four spaces (the only text editor I know of that does not do this is notepad)
or, if for some reason you want a different number, then a different number. even with a different number you are still guaranteed that it will be the same size to anyone who looks at it

exceptional editors also sometimes work backwards, removing the number of spaces that corresponds to those settings when you press backspace. but that's less common

A tab isn't comparable to any number of spaces, because that's not how they work.
Four spaces is just four characters across, whereas a tab aligns you to the next tab stop


spaces are always one character long. but tabs are unpredictable. someone may have theirs set to 2 characters or 8. so it is impossible to ensure that your lines will fit within 80/100 columns if you use tabs
That's one reason why you do use tabs. If someone has their text editor set to a given length for tabs, it's because they want them like that. You don't just go "no forget you you're seeing them at 4 now because I said so"


Also four spaces is four times as many key strokes

That's one reason why you do use tabs. If someone has their text editor set to a given length for tabs, it's because they want them like that. You don't just go "no forget you you're seeing them at 4 now because I said so"
Also four spaces is four times as many key strokes
it doesn't matter what they want their tabs to look like, because the point is to make sure your code is readable. no matter what number you use, if you use a certain amount of spaces, you can, absolutely, make sure every line appears under 80 characters long for every person looking at it
would you write any other parts of your code differently because it's what someone else prefers?

and like I said, notepad is the only text editor I've ever used that does not have a setting to insert a certain number of spaces when you press tab

for the whole tab inserting spaces thing, i haven't really seen an editor that does that. i know codeblocks does it, but everything else i've seen just inserts a \t instead of adding spaces
i don't use a lot of editors outside of notepad++ though

the default setting on Atom seems to be "tabs are twice as large as spaces"

thats neat to know



edit: also
for the whole tab inserting spaces thing, i haven't really seen an editor that does that. i know codeblocks does it, but everything else i've seen just inserts a \t instead of adding spaces
i don't use a lot of editors outside of notepad++ though

i've made the switch from n++ to Atom because (according to the people who recommended it to me) it's more customizable and, like, better and stuff.

iunno, might wanna give it a try. it's gud.
« Last Edit: January 26, 2016, 11:17:41 AM by Tudoreleu »

for the whole tab inserting spaces thing, i haven't really seen an editor that does that. i know codeblocks does it, but everything else i've seen just inserts a \t instead of adding spaces
i don't use a lot of editors outside of notepad++ though
notepad++ does it

it's in "tab settings"

the checkbox is the setting I'm referring to

sublime does it as well. and atom. and komodo edit. and certainly any IDE will do it


You can use also the joe's editor, but you need to compile it (open-source)

It is command line

http://joe-editor.sourceforge.net/

I can see converting to spaces for posting the code on forums or whatever, but for actually doing development I find that seeing spaces as my indentation is completely aggravating. Tabs just seem more efficient and should align well in any respectable editor.

Tabs just seem more efficient and should align well in any respectable editor.
the problem isn't alignment, it's just length. if you use a tab on a line with 75 other characters, the whole line may appear to you as 79 characters long, but someone looking at your code with their tabs set to 8 characters long in a command prompt window won't be able to see the whole line without scrolling or resizing their window
but if you use four spaces, it'll be 79 to everyone, and they can keep their tabs set to 8 without it interfering with reading your code

even microsoft themselves suggest using spaces
"Use the default Code Editor settings (smart indenting, four-character indents, tabs saved as spaces)."
« Last Edit: January 26, 2016, 11:37:07 AM by Foxscotch »

Honestly, forget you if your screen only supports up to 80 characters in width. It's not the 1990's anymore.
Tabs are better

The only time I'd see you having an 80-width screen is maybe if you're using a Linux server. But even then you should probably be managing it through SSH anyways, which fully supports resizing that terminal to a sane resolution.


I mean as of windows 10 even cmd and powershell support having a full-screen width.

Actual question: Why would you set your tab-width to more than 4? I can't really see any good reason to do that.
« Last Edit: January 26, 2016, 11:52:01 AM by Pecon »

Honestly, forget you if your screen only supports up to 80 characters in width. It's not the 1990's anymore.
there are 100 reasons this is completely ridiculous, but most importantly is the fact that command prompt/terminal/console/whatever you wanna call it windows are usually 80 characters wide. I don't know why, but that's how it is, and to my knowledge most people keep it that way. with spaces you can make sure they'll be able to see all of your code without moving to their mouse to resize the window or scroll right. with tabs, you can not