What is wrong with Ruby

Wednesday, 16 December 2009, in categories: Programming, Ruby

After using Ruby massively for a few years, I think I have now enough understanding to finally see its main flaw. As a starting point to try to see it too, consider mentally splitting the Ruby language into two parts - “programming part” and “metaprogramming part”. This is of course a fully artificial distinction, as in reality they are closely tangled together, but I find such an attempt a useful experiment.

What I would consider a part of Ruby’s normal programming features are the things programmers who ship end-user applications use everyday - classes, objects, methods, loops, variables etc. The metaprogramming features are what is mostly used by people who build applications for other programmers, but normally not by the “average Joe”, so the techniques behind things like Rails, RSpec, Rake, Rack and other major Ruby frameworks and libraries. Much of the appeal of those projects lies in the elegance of the languages they make available to their users, making it easy to describe solutions to problems the given framework is targeting. The specific features I have in mind are things like metaclasses, instance_eval, class_eval, method_missing, alias_method an so on, all hidden behind an easy to use abstraction layer. more >>

An open platform for publishing applications

Tuesday, 24 November 2009, in categories: JavaScript, Programming

HTTP, HTML and CSS are inadequate for developing complex end user applications that have hard latency requirements, depend on more sophisticated input-output facilities or need to integrate closely with the clients computing environment. Examples include games, multimedia or attempts to reproduce modern desktop applications on the web.

The failure to deliver browser-based applications in those domains is in my opinion caused by:

  • the weakness of the request-response scheme of HTTP as a basis for a programming model - it works well for the operations on hypertext documents it was designed for, but it is a poor basis in almost all domains that do not naturally deal with documents, especially those requiring sending excessive amounts of information back and forth
  • poor capabilities of the browser itself - what is being made available to the programmer is insufficient for any kind of more sophisticated development, as no access at all is given to important parts of the user environment - neither to the hardware (graphic cards, sound cards, video cameras, gaming devices) nor to the software resources (files on the client computer)

Many technologies were created to deal with the two problems. AJAX, continuations-based web servers or Comet were attempts to workaround the first issue, but they all have been built on top of the flawed model, while also suffering problems with the web browsers, without trying to directly fix them. The second problem was meant to be solved by the likes of Flash or Silverlight, which do not integrate well with the rest of the web (for example search engines), making it questionable why do they at all run inside the web browser, experiencing efficiency and stability issues. Java the platform was the closest to what I want to propose, but even through it had the necessary pieces, it wasn’t clearly steered in this direction and suffered from slow start-up times, slow and ugly GUI tool-kits and weaknesses of Java the programming language.

The author is seeing much potential in an integrated attempt to solve both of those problems with a new set of standardized technologies. We already have excellent protocols for hypertext, efficient file transfer or sending messages, why shouldn’t a protocol for sharing applications exist? Links could be put to apps://musicplayer.com/ on traditional web pages in the same way as links to e-mail addresses or file servers, leaving the browsers with what they do best - processing documents.

The proposed solution that will be described here is called OAPP, standing for Open Application Publishing Platform. The following things should be specified as a part of OAPP:

  1. A virtual machine of predefined capabilities running on the client computer
  2. A way of sending executable computer programs to the virtual machine from the server
  3. A way of singalizing events on the virtual machine to the server
  4. A programming model based on points 1, 2 and 3

more >>

Proel - Project support for Emacs

Sunday, 14 December 2008, in categories: Emacs, Programming

One of the most fundamental features that Emacs is missing among all the goodness available for programmers is the support for handling software projects ie. the way TextMate or IDEs does this. Not having a quick way to navigate between files, classes, methods and other symbols starts to significantly suck if you’re working with bigger bases of source code. Because of this, a year or two ago I rolled two screen pages of Elisp or so, to make the basic operations I want to have available project-wide available. It served me very well ever since than, but it was a dirty hack and I really didn’t knew much Lisp at that time. Recently, seeing some other attempts at solving this problem, I decided to cleanup and extend my solution a little bit and make it available for the general public. So the proel package was born. more >>

Metaprogramming Ruby

Saturday, 19 April 2008, in categories: Programming, Ruby

