A a;rather than:
{
ABuilder builder = new ABuilder();
builder.setX( x );
builder.setY( y );
...
a = builder.build();
}
A a = new ABuilder().setX( x ).setY( y ). ... .build();sure it is more lines of code, but the former makes stack traces and debugging much easier.
A a = new ABuilder()to improve stack traces and debugging but that's no more readable than the first case.
.setX( x )
.setY( y )
...
.build();
Throwing in syntactic sugar for every knee-jerk "use case X would look a
bit better (to me) with _____" feature will not improve readability and
not make any real substantive improvement to the language.
Java's pretty darn good. Sure there are plenty of things that could and
should be added/improved, e.g. closures, but it is critical to (1) get
these things right rather than rush them in and (2) introduce only those
things that bring a substantive net improvement -- introducing other
features only leads to conceptual bloat and makes the whole language
harder to learn, read, remember, and, comprehend.
--
Jess Holle
On Nov 28, 12:04 pm, Jess Holle <je...@ptc.com> wrote:There's no value in saying this other than maybe that some wish it were so. Since it isn't saying it is so makes just makes things harder to follow. Sure an IDE can help you understand the incomprehensible, but the clearer plain source text is (without having to always cross-reference to import statements) the better.There is *NO* difference between list.sort() and Collections.sort(list) in look and functionality. They both sort lists, and looking at just that one snippet of code, it's obvious that's what's happening. You seem rather hung up on the distinction on where the code is actually defined. This is good; it's a very important concept that a host of languages just plain ignore (Just about any language that heavily relies on Dynamic MetaProgramming, for example in java where e.g. date libraries add the 'minutes()' function to the Number class by doing something like Number.minutes = function() {} *AT RUNTIME*, making it absolutely impossible for a compiler, IDE, or even a human being given a sufficiently complex case to find out where the 'minutes' bit in:
None of which has anything to do with supposed unreadability or confusion. That's what IDEs are for.
Yes, this form of meta-programming is very troublesome in large systems in my opinion.There is *NO* difference between list.sort() and Collections.sort(list) in look and functionality. They both sort lists, and looking at just that one snippet of code, it's obvious that's what's happening. You seem rather hung up on the distinction on where the code is actually defined. This is good; it's a very important concept that a host of languages just plain ignore (Just about any language that heavily relies on Dynamic MetaProgramming, for example in java where e.g. date libraries add the 'minutes()' function to the Number class by doing something like Number.minutes = function() {} *AT RUNTIME*, making it absolutely impossible for a compiler, IDE, or even a human being given a sufficiently complex case to find out where the 'minutes' bit in:
- It makes the location of sort() [or the like] hard to determine -- to no real useful purpose in this example except some odd notion of purity of OO syntax.
- Dynamically adding methods at runtime makes tracking what methods a class or instance has and where they came from rather messy.
list.(Hit CTRL+SPACE to activate auto complete - see 'sort' in dropdown - select sort - be puzzled about the need to pass the list AGAIN - realize it's a static function - replace original list instance var with List - continue coding).
list.sort();means any/all lists can define their own sorting any way they choose -- caveat emptor.
Collections.sort( list );means there is a single Collections utility class that defines a sort algorithm on lists. Lists don't get to screw this up in any way -- except where Collections delegates to 'list'.
list.sort();
Maybe we need a way to explicitly state that we're using an extended method, this would solve the "must be readable and understandable at a glance" problem. To reuse a syntax that's been proposed for properties:
list->sort();
We're calling -a- sort() method on list, and its a method that much be explicitly statically imported.
Maybe the import also needs to be explicit:
import static com.foo.Bar.sort () on java.util.ArrayList;
Or even something entirely new:
extend java.util.ArrayList with com.foo.Bar.sort();
The biggest problem we hit with them was:
1. A developer would write an extension function to a class that was
missing what he/she wanted.
2. Other programmers would see that function as useful to and copy it.
3. The method became so popular, it was eventually added to the base class.
4. Old programs then broke due to the collision of the extension
function with the base class method.
My point? I think its very important that the extension function
mechanism deals with the problem of the same method being added to the
base class later.
Personally I don't think this feature adds much to the language. I
would be keeping the language lean in this case. Having used extension
functions, I find them useful in small projects (where its more like
scripting) and a pain in big projects - but this is biased by one
particular implementation of extension functions where they were called
exactly like a normal class method.
Alan
When you deal with a large project with many developers and many years
of maintenance, then many of these good ideas turn out to be very, very
bad ones.
Given that it is very hard to prevent developers on a large team from
using such features, they're best not to have at all -- unless the
language spec is going to specify standard required compiler such as
"disableFeatureX" which could then be used in integration builds.
Of course there are lots of language features which are just purely good
ideas for large and small projects, e.g. generics :-)
--
Jess Holle
At the same time, adding code at runtime can make a large system into a
small system; Ruby's attr_accessor is a fine example of this. I wonder
how many "large" 250KLOC systems could be transformed into smallish
20KLOC systems...
Yours,
Tom