Pages: 1 2 »
  Print  
Author Topic: Indentation Styles  (Read 2438 times)
Offline (Male) Goombert
Posted on: July 20, 2014, 03:07:56 PM

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 3107

View Profile
Well I recently provoked IsmAvatar on GitHub about two spaced indentations in which she raised some interesting counter arguments.
https://github.com/IsmAvatar/LateralGM/pull/128

I also recently updated the coding techniques article to address this.
http://enigma-dev.org/docs/Wiki/Coding_conventions

Anybody with a GitHub account respond there, otherwise respond here.
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Male) Rusky
Reply #1 Posted on: July 20, 2014, 03:10:54 PM

Resident Troll
Joined: Feb 2008
Posts: 955
MSN Messenger - rpjohnst@gmail.com
View Profile WWW Email
Tabs are pretty much superior in every way, but because mixing tabs and spaces is painful everyone seems to have standardized on spaces. Unfortunately.
Logged
Offline (Male) edsquare
Reply #2 Posted on: July 20, 2014, 03:46:21 PM

Member
Location: The throne of ringworld
Joined: Apr 2014
Posts: 402

View Profile
Tabs are pretty much superior in every way, but because mixing tabs and spaces is painful everyone seems to have standardized on spaces. Unfortunately.

So true.
Logged
A child of five would understand this. Send someone to fetch a child of five.
Groucho Marx
Offline (Unknown gender) Darkstar2
Reply #3 Posted on: July 20, 2014, 04:39:01 PM
Member
Joined: Jan 2014
Posts: 1244

View Profile Email
Ever since I started coding I have always used tabs.

As far as how people indent that seems to  vary.  Some start the bracket on the same line, others start it on a new line and anything between it indented.  Personally that's what I do, makes code more readable / cleaner, in my view.

Logged
Offline (Male) Josh @ Dreamland
Reply #4 Posted on: July 20, 2014, 09:44:22 PM

Prince of all Goldfish
Developer
Location: Pittsburgh, PA, USA
Joined: Feb 2008
Posts: 2949

View Profile Email
My aversion to tabs is that they have not been assigned a logical width. People individually choose how big they want their tabs. While that's great for personalization, it's bad for consistency. You can't align variables easily, or use half-indentations or double-indentations without explosion (my double is 4 spaces; some are 16). The biggest offender is when people try to line up variables after "int" or "var." It's not really my style, but it happens; exactly four spaces of indent are required to pad the next line so that all the identifiers line up. You can use spaces to do exclusively the non-indentation alignment, of course, assuming your editor lets you, but I've never seen anyone pull that off.

The lack of size agreement leads to more solid problems, in my case. GNU style seems to be two-space indent, but any leading eight spaces of indent are replaced with a single tab character. This means for me to correctly view anything GNU, I have to set my tab width to eight. My preferred tab width is two. When you send me a file and every fucking line is indented eight tabs, I flip shit. I find lately that I leave my tab widths both at two and manually replace "\t" with "        " in GNU sources.

So yes, in a perfect world, everyone agrees, and we all use tabs. In this world, tabs are any multiple of 1 in size (even that's not playing it safe—some people don't use fixed-width editors, but no one cares what they think). Spaces, however, I have never noticed to be rendered as anything other than a single space of width, with or without special coloring or symbolage to denote that there's actually a character there. So I use two spaces, and my code looks the same whether it's loaded in emacs, in vim, in MS fucking Notepad, or in an actual code editor.


inb4 gr8 b8 m8
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Male) edsquare
Reply #5 Posted on: July 20, 2014, 10:12:31 PM

Member
Location: The throne of ringworld
Joined: Apr 2014
Posts: 402

View Profile
My aversion to tabs is that they have not been assigned a logical width. People individually choose how big they want their tabs. While that's great for personalization, it's bad for consistency. You can't align variables easily, or use half-indentations or double-indentations without explosion (my double is 4 spaces; some are 16). The biggest offender is when people try to line up variables after "int" or "var." It's not really my style, but it happens; exactly four spaces of indent are required to pad the next line so that all the identifiers line up. You can use spaces to do exclusively the non-indentation alignment, of course, assuming your editor lets you, but I've never seen anyone pull that off.

The lack of size agreement leads to more solid problems, in my case. GNU style seems to be two-space indent, but any leading eight spaces of indent are replaced with a single tab character. This means for me to correctly view anything GNU, I have to set my tab width to eight. My preferred tab width is two. When you send me a file and every fucking line is indented eight tabs, I flip shit. I find lately that I leave my tab widths both at two and manually replace "\t" with "        " in GNU sources.

So yes, in a perfect world, everyone agrees, and we all use tabs. In this world, tabs are any multiple of 1 in size (even that's not playing it safe—some people don't use fixed-width editors, but no one cares what they think). Spaces, however, I have never noticed to be rendered as anything other than a single space of width, with or without special coloring or symbolage to denote that there's actually a character there. So I use two spaces, and my code looks the same whether it's loaded in emacs, in vim, in MS fucking Notepad, or in an actual code editor.


inb4 gr8 b8 m8

Yea I have seen code indented like the one that wrote it had a 40" monitor  :o I didn't know it could happen when you indent with tabs on windows I assume, and then open it on linux.  >:(

If this is for Enigma's code editor then you could go the SPE (Stany's Python Editor) and force the size of the tabs to two spaces only and always, when you indent you can use either spaces or tabs, since it converts the tabs to two spaces automatically.
Logged
A child of five would understand this. Send someone to fetch a child of five.
Groucho Marx
Offline (Male) Rusky
Reply #6 Posted on: July 20, 2014, 10:58:08 PM

