|
I prefer to code in Schizophrenic style. At least I think I do. I can never remember which of us decides the code style.
When I go back to my review my code after 6 months, I think "Who the hell was the lunatic that coded this?!"
It is usually after the shock treatments that I remember I'm the only coder.
No single raindrop believes it is to blame for the flood.
-irresponsibility@Despair.com
|
|
|
|
|
When simple code, I use:
if (a[i] > n)
result++;
When some additional logic or comments required, I use:
if (a[i] > n)
{
new Calculator(this).Calculate(a[i], i, n);
}
and
if (a[i] > n)
{
result++;
}
|
|
|
|
|
I agree and voted with 5
|
|
|
|
|
Since we use stylecop for our coding guidelines, single-line statements without braces are no more existant
In my opinion, it improves the reading so I totally agree in using braces always.
Have a nice day and happy coding,
Stops
|
|
|
|
|
// ♫ 99 little bugs in the code,
// 99 bugs in the code
// We fix a bug, compile it again
// 101 little bugs in the code ♫
|
|
|
|
|
|
Also using StyleCop for C# but only using { } when needed (readability, multiple lines etc.)
Which rule "forces" you to use { } always?
A:
if (a)
a();
else if (b)
b();
else if (c)
c();
else
d();
B:
if (a)
{
a();
}
else if (b)
{
b();
}
else if (c)
{
c();
}
else
{
d();
}
If you're paid per code lines you'll prefer B, right?
Some argue using { } always in order to avoid bugs when another developer is adding code e.g. to a if block. But I never produced a but because of this ^^
if (ab)
a();
b();
if (ab)
{
a();
b();
}
|
|
|
|
|
Hi,
It is the rule "SA1503: CurlyBracketsMustNotBeOmitted".
I'm not paid per line, but I still prefer braces for one-liners.
Best regards and happy coding,
Stops
|
|
|
|
|
Thank you for the information.
I am following company guidelines as needed but for my private code (pet projects) I still prefer disabling SA1500 and SA1503
Payed per line: This was just a joke
Kind Regards,
Harald
|
|
|
|
|
You're welcome.
You mentioned it correctly, as long as the company guidelines are considered in company projects, everything is fine.
For private / non-official projects, some rules are mostly a matter of opinion
Have a sunny friday and happy coding,
Stops
|
|
|
|
|
Indeed my behavior is as follow:
if (condition) statement;
if (condition)
{
statement;
}
if (condition)
statement;
However, of course I stick to the conventions used in already written code; i.e. if in the guide-lines for the code say you must write
if (condition)
statement;
then I do so. But in "my" code I prefer my way, of course.
|
|
|
|
|
Ever heard about "collective Code ownership"?
Btw, Code is usually written once and read many times ...
|
|
|
|
|
You can do this too;
if (condition) { statement; }
Someday it will save your life (or that of your successor).
------------------<;,><-------------------
|
|
|
|
|
Counteracted the vote of 1 by some 'tool'. Gave you a 5, you made a valid point. Some would consider it redundant, but who cares?
RedSonja wrote: Someday it will save your life (or that of your successor).
I'm not too sure that writing code will save anyone's life, but whatever floats one's boat.
Enjoy your day
P.S.
It seems that the law of averages here don't work properly. Or perhaps the comment voting system has changed.
Shouldn't 1 (original vote) +5 (my vote) /2 (number of votes) be equal to 3 (true result based on the aforementioned math)? Or is it that my vote isn't truly one vote, as much as it is apparently equal to (0.8/5)=0.16 of a vote point per point that I voted? *shrugs*
Some say that ignorance is bliss... Blissful, aren't they?
|
|
|
|
|
I also find the following easier to read:
if (condition) statement;
|
|
|
|
|
This one made me laugh
'Till a very short while ago say... a couple of months I never done this.
What made me change were my co-workers that were always saying it was a bad practice and they had a bad time reading my code because of that .
To stop earing them I just started doing it... eh... I still don't find it necessary and my brain processes that code with no problem.
Cheers!
Alex
|
|
|
|
|
The way you use braces, end statements etc is entirely down to the syntax of the language, local standards, if any, and personal preference.
The compiler does not care, readable code needs only to be consistent.
Another discussion on the very old topic is, in my opinion, a waste of time.
|
|
|
|
|
Who cares? We do, the people who have to maintain it.
Only valid for serious code, of course.
------------------<;,><-------------------
|
|
|
|
|
That was the entire point of my including consistency. I too have to maintain legacy code as well as developing new and I have been a professional development, degree qualified and chartered, engineer for more than twenty years so I do fully understand the issues. But personal preference has nothing, in this context, to do with writing quality code.
|
|
|
|
|
You'll be surprised (I know I am) how many people care!
Moreover, I had so many pointless discussion on this pointless topic. Apparently it encourage good "maintainability"
I guess it's from people who have little other criteria!
BTW, since I met MVVM, I think my code maintainability has progressed significantly!
(way more significantly that this old pointless debate! :P )
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Paul Darlington wrote: Another discussion on the very old topic is, in my opinion, a waste of time.
And yet you're discussing it. If you're not happy Mr Grumpy-pants, come up with your own survey. This game is open to all.
|
|
|
|
|
Provocative statements invariably generate interesting responses, Fun here isn't it
|
|
|
|
|
That's why I keep coming back.
|
|
|
|
|
Spot on! But suggesting that it is irrelevant won't get you sympathy from readability part of crowd.
I don't wrap... it looks ugly as hell (to me), it's that simple, everything else are just made-up excuses.
|
|
|
|
|
Paul Darlington wrote: Another discussion on the very old topic is, in my opinion, a waste of time
But we're software developers and we love religious wars!
In reality, whatever people answer on this it would not be top of my list of maintainability bugbears.
Kevin
|
|
|
|
|
Every, every time!
In legacy code I inherit this is so often the cause of errors. Anyway, the programming standards demand it. OK, it was me who wrote it in there, but it makes sense.
If you want to save space, you can write
if (errcode == 1) { return iError; }
------------------<;,><-------------------
|
|
|
|