|
I am not lazy (well, I may be, but that's not the point) and the reason I prefer the latter is to reduce the noise. Less noise, more readability.
|
|
|
|
|
Personally, for one line this-or-that...
condition.IfTrue(()=>DoThis()).Else(()=>DoThat());
Marc
|
|
|
|
|
Yes, I am sure for your disciples that's a very good thing
«OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. » Alan Kay's clarification on what he meant by the term "Object" in "Object-Oriented Programming."
|
|
|
|
|
If both branches are a single line, I prefer the second. However, I've seen too much of this abomination:
if (condition)
{
DoThis();
DoSomethingElse();
}
else
DoThat();
|
|
|
|
|
If there's only one "do", the whole thing should be on one line.
The reason the blocks were introduced is because multiple "do"s on one line are hard to read, so insisting that a single "do" be in a block is taking the idea in the wrong direction.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
Perhaps best to blame the language designers for allowing such freedom ?
I'm with Chris L. and others who point out we're no longer in the age of fewer-characters-are-best-because-memory's-so-precious that we can't afford white-space, or beaucoup de braces.
C# code that looks like VB has the smell of sewage to me (note: I do not "hate" VB).
«OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. » Alan Kay's clarification on what he meant by the term "Object" in "Object-Oriented Programming."
|
|
|
|
|
They think, If we write that way then our system will be heavy as each character has some byte.
|
|
|
|
|
How would you feel about
condition ? DoThis() : DoThat(); ?
My plan is to live forever ... so far so good
|
|
|
|
|
condition
? DoThis()
: DoThat();
And now?
All in all none of this really matters. As long as everyone on the project sticks to a predetermined coding standard, then the format doesn't matter as much, as long as its consistent.
Consistency in code can resolve a huge amount of misunderstanding.
|
|
|
|
|
Standard? STANDARD? What's that???
I found that we do keep to standards whenever all the other developers code exactly the same way as I do.
My plan is to live forever ... so far so good
|
|
|
|
|
The reason I moved from VB.NET to C# was the curly braces bro! Don't make me give up the curly braces!
I don't speak Idiot - please talk slowly and clearly
"I have sexdaily. I mean dyslexia. Fcuk!"
Driven to the arms of Heineken by the wife
|
|
|
|
|
I don't care very much as long as it's consistent.
But since you can't make multiple statements without braces...
Wrong is evil and must be defeated. - Jeff Ello
(√-sh*t) 2
|
|
|
|
|
Either one of those suits me fine. The ones I can't stand are these:
if (condition)
{
DoThis();
}
else
DoThat();
if (condition)
DoThis();
else
{
DoThat();
}
Anything that is unrelated to elephants is irrelephant Anonymous ----- The problem with quotes on the internet is that you can never tell if they're genuine Winston Churchill, 1944 ----- I'd just like a chance to prove that money can't make me happy. Me, all the time
|
|
|
|
|
And then there is the choice between:
if (condition) vs if (condition == true)
if (!condition) vs if (condition == false)
I sometimes put in the == false part because the ! is easy to miss when reading.
|
|
|
|
|
Karel Čapek wrote: Why are people so lazy?
Did it occur to you that it may be about style and not laziness?
Some people can have even another style:
if (condition) DoThis();
else DoThat();
To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson
----
Our heads are round so our thoughts can change direction - Francis Picabia
|
|
|
|
|
Fabio Franco wrote: Did it occur to you that it may be about style and not laziness?
No: people who do this tend to shortcut other things (sweeping generalization and/or observation over many years of being a coder) or crush the code into as small a space as possible making it hard to read.
The point is really to have consistency of style and format in the code: braces make it easier to read. Consider this:
int a = 0;
string bean = "green";
float golden= 1.618;
if (condition)
{
x = 42;
bean = "eatme";
golden = a * pi;
}
else
a = 1;
bean = 'foo';
golden = a - x;
I find that style difficult to read and adding the braces would make it much easier to see the flow.
Oh, and then there are tabs v spaces...
|
|
|
|
|
I only remove braces on single-line method preconditions at the beginning of a method:
if (arg==null) throw new ArgumentNullException("arg", arg);
Everywhere else I put braces.
|
|
|
|
|
Vark111 wrote: if (arg==null) throw new ArgumentNullException("arg", arg);
Let me guess - You're used to dealing with Pirated software???
Anything that is unrelated to elephants is irrelephant Anonymous ----- The problem with quotes on the internet is that you can never tell if they're genuine Winston Churchill, 1944 ----- I'd just like a chance to prove that money can't make me happy. Me, all the time
|
|
|
|
|
I personally prefer the former of the two, for readability. I tend to "speed read" classes and utilize the curly brackets as logical breaks in the code.
Basically, for me, it differentiates between code indentations and logic (if, foreach, for, etc.)
ICP-Fan
(The Keyboard Wielding Maniac)
|
|
|
|
|
Karel Čapek wrote: For example, how hard is it to
Both are probably less hard than complaining about it.
But other than that since it is legitimate syntax then it is legitimate syntax and nothing but a preference after that.
Naturally if that is the most important problem facing you day to day or even one that even rises above the noise level in terms of problems you must work at an exceeding stellar place.
I once worked a a place where the VP (most senior person in the entire site) would regularly take down the database through incorrect usage which would shut down the call center (several hundred employees) completely. Now that is a problem.
|
|
|
|
|
I have more
(condition)?DoThis():DoThat();
DoThese[(condition)]();
#define CALL_FUNC(__F) Do##__F
CALL_FUNC(condition);
do
{
if(condition)
{
DoThis();
break;
}
} while(DoThat()&&condition);
<pre lang="cs">
switch(condition)
{
case 1:
DoThis();
break;
default:
DoThat();
}
|
|
|
|
|
On a news site I heard a recording of a man as he was beaten to death.
It would have been offensive but they took care to *bleep* out the swearing.
The insanity of that is difficult to process.
|
|
|
|
|
What??? Why??? What???
People are every disturbing.
|
|
|
|
|
Remember what the MPAA says; Horrific, Deplorable violence is okay, as long as people don't say any naughty words!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Who are we and what have we become? We have made progress with technology, but we seem to still be in the dark ages when it comes to civility and morality.
|
|
|
|