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

var-arrrrrgh!

Last post 02-08-2013 5:20 PM by darkmatter. 8 replies.
Page 1 of 1 (9 items)
Sort Posts: Previous Next
  • 02-07-2013 2:01 PM

    var-arrrrrgh!

    Two posts today. Just found a geniurrrs way of using varargs.

        public static void doThing(String...args)
        {
        	if (args != null && args.length > 0) doMore(args[0]); 
        	if (args != null && args.length > 1) doMore(args[1]); 
        }
    
  • 02-07-2013 2:35 PM In reply to

    Re: var-arrrrrgh!

    It probably used to look like:

    public static void doThing(String...args)
    {
        for( int i = 0; i < args.length; ++i ){
            doMore( args[i] );
            if( i = 1 ) break;
        }
    }
    

    And then someone decided to optimize this by unrolling the loop.

  • 02-07-2013 3:03 PM In reply to

    Re: var-arrrrrgh!

    if( i = 1 )
    Nice touch.
  • 02-08-2013 10:51 AM In reply to

    • Mo6eB
    • Not Ranked
    • Joined on 05-15-2007
    • Posts 73

    Re: var-arrrrrgh!

    lolwhat:

    if( i = 1 )

    Nice touch.

     

    This would be a syntax error in Java unfortunately.

     

  • 02-08-2013 12:55 PM In reply to

    • mozbo
    • Not Ranked
    • Joined on 08-21-2012
    • Posts 10

    Re: var-arrrrrgh!

    Mo6eB:

    lolwhat:

    if( i = 1 )

    Nice touch.

     

    This would be a syntax error in Java unfortunately.

     

     

     

    See, that's why they unrolled it. It wouldn't compile.

     

  • 02-08-2013 4:15 PM In reply to

    Re: var-arrrrrgh!

    mozbo:

    Mo6eB:

    lolwhat:

    if( i = 1 )

    Nice touch.

     

    This would be a syntax error in Java unfortunately.

     

     

     

    See, that's why they unrolled it. It wouldn't compile.

     

    That must be exactly why they used the > operator instead because == vs = was just too confusing.
  • 02-08-2013 4:52 PM In reply to

    Re: var-arrrrrgh!

    Nice. They probably are working in a large messy enterprise code base, and were afraid to change the method signature for fear of breaking something else.
  • 02-08-2013 5:11 PM In reply to

    Re: var-arrrrrgh!

    what, seriously... it's the original darkmatter? screw him for taking my name and then posting so little! edit: interesting how i joined in 2008 and darkmatter wasn't available until he joined in 2012. screw community server too.
    Filed under:
  • 02-08-2013 5:20 PM In reply to

    Re: var-arrrrrgh!

    darkmattar:
    what, seriously... it's the original darkmatter? screw him for taking my name and then posting so little! edit: interesting how i joined in 2008 and darkmatter wasn't available until he joined in 2012. screw community server too.
    I was surprised it was available, usually I have to throw an extra 'r' on the end!
Page 1 of 1 (9 items)
Powered by Community Server (Non-Commercial Edition), by Telligent Systems