VernonDozier commented: Good link +4

What do you think of this?

http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml

This looks like a great link! I've bookmarked it. I was looking at the threads pinned to the top and noticed that there is one at the top regarding C++ books, but not C++ websites. I think one should be started and this link should be in there. Good post.

Use only spaces, and indent 2 spaces at a time.

Yes! Vindication!

Bwaa hah hah hah ha haah


PS I don't like tabs.

Yes! Vindication!

Bwaa hah hah hah ha haah


PS I don't like tabs.

Tabs are cool, but they look like hell on Daniweb if you aren't careful because a tab is like eight spaces so it overflows onto the next line a lot. What looks the worst is if people mix tabs and spaces and then post on Daniweb. If they have fours spaces per tab in their IDE, which is then changed to eight on Daniweb, the indentation gets all messed up. If you just use spaces it'll look fine wherever it's posted.

Congratulations, you've singled out the least important part of the style guide.

Good advice in general. The particularly noticeable poor advice is smoothed out by clearly being specific to Google and practicality with their existing code base. While I can see their reasoning, I very much dislike their stance on exceptions. Hopefully non-Google people reading this guide will ignore that convention.

commented: I really don't like ya avatar, it doesn't convey a professionalism. I think you should change it. -3
commented: jamthwee is just jealous :) +31

Sarehu
The purpose of "style guides" is twofold:

  1. Readability -- Physical layout of source code
  2. Interoperability -- Structural layout of data (functions, variables, etc)

Failure on either account costs significant amounts in terms of cold, hard cash. Business concerns make or break in terms of the amount of time you waste on a project.

I dislike tabs because they don't play nice. Most editors I've used (and I've tried just about every one you can name to me) handle tabs either incorrectly or just plain differently than the editor the guy four cubicles down does. In one case incorrect tab handling actually changed the meaning of my code. But sure, small potatoes.

Lighten up.

Member Avatar for iamthwee

Tabs are a definite no no.

I write code for a living and my employer (my mom) says I should use only SPACES - otherwise there won't be any milk and cookies for tea.

God has spoken.

Congratulations, you've singled out the least important part of the style guide.

Not so, tabs are the most visible. They can destroy the whole program no matter how well-written it is. Tabs look crappy when use in code tags here at DaniWeb because they can render the code almost unreadable.

Just say no to tabs.

Here's why.

1. Almost all forums make a complete mess of tabs, unless you've been exceptionally dilligent in your use of tabs to begin with. ANY mixing of spaces and tabs will destroy the indentation when posted online. Take this example which uses 4 spaces for 1 tab.

int main ( ) {
    int a;  // 4 spaces
	int b;  // 1 tab
  	int c;  // 2 spaces + tab
}

Looks great in my editor, but just sucks and blows at the same time when posted here!.

Given the standard of comprehension and indentation skills (99% can't even use code tags, let alone indent properly), there's no hope.

2. There is no set standard for what a tab should be (ok, there is, it's 8 spaces). But all too often, some smarty-pants has configured code-wrangler 4.2 to make a tab equal 4 spaces. All very good, if that's the only tool you use.

But by the time you're working on a large project, with many different people using all sorts of tools (lint, diff, merge, doxygen, pretty-print, indent etc etc), sooner or later, you're going to end up with a visual mess.

Add to that, if you decide to use several 3rd party libraries (each with their own 1-tab == x-spaces settings (all different)), then you have yet another unholy mess.

If you use only spaces, you GUARANTEE that it looks the same everywhere.

Any code editor worthy of the name has an automatic way of substituting spaces for tabs. Most have "smart" indentation anyway, so there's really no worry about having to hammer the space bar to achieve the indentation you want.

If you use only spaces, you GUARANTEE that it looks the same everywhere.

Any code editor worthy of the name has an automatic way of substituting spaces for tabs. Most have "smart" indentation anyway, so there's really no worry about having to hammer the space bar to achieve the indentation you want.

True. Even tough this is a bit off-topic, here's how to do it in Visual Studio:

- Go to Tools -> Options
- Select Text-editor -> [your program language] -> tabs
- Change the "indent size" to whatever you want (I use 4 spaces)
- Select "insert spaces" instead of "keep tabs"
- Press OK
- Open up some project or file
- Press ctrl-a ; ctrl-k ; ctrl-f
- Code is formatted with spaces!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.