Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Coding Horror

1121315171837

Comments

  • Registered Users Posts: 13,080 ✭✭✭✭Maximus Alexander


    Dacelonid wrote: »
    @Test
    public void testSomething(){
        final String returnValue = "";
        setupMock();
        DBConnectionManager objUnderTest = new DBConnectionManager();
        objUnderTest.doMethod();
     
        assertNotNull(returnValue);
     
    }
    

    There was a bit more code that that in the test, but that was a general structure. I tried to explain the management and the offshore teams, that this wasn't actually testing anything, they didn't really get it.

    Maybe what they were trying to test is whether or not a blank string is null? :pac:


  • Registered Users Posts: 26,985 ✭✭✭✭GreeBo


    Maybe what they were trying to test is whether or not a blank string is null? :pac:

    Is still not null...who knows what memory register madness those other classes are up to!


  • Closed Accounts Posts: 9,046 ✭✭✭Berserker


    GreeBo wrote: »
    I had someone tell me that they could delete a bunch of failing unit tests as "no one would notice and I'm sure no one knows what they do anyway"

    I've had that before. First thing in the morning someone notices that the tests have failed. Someone goes, "comment the failing tests out, so the tests all pass and all looks ok".


  • Registered Users Posts: 197 ✭✭Eogclouder


    Berserker wrote: »
    I've had that before. First thing in the morning someone notices that the tests have failed. Someone goes, "comment the failing tests out, so the tests all pass and all looks ok".

    How is it working in hell? :D


  • Closed Accounts Posts: 2,113 ✭✭✭SilverScreen


    Dacelonid wrote: »
    Just on the topic of tests, last year I had to do an analysis of the unit tests on a ~4 year old project that was currently mostly being developed by an offshore team

    Apart from using @Ignore to turn off tests that were failing, or deleting asserts so that they wouldn't fail, or tests in the wrong class, or tests named for something stupid rather than what it was testing, the one that really stuck in my mind was something along these lines (method names are made up)
    @Test
    public void testSomething(){
        final String returnValue = "";
        setupMock();
        DBConnectionManager objUnderTest = new DBConnectionManager();
        objUnderTest.doMethod();
        
        assertNotNull(returnValue);
    
    }
    

    There was a bit more code that that in the test, but that was a general structure. I tried to explain the management and the offshore teams, that this wasn't actually testing anything, they didn't really get it.
    I'm assuming that doMethod() is meant to return a String and that's what was meant to be tested.

    Otherwise it makes no sense at all :D


  • Advertisement
  • Registered Users Posts: 586 ✭✭✭Aswerty


    I'm assuming that doMethod() is meant to return a String and that's what was meant to be tested.

    Otherwise it makes no sense at all :D

    But returnValue is final when assigned to an empty string!! :pac: WTF?


  • Closed Accounts Posts: 2,113 ✭✭✭SilverScreen


    Aswerty wrote: »
    But returnValue is final when assigned to an empty string!! :pac: WTF?
    Yeah that's another thing. They were more than likely using a static analysis tool like PMD.

    My assumption is to remove line 3 and change line 6 to String returnValue = objUnderTest.doMethod();
    That's if doMethod() actually returns something...


  • Registered Users Posts: 11,262 ✭✭✭✭jester77


    GreeBo wrote: »
    I had someone tell me that they could delete a bunch of failing unit tests as "no one would notice and I'm sure no one knows what they do anyway"

    Should I mention that we are on a drive to improve test coverage?
    And that this person is on that team?

    hah, I came across that recently in a project. There was an initiative to get the builds green. Some took this to mean removing the failing tests :eek:


  • Registered Users Posts: 26,985 ✭✭✭✭GreeBo


    jester77 wrote: »
    hah, I came across that recently in a project. There was an initiative to get the builds green. Some took this to mean removing the failing tests :eek:

    The scarier bit for me was the idea that since the tests were old and that whoever had written them no longer worked at the company, they could be removed as no one would care.
    Did I mention that they passed on a local box but not a jenkins box...lets not find out why, just zap them, "no one uses them".
    How you use a unit test is beyond me, its just there, quietly doing its thing until you do need it.


  • Registered Users Posts: 1,112 ✭✭✭Dacelonid


    I'm assuming that doMethod() is meant to return a String and that's what was meant to be tested.

    Otherwise it makes no sense at all :D
    Aswerty wrote: »
    But returnValue is final when assigned to an empty string!! :pac: WTF?
    Yeah that's another thing. They were more than likely using a static analysis tool like PMD.

    My assumption is to remove line 3 and change line 6 to String returnValue = objUnderTest.doMethod();
    That's if doMethod() actually returns something...

    Just to be clear, doSomething doesn't return anything.
    My guess is that at some point in the past it did. Then they changed the method to not return anything and instead of verifying that the test was actually testing something, they just removed the assignment in the test, ran it again and it passed, so they checked that in


  • Advertisement
  • Closed Accounts Posts: 11 id rather brie


    Came across a ridiculously pointless piece of code recently, the dude who wrote it before me must have been awake for 3, or more days. There was a piece a piece of ASP code that was writing a number into a javascript section, like so:
        var width = <%= Session["ScreenWidth"].ToString() %> - 970 - 1;
    

    I mean if you're going to hardcode all of this poop in...why is this the method you choose...*shakes head*


  • Registered Users Posts: 197 ✭✭Eogclouder


    Hi All,

    Sorry to butt in on the conversation. I am urgently looking for a tutor in HTML and CSS. I don't suppose any of you are in Cork city and willing to provide some evening/ weekend grinds?

    Thank you!

    This is off topic and not relevant to this thread.


  • Registered Users Posts: 14,148 ✭✭✭✭Lemming


    Two in one day ....

    There was the method that's 5000+ lines long this morning.

    And now .... try/catch blocks being used to govern program flow.

    /me heads desk.


  • Closed Accounts Posts: 9,046 ✭✭✭Berserker


    Lemming wrote: »
    And now .... try/catch blocks being used to govern program flow.

    That's a new one on me, I have to admit. What sort of mind came up with that.


  • Registered Users Posts: 7,500 ✭✭✭BrokenArrows


    Lemming wrote: »
    Two in one day ....

    There was the method that's 5000+ lines long this morning.

    And now .... try/catch blocks being used to govern program flow.

    /me heads desk.


    Can you post an example of how he was using the try catch blocks. I can't image how that would work unless he was purposely causing exceptions.


  • Registered Users Posts: 14,148 ✭✭✭✭Lemming


    Can you post an example of how he was using the try catch blocks. I can't image how that would work unless he was purposely causing exceptions.
    double blah;
    try
    {
    	blah = Convert.ToDouble(randomStringValue);
    }
    catch
    {
    	blah = -1;
    }
    

    Ever heard of .TryParse() matey? .... :-/

    The same try/catch is reproduced elsewhere where it does the same with Nullable<T> objects. No basic checks to see if the object has been instantiated and god forbid there be any checking the Nullable<T>.HasValue property ... The original author was just assigning directly and re-assigning of an exception was thrown.

    One of the above examples on its own would be enough for a "f*cks sake" moment followed by refactoring; but this is the pattern used quite extensively throughout this particular class. In particular in that 5000+ line Frankenstein travesty of a method I mentioned earlier. Jesus wept.


    Edit: the above sample can be found inside and out of method calls, and the string values may or may not be populated based on other factors, so it's not a simple case of "this variable REALLY should contain a value when hitting this particular path/line of code".


  • Registered Users Posts: 2,012 ✭✭✭Colonel Panic


    That reeks of someone who comes from a procedural background.

    There are some times though when the .Net framework throws exceptions for stupid reasons. HttpWebRequest for example. Why throw an exception for 404s?


  • Closed Accounts Posts: 9,046 ✭✭✭Berserker


    That reeks of someone who comes from a procedural background.

    There are some times though when the .Net framework throws exceptions for stupid reasons. HttpWebRequest for example. Why throw an exception for 404s?

    What you would prefer it to do?


  • Registered Users Posts: 14,148 ✭✭✭✭Lemming


    That reeks of someone who comes from a procedural background.

    I disagree. It reeks of someone who doesn't remember one of the first things you're told about try/catch blocks in uni; they are NOT execution control mechanisms. I remember that from being introduced to try/catch blocks in C back in the day in my second year of third level education. That's about fifteen years ago ...


  • Registered Users Posts: 2,012 ✭✭✭Colonel Panic


    Berserker wrote: »
    What you would prefer it to do?

    Make a request, get a response, test the response code, do what you've got to do.
    Lemming wrote: »
    I disagree. It reeks of someone who doesn't remember one of the first things you're told about try/catch blocks in uni; they are NOT execution control mechanisms. I remember that from being introduced to try/catch blocks in C back in the day in my second year of third level education. That's about fifteen years ago ...

    try/catch blocks in C? As in SEH? That's quite a specific and not that useful thing to teach in 2nd year of 3rd level education.


  • Advertisement
  • Registered Users Posts: 14,148 ✭✭✭✭Lemming


    try/catch blocks in C? As in SEH? That's quite a specific and not that useful thing to teach in 2nd year of 3rd level education.

    Sorry you're right; it was C++ (and my third year - did C in second - same lecturer for both so it's all blurred together now) but the point still stands.


  • Registered Users Posts: 1,459 ✭✭✭Anesthetize


    Came across something like this during the week:

    if (.....) {
    <some statement>;
    } else
    <some statement>;
    <some statement>;

    It really annoys me when people don't use brackets with if-else statements in Java. Just because you can doesn't mean you should.


  • Registered Users Posts: 306 ✭✭yes there


    Came across something like this during the week:

    if (.....) {
    <some statement>;
    } else
    <some statement>;
    <some statement>;

    It really annoys me when people don't use brackets with if-else statements in Java. Just because you can doesn't mean you should.

    Surely that is down to organisation conventions is it not. That's a personal gripe not a coding horror.


  • Registered Users Posts: 5,246 ✭✭✭conor.hogan.2


    yes there wrote: »
    Surely that is down to organisation conventions is it not. That's a personal gripe not a coding horror.

    Yes, except that there is braces on the if so it is inconsistent.


  • Technology & Internet Moderators Posts: 28,789 Mod ✭✭✭✭oscarBravo


    What makes it a true horror is what was lost by not using code tags on the original post:
    if (.....) {
        <some statement>;
    } else 
        <some statement>;
        <some statement>;
    

    Now that's pure evil.


  • Registered Users Posts: 1,459 ✭✭✭Anesthetize


    oscarBravo wrote: »
    What makes it a true horror is what was lost by not using code tags on the original post:
    if (.....) {
        <some statement>;
    } else 
        <some statement>;
        <some statement>;
    

    Now that's pure evil.
    Yes that's what I meant.


  • Closed Accounts Posts: 2,117 ✭✭✭Defiler Of The Coffin


    yes there wrote: »
    Surely that is down to organisation conventions is it not. That's a personal gripe not a coding horror.

    It's bad practice if it looks deceiving. Especially if the indentation isn't correct.


  • Registered Users Posts: 13,080 ✭✭✭✭Maximus Alexander


    Came across something like this during the week:

    if (.....) {
    <some statement>;
    } else
    <some statement>;
    <some statement>;

    It really annoys me when people don't use brackets with if-else statements in Java. Just because you can doesn't mean you should.

    You'd hate me then, because I'd probably have written:
    if (.....) <some statement>;
    else <some statement>;
    
    <some statement>;
    


  • Technology & Internet Moderators Posts: 28,789 Mod ✭✭✭✭oscarBravo


    (It's at times like this I'm really glad I'm a Python guy...)


  • Advertisement
  • Registered Users Posts: 7,515 ✭✭✭matrim


    oscarBravo wrote: »
    (It's at times like this I'm really glad I'm a Python guy...)

    And then someone mixes up tabs and spaces ;)


Advertisement