Some people are lucky I'm not a sociopath



  • Lately I've been stuck maintaining a C# / .NET application written by an ex-coworker of mine known for his quality code. It's a winforms app used by a private educational institution to keep track of their students, courses, tuition fees etc. There is a lot of fail in the code which I'll be going over over the next few weeks/months, but for now I can share the following little nugget of brilliance with you.

    Students at this institution can take courses whenever they want; they can take a semester, go away for a year and then come back for more when they feel like it. They pay on a per session basis. However, the very first time a student takes part, he/she must pay a one-off registration fee of 25 euros.

    So how does this guy find the names of students that registered for the first time within a certain time period? Simple, he has hardcoded the following in the relevant SQL query (buried deep in a VS2008-created TableAdapter):

    AND Payment.Amount = 25



  • Nice! I can't even begin to count all the ways that can go wrong....



  • It gives a new meaning to the term "implementation specific"

    I don't want to be you (or the person that will be maintaining the application at this moment) when they change the registration fee



  • Or when they have any other payments that are exactly 25 bucks.



  • @ltouroumov said:

    I don't want to be you (or the person that
    will be maintaining the application at this moment) when they change the
    registration fee
     

    OR Payment.Amount = [new amount]

    You just have to cross your fingers that the new amount doesn't coincide with an amount for another unrelated fee.



  • Holy sh-poop. If that's the type of "logic" used throughout the app...... that just gave me heart palpitations.

    <personal rant>


    It also makes me feel better with the app I'm maintaining at the moment (well a coworker and I are maintaining). We work in the same office and every 10 minutes or so we have another, "OMG check this one out.. WTF was ___ thinking... that will fail under these conditions"

    I haven't found something as bad as your example yet though. They are usually a lot more subtle where you can maybe excuse the oversight by imagining him rushed to get feature X. That excuse worked until we found out he worked at another local company at which my coworker used to work at and his brother still works at. A couple emails later and it was verified that he left an abundance of WTF in his wake there as well.

    Of course most of ___'s WTFery would have been caught with simple high level code reviews/walkthroughs:

    PersonWithAClue (pwac): "So step me through what this code does"

    ___: "Well it shuts down the following threads, unpacks the update then if that works it starts the update proc and shutsdown the app."

    pwac: "What happens if unpacking fails."

    ___: "..... OHhhhhhhhhh...... ooops"

    Problem is his most of his code works if edge conditions are avoided, so no one ever bothered looking at his code. Also nothing is tested. Sure TDD isn't for everyone, but this is an embedded app where you want updates to be infrequent and super stable (you want to be releasing new features not bug fixes). No biggie though.. just write tests after the fact, right? No can do. The application is so coupled it is nearly impossible to add testing where it would actually add value. No design was ever done, it was just code code code until it "works". Well guess what? It doesn't work and it's brittle. Bug fixes cause breaks in unrelated parts of the system and new features are higher risk than the value they add (of course management pushes for them regardless, which then destabilizes the system further).

    Luckily a rewrite is in progress..

    </personal rant>

    Oh man that was cathartic.



  • @dubbreak said:

    Luckily a rewrite is in progress..
    For the next 10 years.



  • @RHuckster said:

    @ltouroumov said:

    I don't want to be you (or the person that
    will be maintaining the application at this moment) when they change the
    registration fee
     

    OR Payment.Amount = [new amount]

    You just have to cross your fingers that the new amount doesn't coincide with an amount for another unrelated fee.

     

    You don't even need that. What about students who, in addition to the registration fee, also bought themselves a snickers for $0.99 at the institution's kiosk? They have now a payment amount of $25.99 ...



  • @Daid said:

    @dubbreak said:
    Luckily a rewrite is in progress..
    For the next 10 years.

    We just need you to implement "this one last feature" before focussing on the rewrite.. we swear...



  • @dubbreak said:

    We just need you to implement "this one last feature" before focussing on the rewrite.. we swear...

    Cruel but oh so true.



  •  Are you allowed to use "quality code" and "winforms app" in the same sentence?  Or maybe you were being sarcastic?



  • @El_Heffe said:

    Are you allowed to use "quality code" and "winforms app" in the same sentence?
    Only with negation. Or when asking that question.



  • @El_Heffe said:

    Are you allowed to use "quality code" and "winforms app" in the same sentence?
    I'm a noob at .NET. What are you supposed to use instead and why?



  • @DOA said:

    @El_Heffe said:

    Are you allowed to use "quality code" and "winforms app" in the same sentence?
    I'm a noob at .NET. What are you supposed to use instead and why?

     

    Dunno. I just write some code in whatever portion of existing sites I'm editing.

    I'm a noob too. 🙂



  • @DOA said:

    I'm a noob at .NET. What are you supposed to use instead and why?

    Windows Presentation Foundation?  I'm a noob at WPF, it's got a very shallow learning curve (why do people say steep learning curve?) but there's a lot to like - layout, databinding, data templates etc etc.



  • @upsidedowncreature said:

    @DOA said:

    I'm a noob at .NET. What are you supposed to use instead and why?

    Windows Presentation Foundation?  I'm a noob at WPF, it's got a very shallow learning curve (why do people say steep learning curve?) but there's a lot to like - layout, databinding, data templates etc etc.

    And it came out, what, one year ago?

    So just FYI, the millisecond WPF came out, you should have dropped all Winforms projects like hot potatos and started over.



  • @blakeyrat said:

    And it came out, what, one year ago?

    So just FYI, the millisecond WPF came out, you should have dropped all Winforms projects like hot potatos and started over.

    Hasn't it been out since about 2006?  I didn't say it was new, just that I'm fairly new to it.  And I didn't suggest dropping all Winforms code and starting over - this would obviously be impractical (is this sarcasm detector working?)

    DOA asked about alternatives to Winforms and for desktop .Net apps WPF would appear to be it.



  • 1) Inherit Bad Code

    2) Convince administrators to change registration fee to $9,999,999,999,999.99 in order to 'fix' code.

    3) Profit!



  • Maybe I'm just old-school(ish), but I quite like working with WinForms in .Net.

    Why is WPF so much greater?



  • @DOA said:

    So how does this guy find the names of students that registered for the first time within a certain time period? Simple, he has hardcoded the following in the relevant SQL query (buried deep in a VS2008-created TableAdapter):
    AND Payment.Amount = 25
    Oh holy shit that pisses me off.  This is what I call a "horrible hack".

    Since my shop is making a transition to .NET, I have made a rule: no horrible hacks in .NET.  The legacy code base contains nothing but this shit, and reverse-engineering the business requirements from something like that - when your eyes are bleeding and your lips are swearing - years later - is nigh-impossible.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.