Article:
  Creating Varargs in Java 1.5 Tiger
Subject:   Are varargs an improvement?
Date:   2004-08-19 06:36:52
From:   bmclaugh
Response to: Are varargs an improvement?

Marcin-


Thanks for your comments. I think it's true that varargs have been pretty heralded in Tiger. That said, I've always maintained (or tried to maintain) that they are more about convenience than functionality.


I think what you'll find is that many Java programmers, especially ones for which Java is their first language, really aren't as comfortable as you might think with arrays. It's simply easier to works with Java collections. For these reasons, the idea of converting arguments to an array is a bit of a pain.


And, I do think there are valid uses of varargs, like the classic max(int...) type of method. It really is a pain to throw ten or fifteen variables into an array just to call a method like this (max int[]), at least in my opinion.


All that said, you're very much right that varargs can introduce a lot of hinky bugs. Like almost any new feature, it will probably be overused until some well-defined usage patterns develop. But, that's to be expected with new APIs :-)


Thanks for your comments!


-Brett McLaughlin

Full Threads Oldest First

Showing messages 1 through 1 of 1.

  • Are varargs an improvement?
    2004-10-08 15:55:03  MarcinJeske [View]

    It's good to see that you are keeping an eye on comments. Just to add a few thought:

    You may be right that first-time programmers learning Java, as opposed to those coming from other languages, are not as confortable using arrays. After working with arrays in C/C++, using them in Java is a dream... the same simplicity and power but without the inherent bugs (pointer error, bounds-checking, type errors). As much as the collections classes are necessary and useful to describe dynamically changing groups, set-style notation, and underlying performance needs, nothing beats the ease of creating, initializing, and altering elements in an array. ( new int [] {1,2,3} )

    On the other hand, I wouldn't mind if there were improvements. After becoming familiar with the array operations of Python and Perl, I've found myself wishing for those operations Java, and creating helper methods which mimic them:

    Namely, array slices, where a new array is returned containing a subset of the original between a range of indices ( public Object [] slice(Object [], int start, int end); ), or a subset is returned based on an array of indices ( public Object [] slice(Object [], int [] indices); )

    I much prefer the Python to the Perl syntax...

    Anyway, I appreciate the response.

    Marcin