- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
TRWTF is Visual Basic
Admin
I agree with this, and it's certainly a bad idea to build in null/empty equivalence into the language. However... I can't help but thinking how often I've written a method to return true if a String is null or empty. I can understand the impulse, wrong as it is.
Admin
string.IsNullOrEmpty(string value)
Admin
CAPTCHA: letatio oh how appropriate!
Admin
TRWTF is that none of these two pieces of code compiles. Maybe you two should switch to VB..
Admin
That's pretty funny. When I use VB, comparing Nothing to "" results in a null reference exception. And a database null casting to string throws an invalid cast exception.
Admin
Mindless, unoriginal, but absolutely true.
Admin
Admin
Admin
In theory nothing, it's just syntactic sugar for reflection, however in practice it can lead to a lot of bad code.
Admin
Admin
Strings have tons of syntactic sugar poured all over them, there certainly is no universal right or wrong answer to "Is a null string equivalent to an empty string". The answer to this question is defined in the langauge spec. Personally, I would like a language to handle strings in the most convenient manner possible rather than "getting closer to the metal". I really don't care if a string is really a pointer to a char array any more than I care whether my integers are stored big-endian or little-endian. I don't care if that pointer might be uninitialized or might point to an zero element array.
The right answer to me is to make a string a value type, initialize it to empty string, make assigning null to a string variable reset it to empty string (just like VB already does with other value types like int), and make it immutable so it can live as a reference on the stack. Of course, like every other value type, it can be declared as nullable. This would make for a very sane and consistent experience. Today, a string has a mixture of a reference and value type behaviors, depending on context. What I find strange is that many defend the current string behaviors, and the number one defense of those behaviors seems to be "that's how it's always been" or "that's the right way". Languages will never evolve if no-one ever proposes changes.
Admin
Admin
My comments on the last post evaporated...
What I wanted to say was that nothing, string.empty (which is equivilent to "") and System.DBNull.Value are all different animals. They are not interchangeable, and may not behave the way you expect. That doesn't mean wrong, only that it doesn't work the way you think it should. FYI.
Admin
Null and Empty strings mean different things. It isn't just a language thing, it's a computing thing. Programming languages are meant to bridge humans with computers at a low level; so programmers must be aware of the limitations of the computer (or VM) and be capable to do defensive coding.
Empty strings usually mean that no data was inputted; Null strings mean that something went wrong, or that the data didn't exist, these should be explicitly checked for. Dumbing down this is a bad idea.
Admin
Want a non-C language? There was Foxpro. MS pushed VB because of all the QuickBASIC guys, who owe their 31337 sk33llz to their earlier Apple II/C64/MSX programming experience on BASIC. The end result is that there are now a boatload of developers coding in a language that was not meant to be used on real software, but to introduce non-techies to the wonderful world of programming. In fact, PASCAL did a better job in that matter, so much that "pseudocode" reads much like Pascal.
However, it does seem that C# is gaining traction to an extent; most .NET devs have either switched to C# or began with C# skipping VB entirely. The rest are either doing Java, PHP, or that other weird thing called Ruby. The mere fact that this thread has more VB-haters than VB-lovers shows this is the case.
Admin
I am advocating choice -- the ability to make a non-nullable string where appropriate and a nullable string where appropriate. You are advocating that all strings under all circumstances should be nullable. Why would you be against this choice?
C# hides reference addresses, that would be a form of "dumbing down", is it a bad idea? Garbage collection, connection pooling, object-oriented programming, and just-in-time compilation are all forms of "dumbing down". I'm sure all of the C programmers out there would argue that all of these are bad ideas, but many well-respected people would also argue they are good ideas.
Admin
Admin
Admin
Oh, it is happening now. The big dragons of the consulting industry is sending people right out of school on a one week training in C# or Java and are them selling them as "experts", because they need every person they can find to fulfill their contracts.
In a decade, the same flames directed against VB now will be directed against C#.
Admin
Original BASIC lets you do PRINT and INPUT statements, GOTO, GOSUB and RETURN, and some simple arithmetic and string manipulation. And that's more or less it.
Which is fine if you write Dijkstra-like programs, but not for real software: software that actually does something useful.
Admin
For example, if you have a web service that returns a complex set of data, you would use such an object.
In such a case, and also because JAX-WS/JAXB requires that you have a no-argument constructor, the accessor methods become a bit useless.
Yes, you can use them for 'future compatibility', but with web services, where an object returned via SOAP cannot have any logic in it, there is no point in creating the accessor methods. It just makes the code longer and less legible.
In a proper non-web service API it's different of course, and you'd want to provide read-only access to certain fields.
Admin
TRWTF is six pages of squabbling about VB AGAIN!!!
Admin
Admin
@Jamie
Yeah, that was my dumbass about the null string reference. I forgot the basic fact that operators are static members of the class.
I owe you one! I was quite likely to use null string references to discriminate between empty strings at some point!
Thank you.
Admin
Good point; just keep in mind you can't databind to non-property fields of a class.
Admin
Your DBMS of choice isn't Oracle, I take it.
Admin
how about
Dim list = (New String() {"Hi", "there", "I'm", "a", "list"}).ToList
Admin
Sorry I missed this originally. How is this 'better' par se? I admit I haven't the time right now to compile both and compare the IL so I don't know if that;s where I'll see a difference ....
Admin
[pea-roast as I forgot to quote]
Sorry I missed this originally. How is this 'better' par se? I admit I haven't the time right now to compile both and compare the IL so I don't know if that;s where I'll see a difference ....
Admin
No, we just saw that it fell out of the loop after only one iteration, and scratched our heads trying to figure out why getMessage retuned false the second time it was called, or what else was terminating the loop. Yes, if we'd been thinking clearly we would have noticed that it never called getMessage a second time. But if we were thinking clearly we would have noticed the extra semi-colon. I'm sure a large percentage of bugs are of the "man, that was stupid!" variety. Including my own, of course.
Admin
Admin
I'm not talking about performance. I'm talking about syntax. Sure, there are ways to initialize lists (although, as far as I know, not dictionaries), but they're all things like passing a new array instance to the constructor (or, as someone mentioned above, ToList(), which seems to be pretty much just as bad). If I want to initialize a collection, I should be able to without resorting to workarounds like that. To me, at any rate, new CollectionObject {initial values} is much more readable (and may or may not be more efficient).
Admin
The flaw in your original argument is that you claim that the low maximum amount of a two-byte signed integer was fixed by the addition of a two-byte unsigned integer type with a higher maximum. Throwing out the negative side isn't 'fixing' the existing signed integer type at all.
Admin
In other words, you're making a fool of yourself.
Admin
OK well, syntax I don't think can really be regarded as 'better' or 'worse', its more of a personal preference, but that's just my opinion. What really matters IMO is what it gets compiled to, and how well that code performs.
You could argue that certain syntaxes encourage people to do things in less effective or efficient ways I suppose, but that's not really the matter I was trying to encourage some perspective on :)
Admin
Rereading your original quote I have to agree with what you said.
Apologies for the misquote.
Admin
Rereading your OP I have to agree with you re BASIC.
Apologies for the misquote.
Admin
Admin
Lord almighty, not another of these pissing contests?
I've programmed in pretty much any language you can think of at some point - C, C#, C++, PROLOG at uni - which I actually liked, Ada and SMALLTALK, proprietary ones that would make some of you young folks cack it, Delphi / Pascal, Assembly etc, even the monstrosity that was VB for DOS, and I prefer VB.NET to C#, sorry. I like it more verbose = more explicit, to me.
String comparisons stupid in VB? Don't make me laugh - when was that ever a bottleneck in any serious application.
C# does have some kind of late binding with variants. I do appreciate strong typing which is fully possible in VB - and can be overridden on a per file basis if needed, but it has never stopped any of the really serious shooting self in foot incidents that are possible.
If you are seriously saying it is possible to do interop with Excel or Word with C#, it is - just very stupid. Just write a shim library in VB to handle it - like I do with C# if VB stops short - which is pretty rare.
I've seen godawful code in many forms - VB most commonly, because it has been written by someone who has moved over from VBA. Means nothing. If C had that kind of base then it would have been corrupted the same.
Yes, I am pragmatic but I have always got my projects in on time, had fun doing them and been paid - that is all really
<shakes head at squawking, snobby noobs>
Admin
Admin
Are you sure? I am certain I can come up with a couple of things that are only possible in C#. One of them is Extension Methods.
Admin
?
http://msdn.microsoft.com/en-us/library/bb384936.aspx.
Admin
Yes, yes there is http://msdn.microsoft.com/en-us/library/aa288474(VS.71).aspx
And also VB has a checkbox "Hide Advanced Members" checked by default... C# does not have this checkbox...hmmm
Admin
TRWTF in this case is definately the trackback link - the linking article seems to list this entry as a serious vb property how-to...
Admin
+1 for 'pissing contests'
Admin
Dear Sir or madam, I am glad c# can do the optional parameter thing - I had not spotted that. My central point remains - by all means avoid use of VB.NET. By all means order your underlings to avoid such usage in a power crazed fit of rank pulling. Just drop the supercilious attitude. Unless you wish to correctly be viewed as a bit of a twunt.
Admin
Admin
Reading code: C# problems:
That's harder to read.
Since you read from left to right, when you see a line starting: [type] [identifier] (as in "int foo...") you have to read the entire line to know if it's a function or a variable. (Today C# is approaching VB. Now you have "var" in C#)
switch+break statement vs select case: Switch it's an old prehistoric dinosaur. When C was compiled to assembler, "switch/break" makes sense (if you know what a conditinal jmp is, you'll understand) But today it's a very bad tool, at least compared to VB select case.
Quit the "VB is for kids!" nonsense. You're revealing yourself as an ignorant. c# programmers are not c programmers. if you don't what char **p; means: you're in the managed NET league, where c# and VB.NET are almost the same thing: just "flavors" over MSIL+NET. In this regard, VB is a more powerful tool.
Admin