The Daily WTF: Curious Perversions in Information Technology
Welcome to TDWTF Forums Sign in | Join | Help
in Search

(Over?) Defensive Coding

Last post 05-08-2012 2:19 PM by morbiuswilters. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 05-08-2012 2:08 PM

    (Over?) Defensive Coding

    Just in case $programmingLanguage changes its internal data representation (Snippet from source written/committed circa 2008)

    private int firstByteMask = (int) (1 << 15 | 1 << 14 | 1 << 13 | 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8);
    private int secondByteMask = 1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1;
    private int twelveBitMask = 1 << 11 | 1 << 10 | | 1 << 9 | 1 << 8 | 1 << 7 | 1 << 6 |
               1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1;
    private int fiveBitMask = 1 << 4 | 1 << 3 | 1 << 2 | 1 << 1 | 1;
    private int sixBitMask = (int) ( 1 << 5 | fiveBitMask);
    private int threeBitMask = 1 << 2 | 1 << 1 | 1;
    private int signMask = 1<<15;
    private int exponentMask = (1 << 7 | 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1) << 7;
    private into mantissaMask = ( 1 << 6 | 1 << 5 | 1 << 4 | 1 << 3 | 1 << 2 | 1) << 16 | secondByteMask;

    I tried to recreate the spacing verbatim. I find it curious that the exponent and mantissa seem to be incomplete without "1 << 1" but I haven't analyzed how they're actually being used (however, I believe it likely that it was simply missed.) Also, these are instance variables, not "static final". Explicit casting?

  • 05-08-2012 2:19 PM In reply to

    Re: (Over?) Defensive Coding

    zelmak:
    mantissa
    Incomplete Mantissa: The Unauthorized Biography

    Let the healing begin!

  • I may not agree with everything Morbs just said, but he expresses himself in a way that is dignified, respectful, polite and non-threatening!
Page 1 of 1 (2 items)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems