Mirah
What’s Mirah?
It’s a small, fast,
JVM language that uses
     Ruby syntax.
How’d it come about?
Charles Oliver Nutter,
      JRuby guy
Wanted to write
Java code in Ruby
Wanted to write
Java code in Ruby
Wanted to write Java
code in a language as
 expressive as Ruby.
Expressive as Ruby?
http://www.flickr.com/photos/caroslines/513429518/
Syntactic Sugar

• Optional Arguments
• Internal Iteration(each, map, etc)
• Closures
• Literals
• String Interpretation
Mirah's got the sugar.
How Mirah Differs
   from Ruby
1. It’s statically typed
     and compiled
Basically,
No Runtime
Object/Class
Modification
2. It uses Java’s type
        system
It has slightly different
semantics than Ruby's
e.g.,
Mirah has interfaces
So, what’s it look like?
Fibonacci
Example
Ruby
def fib(a)
  if a < 2
    a
  else
    fib(a - 1) + fib(a - 2)
  end
end
Mirah
github.com/mirah/mirah/examples/fib.mirah
def fib(a:int):int
  if a < 2
    a
  else
    fib(a - 1) + fib(a - 2)
  end
end
See what I did there?
def fib(a:int):int
def fib(a:int):int
Ruby Syntax
+ Java Types
- Runtime Modification
Other Super Powers
Type Inference
      &
   Macros
Type Inference?
Java
class Foo {
  private int bar;
  Foo() {
    bar = 1;
  }
  public int bar() {
    return bar;
  }
}
Ruby
class Foo
  def initialize
    @bar = 1
  end
  def bar
    @bar
  end
end
Mirah
class Foo
  def initialize
    @bar = 1
  end
  def bar
    @bar
  end
end
@bar is inferred to be
     an Integer
Mirah
class Foo
  def initialize
    @bar = 1
  end
  def bar
    @bar
  end
end
Java
class Foo {
  private int bar;
  Foo() {
    bar = 1;
  }
  public int bar() {
    return bar;
  }
}
Mirah        Java
// Generated from foo.mirah
public class Foo extends java.lang.Object
  private int bar;
  public Foo() {
    this.bar = 1;
  }
  public int bar() {
    return this.bar;
  }
}
Ruby Syntax
+ Java Types
- Runtime Modification
+ Type Inference
Macros
For Convenience &
  Awesomeness.
Used by the compiler
For example,
puts
          =>
System.out.println();
Macros:
How each, map, ==, etc
  are implemented
Macro Basics
say you have code like:

logger.debug(
  "this #{takes_too_much_time}"
)
run
takes_too_much_time
    in production?
No,
it takes too much time.
Macros to the rescue
macro def debug debug_input
  quote do
    if logger.debugEnabled
      logger.debug `debug_input`
    end
  end
end
macro def debug debug_input
  quote do
    if logger.debugEnabled
      logger.debug `debug_input`
    end
  end
end
macro def debug debug_input
  quote do
    if logger.debugEnabled
      logger.debug `debug_input`
    end
  end
end
macro def debug debug_input
  quote do
    if logger.debugEnabled
      logger.debug `debug_input`
    end
  end
end
macro def debug debug_input
  quote do
    if logger.debugEnabled
      logger.debug `debug_input`
    end
  end
end
debug(
  "this #{takes_too_much_time}"
)
if logger.debugEnabled
  logger.debug(
"this #takes_too_much_time}"
  )
end
debug(
  "this #{takes_too_much_time}"
)
So, Macros are nifty
Ruby Syntax
+ Java Types
- Runtime Modification
+ Type Inference
+ Macros
Oh, there's another
       thing.
No Runtime Library
You can do this:

$ mirahc -e "puts 'hello BRG'"
$ java -classpath . DashE.class
No Runtime
      ==
Small compiled
  footprint
Small Footprint
      ==
good for mobile
For example,
 see Pindah
Ruby Syntax
+ Java Types
- Runtime Modification
+ Type Inference
+ Macros
- Runtime Library
Get Started

$ rvm jruby
$ gem install mirah
$ mirah -e "puts 'hello world'
Mirah projects to check out:

  • Dubious - Rails-like web framework for
    Google App Engine
  • Pindah - Android App framework
I'm Nick
@baroquebobcat
I work at
We're Hiring.

gnip.com/jobs
A couple links
    mirah.org
github.com/mirah
Questions?

Mirah Talk for Boulder Ruby Group