Resident Troll
Joined: Feb 2008
Posts: 955
MSN Messenger - rpjohnst@gmail.com
View Profile WWW Email
Aligning variables and half/double-indentation are not useful. There are a few patterns in common use that make tabs ugly, but they're easy to get around:

Instead of this:
Code: [Select]
function_call(foo,
              bar,
              baz)
which still pushes code far to the right anyway while you were trying to avoid long lines, I do this:
Code: [Select]
function_call(
    foo,
    bar,
    baz
)
If you really want you could put the parenthesis on the line with the last argument, but this way it matches how you use {}s and lets you move arguments without grabbing the closing parenthesis. Same pattern applies to function declarations, large expressions in control structures, etc:
Code: [Select]
if (
    do_something_really_long &&
    split_up_over_multiple_lines || (
        with_sub_expressions
    )
) {
    stuff
}
Logged
Offline (Male) Goombert
Reply #7 Posted on: July 21, 2014, 12:08:26 AM

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 3107

View Profile
For all the reasons Josh stated is why I agree with him ceteris paribus, the very fact that it opens the same everywhere is the reason it is standard in my opinion because it makes it universal.

And ironically there is a code beautifier by this name.
http://universalindent.sourceforge.net/

Also apparently Wikipedia has this all documented.
https://en.wikipedia.org/wiki/Indent_style#GNU_style

I would just prefer we all use the same indentation style, so that everything opens properly on GNU as well. I get sick of opening up source files either I or someone else edited and the formatting being all wrong, so I asked Josh and he told me to switch to 2 space, and I prefer it because of the universality so I would prefer we just all use that.
« Last Edit: July 21, 2014, 12:12:22 AM by Robert B Colton » Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Male) edsquare
Reply #8 Posted on: July 21, 2014, 12:50:06 AM

Member
Location: The throne of ringworld
Joined: Apr 2014
Posts: 402

View Profile
For all the reasons Josh stated is why I agree with him ceteris paribus, the very fact that it opens the same everywhere is the reason it is standard in my opinion because it makes it universal.

And ironically there is a code beautifier by this name.
http://universalindent.sourceforge.net/

Also apparently Wikipedia has this all documented.
https://en.wikipedia.org/wiki/Indent_style#GNU_style

I would just prefer we all use the same indentation style, so that everything opens properly on GNU as well. I get sick of opening up source files either I or someone else edited and the formatting being all wrong, so I asked Josh and he told me to switch to 2 space, and I prefer it because of the universality so I would prefer we just all use that.

Not sure if I understood correctly, but you mean two spaces for every level or not?
Logged
A child of five would understand this. Send someone to fetch a child of five.
Groucho Marx
Offline (Male) Goombert
Reply #9 Posted on: July 21, 2014, 02:44:59 AM

Developer
Location: Cappuccino, CA
Joined: Jan 2013
Posts: 3107

View Profile
I'm not sure, what I mean is you press tab and the selected text is indented two spaces.
Logged
I think it was Leonardo da Vinci who once said something along the lines of "If you build the robots, they will make games." or something to that effect.

Offline (Unknown gender) TheExDeus
Reply #10 Posted on: July 21, 2014, 04:55:47 AM

Developer
Joined: Apr 2008
Posts: 1872

View Profile
I also like tabs a lot. I don't get the "width" issue though, because it doesn't matter if a tab is 1cm or 5cm. The code will still be indented properly. So I haven't had any problems with that, but I rarely use linux, so I don't know if they have problems there or now. I haven't had any problems in  Code::Blocks, Notepad++, VS and Wordpad. Works flawlessly everywhere. So it's seems to be a linux issue.

edit: I personally use https://en.wikipedia.org/wiki/Indent_style#Kernel_style and https://en.wikipedia.org/wiki/Indent_style#Variant:_1TBS . More the 1TBS.
« Last Edit: July 21, 2014, 05:00:49 AM by TheExDeus » Logged
Offline (Male) Rusky
Reply #11 Posted on: July 21, 2014, 10:50:46 AM

Resident Troll
Joined: Feb 2008
Posts: 955
MSN Messenger - rpjohnst@gmail.com
View Profile WWW Email
My tab style also opens the same in all places, and lets users adjust tab width (I personally think 2 spaces is too small, some people like it, why can't we have both?). It also discourages people trying to be fancy with alignment, which often just hurts readability and takes more effort to maintain.
Logged
Offline (Male) edsquare
Reply #12 Posted on: July 21, 2014, 11:06:23 AM

Member
Location: The throne of ringworld
Joined: Apr 2014
Posts: 402

View Profile
I'm not sure, what I mean is you press tab and the selected text is indented two spaces.

Now I understand, that is what I proposed when said you could imitate SPE, that is exactly what that IDE does.
Logged
A child of five would understand this. Send someone to fetch a child of five.
Groucho Marx
Offline (Unknown gender) egofree
Reply #13 Posted on: July 21, 2014, 11:39:33 AM
Contributor
Joined: Jun 2013
Posts: 603

View Profile Email
If you post a code example with the code tag in the forum, it doesn't work, it works only with spaces.  :D
Logged
Offline (Male) Rusky
Reply #14 Posted on: July 21, 2014, 12:13:23 PM

Resident Troll
Joined: Feb 2008
Posts: 955
MSN Messenger - rpjohnst@gmail.com
View Profile WWW Email
Tabs work fine in Firefox. Chrome and IE suck, as well as this forum software that doesn't deal with the inconsistency.

Code: [Select]
fn see() {
tabs_work_fine();
}
« Last Edit: July 21, 2014, 12:15:37 PM by Rusky » Logged
Pages: 1 2 »
  Print