Tabs vs Spaces

Please compose all posts in Emacs.

Moderators: phlip, Moderators General, Prelates

Re: Tabs vs Spaces

Postby hotaru » Mon Oct 18, 2010 8:53 pm UTC

bytbox wrote:5 tabs. If you're nesting any deeper than that, you're screwed anyway.

apparently you haven't seen much lisp code...
Code: Select all
#include <stdio.h>

int main()
{
 struct { unsigned a:3, b:3, c:2; } n = {0};
  do do printf("%hhu\n", *&n);
  while(!(n.a-- && !++n.b));
  while(++n.c);
  return 0; } 
User avatar
hotaru
 
Posts: 932
Joined: Fri Apr 13, 2007 6:54 pm UTC

Re: Tabs vs Spaces

Postby bytbox » Mon Oct 18, 2010 9:04 pm UTC

hotaru wrote:
bytbox wrote:5 tabs. If you're nesting any deeper than that, you're screwed anyway.

apparently you haven't seen much lisp code...

I'm speaking about bracketed languages only. Other languages, including lisp, often work/look better with spaces. For lisp, I'd go with 4.
bytbox
 
Posts: 56
Joined: Wed Aug 19, 2009 5:43 am UTC

Re: Tabs vs Spaces

Postby Jplus » Mon Oct 18, 2010 11:05 pm UTC

Lines longer than 40 characters happen often enough. Also, I think 8 spaces is just more than you need (and I find it ugly). 4 spaces is already very well readable. And 5 levels of indentation can sometimes not be enough, although I agree you should generally try to stay below that.

I have never experienced that shorter indentations would make me believe I can indent more levels. Actually I find 5 levels of 2-space indentations harder to read that 5 levels of 4-space indentation, and therefore I would also sooner feel urged to do something about it.

I used to auto-expand tabs because that would guarantee my files look the same everywhere, but I recently switched to hard tabs, for a number of reasons. One of them is that other people might prefer to set the tab width to a different number of spaces. Also they take up less space (I also use them to line up comments, so it can make quite a difference on a large project), and they can be removed faster using backspace/delete.
Hey, like coding? Perhaps you should check out the red spider project.
Feel free to call me Julian. J+ is just an abbreviation.
User avatar
Jplus
 
Posts: 1098
Joined: Wed Apr 21, 2010 12:29 pm UTC

Re: Tabs vs Spaces

Postby Thesh » Mon Oct 18, 2010 11:24 pm UTC

If you code in C#, you will find that it is pretty much impossible to write anything significant with less than 5 levels of indentation. 3 levels of indentation is pretty much the minimum:

Code: Select all
namespace
{
    class
    {
        function ()
        {
            //Code
        }
    }
}

That said, I still find setting the tab width to 4 spaces to be perfectly acceptable.
Eppur si mouve.
User avatar
Thesh
Has the Brain Worms, In Case You Forgot.
 
Posts: 2573
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Southern California, USA

Re: Tabs vs Spaces

Postby flying sheep » Wed Oct 20, 2010 6:00 pm UTC

do you really do that in c#? i remember that in java, we did 1 class per file, so the minimum would be 1 level of indentation (stuff inside functions, eeh, sorry, methods)
User avatar
flying sheep
 
Posts: 63
Joined: Sun Jan 31, 2010 12:35 am UTC

Re: Tabs vs Spaces

Postby hintss » Thu Oct 21, 2010 1:03 am UTC

I tend to keep 4 spaces per tab, or for stuff with more levels, I use 2. Then for stuff like <html> and <head> are considered the 0th level: the first level inside isn't indented
"s/god/flying spaghetti monster/"
User avatar
hintss
 
Posts: 1294
Joined: Wed Nov 25, 2009 7:19 am UTC

Re: Tabs vs Spaces

Postby Thesh » Thu Oct 21, 2010 3:41 am UTC

flying sheep wrote:do you really do that in c#? i remember that in java, we did 1 class per file, so the minimum would be 1 level of indentation (stuff inside functions, eeh, sorry, methods)


Yeah, that's pretty much how everything you write is. And yeah, methods... Makes less sense than functions, but we stick to the name anyway (probably because someone wrote the name down in a book somewhere).
Eppur si mouve.
User avatar
Thesh
Has the Brain Worms, In Case You Forgot.
 
Posts: 2573
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Southern California, USA

Re: Tabs vs Spaces

Postby flying sheep » Fri Oct 22, 2010 12:49 am UTC

i meant it like hintss: we didn’t indent the forst level, because it’s quite useless: you don’t gain any more readability, but you have indented 99.999% of your code. i think it’s much better to do
Code: Select all
public class Stuff {

public static void main(String[] args) {
   System.out.println("This command is far to long for a simple print statement");
}

}
User avatar
flying sheep
 
Posts: 63
Joined: Sun Jan 31, 2010 12:35 am UTC

Re: Tabs vs Spaces

Postby Thesh » Fri Oct 22, 2010 2:13 am UTC

flying sheep wrote:i meant it like hintss: we didn’t indent the forst level, because it’s quite useless: you don’t gain any more readability, but you have indented 99.999% of your code. i think it’s much better to do
Code: Select all
public class Stuff {

public static void main(String[] args) {
   System.out.println("This command is far to long for a simple print statement");
}

}


