Globalization



  • They finally fired the guy who did this...

      public class HandlerOfXxx() {

    public static void doTask1(SomeObject data) throws Exception {
    task1_startDate = data.getStartDate();
    task1_endDate = data.getEndDate();
    task1_startMS = task1_startDate==null ? 0 : task1_startDate.getTime();
    task1_endMS = task1_endDate ==null ? 0 : task1_endDate.getTime();
    task1_deltaMS = task1_endMS - task1_startMS;
    // use it
    }

    public static void doTask2(SomeObject data) throws Exception {
    task2_startDate = data.getStartDate();
    task2_endDate = data.getEndDate();
    task2_startMS = task2_startDate==null ? 0 : task2_startDate.getTime();
    task2_endMS = task2_endDate ==null ? 0 : task2_endDate.getTime();
    task2_deltaMS = task2_endMS - task2_startMS;
    // use it
    }

    public static void doTask3(SomeObject data) throws Exception {
    // duplicated, but with: task3_xxx variables
    }

    // ...

    public static void doTask71(SomeObject data) throws Exception {
    // duplicated, but with: task71_xxx variables
    }

    private static Date task1_startDate;
    private static Date task1_endDate;
    private static long task1_startMS;
    private static long task1_endMS;
    private static long task1_deltaMS;

    private static Date task2_startDate;
    private static Date task2_endDate;
    private static long task2_startMS;
    private static long task2_endMS;
    private static long task2_deltaMS;

    private static Date task3_startDate;
    private static Date task3_endDate;
    private static long task3_startMS;
    private static long task3_endMS;
    private static long task3_deltaMS;

    // ...
    private static Date task71_startDate;
    private static Date task71_endDate;
    private static long task71_startMS;
    private static long task71_endMS;
    private static long task71_deltaMS;
    }
    }

     

    And no, the static globals were not used anyplace except in the matching individual methods.


  • Winner of the 2016 Presidential Election

    Was he paid by SLOC?



  • @joe.edwards said:

    Was he paid by SLOC?
    Nope - hourly consultant. I've been cleaning up his code for 2 years, but now that he's gone, I'm beginning to make headway against the onslaught...

     



  • @snoofle said:

    Nope - hourly consultant.
    If you have to write that many lines, it's almost like being paid per LOC...

     


  • Discourse touched me in a no-no place

    71 methods? 355 variables? Is there another method somewhere that calls all those methods in sequence?


  • Winner of the 2016 Presidential Election

    Way back in college, our C++ classwork had us writing parallel arrays. Even as green as I was, I knew it was WTFy.

    Instead of (p-code):

    class Task {
        Date startDate;
        Date endDate;
        long startMS;
        long endMS;
        long deltaMS;
    };
    // ...
    Task[]] tasks;
    

    They wanted us to write:

    Date[]] startDate;
    Date[]] endDate;
    long[]] startMS;
    long[]] endMS;
    long[]] deltaMS;
    

    The OP code somehow manages to be even worse.

    I think the course material is more harmful though because it's teaching the next generation of coders "this is how you should write code."



  • @joe.edwards said:

    Way back in college, our C++ classwork had us writing parallel arrays. Even as green as I was, I knew it was WTFy.
    It's not really bad, it's just the FORTRAN way. It gets a bit messy since you've got to make so many things global.

     


  • Discourse touched me in a no-no place

    @joe.edwards said:

    Way back in college, our C++ classwork had us writing parallel arrays. Even as green as I was, I knew it was WTFy.
    You're not going to like this, but sometimes that's actually the right thing to do. It's like storing the data by the column instead of by the row, and in some cases it can make a huge difference to the amount of overhead in the application.



  • @joe.edwards said:

    I think the course material is more harmful though because it's teaching the next generation of coders "this is how you should write code."
    Indeed. It propagates bad coding habits.



  • @snoofle said:

    @joe.edwards said:

    Was he paid by SLOC?
    Nope - hourly consultant.

     

    Well that explains it. Doing it right would be too fast!

     



  • @dkf said:

    @joe.edwards said:
    Way back in college, our C++ classwork had us writing parallel arrays. Even as green as I was, I knew it was WTFy.
    You're not going to like this, but sometimes that's actually the right thing to do. It's like storing the data by the column instead of by the row, and in some cases it can make a huge difference to the amount of overhead in the application.

    Exactly... the parallel arrays approach might not be pretty, or tidy, or particularly maintainable. BUT depending on the kind of operations you're attempting to do, you might find you get considerably better cache performance from it than the object oriented approach.

    Since this is managed code though, performance clearly isn't something you're interested in, so it is pretty bad.



  • @eViLegion said:

    @dkf said:
    @joe.edwards said:
    Way back in college, our C++ classwork had us writing parallel arrays. Even as green as I was, I knew it was WTFy.
    You're not going to like this, but sometimes that's actually the right thing to do. It's like storing the data by the column instead of by the row, and in some cases it can make a huge difference to the amount of overhead in the application.

    Exactly... the parallel arrays approach might not be pretty, or tidy, or particularly maintainable. BUT depending on the kind of operations you're attempting to do, you might find you get considerably better cache performance from it than the object oriented approach.

    Since this is managed code though, performance clearly isn't something you're interested in, so it is pretty bad.

     

    One can even (With some care) create implementations that actually are backed by the parallel arrays, yet expose a programmatic view that looks like fields within objects...quite common in certain mathematical libraries...


Log in to reply
 

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