Awesome Code of the Day:

Awesome Code of the Day:

 if (length(PNR.LastName)= 20) or
           ((length(PNR.LastName)= 19) and
            (iTemp>0) and
            (length(sIncomingName) - iTemp + 1 > 19)) or
           ((length(PNR.LastName)= 19) and
            (iTemp=0) and
            (PosFromBack(' ', PNR.LastName) <= 2) and
            (PosFromBack(' ', PNR.LastName) > 0)) then
              bLastTruncate := True;

Comments

  1. Had to go Ivy League College to be able design trap like that ;) (regular mortal could not... ) :D

    ReplyDelete
  2. Simon Stuart If they did that, they'd hopefully realize they could split it over multiple lines, with bLastTrucate := bLastTruncate or (...);

    Tho I wouldn't hold my breath ;)

    ReplyDelete
  3. Simon Stuart Was just trying to point out how unlikely it was :P Otherwise the code wouldn't be horrible :D

    ReplyDelete
  4. Simon Stuart Setting the variable with the result of the condition is not the same as setting it to true when the condition is true. There is no clue in the shown code that bLastTruncate has to be false when the condition is false.

    ReplyDelete
  5. Simon Stuart I never doubt that!

    ReplyDelete
  6. I just assume when I see code that bad that any assumption I might make is likely to be wrong. So going "from the name it seems..." is IME the first step to yet another irritating bug. And code like that is generally not short of bugs.

    ReplyDelete
  7. I love all the magic numbers... 19? 20? >19?  =19?  What the heck does all that mean?

    ReplyDelete
  8. Love it, but needs another few lines to achieve a perfection ;)

    ReplyDelete

Post a Comment