• Sometimes you want to raise an exception when a method fails but without losing information about an inner exception. Let me explain it with an example.

    At Watu we have a method that causes a user to be indexed in our search engine. This method is called many times in different situations. One of those situations is when indexing most or all of our users. Recently, something failed and I got this exception:

    undefined method `each' for #<String:0x10dab8fc>

    Something that should be an array is actually a string. In this case the indexing method is correct, it’s just getting broken data. I want to fix the bug in the data generation, but to locate it, I need to know which user has broken data. I added a rescue clause to my indexing method to show me that data:

    def index
      # ...
    rescue
      raise "Error when indexing user #{self}"
    end

    Now I get something like:

    Error when indexing user #<User:1234>

    which allows me know that user 1234 has something wrong in its data. The problem is that now I have no idea what the issue is. I lost the information about trying to call each on a string.

    The solution to this problem is exception wrapping (or nesting). You want the custom exception to wrap the other one so that you have both pieces of information. This, for example, exists in Java and if you search the web you’ll find ways on how to implement it in Ruby. Implementing this manually is not needed anymore since Ruby 2.1. Unfortunately, it’s a bit hidden and the tools haven’t caught up yet.

    The secret lies in a new method in the class Exception called, cause. At the time of this writing it doesn’t even have documentation:

    No documentation for the method Exception#cause
    No documentation for the method Exception#cause

    Using it is very straightforward. Just raise an exception in the rescue clause and the new exception will have the previous one as its cause. For example, in this case:

    begin
      a = 1 / 0
    rescue
      raise "Something went wrong"
    end

    you get two exceptions: the divided-by-zero wrapped inside one with the “Something went wrong” message.

    The problem arrises that nobody seems to be using the causes of exceptions yet. If you run that in IRB, this is what you get:

    RuntimeError: Something went wrong
    	from (irb):4:in `rescue in irb_binding'
    	from (irb):1
    	from /Users/pupeno/.rvm/rubies/ruby-2.1.0/bin/irb:11:in `<main>`

    But the exception’s cause is in there… hidden. If you catch the outer exception you can access its cause. For example:

    begin
      begin
        a = 1 / 0
      rescue
        raise "Something went wrong"
      end
    rescue => e
      puts e
      puts e.cause
    end
    

    would produce:

    Something went wrong
    divided by 0

    The reason why it doesn’t produce something like that by default is because whatever IRB is using to print exceptions is ignoring the exception’s cause. Now we’ll have to wait until all the tools catch up with this new feature.

    Well, we don’t actually have to wait. Aside from the fact that most of them are open source and you can fix them yourself, Ruby allows you to monkey patch so you can fix your own copy of these tools.

    In my case I needed rake to print inner exceptions, so I wrote this monkey patch (which works for rake 10.1.1):

    module Rake
      class Application
        def display_error_message(ex)
          trace "#{name} aborted!"
          display_exception(ex)
          trace "Tasks: #{ex.chain}" if has_chain?(ex)
          trace "(See full trace by running task with --trace)" unless options.backtrace
        end
    
        private
    
        def display_exception(ex, margin = "")
          trace "#{margin}#{ex.message}"
          if options.backtrace
            trace "#{margin}#{ex.backtrace.join("\n#{margin}")}"
          else
            trace "#{margin}#{Backtrace.collapse(ex.backtrace).join("\n#{margin}")}"
          end
    
          if ex.respond_to?(:cause) && !ex.cause.nil? # Ruby < 2.1.0 doesn't have *cause*
            trace "#{margin}which was caused by:"
            display_exception(ex.cause, "#{margin} ")
          end
        end
      end
    end

    This is something that I would like to see in rake itself so I created an issue request (#253). Take a look at it to follow the development of this feature and hopefully, all tools will start displaying causes in one way or another.

  • Working at Watu I came up with the categorization of products by width. There are products that are wide and products that are narrow. They have different traits and understanding those traits is important. Watu is a wide product. Twitter is a narrow product while Facebook is wider. This is not a matter of complexity or size but a matter of how many modules or independent parts a product has. An example of a narrow but complex product is Apple’s Siri.

    GitHub used to be a narrow product: git repositories. Now it is a wider product: git repositories plus issue tracker, plus wiki for documentation, plus public pages. You can think of more features that GitHub could add to make it a wider product: product management, customer management, etc. Adding those features make GitHub a wider product, while adding pull requests handling doesn’t.

    The advantage of wider products is that they are the all in one solution for more people than narrow products. That’s because people tend to have a wide variety of needs. If your social needs is just sending short messages, Twitter is the all-in-one, but if you also share pics, organize events, form groups, etc., then Twitter is no longer the all-in-one product and you need a wider solution, like Facebook.

    The advantage of being the all-in-one product is that if your users are not looking outside your product they are less likely to jump to the competition. They are also more likely to put up with an inferior solution in one or several aspects because the other aspects make up for it and the seamless interconnection of the different parts of the product is in itself a big plus.

    For example, if Facebook implements a Doodle-like module, it doesn’t have to be as good as Doodle to make me switch to it, because I’m already inside Facebook for socializing and event handling, so also using it for deciding when an event happens is very convenient (Facebook, please, don’t kill Doodle… just buy them if you have to).

    But, there are some dangers to building wide products. Once is that it’s harder to keep focus because you need to constantly jump between modules. If I was to develop Twitter by myself I would be much more effective than if I was to develop Facebook, because I would have less context switching. I believe this point is not true when you have more people than modules so each person or team can keep focus. But when you are a small three-person startup, this is something worth considering.

    Another danger of having a wide product is that, even as a developer, it’s scary to jump outside. At Watu we saw several opportunities to build different products where a customer came with a need that didn’t match Watu perfectly. Every time we discarded it because building a new product and making it as wide as Watu was too much work and modifying Watu was undesirable. The truth is that maybe those products didn’t need to be as wide, they didn’t need all these modules and features, but that fact was very hard to see when we were living and breathing Watu every day.

  • I read The Last Theorem by Arthur C. Clarke and Frederik Pohl and an important part of the plot is the construction of a space elevator. There, the authors explain to you what an space elevator is, how does it work, what are the challenges and even who invented them. Apparently in the 19th century some guys already dreamed (and wrote about) space elevators. I bet it was dreamed even before that, but at any rate, I invented them as well.

    Picture of scaffoldingWhen I was a kid, the house where I lived used to have scaffoldings here and there quite frequently. It was never finished. I grew up playing in scaffoldings and like some kids build a house in a tree, I built it on scaffolding. It was amazing! I loved it. Obviously I started thinking how high could I build a scaffold? With my child’s mind I saw no limit but I realized that at some point, the outer part would pull instead of push and I fantasized about a scaffold that would reach the moon. A bit more than a mere space elevator.

    In my phantasy one would climb the scaffold in a space suit, reach the top and when the moon passed by grab onto it: a small grab for a mind, a giant leap for the scaffolding industry.

  • I doubt any cinemas are going to implement this, because like airlines and banks, they seem to be very bad at making software. Nothing surprising there.

    A few months ago I was searching for a room in London. There are about 4 big sites to do that, so I posted ads on all of them, and searched on all of them. Only one provided a web application that allowed me to see whether I contacted someone already or whether I marked a flat as not-suitable. It made searching so much easier that soon I was using that and only that site. The ads weren’t better per se, but the software was.

    I like going to the movies with friends but I dread having to organize it. It’s such a pain because you have to balance the available time of each people, the timetable of the cinema, the shows in which there are still good seats, the fact that the seats might be going unavailable, and handling the money (I tend to pick the cool but expensive theaters).

    If I was in charge of a cinema, I would make a built-in Doodle. Doodle is an awesome application that helps you organize an event. You select all the desirable dates and times, invite the people, and they respond yes or no to each slot. At the end you pick one and go for it. I thought of setting up a Doodle to organize going to see The Dark Knight, but I ended just picking a date and time that was convenient for me and inviting people. It didn’t work.

    The built-in Doodle could work like this:

    1. I go to the cinemas website.
    2. I buy my ticket.
    3. I pick all the shows I can go to.
    4. Set a deadline (maybe, optional).
    5. I send the invite to all the people that might want to join me.

    Notice that I paid for my ticket before picking the date and time. I’m not sure whether that’s a good idea, I would be okay with that but maybe not everybody. What do you think?

    Then each person that I invited goes to the web site and:

    1. Look at all the dates and times I and others picked.
    2. Buy their ticket or tickets.
    3. Pick the dates and times they can.

    Once everybody is in or I’m done waiting, I pick a day and time and I get all the seats assigned together in one action (even though the action of committing to the movie was individual and asynchronous). For those that didn’t get a ticket or those that changed their mind, they get their money back and/or the option to arrange the same movie, another day, with some of the same group and/or adding other people to it.

    For the cinema it’s a revenue booster. It makes it easier for people to commit to going to the cinema. And even people than don’t manage to go one day are compeled to go another because they already paid.

    Build it with nice Facebook and Twitter integration and that’s it, you’ll be the most popular cinema in town.

  • If I was in charge of GitHub, I would build a team of .NET Programmers and have them built an awesome UI for Git on Windows, bundle it with Git itself as well as other usually needed programs like an SSH client and release it for free. Well, as open source of course.

    The reason for that is that almost everybody that I know that’s using Git is also using GitHub and the number one objection I get to Git is Windows support. I myself chosen Mercurial once before just to be able to cooperate with my Windows-using friends. I think it’s time someone fixes that and I think GitHub has the most to win.

    I know Git can be installed on Windows and that it works. But you need more than that. You need on amazing user experience and Git on Windows doesn’t provide it.

    There are several reasons for that. Running Git in Windows is not as nice as Linux or Mac OS X, period. Even if the support was realyl good, the command line itself in Windows is not on par with Bash… even when you run Bash itself on Windows (which the last time I checked, you had to do to run Git).

    Most important than that is that the Windows crowd are just used to UIs, so the most amazing command line tool won’t stand a chance against the crappiest UI. Windows users just search for another tool when no UI is provided. Even myself when using Windows do that. It’s another world with another dynamic and you have to play by their rules to win their game. And I have to admit, if I had to stop using MacOSX I would miss my favorite Git UI a lot, GitX (L).

  • “J. Pablo Fernández” is not my name, my name is J. Pablo Fernández, but I see the former quite often. For example, as a donor for the L5 series:

    That happens when someone takes the UTF-8 encoded version of my name and re-interprets it as Latin-1 or ASCII. Something that sadly happens very often. Programmers of the world, I know thinking about character sets and encodings make your brain hurt and that’s why you pick UTF-8 and forget about it. But otherwise, if you are handling data, you are using a character set and an encoding. You have to know and understand that. A great place to start is Joel Spolsky’s The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!).

    Oh… the first episode of L5 was awesome, go and grab it. I can’t wait for the next one.

  • In one way or another you can type Esperanto in any operating system without using the x-system (which I really dislike). Of all the operating systems and UIs I used (many!), the one that makes typing Esperanto the best is MacOSX, but you have to configure your keyboard properly first (this is for English based Qwerty keyboards, not sure how it would work with others). You want U.S. Extended:

    To type the pointy hats, you press ⌥+6 (that is, alt or option plus the letter 6) which gives you:

    and then the following letter, g, c, S, G, whatever: Ĝ

    For ŭ is the same, but you have to press ⌥+b to get the other kind of hat:

    and that’s all there’s to it.

  • Since I watched 2001: A Space Odyssey for the first time when I was 15 years old, I’ve been wanting to watch it on the big screen. Last Sunday I realized that dream.

    A little story about why that movie was so important to me. There’s a before and an after 2001 in my life. I think it was the first movie that really challenged my brain. The first movie that when the credits rolled up I asked myself “What the fuck just happened?”.

    It was recommended to me by a teacher, so I went and asked him… without the “fuck” I suppose. He told me that if I wanted to understand it, I’d have to read the book. I read the book and I understood more, but I had even more questions. So I read the next book, and the next, and the next. And by the time I had finished I was hooked into reading science fiction for the rest of my life.

    Back to the topic, context. It’s not an entertaining movie. It’s slow, it’s abstract, it’s art. But hey, even if you watch Alien it doesn’t look like entertainment, it’s slow and looks artistic. Honestly, go and watch it, you’ll see. 2001 was released before Armstrong put a foot on the moon, in 1968.

    Let me put that in context for you. Star Wars wouldn’t come out for another 9 years. Star Trek was on it’s second season and not many people were paying attention, yet. I bet for most people, 2001 was the first time in their lives when they saw outer space in the big screen.

    But 2001 isn’t just another silly space opera (of which the space age was probably full of). In 2001, space is silent, like it really is. How important is that? I watched Firefly just because space was silent. That important.

    2001 doesn’t have some magic solution for artificial gravity, like almost all other movies and TV shows. We have huge revolving space stations as well as spaceships with revolving sections. We see amazing shots of people walking on this curved floors. Or using sticky shoes. We not only see space… we see ourselves, for real, in space. I don’t think I’d seen anything that treated outer space as realistically as 2001, ever. And it happened in 1968.

    Put that movie in context, ignore the long psychedelic scenes (hey! it was the 60s!), and it’ll blow your mind. Context is important.

    I also recently read Snow Crash. When the book started describing a kind of physical virtual reality, with people walking on virtual streets, companies putting buildings on those streets, etc. I was honestly disgusted. I couldn’t stop feeling that the author somehow missed the last 10 years of history when we realised that VRML (remember VRML? Virtual Reality Markup Language) was not the way to go. And then I saw the book was released on 1992 and all made sense to me. Reading it in context was awesome and I enjoyed it a lot.

    Thanks to Daniel Magliola and Romina Roca for reading drafts of this.

  • Most applications, web, desktop or mobile, handle some kind of data. When we are developing them we generally generate some sample data to play with and we forget to ever run the application without it. The problem is that the first impression people will get of our app is without data. And first impressions are important.

    In the application I’m building, Watu, we are resorting to just create some sample data for customers to play with. Making the application beautiful and meaningful without data is just too hard. It seems the guys at JetBrains spent some time thinking of this because RubyMine 4.0 shows this when there are no open files:

    I think that simple change it’s a good step towards making the application nicer in the no-data scenario, making people happier, as well as making people more productive in it, making the application more useful.

    I do wonder why they didn’t include the most useful of the shortcuts: ⌘⇧N. I think I press that more than any other. It pops up this little dialog:

    in which you can type and it’ll search among all your files (and files inside the gems, that is, libraries, of your project if it doesn’t match anything in your project or if you enable by ticking the include non-project files):

    What I really like, compared to other implementations of this feature, is that you can add more parts of the path, for example:

    Without that feature, my productivity would drop a 10%. I’m not exaggerating, that’s my estimation, as I recently have to code using TextMate instead of RubyMine.

    Before you send me the hate-mail, I know TextMate has a similar feature although I think not as advanced (not without plugins at least) but since the key shortcut was different, it was almost like it didn’t exist for me, so I experienced coding without that feature at all.

    Another potentially useful way to find code is to use ⌘N which allows you to search for a class:

    But since in a Rails projects most classes are in a file with the same name (but underscore instead of camel case) and the file dialog allows me to find views, wich the class dialog doesn’t, I never use the class dialog.

    No… I’m not affiliated with JetBrains, makers of RubyMine in any way. I just love the tool and I wish more Ruby programmers would give it a try because I think they’ll also find it useful and the more people that are using it, the more resources JetBrains is likely to put into its development which ultimately benefits me. And they are cool guys, a pleasure to deal with every time I report a bug or ask for a feature.

  • Recently I needed the table of correlatives in pure ASCII form and I couldn’t find it online, so I built it (it took more time that I’m willing to admit):

    ┌───────────────┬──────────┬────────────┬────────────┬───────────┬──────────┐
    │               │ Question │ Indication │ Indefinite │ Universal │ Negative │
    │               │ ki–      │ ti–        │ i–         │ ĉi–       │ neni–    │
    ├───────────────┼──────────┼────────────┼────────────┼───────────┼──────────┤
    │ Thing -o      │ kio      │ tio        │ io         │ ĉio       │ nenio    │
    ├───────────────┼──────────┼────────────┼────────────┼───────────┼──────────┤
    │ Individual -u │ kiu      │ tiu        │ iu         │ ĉiu       │ neniu    │
    ├───────────────┼──────────┼────────────┼────────────┼───────────┼──────────┤
    │ Reason –al    │ kial     │ tial       │ ial        │ ĉial      │ nenial   │
    ├───────────────┼──────────┼────────────┼────────────┼───────────┼──────────┤
    │ Time -am      │ kiam     │ tiam       │ iam        │ ĉiam      │ neniam   │
    ├───────────────┼──────────┼────────────┼────────────┼───────────┼──────────┤
    │ Place -e      │ kie      │ tie        │ ie         │ ĉie       │ nenie    │
    ├───────────────┼──────────┼────────────┼────────────┼───────────┼──────────┤
    │ Manner -el    │ kiel     │ tiel       │ iel        │ ĉiel      │ neniel   │
    ├───────────────┼──────────┼────────────┼────────────┼───────────┼──────────┤
    │ Quality –a    │ kia      │ tia        │ ia         │ ĉia       │ nenia    │
    ├───────────────┼──────────┼────────────┼────────────┼───────────┼──────────┤
    │ Amount -om    │ kom      │ tiom       │ iom        │ ĉiom      │ neniom   │
    └───────────────┴──────────┴────────────┴────────────┴───────────┴──────────┘

    I used the DOS box drawing characters and only single lines. Double lines in some common fonts were broken. And the beautiful Unicode box drawing characters were broken in several fonts.

    If you admire the table of correlatives as much as I do, maybe you want to buy some schwag with it: http://www.cafepress.com/correlatives (disclaimer, I’m selling that stuff).

    Isn’t this a great notebook to take to your Esperanto lessons:

    Not allowed during exams