• Ruby on Rails has a special object called flash which hold its contents for one more request. It’s particularly useful to show messages after a redirect. Since it’s good style to redirect after each succesful form post, that’s where you put the messages such as: “You’ve logged in”, “Thank you for your feedback”, “The book has been added”, etc.

    This flash object looks like a hash table. I normally use two items in there: notice, for good stuff and errors, for bad stuff. I want these messages to be displayed in all pages, so whenever something bad or good happens, I just drop stuff in the notice or error and forget about it. This is trivial to do, I just put this:

    <% if flash[:error] -%>
      <p class='error'><%=h flash[:error] %></p>
    <% end -%>
    <% if flash[:notice] -%>
      <p class='notice'><%=h flash[:notice] %></p>
    <% end -%>

    on the application layout.

    The problem with doing that is that it doesn’t look nice. I expect error messages and success messages to be near the forms or UI elements I’m interacting with. That means that every view or page will put it in a different location. No problem, you just add that same snippet where you want the messages to appear.

    Then there’s a second problem: you get messages twice. If you remove them from the application layout, then you have to remember to put in absolutely every view, even those that you don’t expect to never show an error or notice. I don’t trust myself to always remember to do anything, so what happens is that I can’t just drop something in the flash and expected it to be show, I have to check every time.

    I’m doing this in for a pet projects with less than 10 views, but I think big. I think of the project having 100 views and three coders than don’t know all the implicit rules, like adding the display message snippet to every view they create.

    I’ve came up with this solution. I created a partial view with this content:

    <% if not @messages_rendered -%>
      <% if flash[:error] -%>
        <p class='error'><%=h flash[:error] %></p>
      <% end -%>
      <% if flash[:notice] -%>
        <p class='notice'><%=h flash[:notice] %></p>
      <% end -%>
    <% end -%>
    <% @messages_rendered = true -%>

    That partial view is rendered from the views and also from the application layout, but it displays the messages only once. Thankfully Rails renders the partials inside the views first, so that the messages gets displayed according to the view, and if the view didn’t display them, the application layout will.

  • For showing what music I like, keeping track of what music I listen to, discovering new music and finding people with the same tastes I use last.fm. For doing that but with books I use aNobii. Is there anything like that for movies? If not, there’s a market.
  • Docking stationThe post-PC era is when we stop having PCs because we move to something else. You may think that’s unlikely and unrealistic but look at the evidence. At one time we had desktop computers and laptops started to appear. They were just toys for people with lots of money, then they became the second computer of people that spent a lot of time on the go, today most people own a laptop instead of a desktop computer.

    The exodus from the PC is not going to be that easy, because the mobile devices are more different to a laptop than laptops were to desktop computers. But it’s not only leaving PCs for smart phones, also for netbooks. I believe it’s going to happen. Probably not as extreme as the PC to laptop but it’s going to happen. We’ll be using our phones as our primarly way to access data and communicate. And when we come home we’ll plug it in a dock station -that already exists-, so that it can use our nice big speakers -that also exists- and so that we use an external keyboard -that exists in many cases- and a big external screen -that exists, at least in the netbook market-.

    What doesn’t exist yet, I believe, is external processing. When I’m at a bar I won’t play Halo and I’m OK if switching between applications is slow, but when I come home I want my device to become faster. I have seen absolutely no progress at all in being able to add processing power to a machine, to a portable machine. The closer I’ve seen were docking stations, probably IBM, which added better sound and video cards. Sharing processing power is hard, but I think we need it to go mobile.

    Reviewed by Daniel Magliola. Thank you!

  • This can unleash so much hate mail, but here it goes, my inbox is ready!

    Are dynamic languages just a temporary workaround? I’m not sure! I’m switching between the two types of languages all the time: Java, Python, C#, JavaScript. I’ll try to make the long story short.

    Statically typed languages, like Java and C#, are nice because when you do

    blah.bleh()

    you know that blah’s class has a bleh method, at compile time. But better than that, when you typed “blah.” you get a list of methods, and you already know whether there’s a bleh method or not, and if you typed bleh and it doesn’t exist, the IDE lets you know, no need to wait for the compiler. Also you can do very deterministic refactoring, renaming all “bleh” for “bluh” for example.

    Statically typed languages are not nice because they are very verbose and require a lot of boilerplate (if you’ve used Haskell, just bear with me for now please), so you end up with things like:

    List[Car] cars = new List[Cars]();
    foreach (Car car in cars) {
        car.Crash();
    }

    How many “cars” do you read there? And that’s a nice example. There are worse. So come dynamically typed languages and you can write:

    cars = []
    for car in cars:
        car.crash()

    You have less cars, and less (no) lists. That means you are more productive. You start chunking out code faster without having to stop and think “What type of object will this or that method return?”. But crash() can crash your application instead of just the car because you can’t know if it exists until run-time. That might be OK or not, testing and whatnot.

    Then comes C# 3.0 where you can do:

    var cars = new List[Car]();
    foreach (var car in cars) {
        car.crash();
    }

    And you can see that syntactically it got closer to Python, which is what gives you the productivity. Don’t know the type? type “var”. But semantically, it’s still statically typed, like the previous statically typed example. You know that car is going to be of some class that has a crash method. You can actually know car’s class at compile time, no need to run it.

    That’s called type inference. You don’t have to specify the type where the compiler is capable of inferring it for you. C# type inference system is still very limited (but better than Java’s). Let’s see an example in another language

    cars = []
    map crash cars

    That means, create a list called cars, call the function crash on each car. Would you say that that is a statically typed language? or a dynamic one? I’d say it is dynamic, but it is static. Very static. It’s Haskell. Haskell’s compiler will infer all the types for you. It’s amazing, you’ll write code as robust as with C#, but as terse as Python’s (Monads will then kill your productivity, but that’s another story).

    In Python 3 you can define types for arguments. They are mostly useless, but it’s an interesting direction. I think the best it can do is that when a program crashes it’ll tell you: “function blah expected an int, but got a float, not sure if that was the problem, but you might want to look into that”.

    Now, my question is, are dynamically typed languages just a temporary workaround? As our compilers get better, our computers faster, will statically typed languages keep giving us as many or more reassurances about our code and utilities while at the same time they become as simple and terse as dynamically typed languages? Or will dynamically typed languages start to gain types and over time be more static without the programmers that use them ever noticing?

    My question is, will we in the future, 50 or 100 years, look back and said “Dynamically typed languages where a temporary workaround to statically languages being painful to use when human beings and their toy computers were so primitive?” in the same way we can say today that “non-lexical scope was a limitation we had and have due to the limitations of computer hardware 30 years ago”.

    Reviewed by Daniel Magliola. Thank you!

  • cakeSeth Godin wrote an interesting blog post titled “Two ways to build trust” in which he says that, to gain someone’s trust, you have to either be very professional, or very human. You are either like Apple: everything just works because they are super professional, or you are Joe the Baker who would make a custom cake for you.

    The problem is when you try to be like Apple and stuff doesn’t work or you try to be like Joe and your cake says “Made in China”. I’ve never thought about it consciously, but I’ve felt it, and it makes perfect sense.

    I was using an application in my Android phone called BeyondPod. It’s basically a podcast grabber. I liked the application and I wanted to buy it. I was using a limited version. They offer you two ways to buy: through the Android Market, the usual way; or if you live in a country where the paid applications are not available, like me, you could buy a license on the web site. That’s very professional.

    Also the application is quite good. So that was another hint that the maker was a very professional team.

    When I was ready to buy I went to the web site and it looked so 1998ish. Oh-oh. Not good. I’ve looked for a way to buy outside the Market and I’ve found two. Buying it on-line and paying with Paypal or using an alternate Market. The Paypal link didn’t work. Double oh-oh. That alternate market was hard to use, so I’m not totally sure if this is correct, but it seemed the application was not there. Strike three?

    By this point, I’ve already tried to buy the app through several days, failing each time and just going back to whatever I was doing before. The only thing that kept me coming back was that I was using the app, liking it and wanting the unlimited version.

    There was no contact address for support. One day, fed up, I signed up in their forum and said “I want to pay! How?” I wasn’t expecting any answer really, but about 42 seconds latter came a reply “Oh, the link was broken, try again.” That looked like the developer of the app, although he never mentioned that. That’s good. It may not be an Apple, but a Joe the Developer.

    I went to the site, clicked on the Paypal link and was redirected to another web site, a Paypal-clone. That’s it, too much. I’ve dropped a bomb on the forum: “I’ve clicked the paypal link and it sent me to another web site, looks very scammy, I’m not putting my credit card number there”. And I proceeded to search for another podcast reader.

    4.2 seconds latter came “My apologies, that’s my fallback merchant account, the Paypal one is working again”. Having a fallback account? That’s very professional. I know many companies working with Paypal, moving thousands of dollars, and not having a fallback transaction system. In a sense, this guy showed a lot of professionalism in some respect, and being a human being willing to solve the problems for the parts not very well done. I paid right away.

    I almost lost my faith in the product and company, but the owner wasn’t afraid of acting like a little company and that bought me over. I don’t expect a podcatcher for a niche platform to be developed by a corporation full of things with “Enterprise” in their names. I expect it to be developed by a guy on a basement and that doesn’t mean I won’t pay for it.

    Reviewed by Daniel Magliola. Thank you!

  • other-doorOf all the bad practices I see on the web this ranks as very bad and I believe it’s not mentioned enough. It’ll easily make it to my personal top 5.

    I go to a web site, like example.com, and I immediately get redirected to an ugly URL beast, like example.com/news/today?date=2009-06-30&GUID=5584839592719193765662.Wha? Why? First, the site broke any chance I had of making a bookmark of it with just one click. I don’t want to bookmark yesterday’s news (look at the URL, it has a date), and what’s that GUID? Oh well, I go and make the bookmark, pointing to example.com, by hand, because I have no other way.

    Even if it only redirected me to example.com/news/today it’d be pretty bad. That URL may not work tomorrow due to changing software. Or what can be even worse: the software and the content get revamped, the URLs changed and everything is cool again, and since the developers are smart people they leave old URLs working. So my bookmark works, but shows obsolete information.

    With my crazy browsing habits (open a trillion tabs, fast, fast, faster) I go to a page, leave it loading, and when I go back and see a weird URL I end up wondering whether I accidentally clicked on something or something weird happened. I have to go back and check.

    It gets even worse when the URL is rather obscure. My e-banking site has this issue. I go to the bank home page where I can find the e-banking link. I click it and it opens the e-banking page, which sells you the service and in a small corner has a link to the real e-banking application where you can log in and see the big red numbers. I’d say they have a deeper problem than redirecting. They see the bank as a company with its useless propaganda home page and e-banking as a product with its useless propaganda home page and then, the actual e-banking site, somewhere else. They should just have the log in on their home page, like any other on-line service. But I digress.

    Back to redirecting. I click log in and it opens, in another window, a web site with a URL that is measured in meters. Long, ugly and scary. I never even thought of bookmarking that because I’m sure it won’t work the second time. So my bookmark is to the previous page. Just today, after a year of using it, I discovered that there’s a nice short well-formed URL for the log in page, something like: bank.com/ebanking/login which immediately redirects to the ugly one. Thanks to the amazing speeds of Switzerland internet connection and today’s browsers I never noticed.

    If the bank had just been serving the content through that URL, they would have saved more time over a year than it took me to write this post. Literally. I can’t understand why they don’t do it properly. If they are passing session information, they should use session state on the server side and a cookie. If they have a modular structure where the app is located elsewhere, instead of redirecting you they should use a reverse proxy. It takes a day to configure Apache for such a thing if you don’t know what you are doing.

    I’ve been using it for ages to serve Plone sites that are in a subdirectory in a Zope web server which runs in an alternate port, yet the front end is Apache and you are never redirected anywhere. You go to example.com which hits my Apache server and inside makes a request to zope.example.com:8080/example.com and serves you the result, you never leave example.com. Even if you go to the secure version, the SSL part is handled by Apache since Zope is not that good (or wasn’t) at it.

    There are cases to redirect someone on a web site. When the content is no longer available or temporarily unavailable. When the user just submitted a form, you redirect if the form was successfully processed to another page that shows the result of the form (the record created or whatever). There are many reasons to do that but that’s for another post.

    There’s no reason to redirect on load. Please, don’t do it.

    Reviewed by Daniel Magliola. Thank you! Use Other Door picture by cobalt123.

  • NetBeans could make the Ruby on Rails experience great for the vast majority of developers who are using Windows, where installing Ruby, Rails, PHP, MySQL, Python, etc is always a pain and the end result is ugly. But it falls short in some important ways which turned my experience with it into a nightmare.

    The reason I say “for developers using Windows” is because I believe that for everybody else, the experience is great already. Or as good as it can be and NetBeans can be an excellent IDE, but not improve the installation and managing experience.

    This is my story, my rant.

    I downloaded the latest NetBeans and installed it. When creating my first Ruby project, I encountered the first problem. Ruby chocked on my username, which was “J. Pablo Fernández”. You could say it was my fault. Windows 7 asked for my name and I typed it. I wasn’t aware it was asking for my username. Even then I would have typed the same, because Windows 7 doesn’t distinguish between usernames and names, and in the 21st century, computers should be able to deal with any character anywhere.

    I know it’s not NetBeans’ fault, it’s Ruby’s. But! Can you imagine a Software Engineer telling Steve Jobs “oh, copying files in a Mac behaves weirdly because it uses rsync and that’s its behavior, you see, it makes sense because…”? Of course Steve would have interrupted: “You’ve failed me for the last time”. The next developer would have patched rsync, trying to get the patch upstream, or creating an alternate rsync or stop using rsync.

    I’ve spent many hours creating another user, migrating to it, which in Windows is like 100 times harder than it should.

    Hours later, as soon as I created a project I got a message saying that I should upgrade gem, Ruby’s package manager, because the current version was incompatible with the current Rails version. By then I had already played with NetBeans’ gem interface telling it to upgrade everything, it should have upgraded gem as well, not just the gems. Every single developer out there running NetBeans must be encountering this error, and indeed there are quite a few threads about it on forums.

    Trying to upgrade gem with NetBeans was impossible. I think what they did to install and upgrade gems in NetBeans is excellent, but failing to upgrade gem itself was a huge drawback. This one was NetBeans’ fault. Neverfear, let’s do it from the command line.

    When doing it from the command line I encountered another error:

    \NetBeans was unexpected at this time.

    Looking around it seems it’s because of the spaces in “Program Files (x86)”. That means that the command line environment for Ruby that NetBeans installs is broken for everybody. I repeat: everybody. The answer: install it somewhere else.

    Well, I have two things to say about it: first, fix the freaking thing, Ruby, gem, whatever. Paths can have spaces and all kind of weirdness. It’s a big world full of people speaking languages that can’t be represented with ASCII and people that believe computers should do our bidding, instead of the other way around. “If I want spaces you better give me spaces, useless lump of metal and silicon”.

    Second, if you know one of your dependencies is broken, try to avoid triggering the broken behavior or at least warn the user about it. “We see you picked C:\Program Files (x86)\ to install NetBeans, which is pretty standard, but you know, Ruby is broken and can’t work in there, not even JRuby, so if you plan to use those at all, please consider installing it somewhere else.”

    I uninstalled NetBeans, or tried to. The uninstaller didn’t work. I deleted it and tried to install it on C:\ProgramFilesx86, which failed because some other directory created by NetBeans somewhere else existed from the previous installation, which halted the installation. I started a dance of run installer, remove dir, run installer, remove dir, run installer… until it worked.

    Once I finished I found out that NetBeans installed in C:\ProgramFilesx86\Netbeans 6.7.1. Yes, that’s a space. Oh my…

    As a bonus, NetBeans can’t automatically find Sun’s JDK in its default directory. I had to point to it by hand. Sun was, as usually, absolutely disrespectful of the platform conventions and installed its crap in C:\Sun. I would have picked another place but I thought “I’m sure some stupid program will want to pick that shit from there”. Silly me.

    12 hours have passed and I still haven’t been able to write a single line of source code. I contemplated installing Ruby by hand, but it’s so ugly that I decided I’m not going to use Windows for this. I’m going to work on another platform where installing Ruby is trivial and where I would probably never touch NetBeans because I have other editors.

    I know there’s a lot not really related to NetBeans here, for example, the fact that working with Python, or Ruby or MySQL in Windows is a pain; but it’s a great opportunity for NetBeans. There are developers wanting to use those languages and environments and if NetBeans makes it easy for them, they will pick NetBeans not because of its editor, but because of everything else (which is what I was hoping to get out of NetBeans).

    Aside from doing some usability tests, the people working on NetBeans should learn from the people working on Ubuntu (not the people working on Evolution) and instead of asking me for debugging traces when I report a simple obvious bug and then tell me it’s not their fault, they should submit those bugs upstream, to Ruby, gem, or whatever. Whenever someone like me submits that bug to NetBeans they should mark it as duplicate of an existing open bug that points to the upstream bug. I would have followed that link and told the Ruby developers “wake up!”. As it is, I didn’t. It’s too much work for me.

    Reviewed by Daniel Magliola. Thank you!

  • In an effort to increase the quality of this blog I’ve engaged a couple of friends in reviewing my posts before they go out. I’m after typos, grammar and also “Are you serious? are you going to publish that crap?” or “You are going to get into trouble with that”.

    The best way to do this, in my and in the opinion of many, is to let the reviewer modify the post freely and then check the diff. I suppose we are too used to work with source code, where diffs are a necessity.

    I was positively surprised that WordPress can provide very nice colored diffs between each save of each post. Praise to WordPress! I was also surprised, but negatively, that WordPress doesn’t have a reviewer role. Users with the reviewer role would be able to edit unpublished posts but wouldn’t be able to modify published posts or publish drafts.

    I was pointed to Role Scope, an amazing plug in for WordPress. I spent an hour creating a group and trying to give it the proper access, and as that failed, trying to limit the Editor role to only edit drafts. I failed at that too.

    When I gave up and I went back to the usual blogging I found that Role Scoper allows you to give edit access to each post to any user. And that’s it. That’s what I’m using. Whenever I want something reviewed I give access only to that post to the user I want to review it. Quite simple.

    Reviewed by Daniel Magliola. Thank you!

  • twitter-woodHere’s an idea for those Twitter clients, web and desktops out there: deferred posting.

    One tweet per hour during eight hours is much more effective than 8 tweets in a row. But sometimes you want to write eight tweets in a row and I find two reasons to do that.

    You are using Twitter professionally, for your work, as a marketing and social tool. You want to minimize the hit it takes on your productivity so you limit yourself to 15 minutes of tweeting per day. In those 15 minutes you generate tweets for the whole day, you want them to be automatically distributed through the day.

    When you open twitter after some hours of not using it, like after sleeping, you’ll find yourself replying to lot’s of stuff as you go through it. That’s specially true if you are 8 timezones away or so from most people you follow.

    I think a Twitter client should do the distribution automatically. It could distribute them evenly through the day, depending on how many you have on your queue. Whenever you want to tweet you just add it to the queue.

    Why limit itself to one day? why not leave tweets for tomorrow? And if not one day, how long? A way to solve the problem is to try to maintain your speed constant, minimize acceleration and deceleration.

    For example. If you normally tweet 5 times a day, and you have 10 tweets in your queue, do 7 today and leave 3 to tomorrow so that you don’t double the speed, you just increase it a little bit. If tomorrow you add another 10, you’ll have 13 and you are at a speed of 5.2 (previously you were at 5, but yesterday with 7 you sped up a little). So today you get 9 published and 4 left for tomorrow and so on.

    You’ll have different speeds on weekends and business hours. There’s a curve of speed and the Twitter client should try to match it with what you have on the queue.

    If you want to direct tweet, you can do that, just fine.

    Another interesting way is to match the curves of you readers instead of your own. The tweeter client would measure when your readers are posting more, and presumably, also reading more. It’ll make an average and it’ll have the curve of speed of your network. Instead of posting following your previous curve, it’ll post following your network’s curve maximizing the amount of people that is likely to read your Tweet.

    I would call that, Professional Tweeting.

    Another interesting feature would be to set importance to your tweets. More important tweets are sent when the chances of getting it read are highest, when the curve reaches its peak.

    Reviewed by Daniel Magliola. Thank you! Twitter carved-wood icon by gesamtbild.

  • searchWeb browsers, like Firefox or Chrome, are no longer document viewers, but application platforms. I’d like to see browsers start to implement search and replace. Of course not modifying the page, just replacing the matching strings in forms.

    I’m really surprised it’s not implemented yet. In the last two weeks I needed this feature about 5 times. It’s time for search and replace in web browsers already.

    Reviewed by Daniel Magliola. Thank you!