Why I Like If / Endif

Sure lot's of people will laugh at me because I am a VB fan. (You know use If and End if and kiddy stuff like that)

Well read this Nice Article which is about biztalk and a tiny piece of c# code.
Try to read it and spot the error.

If you didn't notice the error before the explanation Then try the following .......

If 'You spotted the error at once' Then
   'You are a good C# Programmer'
Else
   'Consider switching to VB'
End if

Guess everybody understands this one.......

Published 08-19-2004 2:35 PM by Patrick Wellink
Filed under:

Comments

# re: Why I Like If / Endif

Friday, August 20, 2004 2:54 PM by Patrick Wellink
Well, I spotted the error right away so thanks for the compliment ;-)

I guess any good coder will spot the error almost instantly because the absence of brackets in this case is clearly going to cause confusion.

I ALWAYS use {} to keep code readable and maintainable, even with only one line of code.

# re: Why I Like If / Endif

Friday, August 20, 2004 4:00 PM by Patrick Wellink
You forgot the 'h' in which? ;-)

BTW. I guess you mean VB.NET when you speak of VB?

# re: Why I Like If / Endif

Friday, August 20, 2004 5:02 PM by Patrick Wellink
Well Ernst,

This was done by some Microsoft dude.....
I guess they know c#...

Are you saying they are not good coders at MS ??? (or are you only guessing)

And Roland thanks I corrected the error.
And yep I do mean VB.NET.

# re: Why I Like If / Endif

Friday, August 20, 2004 7:18 PM by Patrick Wellink
So, Patrick, what are you trying to say? Everybody at MS is perfect? Is that why we know expressions like "DLL hell" and "blue screen of death"...? :-)

>> "Are you saying they are not good coders at MS" - I think some people would love to argue with you on this one...

And MS released VB for .NET so it's hard to argue they don't make mistakes ;-)

Even guys at MS make mistakes and I've had my share of errors, but I'm just saying that in this particular case, I always use brackets.

# re: Why I Like If / Endif

Saturday, August 21, 2004 1:59 AM by Patrick Wellink
Well Ernst,

I just tried to make clear that the people who invented c# even get confused themselves....

In VB this error would never have happened.
And the code would be more compact.

Something needing only 10 lines of VB code
and perfectly clear to everybody would need 22 lines in C# to be clear.

No wonder all these real programmers (you no c# boyz) need a 40 inc LCD.

# re: Why I Like If / Endif

Saturday, August 21, 2004 1:43 PM by Patrick Wellink
De geneste if in deze code is zowiezo overbodig. Je had ze kunnen combineren in een if statement (zie m'n comment op blog zelf). Voor if statements met slechts een statement erna vindt ik {} de leesbaarheid van de code aanzienlijk verminderen, want in plaats van 2 regels heb ik er nu 4, wat het overzicht over een routine vermindert. Blijft een questie van smaak (en teamafspraken!).

# re: Why I Like If / Endif

Tuesday, August 24, 2004 8:00 AM by Patrick Wellink
hehehe..... Gerke...... long time no see!

# re: Why I Like If / Endif

Wednesday, August 25, 2004 5:02 PM by Patrick Wellink

Come on guys...... admid it

If / Endif RULEZ !!!!!

# re: Why I Like If / Endif

Tuesday, August 31, 2004 11:19 AM by Patrick Wellink
Easy one... when watching/debugging code one of the first things to check is alignment.

Our company policy it to use brackets but I don't agree with that one. The same as also using just one return in a method. If that would be the semantics of a language then the compiler would punish us for being stupid :)

Dennis will probably remember the drills for learning c of the teacher at Zadkine College Christiaan Huygens van 't Hof. Bracket checks and alignment was part of that. The for uninitialized variables but c# won't allow that anymore :) damn those were the days on those f**king old VMS machines.

if statements that contains just one line of code should be put on one line :) but that is my opinion. Not of my employer.

# re: Why I Like If / Endif

Tuesday, August 31, 2004 11:22 AM by Patrick Wellink
B.t.w. the new C++ compiler allows such readable code in .NET that I am thinking of moving from C# to C++ because why use C# when you have workable/readable C++ available?

Then this discussion will turn into a nice VB againt C++ battle like some years ago :)

# re: Why I Like If / Endif

Friday, October 15, 2004 6:18 PM by Patrick Wellink
Ernst is right; it is Good, disciplined coding practice (in any language) to alwaye use braces. It shouldn't surprise you so much that someone at M$ has less-than-perfect coding practices!