Indentation Style which is best?

Started by
28 comments, last by Promit 18 years ago
Quote:Original post by Boder
Are the .NET naming conventions the same as the Java naming conventions?


I think the .NET conventions capitalize the first letter of every word.

Example: GenerateObjects() and such.
That's what I've noticed from C# and VB.NET anyways.
Advertisement
Quote:Original post by Nypyren
Tabs until indent level, spaces for mid-line alignment. That way, any other people who have different tab sizes will see it how they want to see it and won't have mid-line spacing problems.


And as for an editor I would recommend MSVC 2005 Express if you are on Windows.
Quote:Original post by Boder
Are the .NET naming conventions the same as the Java naming conventions?

.NET Naming Guidelines
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
Which ever indentation style you choose, just remember the most important thing... consistency!
Quote:Original post by CTar
Quote:Original post by Nypyren
Tabs until indent level, spaces for mid-line alignment. That way, any other people who have different tab sizes will see it how they want to see it and won't have mid-line spacing problems.


And as for an editor I would recommend MSVC 2005 Express if you are on Windows.


yes! get it while it's free! it's by far my favorite gui-based ide.
This space for rent.
Quote:Are the .NET naming conventions the same as the Java naming conventions?


as i read in an article a while back,

Quote:Don't follow Java's coding/naming conventions...after all, Sun doesn't.



Just a little bit of humor.
---"The problem with problems is that there are always too many"
My C++ indentation style. I'm still working on it, but some ideas might be useful for you.

I use headlines to easily find a position in the code when scrolling up and down. My headlines end at line 80. There are different ways of writing these headlines - the headline itself framed in horizontal lines, the chapter framed this way, or just a horizontal line on top of the headline..
//===============================================================//                                                       MyClass//===============================================================class MyClass {  //  //-------------------------------------------------------------  //                                  MyClass - member functions  //-------------------------------------------------------------  //  void dosomething() {    ...  }  //  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  //                                              MyClass::foo()  // foo is my favourite function name  void foo() {    //    ...  }};


I put my opening brace behind the function name, and try to not use it as a first character. Sometimes I do the same with large argument lists of functions or templates.

Statements like public:, or case xxx: are indented with half tab size. Typical tab size I use is 2 spaces. I always tick "replace tabs with spaces" - this is more a matter of bad experiences with tabs, I don't recommend it as the better solution.

Empty lines in a function or class are filled with comment slashes to maintain the optical flow of line beginnings. This way it's easy to find the start and end of a block. I put these 'decorated' empty lines where it seems appropriate.

I still didn't find the perfect solution for templates, and for defining inheritance. For the class template I define here, I put the ending brace of the template argument list in front of the class header, so the class template can't be confused with a usual non-template class.

//---------------------------------------------------------------//                                               MyClassTemplatetemplate<  class Base,  class T,  template<class> class TT,  bool B> class MyClassTemplate : public Base {  // public:  //  template<int Size>  T* memberfunction(    TT<T> arg1,    float arg2,    float arg3  ) {    ...    if(true) {      see_what_happens();    } else {      see_nothing();    }  }};                                            // MyClassTemplate//---------------------------------------------------------------
Quote:Original post by Roboguy
Quote:Original post by Tradone
Quote:Original post by Roboguy
Quote:Original post by Nypyren
Tabs until indent level, spaces for mid-line alignment. That way, any other people who have different tab sizes will see it how they want to see it and won't have mid-line spacing problems.


I've never understood why the majority of people don't seem to do that.


Can you show me an example?


int main() {	int array = {1,	             2,	             3,	             4};	if (/*...*/) {		// ...	}}


Note which spaces are tabs and which aren't. It will all be lined up regardless of the tab size used.


cool this is the style that I use anyhow!
nice.
Why tabs instead of just spaces? All manual about good style/coding practices recommend tabs. I've been always wondering about it? Why actually does it matter?

Isn't it a more trouble when you switch from one IDE to another?
Another nameless person in the virtual space...
Quote:Original post by NamelessTwo
Why tabs instead of just spaces? All manual about good style/coding practices recommend tabs. I've been always wondering about it? Why actually does it matter?

Isn't it a more trouble when you switch from one IDE to another?


Most people prefer tabs with 4 spaces, but lets say that Dorvo is going to look at your code. Dorve states that he prefers 2 spaces. With tabs you can change the settings of the editor to make tabs another number of spaces. Also it takes longer to delete 4 lines than it takes to delete 1 tab. I can remember two good reasons to use spaces, first to make sure the source code will print properly no matter who is printing and what their settings are. Another reason is so that you don't accidently generate bad indentation, lets say I want to create a simple constructor.
		some_class_123( type obj )				:				_something( obj)

This might look good on GDNet, with tabs of 8 lines, but try pasting it in your IDE, suddenly : and _something isn't right under type, these types of indentation errors can be hard to spot unless you change indentation once in a while.

This topic is closed to new replies.

Advertisement