Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » is there U++ coding style reference?
Re: is there U++ coding style reference? [message #27780 is a reply to message #27768] Tue, 03 August 2010 11:24 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
dolik wrote:
Quote:


Brackets are mostly on the same line



i disagree on that one Smile. i have the impression that finding corresponding brackets is esier when they are placed on new line each. i know that Assist++ marks brackets, but it's also a visual perception of blocks, that matters, and here the new line stuff is better.

another thing:

small functions have their implementation in .h file anyway, and on same line as definition, like
Ctrl& Enabled(bool enable = true) { enabled = enable; return *this; }

rule of thumb: >3 syntactical important statements >> separate definition and implementation properly.

(syntactical important statements: real function calls and variable calculations, return values not counted, return *this is no 'important syntactical statement, only a helper.)

what about template classes?
.h / .hpp / .cpp relation and handling

did you look up my tempc class on that? any comments?

[Updated on: Tue, 03 August 2010 11:25]

Report message to a moderator

Re: is there U++ coding style reference? [message #27784 is a reply to message #27780] Tue, 03 August 2010 12:40 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
Quote:

i disagree on that one Smile. i have the impression that finding corresponding brackets is esier when they are placed on new line each. i know that Assist++ marks brackets, but it's also a visual perception of blocks, that matters, and here the new line stuff is better.

And I disagree with you Smile I prefer more compact code so that I can scan it more easily (one of the reasons I dislike many verbose comments) and I don't find it makes finding pairs any harder. I feel it makes it easier to see the code srtucture personally.
Re: is there U++ coding style reference? [message #27786 is a reply to message #27784] Tue, 03 August 2010 12:50 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
compact code is a good thing, no doubt. but having braces on new line sets the commands apart from the invoker..kind of a structural helper. in any case, this might be one of the points where mirek could give an advice to have kind of a guideline..

here for comparison:
	if(a = 123)
	{
		int abc = 3345;
		for(int i = 0; i < 123; i++)
			abs += i;
	}

	if(a = 123) {
		int abc = 3345;
		for(int i = 0; i < 123; i++)
			abs += i;
	}
Re: is there U++ coding style reference? [message #27788 is a reply to message #27627] Tue, 03 August 2010 13:05 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
I prefer the second option, because I pair the "}" with "if" and that's more interesting for me than pairing it with "{". But I can see this is matter of personal taste. (also I would write "if ( a == 123 ) {" (notice the spaces) to fully satisfy my taste Smile )

And assigning 123 to a in comparision without additional comment about intentionally doing so is not nice Wink (I write in such cases code this way to make my intention obvious: "if ( (a = 123) != 0 ) {", otherwise I consider it typo bug and fix it to "==")
Re: is there U++ coding style reference? [message #27789 is a reply to message #27788] Tue, 03 August 2010 13:39 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

I totally agree with mrjt and his reasoning.Morover, I am using 5 levels of color coded backgrounds (with quite sharp colors), that gives much better idea about blocks than looking forbrackets.

As I said before, the only exception to have bracket on separate line is the first bracket in function definition. I don't like that too much as well, but there I can see the reason - if you set the function name apart from the rest of text, it makes it easier to find the function when "scanning" through long file.

But I would never do this with if, while, etc. Actually I often make the block on the same line, if it contains just a short code:
if(condition){int a = 213;}
for(int i = 0; i < 123; i++){abs += i;}
But that is my personal style, definitely not official U++ Smile

Honza
Re: is there U++ coding style reference? [message #27792 is a reply to message #27789] Tue, 03 August 2010 15:58 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
Quote:


And assigning 123 to a in comparision without additional comment about intentionally doing so is not nice


that was a fast shot, i meant == ofcorse, where we are at the root of the problem Smile.

some people even do stuff like

if(123 == a)
....
and

if(2 <= GetCount())

just to avoid this. i can see the good intention here but, honestly, if you found sth like that in code, you probably like i did, would have to twist your brain Smile to grasp it.

this braces topic is, as we can see, really a question of taste and IMHO not too much affecting the overall code style. thats why i left it out in the code style section that i have uploaded some minutes ago.

please review, correct, add what ever is missing.
thanks
Re: is there U++ coding style reference? [message #27795 is a reply to message #27627] Tue, 03 August 2010 17:28 Go to previous messageGo to next message
mr_ped is currently offline  mr_ped
Messages: 825
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
By reading book "Code complete" I learned to always write:
if ( smaller <= bigger ) ...
even if that leads to things like
if ( 10 <= i && i <= 13 ) ... //i is as expected inside 10..13 range

So 2 <= GetCount() looks reasonably to me. Smile

Anyway, single "=" in if does produce warning anyway, until you use the more complex way like in my post (that's why I'm doing it, so I can detect mistakes from warnings).

But we are going off-topic here. Smile

edit: (joke) also you don't need functional ">" on keyboard when you always use smaller <= greater.. Wink

[Updated on: Tue, 03 August 2010 17:31]

Report message to a moderator

Re: is there U++ coding style reference? [message #27796 is a reply to message #27795] Tue, 03 August 2010 17:34 Go to previous messageGo to next message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
this was a simple example though...there were more complex.
generally smaller < bigger is right. but in terms of semantical thinking it's sometimes not so good to follow it.

in upper case, semantical meaning was 'if count of a vector is at most 2, then...' where the focus or starting point is the count (and not the number 2), which should go first, because one thinks of count first..

offtopic, you're right Smile

[Updated on: Tue, 03 August 2010 17:35]

Report message to a moderator

Re: is there U++ coding style reference? [message #27824 is a reply to message #27786] Thu, 05 August 2010 12:50 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
kohait00 wrote on Tue, 03 August 2010 06:50

compact code is a good thing, no doubt. but having braces on new line sets the commands apart from the invoker..kind of a structural helper. in any case, this might be one of the points where mirek could give an advice to have kind of a guideline..

here for comparison:
	if(a = 123)
	{
		int abc = 3345;
		for(int i = 0; i < 123; i++)
			abs += i;
	}

	if(a = 123) {
		int abc = 3345;
		for(int i = 0; i < 123; i++)
			abs += i;
	}



I certainly use more compact style.

Anyway, w.r.t. to formatting style guidelines, in the very very old past I was irritated when somebody submitted something with different formatting.

Later I have found that it in fact helps me to distinguish my code from other people just by seeing the formatting style Smile

After this, I just do not care. Just produce a good code. If I feel too uncomfortable, I will reformat. By doing this I will also mark for me the code as "checked" Smile Smile

[Updated on: Thu, 05 August 2010 12:51]

Report message to a moderator

Re: is there U++ coding style reference? [message #27825 is a reply to message #27824] Thu, 05 August 2010 12:53 Go to previous message
kohait00 is currently offline  kohait00
Messages: 939
Registered: July 2009
Location: Germany
Experienced Contributor
good idea Smile
Previous Topic: using Ctrl::Add; required for templates / overloaded virtual functions
Next Topic: dll instead of exe
Goto Forum:
  


Current Time: Fri Mar 29 09:25:47 CET 2024

Total time taken to generate the page: 0.02014 seconds