I'm working on porting a small-but-nontrivial Android app to
Mirah/Pindah, and my #1 pain point is lists and arrays and so on. For
the Android-specific part of the app, Mirah doesn't actually buy me
that much over Java, I mean consider this very androidy little squib
def number_from_clipboard:String
cm = ClipboardManager(@context.getSystemService(Context.CLIPBOARD_SERVICE))
s = cm.getText.toString
if s && PhoneNumberUtils.isGlobalPhoneNumber(s)
PhoneNumberUtils.formatNumber(s)
else
nil
end
end
It's cool that it works, but compared to java, it's got, uh, less
semicolons and parentheses. Whoopee.
For me, the first-level big win ought to be in Ruby's elegance in
dealing with lists and blocks and loops. But this just ain't there at
the moment. To start with, consider this array declared in Java like
so:
private static int[] mBarImages = {
R.drawable.b0, com.R.drawable.b1, R.drawable.b2, R.drawable.b3, R.drawable.b4
};
It's really pretty hard in Mirah to create this thing. In another
case, I want to build up a list of phone numbers by appending
selectively, then give it to an Android API that wants a
CharSequence[]. Once again, the obvious ways to do this don't work.
So, on the first, most obvious level, there's clearly a missing piece:
../~/ 501> mirah -e "a=[1,2]; puts a[0]"
DashE:1: Cannot find instance method [](int) on java.util.List
So maybe a basic change would be to make a []-literal denote an array,
and use casting to turn it into a List on request.
But what i think I really want is something Ruby-like that can do <<
and and [a .. b] and be an Enumerable and so on, but I can still use
to give to java methods without thinking too much about it. That is
to say, when a java method wants any flavor of List or array, the
Mirah thing acts like that. And whenever a java method returns such a
thing, we make it into a Mirah array.
I've only been doing Mirah for a day, so no idea if this is possible
or reasonable. But I really want to say something along the lines of:
findPreference('candidate_numbers').setEntries(calls.select {|x|
PhoneNumberUtils.isGlobalPhoneNumber(x)})
(setEntries wants a CharSequence[])
Also, things like "5.minutes" would require that primitives could be
automagically boxed when a method is called on them.
Headius, RibRdb, what do you think? :)
I would pay for these features :)
--
S pozdravem, Regards
Michal Hantl
tel: +420 777 812 167
gtalk: michal...@gmail.com
skype: michal.hantl
One of the big advantages of Mirah is the lack of a runtime library.
If you're looking for Ruby features that require a runtime library,
you might as well go use JRuby — I really don't see what Mirah is
gaining you at that point. Can someone tell me what the case is for
Mirah + runtime over JRuby?
My primary use case for Mirah is writing code that will go into my
programming language, so I can have a much nicer programming interface
than Java while not having to ship another language's runtime with my
runtime. I foresee the argument "But stdlib will be small compared to
a runtime!", but I don't really believe it. Especially not with the
kind of features people are clamoring for.
~~ Robert.
When you write 5.times { ... } now in mirah, is that a runtime library?
No, its just an extension of the Integer object.
Though it might be hardcoded syntactic sugar now, you can look at it
as if it was your own code saying:
class Integer
def times(&block)
[0..i-1].each(block)
end
end
This is very handy to be able to do because it creatly improves
readability of your code as well as expressiveness.
We don't need to ship Mirah with loads of extensions like this but we
should be able to extend Mirah to suit our needs (android, web
frameworks, test framework DSL...) and thats exactly what Mirah is
capable of.
Have you *timed* JRuby recently? It's crazy fast.
~~ Robert.
Okay, slight caveat: my timing of JRuby has only been done on a JDK7
machine, so it may just be that invokedynamic makes it crazy fast. But
I bet even on JDK6, it's within a stone's throw of the speed of Mirah
generated code, since Mirah does create overhead.
~~ Robert.
For giving Android app developers a taste of Ruby, Mirah currently
seems the best bet.
-Tim
One of the reasons I'm looking into Mirah is that the front-end is detached (or somewhat) from the back-end. I eventually want to see it output code for the CLR/DLR and hope to contribute to this ones I'm comfortable with the language and up to date on my compiler theory.
Given this if you want a library you would have to write it completely in Mirah which kind-of breaks the whole purpose in my opinion.
Of course I've only been fooling around with it for a short while but the whole reason for me doing so is the dream of a CLR/DLR version.
//M
--
phone: +46 (0)709 78 40 03
e-mail: m...@upplopp.se
twitter: http://twitter.com/m_mazur
Sure, but then you have the whole scala "issue". You need to ship the stdlib with your application which increases the size of your application and doesn't take advantage of the underlaying environment.
//M