|
The 'one return per function' rule is a bit old school (early 90's ). IBM had it as a requirement when I was contracting there. It's not so much about style and readability as it is about introducing subtle bugs. If a maintenance programmer has to put some code in the function that has to take place before the function ends, he may place it right before the final 'return' near the end of the code block. And if he was working fast, or just working stupid he may not know of the other return points.
Anyway, OOP guidelines of very short (7 +- 2) meaningful lines of code per method made this a moot point.
|
|
|
|
|
You could always do this as:
if (child != null && child.Parent != null && child.PrevNode != null)
{
}
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
I sort of agree, but rather than:
MenuItemNode child = tvMenu.SelectedNode as MenuItemNode;
if (child == null)
return;
MenuItemNode parent = child.Parent as MenuItemNode;
if (parent == null)
return;
MenuItemNode swap = child.PrevNode as MenuItemNode;
if (swap == null)
return;
I would prefer:
MenuItemNode child = tvMenu.SelectedNode as MenuItemNode;
if (child == null)
{
return;
}
MenuItemNode parent = child.Parent as MenuItemNode;
if (parent == null)
{
return;
}
MenuItemNode swap = child.PrevNode as MenuItemNode;
if (swap == null)
{
return;
}
Just to remind me if I add a statement before the return.
|
|
|
|
|
EyeYamFedUp wrote: Public gblnSuperUser As Boolean
Public gblnLogonOK As Boolean = False
Wow. Excellent security paradigm.
|
|
|
|
|
What's your problem with it? He used comments didn't he?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Pete O'Hanlon wrote: He used comments didn't he?
Indeed! Even the polished version ('* ).
Regards
Thomas
www.thomas-weller.de
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Programmer - an organism that turns coffee into software.
|
|
|
|
|
struct _X
{
int field1;
int field2;
int field3;
} anArray[15];
for (int i = 0; i < 15; ++i)
{
anArray[i].field1 = 1;
}
for (int i = 0; i < 15; ++i)
{
anArray[i].field2 = 2;
}
for (int i = 0; i < 15; ++i)
{
anArray[i].field3 = 3;
}
|
|
|
|
|
How horrible this is depends on the language: is it C? C++? something else?
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
It's C, but I don't see how the language makes it any better or worse.
|
|
|
|
|
some languages such as C# allow for code inside a struct; C does not. How would you do it in C?
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
No matter what language - all of them allow at least for summarizing this in one loop construct...
Regards
Thomas
www.thomas-weller.de
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Programmer - an organism that turns coffee into software.
|
|
|
|
|
right.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Exactly the point I was trying to make.
|
|
|
|
|
I don't know, maybe Brain f*** doesn't.
Cheers
You have the thought that modern physics just relay on assumptions, that somehow depends on a smile of a cat, which isn’t there.( Albert Einstein)
|
|
|
|
|
Fatbuddha 1 wrote: I don't know, maybe Brain f*** doesn't.
I'm pretty sure it actually does.
|
|
|
|
|
I especially love the brackets he put around the loop bodies - in case he needs to add some additional instructions there!
|
|
|
|
|
peterchen wrote: I especially love the brackets he put around the loop bodies
Well, this can be a coding guideline. It may look a bit silly and pedantic to put brackets around a single statement, because it makes you write things like:
if (somecondition)
{
return;
}
Tools like e.g. ReSharper (for C#) do that automatically, so you don't have to type. I've seen this often in larger teams, and it brings some more readability to the code. I do it myself...
Or, as you suggest, it's simply an absence of any thinking or understanding.
Who knows ?
Regards
Thomas
www.thomas-weller.de
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Programmer - an organism that turns coffee into software.
|
|
|
|
|
Thomas Weller wrote: Well, this can be a coding guideline.
Excactly - even though I don't subscribe to it, it is a common guideline to avoid a mistake like this:
for (int i = 0; i < 15; ++i)
anArray[i].field1 = 1;
someotherarray[i].somefield = 2;
It's just a strange idea, but someone, in the future, MIGHT come up with maybe another array to be assigned a different value.
|
|
|
|
|
<message deleted="cause I couldn" t="" make="" it="" work="">
modified on Thursday, March 26, 2009 1:17 PM
|
|
|
|
|
that is something different, it generates no run-time code. It may or may not be sufficient for what the original program needed, assuming you duplicate the constants 15 times.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Can't modify a deleted message :P I couldn't make it scalable so I deleted my post:
struct k[15] = { {1,2,3},...}
|
|
|
|
|
bulg wrote: Can't modify a deleted message
No, however you can edit a message instead of deleting it.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
A "good" way to pad your line count.
|
|
|
|
|
I could find better ways.
|
|
|
|
|
glad to see you're back.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|