Why oh why did I get assigned this task.



  • So, I work for a major, huge, massive conglomerate telecomm, like, $30bn+ net profit last year big. I was hired 6 years ago as a C/C++ developer, since then, we've switched to being a .NET shop, we've spent the last 2 years updating and rewriting everything from whatever it was before to C#, and into a nice, company wide VCS.

    I am the most senior person on my team, our primary role is the development (and maintenance, obviously) of employee facing tools, whether they be portals to billing systems, or to equipment in customers homes, our workforce management, whatever. We're a big enough company apparently we always feel the need to roll our own, so that it suits our company perfectly. Generally, this is fantastic, and it allows me to work however I want on some pretty crazy things.

    Rewind to last Tuesday. I was tasked with converting a very large VB.NET project (that someone now on our team, who is mysteriously absent wrote some time ago), you see it's almost year end, and this is used to help a large portion of our budgeting process (and our budget process this year has been alotted 210,000 'man hours' solely for the budget, across the company, it's a big thing). Firstly, I hate VB as much as the next guy, while I don't think it's an entirely useless language, I'm not a fan of it. After seeing the size of the project, I made the simple request that we buy a commercial package for converting VB<->C# projects, and forget about it - however it's "not in the budget", and "shouldn't take me long"... There've been plenty of WTFs since then, but I feel the deeper I go ,the more insane I go, and the crazier the code (terrible, terrible code) gets. I don't think this guy is on vacation, I think he's in a mental hospital. Here's a small representation (note: this function is overloaded 7 more times, they all do the same thing, they just accept/return different types)

        Private Function theDate(ByVal tofixs As String) As String
            Dim response As String = ""
            If InStr(tofixs, "-") = 0 Then
                Dim TodayDate As Date = Date.Now
                Dim YesterdayDate As Date = DateAdd(DateInterval.Day, -1, TodayDate)
                Dim stringFiscalMonthStartDate As String = ""
                Dim stringFiscalMonthEndDate As String = ""
                Dim stringYesterdayDate As String = ""
                If Val(YesterdayDate.Day) >= 22 Then
                    Dim FiscalMonthStartDate As Date = YesterdayDate
                    Dim FiscalMonthEndDate As Date = DateAdd(DateInterval.Day, 12, YesterdayDate)
                    stringFiscalMonthStartDate = YesterdayDate.Year
                    If Len(YesterdayDate.Month.ToString) = 1 Then
                        stringFiscalMonthStartDate = stringFiscalMonthStartDate & "-0" & FiscalMonthStartDate.Month
                    Else
                        stringFiscalMonthStartDate = stringFiscalMonthStartDate & "-" & FiscalMonthStartDate.Month
                    End If
                    stringFiscalMonthStartDate = stringFiscalMonthStartDate & "-22"
                    stringFiscalMonthEndDate = FiscalMonthEndDate.Year
                    If Len(FiscalMonthEndDate.Month.ToString) = 1 Then
                        stringFiscalMonthEndDate = stringFiscalMonthEndDate & "-0" & FiscalMonthEndDate.Month
                    Else
                        stringFiscalMonthEndDate = stringFiscalMonthEndDate & "-" & FiscalMonthEndDate.Month
                    End If
                    stringFiscalMonthEndDate = stringFiscalMonthEndDate & "-21"
                Else
                    Dim FiscalMonthStartDate As Date = DateAdd(DateInterval.Month, -1, YesterdayDate)
                    Dim FiscalMonthEndDate As Date = YesterdayDate
                    stringFiscalMonthEndDate = FiscalMonthEndDate.Year
                    If Len(FiscalMonthEndDate.Month.ToString) = 1 Then
                        stringFiscalMonthEndDate = stringFiscalMonthEndDate & "-0" & FiscalMonthEndDate.Month
                    Else
                        stringFiscalMonthEndDate = stringFiscalMonthEndDate & "-" & FiscalMonthEndDate.Month
                    End If
                    stringFiscalMonthEndDate = stringFiscalMonthEndDate & "-21"
                    stringFiscalMonthStartDate = FiscalMonthStartDate.Year
                    If Len(FiscalMonthStartDate.Month.ToString) = 1 Then
                        stringFiscalMonthStartDate = stringFiscalMonthStartDate & "-0" & FiscalMonthStartDate.Month
                    Else
                        stringFiscalMonthStartDate = stringFiscalMonthStartDate & "-" & FiscalMonthStartDate.Month
                    End If
                    stringFiscalMonthStartDate = stringFiscalMonthStartDate & "-22"
                End If

                stringYesterdayDate = YesterdayDate.Year
                If Len(YesterdayDate.Month.ToString) = 1 Then
                    stringYesterdayDate = stringYesterdayDate & "-0" & YesterdayDate.Month
                Else
                    stringYesterdayDate = stringYesterdayDate & "-" & YesterdayDate.Month
                End If
                If Len(YesterdayDate.Day.ToString) = 1 Then
                    stringYesterdayDate = stringYesterdayDate & "-0" & YesterdayDate.Day
                Else
                    stringYesterdayDate = stringYesterdayDate & "-" & YesterdayDate.Day
                End If
                If tofixs = "fiscalmonthstart" Then response = stringFiscalMonthStartDate
                If tofixs = "fiscalmonthtodate" Then response = stringYesterdayDate
                If tofixs = "fiscalmonthend" Then response = stringFiscalMonthEndDate
            End If
            Return response
        End Function

     

     

    ..... sigh.



  • Wow, that's bad.
    Not as insane as some of the stuff you can see around here, though.

    But however you feel about this VB code, it's not as bad as titling a post "Why oh why did I get assigned this task."
    That title is applicable for almost every thread in this forum.

    You should really try and title forum posts with something meaningful.
    Here, let me help: "VB fiscal date conversion by an insane person"



  • Wait, why does it need to be converted in the first place?  It's still .Net junk so while doing whatever fixes would be annoying (due to language diffs) they wouldn't be bad.  I mean, yes it sounds like a mess but why it needs to be a mess in a different language I don't see.



  • For whatever reason the powers that be have decided everything has to be in the same language, regardless of them both being .NET. I have a feeling it's because the people who've been asked to do anything wiht it besides the guy who wrote it, have immediately come back with "Sorry I don't know VB.", I'm starting to think it's "Sorry no way." :(



  • @locallunatic said:

    Wait, why does it need to be converted in the first place?  It's still .Net junk so while doing whatever fixes would be annoying (due to language diffs) they wouldn't be bad.  I mean, yes it sounds like a mess but why it needs to be a mess in a different language I don't see.

    Exactly, any and all WTF's in the VB.Net codebase will be copied verbatim to the C# codebase..plus every converter introduces some "funnies" of its own.... Aside from the language bias, there is absolutely no value in the recommendation of automated conversion, so ImHO the OP is the TRWTF.



  •  Mmmm no, since they wouldn't pay for a converter (which I suggested before actually seeing it), I'll be doing it all by hand, and be damned if I'm copying it verbatim, it's probably why I got picked to do it in the firts place, I'll actually refactor it into not being done in the most inane way possible.



  • @TrailerParkJihad said:

     Mmmm no, since they wouldn't pay for a converter (which I suggested before actually seeing it), I'll be doing it all by hand, and be damned if I'm copying it verbatim, it's probably why I got picked to do it in the firts place, I'll actually refactor it into not being done in the most inane way possible.

    ... and in the process introduce 67 new defects because you didn't realize that the insane person's date conversion routine had a subtle side-effect that implemented a critical business rule that there is no way you could possibly know about. The only winning move is not to play -- leave it VB.Net. I maintain plenty of VB6 applications that I'm smart enough not to "fix".

    The more insane the original author, the more likely it is that you aren't going to be able to figure out what it really does.



  • @TrailerParkJihad said:

    I made the simple request that we buy a commercial package for converting VB<->C# projects, and forget about it - however it's "not in the budget", and "shouldn't take me long"

    Writing the convertor indeed shouldn't take you long. About half day or so plus half day finding out how to do it.

    See, C# and VB are two different syntaxes for the same language. They both parse to the same AST. Since .NET provides access to the compiler internals, converting between VB and C# is just a matter of finding appropriate parsers and generators in the System.CodeDom and System.CodeDom.Compiler namespaces and passing the code through them.



  •  http://netdecompiler.com/download.html

     7 Assemblies with the trial version.

     I haven't tried it, but I certainly would if I had to translate that code.



  • IIRC, Reflector (before the evil, evil RedGate bought it from Mr Roeder) would be able to RE any .Net assembly, as long as it wasn't obfuscated.  You can convert it to VB.Net, C#, Managed C++, whatever.  There was even a plugin for converting assemblies into a solution in your language of choice.  This path of course, would simply give you the same POS except in C# along with member and variable names like type1, type2, object1, int6, etc.

    I took the second option, junked the old code-base and did a complete rewrite based on the original requirements.  Fuck trying to figure out why in the hell he did something one way or another, or if he wrote it on purpose, or was it an bug in his code...  This will only lead to insanity.



  • I've never seen a VB.NET codebase that DIDN'T look this shitty.  Yet, there seems to be a sizable population of devs who continue to praise and defend the language.  WTF am I missing?



  • @Smitty said:

    I've never seen a VB.NET codebase that DIDN'T look this shitty.  Yet, there seems to be a sizable population of devs who continue to praise and defend the language.  WTF am I missing?
    I've got 100,000 lines of VB.Net that are mostly WTF-free, except for the parts that WiPro "fixed". Bad devs tend toward VB, so there is more bad VB.Net than bad C#, but there is plenty of good VB.Net in the world. However, I'm considering switching to C# just to discourage morons from applying for a job here.



  • @Smitty said:

    I've never seen a VB.NET codebase that DIDN'T look this shitty.  Yet, there seems to be a sizable population of devs who continue to praise and defend the language.  WTF am I missing?
    I recall once hearing that MS will eventually stop maintaining VB.Net, and eventually won't be part of the .Net framework...  Really, the only argument I've ever hear NOT to use C# is because "it's too hard", and with the new dynamic type in .Net 4, you REALLY don't need VB.Net anymore.

    I could be wrong of course, especially because I don't work with it very often.  Can anybody really argue in favor of VB.Net for a new .Net project (assuming .Net 4)?


  • ♿ (Parody)

    @C-Octothorpe said:

    Can anybody really argue in favor of VB.Net for a new .Net project (assuming .Net 4)?

    Of course they could. If they have a team experienced with VB.Net, but not C#, there's a lot of reason not to make the change. I can't comment on the other stuff, which sounds like FUD, but frankly, I don't know or care one way or the other.



  • @boomzilla said:

    @C-Octothorpe said:
    Can anybody really argue in favor of VB.Net for a new .Net project (assuming .Net 4)?
    Of course they could. If they have a team experienced with VB.Net, but not C#, there's a lot of reason not to make the change.
    That is a valid argument, however I find it odd that C# developers (that I personally know, and I've done it myself) can make the switch to VB.Net for a project fairly painlessly, however VB.Net devs have a much harder time going to C#... Why is that?

    @boomzilla said:

    I can't comment on the other stuff, which sounds like FUD
    What "other stuff" in my post are you referring to which is FUD?

    @boomzilla said:

    I don't know or care one way or the other.
    Me too.


  • ♿ (Parody)

    @C-Octothorpe said:

    @boomzilla said:
    I can't comment on the other stuff, which sounds like FUD

    What "other stuff" in my post are you referring to which is FUD?

    Sorry, should have quoted. This bit:

    @C-Octothorpe said:

    I recall once hearing that MS will eventually stop maintaining VB.Net, and eventually won't be part of the .Net framework...

    Whether it is or not, it's the sort of thing that looks like FUD directed at VB.Net.



  • @C-Octothorpe said:

    That is a valid argument, however I find it odd that C# developers (that I personally know, and I've done it myself) can make the switch to VB.Net for a project fairly painlessly, however VB.Net devs have a much harder time going to C#... Why is that?

    Good programmers can switch languages quickly without problems. Bad programmers cannot. It has nothing to do with what language you're switching to/from, it has to do with how well the programmer understands the concepts (as opposed to just the grammar.) The worst programmers pick an environment and not only stay entirely inside it, but actually try to bend everybody else to use it as well-- I knew a guy once who wanted me to put an XML string inside a URL because he literally could not think of a better way to solve the problem.

    I think if you studied this, you'll find your bad C# programmers would be unable to switch to VB.Net as well.



  • @blakeyrat said:

    @C-Octothorpe said:
    That is a valid argument, however I find it odd that C# developers (that I personally know, and I've done it myself) can make the switch to VB.Net for a project fairly painlessly, however VB.Net devs have a much harder time going to C#... Why is that?

    Good programmers can switch languages quickly without problems. Bad programmers cannot. It has nothing to do with what language you're switching to/from, it has to do with how well the programmer understands the concepts (as opposed to just the grammar.)

    I'm glad you made a point in the other thread about statements being practically correct vs. taking them literally, else I might be tempted to think you believe the above is literally true.


  • ♿ (Parody)

    @blakeyrat said:

    Good programmers can switch languages quickly without problems. Bad programmers cannot. It has nothing to do with what language you're switching to/from, it has to do with how well the programmer understands the concepts (as opposed to just the grammar.)

    I think there are some pretty big caveats to that. Or perhaps it's just a clarification to what you've called the concepts. Of course, switching between .Net languages reduces the learning curve on the framework itself. But the details of the languages can require significantly different paradigms. Like the old aphorism, "you can write FORTRAN in any language." Developers with broader experience in terms of varied languages, I think, would be expected to get up to speed more quickly than an expert in one language.

    Either way, if you don't consider this sort of thing when switching from one language to another is a mistake.

    @blakeyrat said:

    I think if you studied this, you'll find your bad C# programmers would be unable to switch to VB.Net as well.

    Perhaps. Though if they're shitty in C#, and then they're shitty in VB, you might judge that its easier to get them up to speed on the new language more quickly than it would take an expert to get near his competency level.



  • @boomzilla said:

    @blakeyrat said:
    Good programmers can switch languages quickly without problems. Bad programmers cannot. It has nothing to do with what language you're switching to/from, it has to do with how well the programmer understands the concepts (as opposed to just the grammar.)

    I think there are some pretty big caveats to that. Or perhaps it's just a clarification to what you've called the concepts. Of course, switching between .Net languages reduces the learning curve on the framework itself. But the details of the languages can require significantly different paradigms. Like the old aphorism, "you can write FORTRAN in any language." Developers with broader experience in terms of varied languages, I think, would be expected to get up to speed more quickly than an expert in one language.

    Either way, if you don't consider this sort of thing when switching from one language to another is a mistake.

    @blakeyrat said:

    I think if you studied this, you'll find your bad C# programmers would be unable to switch to VB.Net as well.

    Perhaps. Though if they're shitty in C#, and then they're shitty in VB, you might judge that its easier to get them up to speed on the new language more quickly than it would take an expert to get near his competency level.

    It is practically impossible to teach good programming to students that
    have had a prior exposure to Visual BASIC: As potential programmers they are
    mentally mutilated beyond hope of regeneration.



  • @DaveK said:

    It is practically impossible to teach good programming to students that have had a prior exposure to Visual BASIC: As potential programmers they are mentally mutilated beyond hope of regeneration.

    That's selection bias, not a problem with VB. People who aren't professional programmers typically back into business programming by way of Excel and Access, so they always learn VB first.

    Besides, it's practically impossible to teach programming, period. Very few people who don't show early promise become good programmers.



  • @Jaime said:

    @DaveK said:

    It is practically impossible to teach good programming to students that have had a prior exposure to Visual BASIC: As potential programmers they are mentally mutilated beyond hope of regeneration.

    That's selection bias, not a problem with VB. People who aren't professional programmers typically back into business programming by way of Excel and Access, so they always learn VB first.

    Yes, but nobody is a professional programmer before they learn their first programming language.  People don't go into business programming and learn VB rather than go to college and learn C because they somehow knew they were predestined never to be professional programmers; it is because they go into business programming and learn VB that they never become professional programmers.

    Also, I wasn't being entirely serious.  It's a mangled quotation from an old Dijkstra article.


  • A little refactoring before conversion makes it a lot clearer:

    <font size="2" face="Consolas"><font size="2" face="Consolas">

      Private Function AppendDashDoubleDigit(ByRef base As String, ByVal toappend As Integer) As String
            Dim response As String = ""
            If Len(toappend.ToString) = 1 Then
                response = base & "-0" & toappend
            Else
                response = base & "-" & toappend
            End If
            Return response
        End Function

        Private Function theDate(ByVal tofixs As String) As String
            'Find the date for the beginning or end of the current Fiscal month.
            Dim response As String = ""
            If InStr(tofixs, "-") = 0 Then
                Dim TodayDate As Date = Date.Now
                Dim YesterdayDate As Date = DateAdd(DateInterval.Day, -1, TodayDate)
                Dim stringFiscalMonthStartDate As String = ""
                Dim stringFiscalMonthEndDate As String = ""
                Dim stringYesterdayDate As String = ""
                If Val(YesterdayDate.Day) >= 22 Then
                    'if today is after the 22nd, the current fiscal month ends in the next calander month.

                    Dim FiscalMonthStartDate As Date = YesterdayDate
                    Dim FiscalMonthEndDate As Date = DateAdd(DateInterval.Day, 12, YesterdayDate) ' push the date into next month

                    stringFiscalMonthStartDate = YesterdayDate.Year
                    AppendDashDoubleDigit(stringFiscalMonthStartDate, FiscalMonthStartDate.Month)
                    stringFiscalMonthStartDate = stringFiscalMonthStartDate & "-22"

                    stringFiscalMonthEndDate = FiscalMonthEndDate.Year
                    AppendDashDoubleDigit(stringFiscalMonthEndDate, FiscalMonthEndDate.Month)
                    stringFiscalMonthEndDate = stringFiscalMonthEndDate & "-21"


                Else
                    'If the current day is before or on the 22nd, the current fiscal month began the prior calander month.

                    Dim FiscalMonthStartDate As Date = DateAdd(DateInterval.Month, -1, YesterdayDate) ' find the prior month
                    Dim FiscalMonthEndDate As Date = YesterdayDate

                    'Determine start date
                    stringFiscalMonthStartDate = FiscalMonthStartDate.Year
                    AppendDashDoubleDigit(stringFiscalMonthStartDate, FiscalMonthStartDate.Month)
                    stringFiscalMonthStartDate = stringFiscalMonthStartDate & "-22"

                    'Determine end date
                    stringFiscalMonthEndDate = FiscalMonthEndDate.Year
                    AppendDashDoubleDigit(stringFiscalMonthEndDate, FiscalMonthEndDate.Month)
                    stringFiscalMonthEndDate = stringFiscalMonthEndDate & "-21"
                End If

                stringYesterdayDate = YesterdayDate.Year
                AppendDashDoubleDigit(stringYesterdayDate, YesterdayDate.Month)
                AppendDashDoubleDigit(stringYesterdayDate, YesterdayDate.Day)

                If tofixs = "fiscalmonthstart" Then response = stringFiscalMonthStartDate
                If tofixs = "fiscalmonthtodate" Then response = stringYesterdayDate
                If tofixs = "fiscalmonthend" Then response = stringFiscalMonthEndDate
            End If
            Return response
        End Function

    </font></font><font color="#0000ff" size="2" face="Consolas"><font color="#0000ff" size="2" face="Consolas"><font color="#0000ff" size="2" face="Consolas"></font></font></font>

Log in to reply