Linked by Thom Holwerda on Tue 15th Jan 2013 21:24 UTC
General Development "I was really excited to write this article, because it gave me an excuse to really think about what beautiful code is. I still don't think I know, and maybe it's entirely subjective. I do think the two biggest things, for me at least, are stylistic indenting and maximum const-ness. A lot of the stylistic choices are definitely my personal preferences, and I'm sure other programmers will have different opinions. I think the choice of what style to use is up to whoever has to read and write the code, but I certainly think it's something worth thinking about. I would suggest everyone look at the Doom 3 source code because I think it exemplifies beautiful code, as a complete package: from system design down to how to tab space the characters." John Carmack himself replies in the comments.
Permalink for comment 549047
To read all comments associated with this story, please click here.
RE[5]: Good article
by henderson101 on Wed 16th Jan 2013 17:45 UTC in reply to "RE[4]: Good article"
Member since:

With regards to "WithEvents" - yes probably. But that's not what the MSDN says. As far as I can see, it's required when the "handles" clause is being used. That's not really legacy then.

VB.NET is completely type safe.

No it's not... not in the "you can't use the wrong type because it won't compile" sense of the notion. VB will happily munge and cast between integral types and Decimal/Double. VB will silently cast a Boolean to an integer. This should not compile, but it does:

Dim X as Boolean

Function WFT as Boolean
Return X
End Function

Switch Case Y
Case WTF ''This could be anything

Also, the switch statement with a boolean is probably going to evaluate to zero,

Yeah, probably. But when you have to run code to verify that fact, it's screaming "walk away" to me.

because that's what a bool of false (default value for the bool value type) evaluates to when converted to an int.

And the compiler silently casts the Bool to an Integer. That might be how VB6 worked, but VB.Net uses the CLR and so an explicit cast is required. How helpful VB.

Oh, and rewinding to "type safe".. try turning off Option Strict and Option Explicit and see how much worse you can make stuff... you don't even need to declare the return types of Functions... VB just guesses for you and silently casts the result to the type you assign the result to. Even with it on, you can still do everything else I mention. The first thing I do with VB code these days is look at the project properties and if it isn't already set, build it with Option Explicit and Option Strict turned on and fix all the errors. It is far, far too common to still find shops using VB.Net as if it was VB6.

Reply Parent Score: 2