Regardless of what API was chosen, the resulting for-expression is much
easier to read and has higher SNR.  No matter what API you use in java,
building up a list of items from some other datastructure usually requires
insantiating the list, then iterating over all elements, testing various
conditions, then placing them in the list.  Finally, you return the list.
Using for expressions, you have a lot less noise to accomplish the same task
without losing readability.

Should I also show examples of:

1) Parsing text files
2) Resource Management
3) Tree/Model Manipulation
4) Declaring Class Hierarchies


Don't get me wrong.  I like the Java language.  However, I see its days as
the general purpose language of choice being numbered.  I actually like the
Swing framework for being amazingly powerful.  I had to write a
high-performance graphing library (live interactions/updates) and the Swing
API really saved us a few times by allowing us to be crazy flexible.
However, the other 80% of the time, I wish there was some simpler way of
defining my app (or at least, better databinding).  I don't see Java
disappearing, I see java being the "if you want high-performance on the JVM,
you write it in java" vs. "if you need to get this done quickly and its
execution time isn't critical" being other languages.

If you look at what is being done on top of the JVM nowadays, it's pretty
phenomenal.  I really think this is crucial to JVM success.  Not every
language is suited to every task.  You should choose languages
appropriately.  JavaFX appears to be a really great language for UI
development.  As it speaks to "native java", you could mix this with a
Scala middle-tier, some groovy glue code and some java
highly-performance-tuned areas and you have a nice app, all cohesive running
on the JVM.   This is where I'd liek to see java go, and with the Posse
covering topics from alternative languages on the JVM, I see them as helping
lead the community towards that vision.

Please, more interviews on languages like, Fan, Clojure, Scala, Groovy,
JRuby, Ioke (preferably from people using them in production applications).
I'd really like to hear thoughts on Fan's "baked-in" module system vs. OSGi
vs. Jigsaw, etc.

-Josh


On Thu, May 7, 2009 at 7:41 AM, Reinier Zwitserloot <reini...@gmail.com>wrote:

>
> Trying to prove java sucks by showing code that uses the DOM library
> is stupid.
>
> The DOM library sucks. That's what its designed to do; utter bilge for
> manifestly typed languages. Fortunately, there's XOM, JAXB, XPath, and
> many other alternatives. Not a valid example, unless you want to
> highlight that java tends to suck when attempting to use it as some
> sort of DSL, in which case: Absolutely right, but coin isn't going to
> change this, and there's plenty of resistance to expanding language
> flexibility to address such an issue, because it also has many
> disadvantages. So, that's a completely different argument.
>
> On May 7, 4:48 am, Josh Suereth <joshua.suer...@gmail.com> wrote:
> > Perhaps a better example of scala making life easier.  Here I'm use "for
> > expressions" along with "operator syntax" and "lambda expresisons" on the
> > Scala XML dom to parse out all link URLs from a web document that end
> with
> > rpm
> >
> > val urls = for {  link <-   webpageDom \\ "a"
> >                      location <-  link.attribute("href").map(_.text)
> >                      if location.text.endsWith("rpm")
> >                } yield location.text
> >
> > Here's similar java (but using a different path)...
> >
> > List<String> urls = new ArrayList<String>();
> > NodeList links = webpageDom.getElementsByTagName("a");
> > for(int i =0; i < links.getLength(); i++) {
> >     Node link = links.item(i);
> >     if(link instanceof Element) {
> >           Element linkAsElement = (Element)link;
> >           if(linkAsElement.hasAttribute("href") &&
> > linkAsElement.getAttribute("href").endsWith("rpm")) {
> >               urls.add(linkAsElement.getAttribute("href");
> >           }
> >     }
> >
> > }
> >
> > Groovy provides an "XmlParser" for nicer syntax as well....  However,
> I'll
> > let a Groovy expert show the simplified code for this (I'm pretty sure
> it's
> > close to a one liner using a depthFirst call with a closure filter.
> >
> > Lastly, here's a JavaScript example (using jQuery):
> >
> > var links = [];
> > $('a').each( function(idx, link) {
> >                  if(link.href && link.href.match(/.*rpm/)) {
> >                       links.push(link.href);
> >                  }});
> >
> > //Note we are not using map because we want to filter based on link
> ending!
> >
> > Anyway, on to the point:   Which of these has the least signal to noise
> > ratio?  Which one is the clearest?  I leave that for you to decide.
> >
> > I also want to point out that this expressiveness (of other languages vs.
> > java langauges) is not limited to XML parsing.  I would also be remiss if
> > not mentioning that I neglect to include a C version of the XML code
> because
> > I just didn't feel like taking the time to write one, and then make sure
> it
> > compiled/ran.  I'd love to see a JavaFX script version of this code, as I
> > have a sinking suspicision it will still have higher SNR than Java.
> >
> > -Josh
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to javaposse@googlegroups.com
To unsubscribe from this group, send email to 
javaposse+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to