New commenting Scheme

Pages: 12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>

int main()
{
    int a;
    std::cout << "Please enter the first variable: " << std::endl;
    std::cin >> a;

    int b;

    do
    {
        std::cout << "Please enter the second variable to match the first: " << std::endl;
        std::cin >> b;
    }
    while (a != b);

    std::cout << std::endl;
    if (a > 0)
        std::cout << "The variables are positive!" << std::endl;
    else if (a == 0)
        std::cout << "The variables are zero!" << std::endl;
    else
        std::cout << "The variables are negative!" << std::endl;

    int c;
    std::cout << std::endl;
    std::cout << "Please enter the third variable to multiply by: " << std::endl;
    std::cin >> c;

    int d = 0;
    for (int i = 0; i < c; i ++)
        d += a;

    std::cout << a << " * " << c << " = " << d << std::endl;

    return 0;
}
Last edited on
Tabs/Spaces?
No, de nuevo no...
No de nuevo, decĂ­a.

Tabs, 4 spaces width. K&R style but openning braces in functions are in the same line.

I find interesting that you two are using 3 spaces.
only because I didn't notice he used 3 spaces, I didn't think about it, it's very close to the 4-space tab I use, fixed.
Last edited on
I don't know, I don't see the reason to use four spaces. I guess the biggest reason for me is I use nested if's a lot and since I have a space between if and the parenthesis...I don't know what I'm getting at...but regardless, I feel three spaces is just as easy to read as four and doesn't look so bad with multiple nested control statements.
yeah, 3 look fine, although I think 2 is a bit too short, and 8 is way too long.
I use 16 and a half spaces for indentation, anything else is just stupid.
How can you use half a space? And 16??? So this code:
1
2
3
4
5
#include <iostream>

int main() {
   return 0;
}


Becomes:
1
2
3
4
5
#include <iostream>

int main() {
                return 0;
}


That's ridiculous!!!

Edit: Or do you do the GNU style (I believe it's called):
1
2
3
4
5
6
#include <iostream>

int main()
        {
                return 0;
        }
Last edited on
The joke

__________

your head.


:P

edit:
I actually just use 4-space tabs. I have the tabs converted to spaces (among other formatting things) when I commit and back to tabs (and other preferred formatting things) when I'm editing. I don't like dealing with spaces, and I have my own way of formatting things, This way I can make things look pretty across my editors and not worry about bothering other coders when I'm working in a group
Last edited on
why convert them to spaces? wouldn't it would be better to leave them as tabs, so that it shows up as 2/3/8/whatever space indentation according to what they set.
closed account (1yR4jE8b)
Because most editors have different defaults about what tab sizes should be, and if you mix tabs and spaces things look extremely messy if your tab settings aren't the same as everybody else's. Not everybody has the same editor tab settings but space size is universal. Some editors also know when spaces are used for indentation and delete the appropriate amount of spaces so you can't even tell the difference anyway.
The best example of why not to use tabs is here. When people paste their code, the default size for tabs is 8 spaces, this is pretty big, and let's say they had several lines where they spaced over. You end up getting something that looks like this:
1
2
3
4
5
6
7
8
9
        int a = 5;
        int b = 20;
    float c = 4;
        if (a == b) {
                c = 25;
        cout << "haha";
        cin >> b;
    }
        // This is where proper indentation matters! 
I don't see why you would get that effect if you used tabs, unless you also used spaces. The moral of the story is not to mix tabs with spaces.

I still do it for comments, though:
1
2
3
	/*
	 * Like this.
	 */

I can't see any way around it except for removing the space before the asterisk, but that would look bad so I won't do it.
Last edited on
Use tabs for indentation.
Use spaces for making pretty adjustments.
My IDE changes the behavior of tabs to x spaces, which is one of the best features of a good IDE/Text Editor. Also, using a code beautifier, like AStyle, will change all spaces to tabs or all tabs to spaces depending on the options. I prefer spaces so it will look the same in my IDE, your IDE, someone else's text editor, and when posting it online. Using a 3 space tab on your system might like nice, but when it's posted online and it's converted to an 8 space tab, nested statements even 4 deep gets very long just from indentation.
My IDE changes the behavior of tabs to x spaces, which is one of the best features of a good IDE/Text Editor. Also, using a code beautifier, like AStyle, will change all spaces to tabs or all tabs to spaces depending on the options. I prefer spaces so it will look the same in my IDE, your IDE, someone else's text editor, and when posting it online. Using a 3 space tab on your system might like nice, but when it's posted online and it's converted to an 8 space tab, nested statements even 4 deep gets very long just from indentation.


Honestly, I could say the same thing if someone likes to have 8 space indentation on their system; I don't want to see that. I'd prefer it to be my own size.
if someone uses an 8-space tab, they like deep indentation. if someone use 8 spaces, and someone else uses 2, the one with 2 has to stare at these 8 spaces of indentation, either changing it manually or using a program to do it, and honestly I'd prefer it if they just used tabs, then my editor could do it seamlessly.
Astyle is built into Code::Blocks and after setting my options, all I need to do is right click and select format using Astyle and the code is instantly transformed. Regardless, unless you're 100% self conscious about only using tabs, there is bound to be issues unless. I use tabs quite frequently to easily indent my code, but since it's automatically converted to spaces, I don't have an issue with the formatted display anywhere but on my machine.

I also find it less likely for someone to use 8 spaces than it is for someone to have a mix of tabs and spaces. My point being that the slim chance you might actually get someone who spaces 8 times for one indentation isn't worth only using tabs in your IDE (that persons code is going to show up the same way in all editors regardless).

Maybe the tab thing comes from some old school learning?

Regardless, I still find it interesting to see what everyone's opinions are about code formatting and what they think I'd easiest to understand. On that I've found hard to read is code that had the braces at the same indentation as statements within those braces. The braces are flush with the statement rather than the control.
you mean

if (true)
{
do xyz
}

?

I love that style, it makes it so clear where scope ends or begins, where as

if (true) {
do xyz
}

makes me have to look for so many different things, function/if/while/do/for/else/else if/}/etc to know where scope starts.

I'll keep using tabs, not because I was taught to use tabs, but because changing it to spaces and forcing someone else to be stuck with those spaces if their editor can't change it isn't fair, and make absolutely 0 sense to me.
Last edited on
Don't invent statistics.

If you are working on a team, make sure that all will use the same style.
Considerer version control.
closed account (1yR4jE8b)
We have hooks that run in our central git repo that runs AStyle on all the changed files and amends the diffs. It works beautifully for keeping code consistent in the central system.

someone else to be stuck with those spaces if their editor can't change it isn't fair


Every default editor in Linux can do this (gEdit, Kate, kwrite, vim, emacs, etc...), Notepad++ does this, Visual Studio does this, Eclipse does this, CodeBlocks does this, Netbeans does this...what are they coding with...Notepad?

This is one of the most basic features of any editor, if their editor can't do that...well, shit.
Topic archived. No new replies allowed.
Pages: 12