• (cs)

    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!

  • (cs) in reply to Mark Bowytz

    Bring back MFD!

  • (cs)

    Wow, that response from Herb Jenkins really is icing on the cake.

  • QJo (unregistered)

    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?

  • JimmyCrackedCorn (unregistered)

    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.

  • JimmyCrackedCorn (unregistered) in reply to QJo

    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

  • Rennis Ditchie (unregistered)

    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".

  • JimmyCrackedCorn (unregistered)

    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.

  • Ben (unregistered)
    So many problems. Merging data one row at a time...was the merge command really meant to work that way?

    Erm, maybe yes? Maybe write simple code instead of clever code?

    Making calls to the database to check if columns and tables exist after the XML file has already been validated earlier in the program.

    Erm, race conditions?

    And perhaps the most infuriating detail: THE FACT THAT THE ORIGINAL DEVELOPER DIDN'T THINK THAT MAKING OVER 40,000 CALLS TO THE SQL SERVER TO PROCESS A SMALL DATA FILE WAS GOING TO LEAD TO “SLOW” PERFORMANCE!

    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.

  • faoileag (unregistered) in reply to QJo
    QJo:
    setValues = setValues + " Set " + "@" + dataTable.Columns(i).ColumnName.ToString() + "=" & ConvertedSetVal.ToString & ";" (...) So you can increase the processing speed profoundly by turning ...+ " Set " + "@" +... into ...+ " Set @" +...
    And removing the completely redundant ToString() method call from dataTable.Columns(i).ColumnName property will save further milliseconds!

    Yeah, you're right: code reviews can have a significant impact :-)

    SCNR. And yes, I know the string stuff was meant as a joke ;-)

  • Bob (unregistered) in reply to Ben
    Ben:
    Making calls to the database to check if columns and tables exist after the XML file has already been validated earlier in the program.
    Erm, race conditions?
    Send in code where you work around race conditions in a *DB schema*, that would be good DWTF article. Otherwise, nice troll.
  • QJo (unregistered) in reply to faoileag
    faoileag:
    QJo:
    setValues = setValues + " Set " + "@" + dataTable.Columns(i).ColumnName.ToString() + "=" & ConvertedSetVal.ToString & ";" (...) So you can increase the processing speed profoundly by turning ...+ " Set " + "@" +... into ...+ " Set @" +...
    And removing the completely redundant ToString() method call from dataTable.Columns(i).ColumnName property will save further milliseconds!

    Yeah, you're right: code reviews can have a significant impact :-)

    SCNR. And yes, I know the string stuff was meant as a joke ;-)

    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.

  • faoileag (unregistered) in reply to Ben
    Ben:
    And perhaps the most infuriating detail: THE FACT THAT THE ORIGINAL DEVELOPER DIDN'T THINK THAT MAKING OVER 40,000 CALLS TO THE SQL SERVER TO PROCESS A SMALL DATA FILE WAS GOING TO LEAD TO “SLOW” PERFORMANCE!
    Erm, where's the server? Elbonia? TRWTF is running this on a different physical machine to the database.
    Wow, that one's nice: two WTFs in one sentence! :-)
    1. 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.

    2. 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)?

  • (cs) in reply to Mark Bowytz
    Mark Bowytz:
    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: ((snip)) Enjoy!
    Actually, I was thinking more along the lines of Marla being Marla Singer...

    But (for the slow on the uptake) the first rule of (do I need to go on here?)...

  • David (unregistered) in reply to Ben
    Ben:
    It works. It's been tested. Leave it alone unless there is an issue.

    Proof that any sufficiently advanced troll is indistinguishable from a moron.

  • D8 (unregistered) in reply to Rennis Ditchie

    You have a programmer who wrote that code and now you want him/her to attempt to optimize it?

  • (cs) in reply to D8

    Cheap optimization: shouldn't wrapping it in a transaction dramatically speed things up?

  • faoileag (unregistered) in reply to QJo
    QJo:
    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.
    I agree with you in so far as I would take the whole method as a good indicator that the programmer in question is probably a very junior one and would benefit from a senior mentor, and, indeed, from regular code reviews by that mentor.

    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.

  • ANON (unregistered)

    What are ConvertedUpdateVal and ConvertedInsertval for? They are just declared as null and never used, right?

  • ANON (unregistered)

    And great story it involves xml, but xml is not the wtf. Never heard that before.

  • aragaer (unregistered)

    I am starting to like stories where the fun part is a huge chunk of code in a language I don't know.

  • J. Strange (unregistered) in reply to aragaer
    aragaer:
    I am starting to like stories where the fun part is a huge chunk of code in a language I don't know.

    Second. Beats the hell out of Hanz stories.

  • (cs) in reply to Ben
    Ben:
    Erm, race conditions?
    Under race conditions, you've got to change the tires as fast as possible, not send out a dispatch rider to get each new wheelnut from the shop in the next factory, wait for them to get back and then send out a whole new dispatch rider for the next nut.
  • (cs)

    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?

  • faoileag (unregistered) in reply to aragaer
    aragaer:
    I am starting to like stories where the fun part is a huge chunk of code in a language I don't know.
    Pffft, Visual Basic is easy. Wait until an article appears in which you are presented a huge chunk of LISP :-)
  • faoileag (unregistered) in reply to ANON
    ANON:
    And great story it involves xml, but xml is not the wtf. Never heard that before.
    I'm also missing the usual "Of course, TRWTF is Visual Basic".
  • Krunt (unregistered) in reply to Ben
    Ben:
    Erm, race conditions?

    Why you gotta bring race into this, man?

    Ben:
    It works. It's been tested. Leave it alone unless there is an issue.

    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."

  • anonymous (unregistered) in reply to Ben
    Ben:
    So many problems. Merging data one row at a time...was the merge command really meant to work that way?

    Erm, maybe yes? Maybe write simple code instead of clever code?

    Making calls to the database to check if columns and tables exist after the XML file has already been validated earlier in the program.

    Erm, race conditions?

    And perhaps the most infuriating detail: THE FACT THAT THE ORIGINAL DEVELOPER DIDN'T THINK THAT MAKING OVER 40,000 CALLS TO THE SQL SERVER TO PROCESS A SMALL DATA FILE WAS GOING TO LEAD TO “SLOW” PERFORMANCE!

    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.

    If your idea of "race conditions" is "columns and tables might have disappeared without me knowing", you don't belong anywhere near code - or a database, for that matter.

  • faoileag (unregistered)

    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.

  • dguthurts (unregistered) in reply to Ben

    Uh, the article starts off by saying that Marla as asked to look at a problematic load...

  • eVil (unregistered) in reply to aragaer
    aragaer:
    I am starting to like stories where the fun part is a huge chunk of code in a language I don't know.

    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.

  • (cs) in reply to eVil
    eVil:
    aragaer:
    I am starting to like stories where the fun part is a huge chunk of code in a language I don't know.

    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.

    #Honestly, if you are not using Option Strict on in Vb.NET you are the wtf. Building a bigger program without that option is like building on mud. Even if you are doing Office interop, you can use strict on, with the possible exception of late binding.

  • eVil (unregistered) in reply to HerrDerSchatten
    HerrDerSchatten:
    Honestly, if you are not using Option Strict on in Vb.NET you are the wtf. Building a bigger program without that option is like building on mud. Even if you are doing Office interop, you can use strict on, with the possible exception of late binding.

    TBH, using VB.NET when C# is available (e.g., always) is the real WTF, Option Strict or not.

  • ¯\(°_o)/¯ I DUNNO LOL (unregistered)

    So the BaseWTF is that management doesn't care?

  • T.R. (unregistered)

    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 ?

  • Andrew (unregistered)

    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?

  • Tom (unregistered) in reply to faoileag

    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.

  • My name indeed (unregistered)

    I think I've got the gist of it:

    Marla was asked to take a look at....the project's VB code....THE ORIGINAL DEVELOPER DIDN'T THINK!

    management..."We're going to sit"

  • b0b (unregistered)

    The real WTF isn't the amateurish code, it's management's response. All too common, though.

  • vali1005 (unregistered)

    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.

  • (cs) in reply to QJo
    QJo:
    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?

    http://en.wikipedia.org/wiki/String_interning

  • (cs) in reply to Tom
    Tom:
    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.

    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.

  • (cs) in reply to JimmyCrackedCorn
    JimmyCrackedCorn:
    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.

    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.

  • (cs) in reply to caffiend
    caffiend:
    Tom:
    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.

    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.

    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.

  • (cs) in reply to HerrDerSchatten

    this

    HerrDerSchatten:
    #Honestly, if you are not using Option Strict on in Vb.NET you are the wtf. Building a bigger program without that option is like building on mud. Even if you are doing Office interop, you can use strict on, with the possible exception of late binding.

    Definitely mandatory.

  • (cs) in reply to eVil
    eVil:
    aragaer:
    I am starting to like stories where the fun part is a huge chunk of code in a language I don't know.

    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.

    It'd suck if there was a much more highly regarded language that was even looser with its types :cough: JavaScript :cough:

  • eVil (unregistered) in reply to caffiend
    caffiend:
    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.

    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.

  • (cs) in reply to eVil
    eVil:
    HerrDerSchatten:
    Honestly, if you are not using Option Strict on in Vb.NET you are the wtf. Building a bigger program without that option is like building on mud. Even if you are doing Office interop, you can use strict on, with the possible exception of late binding.

    TBH, using VB.NET when C# is available (e.g., always) is the real WTF, Option Strict or not.

    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.

  • (cs)

    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

  • (cs) in reply to chubertdev
    chubertdev:
    It'd suck if there was a much more highly regarded language that was even looser with its types :cough: JavaScript :cough:

    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.

Leave a comment on “A Careless Merge”

Log In or post as a guest

Replying to comment #:

« Return to Article