|
I'm happy with
if (parameter == null) return; and so on, but anything more complex than "return" or "throw" I put in brackets over three lines:
if (parameter == null)
{
...
} The only time I will omit the brackets is for a very short instruction on the same line as it's test.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I do brackets because, sooner or later, I'll be adding something else in there.
|
|
|
|
|
I agree. I always do brackets even for one-liners because, in the words of Forrest Gump, "That's one less thing to worry about".
- I would love to change the world, but they won’t give me the source code.
|
|
|
|
|
|
braces and comments reduce performance
Real programmers use butterflies
|
|
|
|
|
Draws breath
Nah, bugger it. Save the religion stuff for another couple of days. It's only Thursday.
Closes mouth and turns away.
|
|
|
|
|
Only of the build.
- I would love to change the world, but they won’t give me the source code.
|
|
|
|
|
Real programmers use butterflies
|
|
|
|
|
Very true for interpreted languages!
...and who wants to waste time writing the parser for a comment when devs do not use comments anyway.
|
|
|
|
|
Confused, because I can always add the brackets if I add more lines.
|
|
|
|
|
Firstly, I'm coding in a very old language. Here's the exact line of code. Hopefully you can translate to a 'proper' language.
IF ERROR.MSG = "" THEN ERROR.MSG = "Error ":ERROR.CODE
It was a catch-all I inserted, (without being asked), to ensure that an error message would always be returned, even when it was an unknown error code. Yes, it's a single "=" for both conditions and assignments. And I was made to change it to upper-case. FFS!
What they wanted, was:
IF ERROR.MSG = "" THEN
ERROR.MSG = "Error ":ERROR.CODE
END
But, the point that I was trying to make was: not that my way is right, but: if they want it doing a particular way, it should be documented - particular as the code-base contains a, pretty much, 50:50 split of both syntaxes.
|
|
|
|
|
|
Richard MacCutchan wrote: Cobol?
It's slightly easier than that! It's a (fairly significant) variation on Basic, which comes as part of the Universe DBMS. It's derived from Pick DataBasic (another one you won't have heard of!) and is actually very easy to develop with - albeit limited in scope. i.e. It's for dumb terminal applications. I like it though.
|
|
|
|
|
5teveH wrote: Pick DataBasic (another one you won't have heard of!) Don't be too sure. I have been writing code on quite a few different systems (a few whose name I cannot remember) since 1966 (yes, that is really nineteen-sixty-six).
|
|
|
|
|
You do it all wrong! The correct syntax is:
if (parameter == null)
{
return;
}
else
{
}
Reason: always add an else to an if, even if it's empty, because otherwise a future nested if could accidentally add an else at the wrong nesting level!
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Take thy code to The Weird and The Wonderful[^] where it belongs!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Well, it definitely doesn't belong on an agile forum.
But it would be fun
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Nah! The correct syntax to use is:
if (parameter =
= NULL)
{
return;
}
else
{
}
|
|
|
|
|
if (null == parameter) -> even better.
|
|
|
|
|
As soon as I switch to a multi-line statement inside any conditional I put in the brackets. I've had too many bugs over the years because the brackets weren't there.
|
|
|
|
|
I'll do a single line if-statement if the code inside the braces is a single line, function call, etc. If I were reviewing another's code, either way would be suitable.
|
|
|
|
|
This is why we use a code formatter at our place, to avoid the drama and debates on the code reviews! Everyone's code looks equally terrible.
|
|
|
|
|
If you can keep your head while those about you are losing theirs, perhaps you don't understand the situation.
|
|
|
|
|
|
Agree. Similarly, we use Resharper. I just accept whatever it does and move on.
|
|
|
|