I agree with all that. Having gone from C# to Java full time about six
months ago, I also miss the way C# gives you a choice between stack
and heap storage for objects, and the lack of obligatory checked
exceptions (now that really might start a flame war).
Jim
C# is doing and in many cases has already done the hard yards, IMHO
the way that these language features have been implemented in C# are
proven, easy to understand and very effective, let's not let them get
too far ahead and implement these features into Java. Scala is a good
example of being proactive about providing these feature sets.
C# is standing on Java's shoulders, let's learn from C# and stand on
theirs a little, there's no shame in this. I don't want Java to become
the new C.
-Brett
I'm sorry Casper, that's not a darn good question. And the Java
community takes C# very seriously. Look at Java 5, and tell me which
new language feature is not inspired by C#?
> You can run all kind of weird languages on top of the JVM, but
> not C# which for all intents and purposes is Java.next.
You also can't run C++, nor Perl, nor Common Lisp, nor PL/I on top of
the JVM.
There are a lot of things that are theoretically possible but is not
being done in reality. They are not done because doing them helps no
one. Why don't people write cross-platform applications in the Windows
API? With WINE, it is theoretically possible.
> The mindset
> also shines through in this podcast, while the posse guys are of
> course free to interview whom they want, it's sad (and in stark
> contrast to i.e. .NET rocks) how they never once crossed over to the
> other side to assert how green the grass is or isn't there - as if
> nothing good could come out of it.
It's not like we (the Java Posse listeners) can't find DotNet Rocks or
Channel 9 ourselves if we want to hear interviews with Anders Hejlsberg.
> The merge of the JVM and the CLR has been proposed in the past, it
> might happen with the Mono VM eventuall (which will quite happily run
> Java code and whos designers plan to take full advantage of
> interesting OpenJDK bits) and that's also why platform-hybrid
> languages such as Fan is an interesting thing to follow.
Not all things in the world are meant to be abstracted away. As the
world stands now, JVM and CLR are the two dominant runtime platforms.
Others may come along later on. This is no different from other
dichotomies in the programming world:
vi vs. EMACS
UNIX vs. Windows
C++ vs. Smalltalk
System V vs. BSD
RPM vs. deb
GNOME vs. KDE
Spring IOC vs. Guice
The urge to unify similar things in computing is very strong, but any
attempt at doing them all ultimately fail.
--
Weiqi Gao
weiq...@gmail.com
http://www.weiqigao.com/blog/
I can't speak for all java programmers, but for my everyday work, Java
does most things I need. If I need more flexibility, I'd use Groovy or
JRuby for those sections. I'm doing Scala on the weekends to learn
functional programming.
C# to me doesn't seem to offer enough that is different (from my
admittedly quick looks at feature bullet point lists) to sacrifice
even more of my spare time to learn it. The fact that I don't like
Microsoft's business practices and try to stay away from anything
associated with them for that reason is just icing on the cake.
Cheers,
Lars
A lot of these language features need to come to java and they need to
come soon. C# is gaining a lot of traction and is evolving pretty
quickly, it's got a healthy following and a thriving community of
content and control authors. I'm not saying java doesn't have this
sort of ecosystem, but the java ecosystem isn't expanding as fast as
the .NET ones are. Who knows what's to come now that Windows Azure has
been launched.
Your V's list is very true, and healthy; but wouldn't it be good for a
KDE developer to use Gnome, and a vi user to use EMACS once in a
while? Most .NET developers I know also know Java, but not as many
Java developers know C#, why is that? Would you think that MS
developers are using OSX? I could bet my house on it, I'd also bet
someone in Redmond is looking at whats going on in Java.
-Brett
Well yes, there is the argument that Java.next already exists -and is
called C# :-) (or is java.next called android?)
BoD
I very much agree with you that the java ecosystem has a vast plethora
of frameworks to help us along, mind you C# is starting to pick up the
pace with codeplex and IoC/DI frameworks like Unity. They also didn't
really need a NIO because they got IO right from the beginning. The
build system also got replaced in .NET 2.0 to behave more like ant
(though IMHO it still sucks), and there's always nant.
I must point out though that in your list of benefits to the Java
language there aren't really any rich client benefits, they're biased
towards backends.
Properties, Events and Delegates are the three things that really go
hand in hand with rich client development. For someone who might be a
server side developer where most tasks are stateless they may seem a
little useless. I haven't used JavaFX yet, but if it's statefull then
it could definately benefit from these three components.
Take the following swing snippet
myButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
// Handle action event
}
}
Does it look neater to see this instead?
myButton.ActionPerformed += new EventHandler(doMyButtonAction);
// And have the event handler elsewhere.
private void doMyButtonAction(Object sender, ActionEvent args) {
// Handle action event.
}
The real pain though is trying to fire an event in Java, you need to
hold a collection of listeners, then traverse over them fireing events
one after the other.
Firing an event in C# is as simple as calling it, just like a method,
it will traverse the function pointer graph for you.
MyEvent(Object, MyEventArgs);
-Brett
> again -take a long view -C# is doing the heavy lifting right now,
> implementing experimental stuff like linq that will take its toll on
> the language, and inevitably cripple c# with backwards compatibility
> restrictions, -about then would be a good time for son-of-java
> (literally in many cases! -hopefully daughter of java in others which
> might do more for language wars than anything technical)
LINQ is basically some syntactic sugar over Lambda expressions that
have been in the language since 2.0. The current closures spec is
supposed to cover lambda expressions right?
Up until now I didn't give it much thought on HOW lambda will be
implemented in Java, but now I'm confused how it's going to be done,
Lambda expressions `depend' on function pointers since they are
anonymous functions. I don't think we should have LINQ type language
embedded into Java just yet, but we could definately benefit from
Lambda expressions.
// The following C# snippet demonstrates lambda expressions,
// note that the FineAll method accepts a delegate/function
// pointer.
List<String> myList = new List<String>() {
"One", "Two", "Three", "Four"
);
List<String> filteredList = myList.FindAll(s => s.StartsWith("T"));
Properties, Events and Delegates were in C# since 1.0 so what's that,
8 years, nearly 9 that they've been able to prove that it works?
They also got Generics right because they were't concerned with going
over the existing class libraries and retrofitting generic support to
them, they rightfully left the whole lot alone and created new classes
with generic support and deprecated the old ones. I didn't see the
light when they first did that, but I learnt to understand the meaning
behind their madness.
So hey, now we have PEDL, the four language features required to power
Java ahead of C#.
Properties, Events, Delegates and Lambda expressions :)
-Brett
So hey, now we have PEDL, the four language features required to power Java ahead of C#. Properties, Events, Delegates and Lambda expressions :)
Properties are a 1-to-1 relationship of a classes member and the state
it's representing, currently we don't have this support in Java.
Trying to traverse the object graph to find what members are
properties is currently painful, I wrote an example the other day to
explain to a friend this fact (attached), if you never have to write
this sort of code then you're extremely lucky.
Registering a listener in Java isn't the main problem, it's a real
problem for a component author where you have to maintain a list of
listeners, then call them when the event occurs. You end up with at
least 15 lines of code, take a look at
javax.swing.AbstractButton.fireActionPerformed(ActionEvent) as a
classic example of this.
To properly get closures, you need function pointers, and that's why
we need them in Java, and with function pointers we can implement
proper events fairly easily.
I don't want to assume, but are most people who couldn't care for
events/properties server side developers? The real benefit to these
features is with statefull code, not so much with stateless, since
stateless code can't really listen to events in the first place.
-Brett
> To properly get closures, you need function pointers, and that's why
> we need them in Java, and with function pointers we can implement
> proper events fairly easily.
>
You need to make methods first class citizens and then you can implement
closures properly. Exposing pointer is something we want to avoid IMHO.
> since
> stateless code can't really listen to events in the first place.
>
Why not?
Regards,
Kirk
>> Properties are a 1-to-1 relationship of a classes member and the state
>> it's representing,
> which is a violation of encapsulation and promotes unnecessary couplings.
That 1-to-1 relationship is the encapsulation, and it's actually
promoting the point.
>> To properly get closures, you need function pointers, and that's why
>> we need them in Java, and with function pointers we can implement
>> proper events fairly easily.
> You need to make methods first class citizens and then you can implement
> closures properly. Exposing pointer is something we want to avoid IMHO.
To the casual C# programmer they wouldn't even know they were actually
using function pointers. The language takes care of
>> since
>> stateless code can't really listen to events in the first place.
>>
> Why not?
Well you can, but more so why would you? Events are more suited to
something that is going to hang around for a while in a state-full
fashion.
-Brett
Regards,
Kirk
I don't think they are syntactic sugar, like I've mentioned previously a Property isn't simply a wrapper around getFoo/setFoo methods, they are a separate construct that does allow for type safety of some state. If you're a component designer and you come across a class with String getFoo(); void setFoo(Integer val) what do you do? Do you treat Foo as a single read-only property of String or do you not show it at all?
Properties are a 1-to-1 relationship of a classes member and the state it's representing, currently we don't have this support in Java.
Trying to traverse the object graph to find what members are properties is currently painful, I wrote an example the other day to explain to a friend this fact (attached), if you never have to write this sort of code then you're extremely lucky.
Registering a listener in Java isn't the main problem, it's a real problem for a component author where you have to maintain a list of listeners, then call them when the event occurs. You end up with at least 15 lines of code, take a look at javax.swing.AbstractButton.fireActionPerformed(ActionEvent) as a classic example of this.
To properly get closures, you need function pointers, and that's why we need them in Java, and with function pointers we can implement proper events fairly easily.
I don't want to assume, but are most people who couldn't care for events/properties server side developers? The real benefit to these features is with statefull code, not so much with stateless, since stateless code can't really listen to events in the first place.
@kir
Properties are a 1-to-1 relationship of a classes member and the state it's representing,which is a violation of encapsulation and promotes unnecessary couplings.That 1-to-1 relationship is the encapsulation, and it's actually promoting the point.
You need to make methods first class citizens and then you can implement closures properly. Exposing pointer is something we want to avoid IMHO.To the casual C# programmer they wouldn't even know they were actually using function pointers. The language takes care of
since stateless code can't really listen to events in the first place.Why not?Well you can, but more so why would you? Events are more suited to something that is going to hang around for a while in a state-full fashion.
Encapsulation is exactly what properties provide. Take the following
encapsulation of member variable foo:
private int foo;
public int Foo {
get { return foo; }
set {
if (value < 0)
ArgumentOutOfRangeException("Value for property Foo must be >= 0");
foo = value;
}
}
-Brett
> There are plenty of good use cases for a stateless listener, but clearly
> UI's involve state no matter how you try to avoid it :-)
Point taken ;-)
Regards,
Kirk
private int foo;
public int getFoo() { return foo; }
public void setFoo( int value) {
if (value < 0)
ArgumentOutOfRangeException("Value for property Foo must be >= 0");
foo = value;
}
Maybe I've missed the point but.... :-)
Regards,
Kirk
Yes, these two are vastly different, as I've expressed earlier you
can't simply identify a property on a Class, take my attached example
a few posts ago and you'll see what I mean.
When you traverse Foo.class.getDeclaredMethods() that match a pattern
of set|get.* and then pair the two up as a property. as also
mentioned, what if getFoo returned a String, while syntactically
correct, this is not type safe.
get/set methods hide the implementation, but they don't enforce the
fact. A property enforces this by exposing the get/set as one.
-Brett
+ Correction, I forgot the "throw" statement on the exception above.
Yes, these two are vastly different, as I've expressed earlier you can't simply identify a property on a Class, take my attached example a few posts ago and you'll see what I mean. When you traverse Foo.class.getDeclaredMethods() that match a pattern of set|get.* and then pair the two up as a property. as also mentioned, what if getFoo returned a String, while syntactically correct, this is not type safe. get/set methods hide the implementation, but they don't enforce the fact. A property enforces this by exposing the get/set as one.
There's no reason that the getter/setter conventions from the JavaBeans spec cannot be interpreted in just as type-safe a manner as some official "Property" construct.
I will not argue that the current state of affairs is anywhere near perfect here in Java. For starters:
- One should be able to use properties more directly in a type-safe manner (e.g. via an -> operator)
- The Java compiler would understand JavaBeans as components and do type-safe usage thereof -- rather than forcing one to go through reflective APIs.
- One should be able to communicate details to JavaBeans metadata more easily, e.g. via annotations
But it's not baked into swing and other areas where a component model
is needed, there maybe API's out there, but they aren't something I
can discover. If I'm given a component from some component author who
has quite simply developed some swing control, how do I place that
control on a designer and be able to expose the properties of that
component? Exposing events aren't as bad although not as easy as if we
had true events.
In the end we do something like the attached example I posted a few
posts ago that iterates over the classes declared methods. Even still,
I've just realised my example doesn't take the Boolean `is' into
account.
http://bean-properties.dev.java.net may be one solution, but whatever
the solution is the actual components need to be unified to support
property discovery.
If you do have a way to unify getters/setters into a property without
having to try and discover them I'd be interested to see.
-Brett
Regards,
Kirk
IMHO, events and listeners should have been baked into the class
hierarchy as they are in Smalltalk. This simplifies things enormously.
Regards,
Kirk
The call
Introspector.getBeanInfo(Foo.class).getPropertyDescriptors()
will give you all the properties on the class Foo, their name, type,
getter, setter, bound-ness, constrained-ness, PropertyEditor, etc.
And according to it, your earlier example
class Bar {
public String getFoo() { return ""; }
public void setFoo(int val) {}
}
has a read only property named "foo" of type String.
The JavaBeans spec was written when AWT was still being hyped heavily,
and Java people were dreaming of a drag-and-drop type of GUI painting
paradigm. Anyone remember Bongo? I'm sure it would qualify as a Java
app of the week had the JavaPosse been on the air then.
Java did not dominate in GUI development. Looking back, that's when a
nice developer box have 16MB, maybe 32MB RAM, and production servers
have 64MB RAM. My VB5 developer colleagues were laughing their heads
off when I downloaded Swing 0.3 (or 0.4) and the SwingSet demo started
up in 20 minutes!
--
Weiqi Gao
weiq...@gmail.com
http://www.weiqigao.com/blog/
http://bean-properties.dev.java.net may be one solution, but whatever the solution is the actual components need to be unified to support property discovery. If you do have a way to unify getters/setters into a property without having to try and discover them I'd be interested to see.
Do you like using Introspector? ;) Okay it might be a tongue in cheek
question, but I'd still much prefer being able to do
foo.getDeclaredProperties() and have a PropertyDescriptor array
returned without the penalty of the Introspector having to go and
discover them.
-Brett
I think we've gone off on a tangent ;)
-Brett.
@Weiqi Do you like using Introspector? ;) Okay it might be a tongue in cheek question, but I'd still much prefer being able to do foo.getDeclaredProperties() and have a PropertyDescriptor array returned without the penalty of the Introspector having to go and discover them.
Introspector.getBeanInfo( Foo.class ).getPropertyDescriptors();and
Foo.class.getBeanInfo().getPropertyDescriptors();and
foo.getBeanInfo().getPropertyDescriptors();is immaterial in my book.
My attached ad-hoc code was not meant to be used, it was to
demonstrate what Introspector or any other inspector needs to do to
discover properties. What you get back are `assumed' properties (if
BeanInfo classes haven't been defined).
-Brett
I don't disagree with you.
Like I said, the JavaBeans API was written in another era for a
destination that Java eventually did not go. The hype was that in a
couple years, you could buy ready made components on the commercial
market and plug them into your Visual Cafe's GUI painter palette.
I will welcome properties and events support in the language level in
Java. And I will use those features if and when they become available
and their usage appropriate to the task at hand.
Before then, the JavaBeans framework is the closest approximation.
It's one thing to be enthusiastic about adding your favorite features
into the language. It is entirely a different thing to carry out your
daily work with the language and tools as they exist now.
Are we done with discussing properties? Can we move on to
+ closures: BGGA, CICE, FSM, anyone?
+ generics: The Wall of Erasure? Reifications?
+ XML literals
+ Regular expression literals
+ Multi-line strings
+ Removing wait(), notify(), notifyAll() from java.lang.Object
+ Putting Groovy into the JDK
+ Putting Google Guice into the JDK
+ Removing AWT Widgets from the JDK
+ Removing the HTML 3 parser/renderer from the JDK
+ Adding all 694 Apache Commons jars into the JDK, I'm tired of
getting them one by one by one by one by one....
+ Heck, why don't we put Ant into the JDK? Maven?
+ And ANTLR. And don't forget to rewrite javac to use ANTLR
now?
Are we done with discussing properties?
Can we move on to + closures: BGGA, CICE, FSM, anyone?
+ generics: The Wall of Erasure? Reifications?
Just say no! Next it will be literals for CSS, and my favorite non-Java niche grammar du jour. XML isn't that holy or special.+ XML literals
These would be kind of nice, but are not a huge deal either.+ Regular expression literals
Yawn. The + trick works fine in my book.+ Multi-line strings
+ Removing wait(), notify(), notifyAll() from java.lang.Object
+ Putting Groovy into the JDK + Putting Google Guice into the JDK
+ Removing AWT Widgets from the JDK
+ Removing the HTML 3 parser/renderer from the JDK
+ Adding all 694 Apache Commons jars into the JDK, I'm tired of getting them one by one by one by one by one.... + Heck, why don't we put Ant into the JDK? Maven?
+ And ANTLR. And don't forget to rewrite javac to use ANTLR
Isn't there a site somewhere with a list of suggested improvements for
the language, where people can vote for the ones they want?
BoD