Pet Peeve
-
Why are people so lazy? For example, how hard is it to
if (condition)
{
DoThis();
}
else
{
DoThat();
}as opposed to:
if (condition)
DoThis();
else
DoThat();Pedants :sigh:
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."
-
This is true. I always use separate lines for everything myself, but all I was saying is I find
if (if stuff) [then stuff];
on one line more readable, in established and (hopefully) debugged code. If I have to debug it myself, I just hit enter and add a breakpoint on the new line. Then use the "source control undo" in solution explorer to revert back to the prior pristine state.No object is so beautiful that, under certain conditions, it will not look ugly. - Oscar Wilde
I understand... and I can't say I disagree... that arrives to the point of preference, not to the point of usefulness. But one thing I never do is 2 (or more) real calls in the same line: SomeObject.DoCallOne().DoCall2(otherObject.AnotherCallWithAResult(), evenAnotherObject.WithEvenAnExtraCall(), theFinal.ObjectWithTheFinalCall());
-
Why are people so lazy? For example, how hard is it to
if (condition)
{
DoThis();
}
else
{
DoThat();
}as opposed to:
if (condition)
DoThis();
else
DoThat();Pedants :sigh:
They think, If we write that way then our system will be heavy as each character has some byte. :) :) :) :-D
-
Why are people so lazy? For example, how hard is it to
if (condition)
{
DoThis();
}
else
{
DoThat();
}as opposed to:
if (condition)
DoThis();
else
DoThat();Pedants :sigh:
How would you feel about
condition ? DoThis() : DoThat();
?
My plan is to live forever ... so far so good
-
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.
-
Why are people so lazy? For example, how hard is it to
if (condition)
{
DoThis();
}
else
{
DoThat();
}as opposed to:
if (condition)
DoThis();
else
DoThat();Pedants :sigh:
-
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. ;P
My plan is to live forever ... so far so good
-
That's not good enough...
if
(
condition
)
{
this
.
DoThis
(
)
;
}
else
{
this
.
DoThat
(
)
;
}It's not properly formatted until there's only one token per line. :)
Proud to have finally moved to the A-Ark. Which one are you in?
Author of the Guardians Saga (Sci-Fi/Fantasy novels)Totally agree...but for a very spesific reason. I'm using a Braille display with a maximum of 40 chars per line, so it have a influence on my format preferences... ;P Seriously though, if (condition) { Action1(); } else { Action2(); } is my real preference, and there's a plus to that, whenever the situation change to have more than one statement for the if test, the person who has to change it doesn't have to remember to go and fill in the {}.:cool:
-
I understand... and I can't say I disagree... that arrives to the point of preference, not to the point of usefulness. But one thing I never do is 2 (or more) real calls in the same line: SomeObject.DoCallOne().DoCall2(otherObject.AnotherCallWithAResult(), evenAnotherObject.WithEvenAnExtraCall(), theFinal.ObjectWithTheFinalCall());
Just your contrived example hurts my eyes. I'd hate to see that in real life. :~
No object is so beautiful that, under certain conditions, it will not look ugly. - Oscar Wilde
-
if (condition) { this.DoThis(); } else { this.DoThat(); }
You probably meant
Ian Shlasko wrote:
It's not properly formatted until there's only one token per line in the entire application.
I guess it's theoretically possible... :~
public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
} -
Why are people so lazy? For example, how hard is it to
if (condition)
{
DoThis();
}
else
{
DoThat();
}as opposed to:
if (condition)
DoThis();
else
DoThat();Pedants :sigh:
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 (√-shit)2
-
I agree with you. And I am actually the kind of person that when has to modify something like:
if (something)
{
DoA();
DoB();
}To only call a DoAB(), I will go there and kill the extra { and }. So, I have more work doing that, but I keep consistency. So, it becomes:
if (something)
DoAB();That works fine until you get this in the code after all :)
if ((err = SSLHashSHA1.update(&hashCtx, &serverRandom)) != 0) goto fail; if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0) goto fail; goto fail; if ((err = SSLHashSHA1.final(&hashCtx, &hashOut)) != 0) goto fail;
When I first saw that bug I got even more convinced see that my approach to braces everywhere as a must works better in the end.
Banking establishments are more dangerous than standing armies. T.Jefferson
-
Why are people so lazy? For example, how hard is it to
if (condition)
{
DoThis();
}
else
{
DoThat();
}as opposed to:
if (condition)
DoThis();
else
DoThat();Pedants :sigh:
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 -
Mladen Janković wrote:
it can make you look obnoxious.
But I am obnoxious
Well I can't argue with that :)
-
Why are people so lazy? For example, how hard is it to
if (condition)
{
DoThis();
}
else
{
DoThat();
}as opposed to:
if (condition)
DoThis();
else
DoThat();Pedants :sigh:
-
Why are people so lazy? For example, how hard is it to
if (condition)
{
DoThis();
}
else
{
DoThat();
}as opposed to:
if (condition)
DoThis();
else
DoThat();Pedants :sigh:
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
-
I prefer
if (something) DoAB();
for the latter. I never use it, but have recently come across it. It seems more readable to me.
No object is so beautiful that, under certain conditions, it will not look ugly. - Oscar Wilde
It's slower to read an if statement with code on the same line because your eyes have to track to the right. It's the same reason why you shouldn't place form titles and fields on the same line. Here's some articles on it: http://www.uxmatters.com/mt/archives/2006/07/label-placement-in-forms.php[^] http://uxmag.com/articles/eye-tracking-and-web-usability-a-good-fit[^]
Daniel Vaughan Twitter | Blog | Microsoft MVP | Projects: Calcium SDK, Clog | LinkedIn
-
It's slower to read an if statement with code on the same line because your eyes have to track to the right. It's the same reason why you shouldn't place form titles and fields on the same line. Here's some articles on it: http://www.uxmatters.com/mt/archives/2006/07/label-placement-in-forms.php[^] http://uxmag.com/articles/eye-tracking-and-web-usability-a-good-fit[^]
Daniel Vaughan Twitter | Blog | Microsoft MVP | Projects: Calcium SDK, Clog | LinkedIn
Cool, thanks. I've bookmarked those.
No object is so beautiful that, under certain conditions, it will not look ugly. - Oscar Wilde
-
Sure it's easy, until another developer adds a second line and forgets to add brackets. I've been working in some source code that didn't use brackets for single statements. I introduced a few bugs by not adding them when I had to and I've been wondering more than once if the original developer REALLY meant not to add brackets....
if (condition)
DoThis();
else
DoThat();
DoAnotherThing();is really weird to look at and at the very least makes you wonder if it was intended... Especially if
DoAnotherThing();
isn't properly in/outdented!public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
}I am currently working on a system where most of the software was written in C in the early 1980s. It is formatted so badly that stuff like
if (condition) DoThis();
else DoThat();
DoAnotherThing();is not uncommon at all. Add to that, there is no consistent use of tabs vs. spaces, no consistent tab stops, no naming conventions. Honestly, use the braces or don't, just be consistent, dammit. Proper indentation is far more valuable than brace usage; don't use TAB for indentation, and do stuff the same way, every damn time.
"The only thing a free man can be forced to do is die." "The right to defend oneself and ones neighbors is the beginning of freedom." "Freedom? That is a worship word. . ." -- Cloud William "It is our worship word, too." -- James T. Kirk
-
Why are people so lazy? For example, how hard is it to
if (condition)
{
DoThis();
}
else
{
DoThat();
}as opposed to:
if (condition)
DoThis();
else
DoThat();Pedants :sigh: