Language of the Month: Lua

New month, new language. So far in this series:

I think I do want to amend the original rules set up for this Language of the Month series. At first I though I can write a new project in any language I learn. That is probably too ambitious. So new rules: every month write a new project in the given language OR contribute to an open-source project in that language. This should take away most of the stress and add some social aspect as well. :)

Lua

I’m intrigued by this language because of it’s niche: scripting language within other software. How one sets out to do something like this? What are the requirements for the language, in terms of design, syntax and so on?

Lua programming language logo
See, the moon!

First impressions

So far I was trying out some code snippets and example scripts. First thing to notice was that Lua is pretty darn quick to start. And pretty quick to run as well, though I haven’t used it for very heavy computation yet. E.g. the “get_all_factors” code at the Lua Crash Course (using a larger example number, 1029384756) is timed at ~7ms, wheres the same version on Python (the language that I probably know best and compare other languages to) runs ~10x slower. The snappiness of a scripting language is a surprisingly happy feeling. :)

Tables look very interesting, how the same thing can implement several data structures at once (it’s like Python’s dict, list and kinda-struct at the same time).

Quite intriguing that the Lua Virtual Machine is stack based, probably that’s the reason the language is so embeddable. A while back I was looking for a language with small resource (especially memory) requirements. I had a few suggestions (Dalvik, Forth) that were interesting, but maybe Lua is the one?

The “local” keyword (and the reasons for having it) seems to be a possible source of many harder to debug scenarios. Got to keep this in mind, again not being in Pythonland anymore.

Interesting how the “function” can be defined inline, so looks like there’s essentially no need for a special “lambda” keyword, at the expense of tying a few characters more…

The interpreter is quite well done (with it’s intelligent indentation probably even better then ipython, though would love to see more colours ^^)

As an exercise, here’s a version of FizzBuzz:

Links

This section will be updated gradually as I find more information.

(Edit: added the second part of this experiment.)

Install

Tutorials

Books

Articles and info

Source of code

Projects using Lua

Language of the Month: Scala, part 3

This is a post I should have written yesterday, actually, since it is already June, ready for the next “Language of the Month“. Still, let’s finish off this May Edition.

Taking score

First, I should have spent more time on practicing Scala, as I haven’t actually finished anything in the end. It is probably an excuse, but after using Python for such a long time, getting used to a compiled language with its own weird path-, naming- and import conventions, was just a little bit too much. Mostly I was reading the Pragmatic Bookshelf: Programming Scala, practicing the examples within. That book uses Scala 2.7.x and the current version is 2.9.0.1, so there are a few things that work differently and I ended up having strange error messages with little to no clue how to fix them (mostly imports, and some method signatures must have changed as well). So it was a limited but exciting success.

Scala screenshot
Using them example code

All in all, I liked the language even if I don’t have a clear usage case for it in my mind (just yet). Some bullet-points of my experience:

Good

  • Different way of thinking about “batch” operations (i.e. foldLeft)
  • Once I figure out the Actors that well that I can write related code without referring to the tutorials, that’s going to be a very powerful tool
  • Pattern matching, pattern matching everything. This is one thing that blown my mind in the little Haskell I checked so far, and missing from Python a lot.
  • Flexibility with class definitions, they can handle so many different situations in a very logical and powerful way

Bad

  • Length of compilation and program start. Will have to get used to it, though I read some hints that this can be improved.

Ugly

  • Pretty frequent need of using things directly from Java, so one is never quite independent
  • Special methods that have reserved name for certain functionality (act, apply, …) that are non-obvious, and not easily distinguished from the arbitrarily defined methods.

Future

Definitely will come back to it and learn it in more detail. It looks like a fine language to do parts of larger projects in. In the meantime I will update the link collection in the previous post with new links that I find. I certainly notice more and more Scala posts on Hacker News these days.

Language of the month: Scala, part 2

For the last 3 weeks or so I was checking out Scala, and will do for a little while more, so just want to do a little catch up where things are at the moment.

Start

I tried to find a couple of starting points to start to know about Scala. First thought video tutorials or talks would be useful, so been around checking on YouTube. It seems the mainly referenced intro is Scala: a scalable language. Well, it told me a lot about how Scala compares to other languages and how is it better than those, but not much to start learning it. Though the talk made it sound like it is one of the best and most modern languages out there, taking the most useful ideas from loads of other languages.

Had a copy of the Pragmatic programmer: Programming Scala, and just finished going through it. By that I mean that skimmed all the chapters and did try some of the code samples that looked interesting or strange. Not bad, but from the book I just have a very limited answer to the question of: “but what is it really great for?” Concurrency, sure, but that is probably not all.

I don’t know a language before I code enough in it, but before I know it I don’t have to much inspiration what to code. In this case, programming puzzle sites come very handy, though not all of them support Scala. I went to Coderloop because they do and I can submit my solution for performance testing, or could use Project Euler because they are language agnostic (one sends the results only).

Experience

Since Scala is built upon the Java Virtual Machine and supports pretty much all of Java, it feels a little Frankenstein language: every now and then, even for some things that should be quite commonly used, things have to be programmed in Java. Lots of language features are cool, though, even if most of it feels just syntactic sugar. In a way, maybe the whole language is just that? It’s not bad, makes things very concise and powerful, but always feels there’s something more in the background.

Actors and concurrency are pretty cool, though. In the talks I’ve seen people compared them to Erlang, just even more powerful. This is something more to play around with, would like to make something interesting, scalable and fault-tolerant – those are the fun stuff aren’t they? (But this also makes me want to try Erlang soon so I can compare).

Since I was doing mostly Python lately, it feels a bit weird to use a compiled language. For simple programs, it takes quite a long time to do that compilation, enough to wind me up a little when I was troubleshooting. That said, maybe I’m doing a little bit too much “programming by accident“, so I deserve it? Also, starting a Scala program takes a while as well, though once it is up and running, it’s pretty fast.

At this point, I’m not totally sure yet what project to make until the end of the month. I need more programming itches to scratch. The only ideas I came up so far are self-playing games with actors. Or some server/provider. Well, just keep brainstorming, something better has to come up. Maybe when I dive a little bit more into it, since at the moment I cannot really “think Scala” yet.

There’s also a web framework for it, called Lift, which is probably not surprising. The close connection wit Java (and hence with so many of enterprise software) and event based, fault tolerant concurrency is just too juicy. Not sure if anyone’s hosing it, tough (got to check out), either way I can just try it on my local network. I wonder how does it compare to Django, since that’s what I have a bit of experience with.

Links

Information

Example sources

Companies using Scala

Others writing about Scala

(Last updated: 2011 June 23)

Igniting Taipei

A few weeks ago with a couple of friends we started to organize the first Ignite Taipei. There’s still 5 weeks and a bit to go, but it has already been a fun experience. In many ways, starting a community feels very similar to how doing a startup would feel (I imagine). No surprise there, the startups I would want to create would want to have a great community. :)

So far it is mostly about choosing the place, the time, starting to invite people, keeping in touch with them, building involvement by others and keeping those “fans”. It’s shaping up nicely, but there’s a lot more to go, we are not ready yet.

Another connection I found with doing an business: the best way to build up one’s own enthusiasm is to be as closely involved as possible. I keep watching Ignite videos on YouTube and sharing them. Writing a blog about what’s going on. Talking to people about it and see what they are interested in. Since at the actual event I think I will be managing the technical issues, there’s one thing I haven’t thought about before: what kind of talk would I give? How would I use my 5 minutes / 20 slides to have an impact? Unless I know that, I cannot really recruit speakers well, cannot help them effectively and would miss out on the core of the things. Also, it does help to exercise my idea muscles [1].

Ignite talk brainstorming
What _else_ to talk about?

Here’s the copy of the brainstorming I had today while I was waiting for my lunch:

  • 30 day challenge: take different bus route I haven’t taken before
  • 100 uses of measuring time
  • Hungarian for dummies
  • Comparative tea-ology
  • Feynman’s spaghetti-braking experiment
  • “How to measure the high of the lighthouse with a barometer”
  • Camino de Santiago
  • Organizing Ignite
  • Geocaching
  • Version control systems for fun and profit
  • Rejection Therapy
  • Startupbus
  • Everyday physics
  • A very short introduction to <insert author’s name here> (e.g. Palahniuk, Vonnegut, Beckett)
  • Kitchen in a pot: the electric rice cooker
  • Long distance travelers of ancient times
  • 100 uses of a wiki
  • Open-source hardware
  • Movie stars’ movies before they became really famous
  • All those different ways of brewing coffee

