Taking Polyglot Programming Further

| | Comments (2) | TrackBacks (0)

I consider polyglot programming to be using the best tool for the problem. Some languages are inherently better at solving certain types of problems. We should embrace these advantages and switch freely between languages.

Today, we are introducing Hydra, the meta-language that runs on the JVM. Hydra supports (and encourages!) any JVM-based language at any time in the file.

Example: Person.hyrdra

:groovy
class Person {

  :ruby
  # define properties
  attr_accessor :first_name, :last_name

  :python
  """ 
    Get the full name by concatenating first, last
  """
  def full_name (self):
    print "%s %s" % (self.first_name, self.last_name)

  :java
  /**
   * Set the firstName attribute to name. (Useless javadoc)
   *
   * @param name the new first name value
   */
  public void setFirstName(String name) {
      String prefix = "Setting first name to ";

      :clojure
      (print prefix)
      (defn printChar [c] (print c))

      :javascript
      name.forEach(printChar);
:java this.firstName = name; } // Switch to python so ending '}' isn't needed ;) :python

Sent from my iPad

2 Comments

Bryan Hughes said:

Lame until I hit the "Sent from my iPad" part. Happy April 1. ;)

David Keener said:

Nice April Fool's joke (or, at least, I hope it was a joke). 8-)

Leave a comment


Type the characters you see in the picture above.

0 TrackBacks

Listed below are links to blogs that reference this entry: Taking Polyglot Programming Further.

TrackBack URL for this entry: http://www.nearinfinity.com/mt/mt-tb.cgi/637