- 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
Oh, by the way, if you came to the comments to complain...er...point out the Mandatory Fun Day reference in today's article, then this is for you:
[image]Enjoy!
Admin
Bring back MFD!
Admin
Wow, that response from Herb Jenkins really is icing on the cake.
Admin
I've found TRWTF:
setValues = setValues + " Set " + "@" + dataTable.Columns(i).ColumnName.ToString() + "=" & ConvertedSetVal.ToString & ";"
Everybody knows how inefficient string concatenation is. So you can increase the processing speed profoundly by turning ...+ " Set " + "@" +... into ...+ " Set @" +...
Surely you don't need management approval for that?
Admin
The complaint could easily come from anyone else trying to run their process against that SQL Server instance.
Of course, it's almost a valid course of action to see if there are complaints if you have a busy IT shop, but something this obviously brain dead should have been immediately addressed.
Admin
To me anything that hits the SQL server in multiple calls is going to be the TRWTF. Network traffic, latency, unreasonable server load, etc etc etc
Admin
Every time I see code like this I get the feeling it was written by a believer in the church of "premature optimisation is the root of all evil".
Admin
I also know from real life experience that just about anything is going to be faster than trying to process an update like this using VB. Anything.
Admin
Erm, maybe yes? Maybe write simple code instead of clever code?
Erm, race conditions?
Erm, where's the server? Elbonia? TRWTF is running this on a different physical machine to the database.
No, wait: TRWTF is fixing things nobody is complaining about when there are things they ARE complaining about!
It works. It's been tested. Leave it alone unless there is an issue.
Admin
Yeah, you're right: code reviews can have a significant impact :-)
SCNR. And yes, I know the string stuff was meant as a joke ;-)
Admin
Admin
A good rule of thumb here, of course, is that careless and lazy code like the above is a good indicator of code being careless and lazy elsewhere in the application as well.
Admin
The database running on a different machine is the norm. Especially in a web environment. And no, the database server will not be in Elbonia but probably in the same rack.
The slow performance does not come from bad network performance but from the database having to handle 40,000 or more seperate requests for someting that can probably be done with two.
I haven't worked with .Net DAOs for some years, so excuse me if I talk rubbish, but wouldn't you prepare a data object with the existing data (1st request), prepare a data object with the XML data, from the two create an obdated data object and use that data object to update the database (2nd request)?
Admin
But (for the slow on the uptake) the first rule of (do I need to go on here?)...
Admin
Proof that any sufficiently advanced troll is indistinguishable from a moron.
Admin
You have a programmer who wrote that code and now you want him/her to attempt to optimize it?
Admin
Cheap optimization: shouldn't wrapping it in a transaction dramatically speed things up?
Admin
But "Set " + "@" instead of "Set @"? That's not careless or lazy, it's plain wrong in Visual Basic, as the "&" operator is used for string concatenation ("+" is for adding numbers) and "Set " + "@" might even throw an exception (I don't know, I'm currently not working in a .NET shop).
But if it doesn't throw an exception, chances are good that it doesn't slow down your performance since the compiler might optimize it away (what it will probably also do with the redundant ToString() call).
And if you really think string concatenation is an issue, you wouldn't micromanage by replacing "Set " & "@" with "Set @" but would use StringBuilder instead.
Admin
What are ConvertedUpdateVal and ConvertedInsertval for? They are just declared as null and never used, right?
Admin
And great story it involves xml, but xml is not the wtf. Never heard that before.
Admin
I am starting to like stories where the fun part is a huge chunk of code in a language I don't know.
Admin
Second. Beats the hell out of Hanz stories.
Admin
Admin
Given how "Magenta Corp" was shown in MFD (I kinda miss that.. god help me..), I imagine the WTFery there would be intentional, like some kind of bumbling Hank Scorpio from The Simpsons:
Mr. Magenta: Jenkins, I have a new diabolical plan! We'll make OVER FORTY THOUSAND database calls to process this small XML file, and our users will have to pay us to speed things up. I'll be rich! Mwa-ha-ha-ha-ha!
Jenkins: Great plan, sir. I'll get the Reverse Polish Vampires on it immediately.
Mr. Magenta: Excellent! Mwa-ha-ha-ha! thunder rumbles BWA-HA-HA-HA-HA
Or actually.. kind of like Professor Chaos (AKA Butters), doing stupid things that he thinks will make him an evil supervillain. Wait... maybe Mr. Magenta is an older Butters?
Admin
Admin
Admin
Why you gotta bring race into this, man?
Genuine agreement. Assuming "Jenkins" response email was pasted word-for-word, it appeared as a very thinly disguised "We didn't ask you to waste company time on this when there are other things we ARE paying you to be doing right now, but I don't feel like chewing you out."
Admin
Admin
Today's wtf is wonderful. This is - as opposed to yesterday's story - what I come here for.
The code supplied is a real cornucopia of wtfs, including the odd global variable (or where does dataSet come from?) and the woderfully misleading comments (the check performed seems to do the opposite of what the comments say).
The code in the article would make a wonderful "what's wrong with this?" sort of question when interviewing job candidates (for VB .NET jobs).
I'll definitely keep it.
Admin
Uh, the article starts off by saying that Marla as asked to look at a problematic load...
Admin
Not knowing Visual Basic is no bar to writing code in it.
I'm only being partially flippant; the language provides a whole bunch of features like automatically converting between types, so that you can concat numbers to strings, or use strings as numbers. It is pretty forgiving in attempting to figure out what code you MEANT to write, rather than the code that you actually wrote.
Rather than resulting in fewer bugs, however, this serves only to encourage the feckless.
Admin
Admin
TBH, using VB.NET when C# is available (e.g., always) is the real WTF, Option Strict or not.
Admin
So the BaseWTF is that management doesn't care?
Admin
So management asks for an investigation on a problematic load, then decides the load wasn't problematic because no user complained... then why launch the investigation in the first place ?
Admin
I haven't written VB for a long time so I don't know for sure but wouldn't that code throw an error every time the main loop runs because they keep redimensioning their variables?
Admin
Actually, + and @ are equivelant for string concatenation in VB. The & is the explicit string concatenation operator, as it always returns a string, but + is perfectly acceptable.
As to concatenation in general... StringBuilder is intended for code where you do something like a = a + "something" in a loop. Using StringBuilder for a single line variable assignment isn't going to buy you much, and it might even take you backward, since allocating and deleting objects has its own overhead.
This whole code section is a newbie mistake, but it doesn't so much make scream out in anguish as just shake my head.
Admin
I think I've got the gist of it:
Admin
The real WTF isn't the amateurish code, it's management's response. All too common, though.
Admin
Management's response was a WTF from the point of view of a common-sense developer ("always strive to do/implement things the right way").
But, from management's point of view, if the customers are not complaining, then it ain't broke, therefore, it doesn't need fixing, therefore, development resources can be put to use on more urgent matters.
Admin
http://en.wikipedia.org/wiki/String_interning
Admin
Hate to be the one to say that VB is TRWTF, but I don't get why VB is so prolific or why newbies decide to start their programming careers by learning it.
I hear people say that it's "easy", but the fact that there exists an "explicit" and a "not explicit, but still acceptable, yet may have unintended consequences depending on some arcane quirk of the type system" operator makes me sad. Whilst I still respect people who know a language well, I never thought there could be so much complexity in a language which is supposed to be "easy". C++ is renowned for this kind of "gotcha" bullshit, which is why most people are scared of it, and generally avoid it in this day and age (and rightly so).
My theory is that rookie programmers get frustrated by compile-time errors (and give up), cause they can't see the fruits of their labors, but are happy to persevere for hours on end with runtime errors, cause they can see the effect of their changes, then tweak the shit out of it till it "works". And it is at 4am after hours of perseverance when code like this is born, and the (soon to be "rockstar") novice goes to bed satisfied and contented that they've made a positive contribution to the world. Then, cause their code "works" and they got it done so quickly, plus they're so proud of themselves they cant shut up about how "innovative" they are, they're on the fast track to becoming CTO.
Admin
Seeing as how it's VB .NET, it will be just as fast as poorly-written C# .NET. And probably a couple of orders of magnitude quicker than poorly-written Java, also simply known as Java.
Admin
There are things that I like and things that I HATE about VB. If you compare VB's Select Case to any C-syntax switch statement, it's far superior. But when you look at the Iif() function, using + as a string concatenation operator, and all these little things that try to make what was VB6 more .NET-ish, it just ends up being a bunch more WTFs.
That being said, I always enable Option Explicit and Option Strict in the VB projects that I work on. Some people complain about it, but there are fewer complaints from the end users, which matters more.
Admin
this
Definitely mandatory.
Admin
It'd suck if there was a much more highly regarded language that was even looser with its types :cough: JavaScript :cough:
Admin
Well, VB is really for business owners, who would be intelligent enough to be able to roughly formulate models of their business in logical "maths-y" ways, but who are not engineers and are not really interested in making something efficiently.
So it does a bunch of stuff that makes it nice for the non-engineers. Unfortunately, the result is that totally non technical people think they can code well, when actually they can really only code something that just-about-works.
The additional result, is all the engineers having to clean up the mess, and non-technical managers not understanding what all the fuss is about.
Admin
I consider the difference between the two similar to American and British English. Not exactly the same, but compared to other languages, very little difference.
Admin
Definitely a good read for the people here that haven't touched VB since 1998:
http://visualstudiomagazine.com/Articles/2011/05/01/pfcov_Csharp-and-VB.aspx?Page=1
Admin
Static vs. Dynamic typing is a different issue, and each have their benefits depending on the application. Statically typed languages are awesome for refactorability, code-completion and (with reflection) useful domain objects. Dynamic languages are great for metaprogramming and scenarios where there are cross-cutting concerns which don't fit neatly into the traditional OO inheritance model. Chose the right tool for the job.
It's VB's bizarre combination of the worst aspects (none of the benefits, all of the drawbacks) of both which has always done my head in.