Makes sense to me, but default .NET templates, code samples from Microsoft, and all of the code I seen is like I posted. I agree that it is a waste, especially with the namespace. I generally prefer the C++ style of defining functions outside of the class. Check this example from msdn, they even nest namespaces:

http://msdn.microsoft.com/en-us/library/z2kcy19k(v=VS.100).aspx

Code: Select all
namespace SomeNameSpace
{
    public class MyClass
    {
        static void Main()
        {
            Nested.NestedNameSpaceClass.SayHello();
        }
    }

    // a nested namespace
    namespace Nested   
    {
        public class NestedNameSpaceClass
        {
            public static void SayHello()
            {
                Console.WriteLine("Hello");
            }
        }
    }
}
// Output: Hello
Eppur si mouve.
User avatar
Thesh
Has the Brain Worms, In Case You Forgot.
 
Posts: 2573
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Southern California, USA

Re: Tabs vs Spaces

Postby cjmcjmcjmcjm » Fri Oct 22, 2010 5:06 am UTC

Tabs
frezik wrote:Anti-photons move at the speed of dark

DemonDeluxe wrote:Paying to have laws written that allow you to do what you want, is a lot cheaper than paying off the judge every time you want to get away with something shady.
User avatar
cjmcjmcjmcjm
 
Posts: 1022
Joined: Tue Jan 05, 2010 5:15 am UTC
Location: Anywhere the internet is strong

Re: Tabs vs Spaces

Postby flying sheep » Sun Dec 05, 2010 2:26 am UTC

to the “we want people with crappy editors to be able to edit our code”-people:
as soon as elastic tabstops are implemented in more editors, you will have to whine even more
User avatar
flying sheep
 
Posts: 63
Joined: Sun Jan 31, 2010 12:35 am UTC

Re: Tabs vs Spaces

Postby Darryl » Sun Jan 23, 2011 12:43 am UTC

cjmcjmcjmcjm wrote:Tabs

Though nothing more than this truly needs to be said (as well as spaces for alignment, natch), an explanation beyond "it's what my professors insisted on".

I use(d) weird indentation (past tense since I haven't actually written code since 2004, and have since changed majors to math education). I like 3 space indentation, as it looks good to my eyes. No one else I knew used 3-space, so I set my editor to display tabs at a length of 3, while others left theirs at their preferred lengths. If you indent with tabs, I see it in my preferred 3, you see it at 2, and Johnny sees it at 7 (because while I may be a bit eccentric, Johnny's just plain weird ;) ), but if you indent to your 4 spaces with spaces, it clashes with what others expect in indented code. While having your aesthetics respected on your screen is good, tabs let you do this and still respect those of others when they have to look at your code for various reasons.
yurell wrote:We need fewer homoeopaths, that way they'll be more potent!
Darryl
 
Posts: 287
Joined: Mon Sep 22, 2008 2:32 pm UTC

Re: Tabs vs Spaces

Postby happosai » Thu Feb 03, 2011 6:06 pm UTC

"tabs for indentation" and "spaces for aligning". Works perfectly, making both the "tab" and "spaces" people happy. Everything was happy, until people started using code editors with variable width font. frackers.
happosai
 
Posts: 3
Joined: Thu Feb 03, 2011 5:37 pm UTC

Re: Tabs vs Spaces

Postby Darryl » Thu Feb 03, 2011 8:53 pm UTC

happosai wrote:Everything was happy, until people started using code editors with variable width font. frackers.

That abomination does not exist. Changing to a different fixed width is fine (I've used Lucida Typewriter in Visual Studio when I had to use that editor), but a variable-width? That shouldn't even be an option in code editors.
yurell wrote:We need fewer homoeopaths, that way they'll be more potent!
Darryl
 
Posts: 287
Joined: Mon Sep 22, 2008 2:32 pm UTC

Re: Tabs vs Spaces

Postby flying sheep » Fri Feb 04, 2011 2:57 am UTC

happosai wrote:"tabs for indentation" and "spaces for aligning". Works perfectly, making both the "tab" and "spaces" people happy. Everything was happy, until people started using code editors with variable width font. frackers.

then they have to use elastic tabstops or not use visual alignment alltogether:

Code: Select all
this = {"looks": "shitty",
        "with":  "variable"}
character("width.",
          "and without elastic tabstops")

Code: Select all
this = {
   "looks": "good",
   "with": "variable"
}
character(
   "width,",
   "too"
)

note that this forum converts tabs into spaces. of course this is written with tabs.
User avatar
flying sheep
 
Posts: 63
Joined: Sun Jan 31, 2010 12:35 am UTC

Re: Tabs vs Spaces

Postby Pesto » Tue Mar 08, 2011 1:11 am UTC

Tabs cause the testing framework in Groovy on Grails to give icky output. It gave me a sad.
User avatar
Pesto
 
Posts: 729
Joined: Wed Sep 05, 2007 5:33 pm UTC
Location: Berkeley, CA

Re: Tabs vs Spaces

Postby flying sheep » Sat May 07, 2011 9:41 am UTC

my day was just made by discovering that someone picked up my GSoC idea of implementing elastic tabstops into kate.
User avatar
flying sheep
 
Posts: 63
Joined: Sun Jan 31, 2010 12:35 am UTC

Previous

Return to Religious Wars

Who is online

Users browsing this forum: No registered users and 3 guests