• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What would you add to Java?

 
Frank Spychalski
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Justin Gehtland
author
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Posts: 17
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    So, why JRuby over Groovy? To the untrained -i.e me javascript: x()
    Wink they look very similar in syntax.
     
    Stuart Halloway
    author
    Greenhorn
    Posts: 2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 8933
    Firefox Browser Java Spring
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Mixins without having to resort to AOP

    How does that work?
     
    Lasse Koskela
    author
    Sheriff
    Posts: 11962
    5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Pradip, you can read about mixins from the online version of Programming Ruby.
     
    Justin Gehtland
    author
    Ranch Hand
    Posts: 31
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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 ]
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic