Silly placeholder post
Saturday, 4 April 2009
I should update this blog more. Maybe just a little thing right now: I really like the option parsing library Trollop for Ruby. It's a great little system, and its values (or the ones important to me, at least) are that it is as easy as possible for the library consumer to use. I've been experimenting with making one with similar values for Scala, adding in the type safety and the like that you get with that language, while aiming to still keep a fluent interface.
Using it looks like this:
object Main extends OptionApplication { val options = new Options { banner = """ This is my test application. There are many like it, but this one is mine. Usage: Main [options] """ val name = string( "Name to greet", default( "Nobody" ) ) val alternativeGreeting = flag( "Use an alternative greeting" ) } import options._ def main() { val greeting = if( alternativeGreeting.value ) { "Bonjour, %s!" } else { "Hello, %s!" } println( greeting format name.value ) } }
Calling it from the "command line" (okay, I did it through Eclipse):
> Main --help This is my test application. There are many like it, but this one is mine. Usage: Main [options] Options: -a, --alternative-greeting - Use an alternative greeting -h, --help - This help page -n, --name - Name to greet (default: Nobody)
> Main -n Calum --alternative-greeting Bonjour, Calum!
> Main --pleasehelpme Problem with options: unrecognised argument 'pleasehelpme' Try --help for help.
Anyway, beyond just a random tour of that, why do I think this sort of thing is interesting? I like the idea that Scala works as a statically-type "scripting" language, as well as in the domains where Java works. I like the idea that command line tools and so on could be built with this easily. Java tends to only be used for huge big systems run inside containers and the like, because it's geared very much towards building the sort of huge system where this makes sense. Scala is fluid enough to give a lot of the advantages in fluidity you see from languages like Python and Ruby, and while it's a little more verbose, I think it's a useful alternative depending on your values.
What Scala is really missing, to me, is little "fun" libraries like you find in the form of Python Eggs and Ruby Gems. There's a lot of nice, impressive, projects but I'd like to see more in the realm of small projects that aren't necessarily a work of architectural genius, but are useful (or quirky) and encourage people to dabble and play. Java lacks a sense of fun and there's no reason that Scala should end up down that route. I might go into more detail with that feeling later; this is pretty poorly-drafted. Oh well!
6 Comments:
This comment has been removed by the author.
Howzit Calum? This is Gen. We met briefly at David's wedding. I'm guessing everyone whose blog has a link on David's page has ceased blogging?
Hey Gen! I haven't really stopped blogging, I've just not finalised the next bloody thing to write. I update my tumblr (and Twitter) with nonsense quite a lot, I tend to leave this blog for lengthy techy stuff. I do most of my techy stuff at work, and I can't really write about that in any depth online, so I don't write enough :(
How's yourself?
Ah, I see. Who are you on Twitter? What's your line of work again?
I'm trying to finish up my last year of law school (last few weeks, really) though I can't stop procrastinating for some reason. After that, I'm moving back to the "left coast" - Seattle to be precise. DC is just starting to grow on me, but it's a little too far from home in a lot of ways. Where do you live?
I'm "zootm" on Twitter (and some other places). I work as a software developer, hence this HYPERNERD blog. I live in Edinburgh, but it's funny you mention Seattle since I work for a Remote Development Centre of Amazon.com, so most of the company I work for is based over there. Good luck there!
This comment has been removed by a blog administrator.
Post a Comment
Subscribe to Post Comments [Atom]
<< Home