On this year’s RuPy I gave a talk about Metaprogramming Ruby. Unfortunately I didn’t have the time to prepare the presentation exactly the way I wanted, nor did the organisators gave me enough time to present what I wanted to present. Anyway, I made some changes to the slides, which are now of some value on they own I believe, so I put them here for everybody to enjoy. Things covered include: Ruby’s object model, differencies between instance_eval/class_eval, hooks, reflection, wrapping methods, DSLs, Higher-Order Messanging, getting the parse tree from Ruby code and vice versa, and so on. There is also a nice resources section, where you will find the gems I found across all the available material about the topics covered, and from which I’ve picked up a lot of really interesting meta-ideas. If you find any errors, please let me know, this stuff is really fuzzy, and I really want to have it covered in a clear and precise way.

Despite the quirk with my own presentation, I really enjoyed RuPy as a participiant and I think it’s a great event. Zed Shaw had a really nice presentation, with some funny bits, but also with many things you can pick up and use weeks after the conference ended. I also liked the talk about PyPy by Carl Friedrich Bolz, even through I’m a Ruby guy - they really have some interesting ideas about compiling/interpreting dynamic languages and they made a hell of the effort to push it forward. I hope I will be able to visit Poznań again the next year and I encourage you to do the same too.

Erlang, the functional Smalltalk?

Saturday, 1 December 2007, in categories: Erlang, Programming

Let’s start with a confession. I’m not a Erlang weenie, I’m not even a decent part-time Erlang hacker. But for some reason, I keep coming back to it, even through I don’t normally work in the problem domain I think Erlang is best suited for, like servers of various kinds (from MMORPG games to Jabber), or large scale, distributed applications. But in this case, it works differently - I keep coming up with problems that could be nicely solved in Erlang, instead of matching the language to the problem.

I wrote about the great fun factor of programming in Erlang before, but I didn’t quite get the reason this is the case. Now, after thinking about for a while, I think I know what Erlang does so well, that it makes programming a joy. more >>

Html generation in JavaScript

Sunday, 10 June 2007, in categories: JavaScript, Programming

I started playing a little bit more with JavaScript recently, and one thing that bothered me was generating HTML. For example, if you have a AJAX application of any reasonable size, it probably has to change a lot of stuff inside of the various divs or other elements as it runs. For that, you need to write a lot of ugly-looking, long-running string concatenations. So, I took an idea used by the Lisp folks or in the Ruby Markaby library and I created a library to write HTML in JavaScript. I’m not sure if I’m the first one to come up with this, but my Google-fu failed in this case, so maybe… Anyway, with my JsTemple you write something like this:

$table({cellpadding: 10},
  $tr(
    $td(
      $div({klass: 'container', id: 'main'},
        $h1('Foobar'),
        $h2('Foobar2'),
        $h3('Foobar3'),
        $h4('Foobar4'),
        $h5('Foobar5'),
        $div({id: 'layer', style: 'border: solid 3px #f00; padding: 10px;'},
          $p({klass: 'foo'},
            'foo', $strong('bar')),
          $p({klass: 'shmoo'},
            'shmoo'))))));

And you get this:

<table cellpadding="30">
  <tr>
    <td>
      <div class="container" id="main">
        <h1>Foobarh1>
        <h2>Foobar2h2>
        <h3>Foobar3h3>
        <h4>Foobar4h4>
        <h5>Foobar5h5>
        <div id="layer" style="border: 3px solid #f00; padding: 10px;">
          <p class="foo">foo<strong>barstrong>p>
          <p class="shmoo">shmoop>
        div>
      div>
    td>
  tr>
table>

I generated the necessary data about tags / possible properties from HTML 4.01 W3C specification, so all the tags should work and invalid properties should be ignored. “Should”, because the generating was a little bit tricky and I’m not 100% sure if everything is the way it should be. The dollar sign is a bit annoying, too, but my goal was to avoid cluttering of the global namespace, especially a variable name like “i” may be quite popular… I don’t know how it works performance-wise or memory-wise either (certainly some optimizations are possible), but it seems to work under Firefox, Opera, Konqueror (Safari?) and MSIE 6/7 and it even doesn’t crash any of them in a short time, what I consider a big success. I don’t really know if this is useful at all (most people don’t seem to like balancing parenthesis or don’t know a decent editor which highlight pairs of matching parenthesis, judging by Lisp popularity), but you can grab it here. To start using it simply include the js file using

One more tip: keep in mind that jsTemple just returns a string, so you can for example use it with Prototype’s Template class.

