Tuesday, June 28, 2011

[Insert clever play on the name Io]

And so goes the second week and the second language on our seven week trip. Compared to the first week in Ruby, I struggled a lot more with Io. It's a language with very simple rules which, for me, made the edge cases all that more confusing. I also was a bit preoccupied with other, unrelated issues and so I skimped on a lot of the examples. Thankfully, Alberto did a lot of that work and wrote about it in a series of excellent posts. If you want to know more about Io, you should really read those.

As such, I'm going to keep it short with my own observations. As an abstract, Io is a prototype based OO language where everything is either an object or a message passed to it.

  • I was unable to build Io in Windows and I don't know what I would've done if I hadn't found some forum posting with a link to pre-built binaries. 
  • I particularly liked the way conditionals were also just messages, apparently just extending the base boolean types
  • Yet I don't really understand message precedence and how something like self sum / self size works. self size obviously gets evaluated before being passed to the divide operator, which I didn't expect
  • getSlot('foo') code print will print a method definition, similar to Javascript's foo.toString() (where 'foo' is a method/function)
  • sadly, that is not usable for the language constructs as they are written in C
  • Io has a pretty solid concept of coroutines, actors and futures, much unlike Javascript. Quickly writing some parallel code might indeed be one of the languages strong points
It seems the book deliberately started with Ruby to ease me in and then started to get a bit more challenging with Io to progress to Prolog, which I guess will be quite a bit different from what I'm used to. 

I'm again grateful for our study group. Our little skype conference showed that I wasn't the only one struggling with Io and I'm not sure I would've gotten much out of this chapter if it wasn't for other people's blog posts further explaining things. This isn't really a failure of the book as much as I just wasn't able to commit the time to really dig into the examples.

And now it's on to Prolog, which should get interesting, as I haven't worked with logic languages before. This time, installation is easy, as there is a package in cygwin that provides the 'pl' executable. (And, once again, let me recommend also getting mintty.)

Friday, June 17, 2011

First language done; inspiration had

Continuing on through Seven Languages in Seven Weeks I've finished the chapter on Ruby. I'll quickly list a few more things I've noticed and then do a little initial retrospective.
  • I was a bit confused with how method definitions apply to classes v. instances and how module inclusions and extending classes work into that
  • Interestingly, I feel reminded of similar troubles I had with understanding Javascript prototypes, functions and new. 
  • obj.freeze appears to be a way to dynamically declare variables final. I suppose that could be useful
  • you can always pass blocks to functions even without having declared them as arguments
  • there is what I'd call reverse varargs that lets you explode arrays to match method arguments using the same notation as varargs, which I quite like. def foo(one, two, *rest) …
    foo(*[1,2], 3, 4, …)
  • Having things like .methods on all objects to do reflection for debugging/getting to know the language is really helpful
  • if I had worked through this before and added a bit of rspec knowledge I might have been able to contribute a lot more on the occasions I paired on Ruby at code retreats
Code is here

So now a little bit about the learning experience. I'm greatly enjoying this so far and I think it comes down to three things.

The book

The book is great for getting you started in a language. As I mentioned on twitter I left with more questions than answers. But I now have a vague idea of where to look to find those answers. It's a really great achievement to pique the interest to go into the details of a language and to not make you feel completely lost doing so. I'm already looking forward to learning about Io.

The group

I'm also really enjoying our little virtual study group. People share their questions, answers or just share their fun in the learning. There's a lot of interesting blog posts already (aggregated here) and also quite a bit of activity on the github network for the project. I find this both liberating and motivating. It's safe ground for exposing your ignorance and at the same time I feel challenged not to slack off and actually keep working on it and do things like writing blog posts. 

The technology

And I love the technology that enables this and the fact that there are people that care enough to take part in this. We live in amazing times! Programming is fun and being able to share that with others makes it even more fun. I love that it's so easy to organize this on twitter more or less on a whim (at least my taking part was on a whim). I love that to get started reading I only needed a few clicks on pragprog (even if the kindle version has its little issues). I love that github lets me see how others solved the problems given in the book, both reassuring me that I did something right or helping me along to find better solutions. And then of course it's great to be able to just download and try out all these languages.

Tuesday, June 14, 2011

Seven Languages In Seven Weeks

I'm stuck trying to put my thoughts on estimation, conferences and switching jobs into writing. So many unfinished drafts, oh my!

So instead I'm now trying to write the odd post about my experience working through Seven Languages In Seven Weeks.

aimee daniells had the great idea to start an online study group for said book (not gonna type that title again, nu-uh). And since it helps distracting me from worrying about finding a new place to live within the next 3 weeks I gladly took the opportunity to join. (Sidenote: if you're looking for a flatmate in Hamburg please do get in touch.)

The book is very interesting to me because I don't know all that much about any of the languages but have been meaning to take a closer look at Clojure, Ruby and Erlang for some time. It's nice to have something concrete that gets me doing that.

The first language is Ruby. I've worked through days 1 and 2 now and here's a quick summary of what I took away from it.

Ruby has a lot of syntactic sugar. Enough to almost certainly give you diabetes. Parts of me (the old, elitist parts) feel somewhat uncomfortable with that. Other parts of me (the ones trying to get work done in Java) just feel jealous.

There were some more notes I took that I'll just list here without trying to add context (or sense)

  • The kindle version of the book doesn't wrap the code examples correctly with larger text sizes. That's pretty annoying. Does no one test these things?
  • When googling for the api docs one should be careful that one reads the docs for the correct version of ruby one is using. I spent 10 minutes wondering why str.match(regexp) { block } never executed the block until I figured out that that feature just didn't exist
  • String and exec expansion seem to behave pretty much like in bash. Single quote string get left alone, double quote strings get processed and backticks execute native programs. (I hope I'm not misremembering my bash there)
  • if and while have counterparts in unless and until. Sugar++
  • Sugar++ would not actually work. Sugar += 1 does, however. And I think I like why that is the case
  • Numeric zero and empty strings evaluate to true, which i find pretty disgusting
  • Running in a windows shell I successfully ran into encoding issues for Umlauts. Probably Windows' fault. I hate character encoding
  • Cygwin can install ruby and Umlauts look ok there. Calling the windows ruby executables from inside cygwin, which I tried first, had some really weird issues
  • On that note: mintty still rocks
  • Enumerable has all the nice sugar you can only get via Google's guava in Java. And with blocks it's a lot better readable
  • And you can mix all that into your own classes, with just a bit of duck typing. Very nice
  • All that duck typing really makes me long for some grapes
  • If I understand it correctly, Hashes can lazily evaluate values from keys which reminded me of the guava MapMaker. Also very nice. 
  • Hash.invert seems almost too sugary but could be useful
  • Same goes for String.next. Instant tooth decay!
  • A File API with permissions and methods to create symlinks? I never dared dream of that (although, wasn't there something in that regard in the works with Java, too? About time anyway)
  • IO.readlines/foreach is really handy. Convenient enough to never look at perl again. 
  • The automatic closing of files when using blocks is also nice. Kinda like using() in C#, implicitly. (Wasn't there also something like that coming to Java? I can't remember all the things that may or may not go into the language)
  • I felt pretty clever doing Array.new(16) {|x| x+1} until I saw (1..16).to_a
Code is here.

All good fun so far.