ENIGMA Forums

General fluff => General ENIGMA => Topic started by: Goombert on July 20, 2014, 03:07:56 pm

Title: Indentation Styles
Post by: Goombert on July 20, 2014, 03:07:56 pm
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.
Title: Re: Indentation Styles
Post by: Rusky on July 20, 2014, 03:10:54 pm
Tabs are pretty much superior in every way, but because mixing tabs and spaces is painful everyone seems to have standardized on spaces. Unfortunately.
Title: Re: Indentation Styles
Post by: edsquare on July 20, 2014, 03:46:21 pm
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.
Title: Re: Indentation Styles
Post by: Darkstar2 on July 20, 2014, 04:39:01 pm
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.

Title: Re: Indentation Styles
Post by: Josh @ Dreamland on July 20, 2014, 09:44:22 pm
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
Title: Re: Indentation Styles
Post by: edsquare on July 20, 2014, 10:12:31 pm
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.
Title: Re: Indentation Styles
Post by: Rusky on July 20, 2014, 10:58:08 pm
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
}
Title: Re: Indentation Styles
Post by: Goombert on July 21, 2014, 12:08:26 am
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.
Title: Re: Indentation Styles
Post by: edsquare on July 21, 2014, 12:50:06 am
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?
Title: Re: Indentation Styles
Post by: Goombert on July 21, 2014, 02:44:59 am
I'm not sure, what I mean is you press tab and the selected text is indented two spaces.
Title: Re: Indentation Styles
Post by: TheExDeus on July 21, 2014, 04:55:47 am
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.
Title: Re: Indentation Styles
Post by: Rusky on July 21, 2014, 10:50:46 am
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.
Title: Re: Indentation Styles
Post by: edsquare on July 21, 2014, 11:06:23 am
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.
Title: Re: Indentation Styles
Post by: egofree on July 21, 2014, 11:39:33 am
If you post a code example with the code tag in the forum, it doesn't work, it works only with spaces.  :D
Title: Re: Indentation Styles
Post by: Rusky on July 21, 2014, 12:13:23 pm
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();
}
Title: Re: Indentation Styles
Post by: Goombert on July 21, 2014, 03:38:36 pm
Most websites with code boxes fuck up in Firefox for me, I actually find it really really annoying.
Title: Re: Indentation Styles
Post by: Ideka on July 27, 2014, 06:04:53 pm
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.
The problem with tabs is that each editor can be configured to display them differently, so code written in some editor will likely look different in another one. It will still be properly indented but it may become too wide to be comfortably read, or things might end up misleadingly aligned when they shouldn't.
It's not a Linux issue.
Title: Re: Indentation Styles
Post by: Rusky on July 27, 2014, 09:44:08 pm
You shouldn't align things that way. It causes a host of other problems whether you use tabs or spaces.