aspose file tools*
The moose likes Other Languages and the fly likes What would you add to Java? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Languages » Other Languages
Bookmark "What would you add to Java?" Watch "What would you add to Java?" New topic
Author

What would you add to Java?

Frank Spychalski
Greenhorn

Joined: Mar 19, 2006
Posts: 3
This is not really a Rails specific question.

Neal Gafter blogs about adding closures to java. Which Ruby (or any other language) features would you like to add to the Java language. Or do you think it is possible to create a Framework with the power and flexibility of Rails with Java without any changes?
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Personally, I'd like to have support for regular expressions built into the language syntax itself as well as expression interpolation in literal strings. E.g. something like



Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Justin Gehtland
author
Ranch Hand

Joined: Jan 30, 2007
Posts: 31
Personally, I'd much rather we just started using jRuby for all of our programming on the JVM. As Stuart would say were he online right now, in a perfect world, we'd write code in jRuby and Java itself would become the Assembler (and not the COBOL) of our generation.

Put a gun to my head, and I'd say:
  • Regular expressions as first-class entities
  • Closures (and related items like enumeration support that makes use of them)
  • Open classes
  • Mixins without having to resort to AOP
  • Terry Jeske
    Greenhorn

    Joined: Apr 06, 2004
    Posts: 17
    So, why JRuby over Groovy? To the untrained -i.e me javascript: x()
    Wink they look very similar in syntax.
    Stuart Halloway
    author
    Greenhorn

    Joined: Jan 04, 2007
    Posts: 2
    JRuby and Groovy have a family resemblance, but they are distant relations. The last time I looked Groovy code still gets "hardened" into Java classes. JRuby code, on the other hand, follows the Ruby way of being "the glue that never sets." JRuby code can dynamically modify the behavior of other JRuby code.
    The subtle danger is that JRuby and Groovy are similar for about the first 50% of what makes Ruby cool. For the latter half, only JRuby delivers the goods.
    Pradeep bhatt
    Ranch Hand

    Joined: Feb 27, 2002
    Posts: 8919

    Mixins without having to resort to AOP

    How does that work?


    Groovy
    Lasse Koskela
    author
    Sheriff

    Joined: Jan 23, 2002
    Posts: 11962
        
        5
    Pradip, you can read about mixins from the online version of Programming Ruby.
    Justin Gehtland
    author
    Ranch Hand

    Joined: Jan 30, 2007
    Posts: 31
    So, let's say you have a class that's buried somewhere, like, Rails' ActionController. And you want to add a new method to it, like, "help" (so that all your controllers had a /your_controller/help url that tells what that controller is for).

    You can create a module to hold the new, shared method:


    Then, you can, from anywhere in the code, call:



    Voila. Your controller now has a "help" method.

    What if you wanted to wrap a method already in a class? For that, you would use .



    If you then extend that into a class with a "save" method, it renames the original method, creates a new method of the same name (a proxy, if you will), and when it is called, the new method logs the process and forwards the call to the original method.

    There is a new addition to Rails 1.2 called alias_method_chain which makes the whole process a little cleaner, as well.
    [ January 31, 2007: Message edited by: Justin Gehtland ]
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: What would you add to Java?