Tab-space VS 4-spaces

Pages: 12
I switched back to Tabs. Backspacing white spaces is just SOOOOOOOOOOOOOOOOOOOOOOOO ANNOYING. How do you people bear with it? I can't even imagine. And like Peter, I particularly hate having uneven indentation (1 more space or 1 less space than other lines) so that adds to the frustration.

Goodbye white-spaces. We've had a good time together for those 2 minutes that we were together. Oh and sorry for the cussing or whatever.
"Whitespace" refers to any invisible character, such as tabs, spaces, newlines, ZWNBSP, etc.; not just to the space character (U+0020).
😅
I spent many years indenting with tabs. I figured that if you didn't like the spacing you could just change your tab width.

But for the past several years I've stuck with the default (tab==8 spaces) and used an indent size of 4.

My feeling is that the braces are there to tell the compiler what the block structure is, but humans inevitably use the indentation. So I cuddle the braces with the code except for the last closing brace. Also, this lets me see more of the code in a given window. I having to scroll up and down dozens of lines to see a tiny bit of functionality.
1
2
3
4
5
if (blah) {
    foo();
} else {
    bar();
}


I don't like telling other people how to indent their code. To each his own.

If I need to look at someone else's code, I almost always run it through GNU indent first. In fact, when debugging code here on the forum, that's the first thing I do.
I've stuck with the default (tab==8 spaces) and used an indent size of 4.
I'm not sure what you mean. Are you using a size of 4 or 8? Your code suggests 4-space.
I indent 4 spaces. The editor is set so that tab stops are every 8 spaces. This the indentation is represented as
1 level: space space space space
2 levels: tab
3 levels: tab space space space space
4 levels: tab tab
...

I hope this makes sense.
Dave
Ugh! Please stop doing that. Your code looks completely wrong to people who don't use the same tab size as you. Every time I need to read a source that's formatted like that I have to decide whether to change my settings or reformat the entire file.
IMO it doesn't matter too much if you use spaces or tabs, but do use only one.
I use tabs because they are an "indent marker". Using spaces instead of tabs to me is not writing a function and just manually copy pasting the same blob of code everywhere you need it.

That way, someone else can come in and open your file and set the indent size to whatever they want, and your code looks fine.
Reviving this to ask a question about style.

Can someone explain the rationale behind putting the return type of function on its own line, in their own words? What are the benefits of this? (Just to be clear: I'm not arguing, I am just perplexed by this because I rarely see it.)
closed account (z05DSL3A)
Used to be something back in the day with C. I don't remember any reason other than readability possibly search-ability.
closed account (E0p9LyTq)
Can someone explain the rationale behind putting the return type of function on its own line, in their own words? What are the benefits of this?

https://softwareengineering.stackexchange.com/questions/200828/reason-for-placing-function-type-and-method-name-on-different-lines-in-c
closed account (E0p9LyTq)
Most every template example I've seen uses a modified version of the "return type on a separate line," putting the template<class/typename T> keyword on a separate line from the function name.

The 80 char line limit and readability/searchability would be just as good reasons as the return type on a separate line.

The trailing return type form is really confusing, at least to me. Example: auto foo() -> int;

I have read the trailing return type is useful for templates/lambdas, but I haven't needed it when writing a template or lambda.
Last edited on
closed account (E0p9LyTq)
Interesting read on the placement of the asterisk (*):

https://stackoverflow.com/questions/6449997/why-is-it-thought-of-t-name-to-be-the-c-way-and-t-name-to-be-the-c-way
Ah so it started with GNU.
[boost parameterized template ]
Now we can search for the regex ^start_of_a_long_func and get taken immediately to the function we're searching for.

Yeah those are fair points, I can see the merit. Seems pointless for some functions but definitely helps split up some of those longer functions.

Interesting read on the placement of the asterisk (*):

Ha, I was just thinking about that (Whether or not a C programmer would put the * as part of the return type or the name of the function.) I suppose they would do something like:
1
2
int *
func_name(int param)


1
2
int
*func_name(int param)
seems way too confusing, but I'm sure some C'tizens prefer it.
Last edited on
closed account (E0p9LyTq)
I use an IDE, Visual Studio 2017, so searching for things like function/class/etc. declarations/definitions is done without the need for regex.

Without the overlying structure of an IDE I do see the need for easy searching within source files.

Re: asterisk placement.

I personally find the placement with a space on either side to be annoying, as well as tying the asterisk to the name. Personal pref is to bind the asterisk to the type. int* foo;
I always go with the way you just posted when it comes to pointers. It's the only correct way in C++ as far as I'm concerned. :D
closed account (E0p9LyTq)
If I need to look at someone else's code, I almost always run it through GNU indent first.

Visual Studio 2017 can automatically format pasted code, so when looking at posted code here that has a different formatting VS will make the code look the way I can easily read.
closed account (z05DSL3A)
It's the only correct way is however the person you are doing it for wants it. ;0)
closed account (E0p9LyTq)
It's the only correct way is however the person you are doing it for wants it.

Seeing the formatting some people use, or don't use, maybe a "gentle nudge" with consistent formatted code might be helpful.
Topic archived. No new replies allowed.
Pages: 12