| | |
C++ Style
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2008
Posts: 3,833
Reputation:
Solved Threads: 503
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.
•
•
Join Date: Jan 2008
Posts: 3,833
Reputation:
Solved Threads: 503
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.
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.
I'm here to prove you wrong.
Sarehu
The purpose of "style guides" is twofold:
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.
The purpose of "style guides" is twofold:
- Readability -- Physical layout of source code
- Interoperability -- Structural layout of data (functions, variables, etc)
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.
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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
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.
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.
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.
c Syntax (Toggle Plain Text)
int main ( ) { int a; // 4 spaces int b; // 1 tab int c; // 2 spaces + tab }
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.
![]() |
Similar Threads
- Change the Start Menu Style (Windows tips 'n' tweaks)
- "Style Filters" and Internet Explorer (Web Browsers)
- Sooo ... how long do you think this style will last?! (DaniWeb Community Feedback)
- ASP.NET controls in Office 2003 style? (ASP.NET)
Other Threads in the C++ Forum
- Previous Thread: storing * and # in an array
- Next Thread: fstream Tutorial
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






