• Perly (unregistered)

    First.getProcessor

  • Prime Mover (unregistered)

    I had a colleague who was screaming and shouting at me because he didn't like the fact that the language he was using behaved exactly as this post describes. I tried to explain about references.getProcessor but I'm still sure he never got it.

    A few weeks later, when a manna-jar asked for input into questions for interview candidates, I sent him my colleagues faulty code to offer up to the candidate as a "What's wrong with this?" sort of question.

    That suggestion was unfortunately not taken up, I believe because the manna-jar himself did not understand the code or the thinking behind it.

  • (nodebb)

    Eight lines of code and I count six red flags.

    • There are two instances of comparing strings in Java using == or !=.

    • There's a collection with 1-based indexing (not an issue with this code fragment but with the design of the collection).

    • There are two lines that assign a return value to a local variable that is immediately discarded/overwritten and not stored back to the collection.

    • There is inconsistent naming between the two convertTo methods (not an issue with this fragment but with the definition of an image processor).

  • martijntje (unregistered) in reply to Perly

    You misspelled "Frist" there.

  • (nodebb)

    I'm trying to figure out what the hidden meaning behind the extra "getProcessor" in the story is.

  • Barry Margolin (github)

    Python mostly avoids the problem of not knowing whether a method returns something new or modifies in place. Operations that work in place conventionally don't return anything, while operations that return a new object don't mutate it, so trying to use it the wrong way just fails. So we have list.sort() that works in place and returns None, and sorted() that returns a new list (and also accepts any iterable as the argument).

    Beginners may take a little while to learn what's what (Stack Overflow is full of questions about why list = list.append(thing) sets list to None), but pretty soon it becomes second nature.

  • Hameem (unregistered)
    Comment held for moderation.
  • Your Name (unregistered)
    Comment held for moderation.
  • Rohan Roy (unregistered)
    Comment held for moderation.
  • Rohan Roy (unregistered)
    Comment held for moderation.
  • Donald Klopper (google)

    No comments about string equality testing in Java needing to use the .equals method? I guess this isn't really a Java forum.

  • Maia Everett (github) in reply to Donald Klopper

    Jeremy Pereira did note that.

  • Craig (unregistered)

    TRWTF is zero-based indexing. But if you're unfortunate enough to be working in a language/environment that forces it upon you (sadly, these days pretty much anything other than Fortran or VBA), it's still bad form to deviate.

Leave a comment on “Counting References”

Log In or post as a guest

Replying to comment #:

« Return to Article