Guerilla Computing

Saturday, 2 June 2007, in categories: Emacs, Getting Things Done, Lifehacks, Linux

The title mem spawned in my mind as a result of two things. First, I finally tried a tiling window manager, after many people recommending it to me throughout the last year or two (most recently in the comments to “My Linux Stack”, thanks Torben!). Secondly, I didn’t have too much time recently to play with my setup, having high school final exams and getting back to work, so I found 900mb of updates waiting for me in portage.

Now, 900mb is a lot. A few years ago I had a pretty complete and useful Slackware setup on my old computer weighing 900mb. I choosed packages by hand, I used some advice from the Saving Space HOWTO, made ruthless decisions about what software I need and what not. Now, I have 12gb filled up on the partition with Gentoo. I wonder how much of it is garbage. I decided I don’t want it this way anymore and I don’t want to spend that much time on keeping up to date with the software, upgrading packages, fiddling with this stuff etc. more >>

Erlang For The Practical Man

Wednesday, 9 May 2007, in categories: Erlang, Programming

Table of contents:

1: General overview

3: Fighting with POP3 / SSL
4: Serving the thing through HTTP
5: Putting the pieces together
6: Conlusions

This article is my submission for the Erlang blogging contest. You can also grab it as a PDF file - in a4 format or in letter format.

1: General overview

Functional programming languages are often underestimated, as they seem to be not suited for the “real world”, being thought of as designed by scientists who spend their time mainly developing theories, not practical software. What makes Erlang stand out from the crowd is the fact it was designed by the industry and for the industry. Ericsson, where the language originated, has a telecom switch with more than 2 million lines of Erlang code running it that has a downtime of a few minutes per year - now this is reliability!

Telecom switches don’t make programmers too excited those days through, so we will try to do something more related to your everyday hacking. In this tutorial I will show you how to write a standalone daemon, that checks your email every x minutes, and makes the results available as an RSS feed. If you want to centralize all your notifications around RSS this may even be useful a bit and even if not, at least it makes a good example of some of Erlang strengths. I try to explain everything in as much detail as possible, but be warned - we won’t be writing any “hello worlds” here, we will just rapidly introduce a lot of awkward stuff as it becomes necessary, so if you don’t have a solid programming background you may have serious trouble. Either way, you will probably want to consult Programming Erlang and the free, official Erlang docs if you want to do anything serious in Erlang. Also see my previous post for an overview of general high level Erlang concepts. more >>

Having Fun With Erlang

Monday, 12 March 2007, in categories: Erlang, Programming

It seems that the times when programs run sequentially using one main processor are finally getting to an end… Not only more and more computations get so complex you need to use a whole network of computers to do them, not only computer clusters are increasingly popular, but also our own home computers finally have become somewhat “parallel”. As we reached the border where we can’t tune the processor frequencies so much, chip vendors seem to look for hope in multi-CPU, multi-core circuits as in Intel Core 2 Duo for example. This has multiple benefits, but also raises one big issue - the troubles with writing programs that use the multiple chips or even multiple computers efficiently. At the same time, the Web still grows, and we have more and more systems where hundreds of thousands of people interact with the software in real time (examples vary from MMORPGs to web servers).

more >>

Language of the gods? C.

Sunday, 18 February 2007, in categories: Programming

When you look at popular articles/posts about programming in the last few years, one topic comes back over and over and each time its extremely popular - the “enlightenment” that comes with learning Common Lisp, Scheme, Haskell or sometimes yet another not-so-mainstream language like Smalltalk. Recently people started even bragging about the “language of the gods”. I think the thing that started the buzz was the “Howto become a hacker” text. But I didn’t seen any particular too much wonderful Lisp applications written by ESR…

After thinking about it for a while, come on, it’s total bullshit. Someone can conclude from those articles that learning macros, continuations, monads or whatever will turn one into a alpha programmer, or a super-human. Yes, those are all interesting concepts, they stretch your mind, you get a better programmer as you learn it. I greatly appreciate it and I try to learn things like that myself all the time. But don’t get trapped into believing that this is THAT important - there are other as important or even more important fields no-one is blogging about. Its also a lot like saying that just getting a new guitar will make you a better guitarist. The language is just a tool, maybe it’s time to stress more other topics like problem solving techniques, good design skills, which are current all the time.

more >>