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.


  • 🚽 Regular

    @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?


  • Discourse touched me in a no-no place

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



  • @Joel B said:

    Maybe I'm just old-school(ish), but I quite like working with WinForms in .Net. Why is WPF so much greater?
    You can skin WPF and do hardware-accelerated 3D.  This comes in handy, since flashy UI can often be converted into political capital.  It's also closer to Silverlight, which lets you deploy in both thin and thick-clients. 

    Also, sometimes you don't have a choice; sometimes, you actually have to sell your software.  If you're in an IT department like me, your company's clients are in a position to consume some of your software, which where I work means it must pass a minimum sexiness test.



  •  Hardware accelerated 3d is a useful thing for the UI of a typical desktop app?



  • @upsidedowncreature said:

    I'm a noob at WPF, it's got a very shallow learning curve (why do people say steep learning curve?)

    At first glance WPF might not seem that much different from WinForms, you can drag and drop some controls and then write event handlers and it will work. But when you start digging deeper and want to use WPF like it was supposed to, it quickly becomes a completely different beast. It helps to have knowledge of other fields like XAML is easier to understand if you know HTML+CSS, layouts are easier if you have ever done UIs in Java and so on. But it gets even more complicated than that, you soon find out you have to make all of your data objects DependencyObjects that use DependencyProperties, collections turn into ObservableCollections, event handlers turn into commands (Swing also has something like this).

    If you do it right your program will be very uncoupled, UIs would have almost no code, all data is displayed with bindings and converters. Then when you start using background worker threads you find out you need to do all your data access through a Dispatcher object.

    Another similarity to Java and HTML is that by default the controls look like crap. You have to make an effort to design an attractive UI. You actually kind of need to have a good UI designer to make it look good. This is also why the code can be separated from the UI to such an extent, the designer can create a fancy UI and hand the XAML file to the programmer who hooks it up to the code.

    And if you're talking about design, there is almost no limit to what you can do (why yes, you can restyle your scrollbars!), Microsoft themselves have admitted that the days of consistent UI design are over, every application should look different, just like every website has a unique look. You can see this philosophy in Microsoft's own applications already. Whether that's a good thing or bad thing depends on your viewpoint.

    I will also admit that I'm no WPF wizard here, I have only done a couple of small apps in WPF with the help of this book, but I will say this: WPF is very complex and it will take some time to fully master it, but when you do, it's worth it.



  • @SlyEcho said:

    ...snip...

    WPF is very complex and it will take some time to fully master it, but when you do, it's worth it.

    Agree with all you said - I didn't express myself clearly.  I meant the learning curve is shallow in that volume of stuff learned (y axis) increases slowly compared to time spent learning said stuff (x axis).  Or maybe it's just that there's so much new stuff to learn.



  • @DescentJS said:

    Hardware accelerated 3d is a useful thing for the UI of a typical desktop app?
    Weren't you listening?@hoodaticus said:
    Also, sometimes you don't have a choice; sometimes, you actually have to sell your software.  If you're in an IT department like me, your company's clients are in a position to consume some of your software, which where I work means it must pass a minimum sexiness test.



  • @SlyEcho said:

    Another similarity to Java and HTML is that by default the controls look like crap. You have to make an effort to design an attractive UI. You actually kind of need to have a good UI designer to make it look good. This is also why the code can be separated from the UI to such an extent, the designer can create a fancy UI and hand the XAML file to the programmer who hooks it up to the code.

    And if you're talking about design, there is almost no limit to what you can do (why yes, you can restyle your scrollbars!), Microsoft themselves have admitted that the days of consistent UI design are over, every application should look different, just like every website has a unique look. You can see this philosophy in Microsoft's own applications already. Whether that's a good thing or bad thing depends on your viewpoint.

    Although I suppose it was a foregone conclusion in this day and age... sigh.



  • @upsidedowncreature said:

    Agree with all you said - I didn't express myself clearly.  I meant the learning curve is shallow in that volume of stuff learned (y axis) increases slowly compared to time spent learning said stuff (x axis).  Or maybe it's just that there's so much new stuff to learn.

    I think the learning curve is more like:

    x axis = stuff you can do

    y axis = how much time you have to spend learning.

    So if something has a steep learning curve, you have to learn a lot of stuff before you can do much.

     

    At least that's how I've always understood it.



  • @Sutherlands said:

    @upsidedowncreature said:

    Agree with all you said - I didn't express myself clearly.  I meant the learning curve is shallow in that volume of stuff learned (y axis) increases slowly compared to time spent learning said stuff (x axis).  Or maybe it's just that there's so much new stuff to learn.

    I think the learning curve is more like:

    x axis = stuff you can do

    y axis = how much time you have to spend learning.

    So if something has a steep learning curve, you have to learn a lot of stuff before you can do much.

     

    At least that's how I've always understood it.

    I always think of it as about pain, more than time:

    x axis=stuff you can do

    y axis=amount of pain required to learn how to do it

    So if a language has a steep learning curve, every step beyond "Hello world!" involves much thumbing thru the manual, grumbling, and swearing.

     



  • When the term "learning curve" was introduced, it was used in [b]upsidedowncreature[/b]'s sense: amount of stuff learned as a function of time or effort, so a steep learning curve meant you learned a lot quickly and was a good thing. However, over time it became more often used to describe the difficulty rather than the ease of learning (steep slopes are hard to climb in reality - I think this is probably why the usage changed) so that a steep learning curve now usually means it takes a lot of effort to learn the task. But both meanings are still in use, which makes for all sorts of fun.



  • @Scarlet Manuka said:

    When the term "learning curve" was introduced, it was used in upsidedowncreature's sense: amount of stuff learned as a function of time or effort, so a steep learning curve meant you learned a lot quickly and was a good thing. However, over time it became more often used to describe the difficulty rather than the ease of learning (steep slopes are hard to climb in reality - I think this is probably why the usage changed) so that a steep learning curve now usually means it takes a lot of effort to learn the task. But both meanings are still in use, which makes for all sorts of fun.

    I'm sure all of the user's(*) of the phrase could(*) care less about the actual words they speak.  Most people seem to be happy that they were at least able to make the other person figure out what they meant.  Maybe it's an attempt to stop outsourcing, kind of like "I dare you to figure out English now that every phrase requires 20 years of insider information to figure out".

     * improper usage intended



  • Then of course there are some of the Linux kernel-developer learning curves where you need a tall stepladder to even reach the bottom of the curve.

     

     



  • @DOA said:

    AND Payment.Amount = 25

    Ah, now I know where my Gas Co. got that idea.

    When I pay my gas bill, I have to pay the exact amount, down to the last cent. That's because they have no fricking reference system for bank payments, so their only method is basically "deposit money to X account". The only thing they can control is the payment amount, so that's what they use. Sheesh.


Log in to reply