These I think fall into two categories: things I know a little about, and things I know too little about but would use Ignite as an excuse to learn more. Actually, since I wrote up this list more ideas keep flowing in and I think I will have to prepare some of these, even without a plan to show them to anyone: why would one need an excuse to do something awesome?

Any more ideas to talk about?

[1] “Idea muscles” come from James Altucher, one of my favorite blogger/writer lately. It is the habit of being creative, or by his word:

Every day I write down ideas. I write down so many ideas that it hurts my head to come up with one more. Then I try to write down five more.

I’m not that good at this just yet. The list above is as long as it is because that’s where my page got full. Not as if there are no 97 other, empty pages in my notebook… Maybe I’m too pain averse, but got to overcome that. I actually long for the feeling of doing as many ideas that it hurts thinking more…

Social networking exit strategy

This is the kind of thing I read so many times on Hacker News: someone manages a “page” on Facebook, only to have it disabled/deleted one day, out of the blue. The difference is that this time it was the page I was managing.

A few years back I took over the page for Inkscape, and updated it every now and then. Quite enjoyed it and even a relatively small following (3774 at the last count I had) people were very active. Then this week once when I logged in and wanted to send out an update – I just couldn’t find the page. Disappeared from the search, from the control panel, everywhere. I could only see the page that was created from its Wikipedia article, and there was the Inkscape “group” which is much smaller.

Inkscape
Draw up some good stuff with Inkscape

I was looking around for a long time for a support contact, and there was practically nothing. It’s a hell of a challenge for coming up with Google search keywords because there’s just too much noise for Facebook + support related terms (that’s a pretty bad sign). In the end I go to this form, that supposed to be used to report problems with a page. Too bad half of it I couldn’t fill out. What is my page’s web address? I don’t know, it was “on Facebook”. What happened to it? Have no idea, I haven’t had any notice about it. Attach a screenshot. I wish I could but did I mention that it disappeared? Anyway, after submission I’ve been told that I’ll receive an email and it is crucial to act on it, otherwise the procedure won’t go forward. That’s been 4 days ago, and no email since.

Contingencies

By now I have given up on getting it back, it’s just does not worth the effort. On the other hand, I do have another page, Ignite Taipei which we manage/organize together with a couple of friends. That would hurt much more if that would disappear, especially because there’s not much presence elsewhere on the net just yet.

Strange, but actually this whole issue bothers me much less than it would have about a year ago, even if I got locked into Facebook even more. Maybe I know now better that shit will always hit the fan, whatever you do, just have to be prepared for it.

Sometimes it's time to leave
Please exit in an orderly fashion

So, how about extending the idea of the World Backup Day to social identities? How can I prepare to lose the least in case my pages or even my profile gets blocked/hacked/deleted?

  • The personal information is the most valuable, who are my friends and how to reach them. Should write a script that can run somewhere in the background, backing that info up periodically. At least names and emails. Maybe even import them into GMail contacts right away…
  • Establish links with people outside of Facebook. I already use email instead of Facebook messages whenever I can, now I have to extend that really to everyone.
  • Build a proper site / blog for the pages I’m involved with and make people aware of it. Always have a point of contact outside of FB.
  • …. what else did I forget? (leave me a message in the comments if you have more idea)

Why Facebook?

Do I ever fret that Google might block me? That Tumblr would delete my stuff? That Twitter removes my account? Nope, didn’t even really occur to me, they are “not like that”. On the other hand, the power Facebook has over online identities makes people cringe. Why are they different? I feel it’s because they not at all transparent in their decisions and also quite arbitrary. Too many innocent were punished to go unnoticed, and every decision is final. Unless of course one is so big like Ars Technica who had contacts within the HQ.

I was reading an article lately how Facebook want to manage their growing pains algorithmically: more math instead of more people. To me that means that there will be just more arbitrariness and even less transparency…. I wish if instead they would have more support people and start to clean up the mess instead. But of course, if I’d know how to manage Facebook, I would have invented Facebook. :)