• 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!

  • I like Python’s way to format strings because you can use it everywhere, it’s part of the strings. You can do

    print("Welcome %s!" % user.name)

    as you can do

    Console.Writeln("Welcome {0}!", user.Name)

    But then in Python you can also do

    randomMethodThatTakesAString("Welcome %s!" % user.name)

    In C# it gets trickier, because the call to Console.Writeln takes extra arguments for the string arguments, while RandomMethodThatTakesAString doesn’t. It just takes a string. So the only way to go is

    RandomMethodThatTakesAString(String.Format("Welcome {0}!", user.Name))

    which is ugly.

    Thanfully C# 3.0 has extension methods, so I quickly wrote this method:

    blah blah

    and now I can write:

    RandomMethodThatTakesAString("Welcome {0}".Args(user.Name))

    which is more verbose that Python’s version, but equally nice in my eyes.

    If you can understand why allowing the language to be extendable in one aspect was a win here, then you can understand why so many, me included, love Lisp that is extendable in every possible way.

    Reviewed by Daniel Magliola. Thank you!

    Update 2009-09-17: For those complaining that I didn’t show how I did it, here is the Args method:

    public static class StringExtensions {
        public static string Args(this string str, params object[] args) {
            return String.Format(str, args);
        }
    }
  • forgot-passwordOpenID has many advantages. For the average user, the main one is not having to remember a thousand passwords. That’s obvious. But also consider not having to remember the username. Many web sites use the email address as username and that’s nice, but many don’t. And most people are not lucky enough to have a username that’s free everywhere. For my wife, remembering the username is sometimes as hard as remembering the password.

    Not having to worry about poorly programmed web sites leaking your password because they stored it in plain text and they have phpMyAdmin open without any password is also a big plus, but not something the average user would see.

    But for the developer, it has many, many advantages.

    Not having to decide on what identifier to use for your users (users vs emails vs ids). Not having to implement a log in screen, which means not having to worry about SSL encryption which means not having to get a dedicated IP address, a certificate, configure the web server accordingly and ensure that the site switches to https when it must.

    Not getting password for the user means you don’t have to store a password. You don’t have to figure out what is the appropriate encryption mechanism so that if your encrypted password leak, they are not readable. Not using plain text is not enough, as some encryption mechanisms are easily broken. Not having to worry about that is huge.

    You don’t have to create a signup page, people just log in. You don’t have to validate the password by asking for it twice or validate its strength or any other stuff like that.

    You don’t have to create a remember password page, which means one less place where you have to deal with sending emails. That’s always good. Also it means that you don’t need to store the email of the user. You may want to, but that’s your option.

    I’ve always been a fan of canned authentication and authorization systems. I’ve been using them since the days of PHP 4.0 and I used them in Django and ASP.NET (MVC). But with OpenID, it seems the authentication became almost trivial. Canned solutions were always troublesome because they had to work for everybody so they implemented a lot of stuff you don’t actually need and sometimes you spend more time fighting the bureaucracy of the system than producing something.

    Is it possible that without OpenID authentication and identity for the developer of a web site becomes something simple and trivial? Where rolling your own solution not only is simple enough, but also the way to go. I’m looking forward to my users being just in the user table, and not all over the place in users, profile, membership, etc. I’m giving the roll-your-own-with-OpenID a try. I hope to post positively about it soon.

  • Broken bridge, picture by Ghost V

    There seems to be a lot of discussion about software complexity, and although I think many people are talking about different stuff, here’s my take on it. We often compare writing software with other professional disciplines, like civil engineering and medicine, which allows us to pick at possible futures of writing software.

    I believe writing software is hard, very hard, extremely hard. Probably one of the hardest thing to do. Any non trivial piece of code has an amazing amount of moving pieces. I bet the average software project is more complex than a car or a bridge. But how do we reconcile that with the fact that we have children programming and not children building cars or bridges?

    Well, we do have children building cars and bridges, just that they are toy cars and toy bridges. Toy cars and bridges are very different from real cars and bridges. Toy software is not much different from real software. The path for going from toy to real in software, unlike in medicine, motor and civil engineering, is smooth. You don’t jump from building toy software into building real software, you just build better and bigger software until it’s real or professional.

    That makes sense because software is abstract. Software is like ideas. There’s no jump between having toy ideas and having real ideas. If you don’t buy it, let’s do the analogy with math. There’s no jump between doing toy math and real math. You learn more math, more operations, more tools, but the sums and multiplication you learned when you were 5 years old are the same you use in civil engineering. There’s no toy sums vs real sums.

    At some point in time, ages ago, math was primitive. A 12 year old could discover something new in math. We are at that period in the world of software writing. We are young and there’s not a lot out there. That’s why even though it’s extremely complex, a kid can still do something meaningful.

    There’s something special about software. Even though it is abstract like math, it has a concrete impact, like civil engineering. So the 12 year old kid can do something new and it’s not just a piece of paper with a couple of numbers on it. It’s a real usable thing that other people can start, well, using. And that’s why I believe programming is so wonderful.

    There’s another very important property of software that makes it so complex and still approachable. Imagine the world ages ago when 12 years old where doing math discoveries. Probably 99.9% were wrong in what they discovered as 99.9% of the software written by kids is wrong in the way it has bugs. But buggy software is still software and it’s still usable. Buggy math is wrong and should be discarded, buggy bridges kill people. Buggy software is a nuisance, but usable.

    There’s some code in which only very smart and professional people put their hands on. Code written at NASA has something like 10 times more code to test it. Code put in a machine that can kill people, like a robot at a factory or a radiotherapy machine is written quite differently than the latest web toy or even the operating system you are using (last time I checked my analytics, nobody was using QNX to access this web site).

    Rocket picture by SWP Moblog

    As software becomes more important in our lives, more of it has to be written rigorously. You can accept the latest web toy to crash, but you cannot accept your phone to crash. And then, the latest web toy becomes very important, like Twitter, and you cannot accept it to crash. The way code is written at NASA is more similar to the way a civil engineer makes a bridge: accounting for all possible variables.

    It’s a real possibility that in 20 or 30 years all code will have to be written very rigorously. That means that you probably won’t be able to get a job working as a programmer in many, many places unless you have a proper degree, certification and license. I know it sounds crazy, but extrapolate about who was building bridges ages ago (anybody) and who are building them now (civil engineers) to who is building software now and who is going to be building software tomorrow.

    For me, that sounds very depressing. I like the chaos of innovation that software is today. I probably couldn’t live in a rigorous software environment. One aspect that I haven’t analyzed is that, unlike civil engineers, software programmers will most likely always be able to build software by themselves, put it out there and be out of the loop of rigorous working. Anyone can build a bridge in their back-yard and nobody will use it, because it doesn’t stand a chance of being useful. But the back-yard of a programmer is the Internet. The only question is whether people will use that crapy web toy built by a 12-year old 20 years from now. I honestly hope so because that will keep the thriving environment of chaotic innovation that programming is today.

    Reviewed by Daniel Magliola. Thank you! Broken bridge picture by Ghost V, rocket picture by SWP Moblog.

  • some-key-stickersI started using computers ages ago in Argentina. We only had US Qwerty keyboards back then and I’ve got used to them. The Spanish keyboards appeared later on and I never switched. I never understood what was the deal with those. I can type almost any character I want with a US Qwerty keyboard, even Spanish ones like á, é, í, ó, ú, ñ, ü. But furthermore, most characters used for programming are much harder to access in a Spanish keyboard.

    Years latter I switched to Dvorak, making my problems of layout even worse, but increasing my geek-coolnes. In some keyboards you can move the keys around to convert US Qwerty into Dvorak, but you cannot convert Spanish into Dvorak by moving keys around. That’s because the symbols are not grouped in the same key. While in both US Qwerty and Dvorak you have a key that has “.” (dot) and “>” (greater than) in Spanish you have a key that has “<” (lower than) and “>” (greater than).

    So if you want to switch Spanish to Dvorak, like I did, or you want to switch Spanish into US Qwerty or French into German, or whatever, you have to totally re-label the keyboard. There’s a company called Hooleon that makes a Keyboard Replacement Overlay Kit that will allow you to turn any keyboard into US Qwerty, or Dvorak, or anything you can think that uses the US Qwerty set of keys. It’s basically a set of stickers that you put on your keys. They are very durable, more than some keyboards, and they look quite good.

    They also make a Qwerty-Dvorak conversion kits, which is the best option to convert US Qwerty into Dvorak (they don’t provide numbers and other keys that stay the same). And if you switch to another language they have many language-changing kits to many languages. If you have a keyboard, you might just swap it for another one, but if you have a laptop, this solution is excellent. I’m really grateful there’s a company providing this product because it’s served me well for ages until I got a really good keyboard.

    Now I have a MacBook Pro with beautiful back-light keys. I’m not going to put stickers on them, I have to remove them and re-place them. That’s not trivial in a laptop keyboard, so I’m still building up courage.
    key-stickers

    Disclaimer: I’m in no way affiliated with Hooleon, I just love their products.

    Reviewed by Daniel Magliola. Thank you!

  • fileI’m not sure why ASP.NET MVC was shipped without a file input type for forms. Maybe it’ll come in MVC 2.0 or 3.0. Meanwhile, I created one. I spent two or three hours trying to figure out how to go from Object to IDictionary<String, Object> to follow the same ASP.NET MVC style where you have methods like:

    TextBox(HtmlHelper, String, Object, IDictionary);
    TextBox(HtmlHelper, String, Object, Object);

    which are essentially the same. The last argument is a dictionary of extra HTML attributes, like style=”float: left;”. The good thing about accepting Object Is that you can call it this way:

    Html.TextBox("email", new { style="float: left;" })

    which is very handy for forms. The bad thing is that it is a pain in the ass to do that hocus pocus in C# using reflection. Thankfully ASP.NET MVC is open source. I downloaded the source and after 15 minutes I got it working nicely (and without manually using reflection). Use the source Luke!

    In a recent episode of Hansel Minutes podcast someone argued what was the value of releasing the code of ASP.NET MVC at all. Well, this is the value. You help developers, you build a better developing community.

    Without further ado, here’s the code:

    public static class HtmlHelperExtensions {
       /// <summary>
       /// Returns a file input element by using the specified HTML helper and the name of the form field.
       /// </summary>
       /// <param name="htmlHelper">The HTML helper instance that this method extends.</param>
       /// <param name="name">The name of the form field and the <see cref="member">System.Web.Mvc.ViewDataDictionary</see> key that is used to look up the validation errors.</param>
       /// <returns>An input element that has its type attribute set to "file".</returns>
       public static string FileBox(this HtmlHelper htmlHelper, string name) {
           return htmlHelper.FileBox(name, (object)null);
       }
    
        /// <summary>
        /// Returns a file input element by using the specified HTML helper, the name of the form field, and the HTML attributes.
        /// </summary>
        /// <param name="htmlHelper">The HTML helper instance that this method extends.</param>
        /// <param name="name">The name of the form field and the <see cref="member">System.Web.Mvc.ViewDataDictionary</see> key that is used to look up the validation errors.</param>
        /// <param name="htmlAttributes">An object that contains the HTML attributes for the element. The attributes are retrieved through reflection by examining the properties of the object. The object is typically created by using object initializer syntax.</param>
        /// <returns>An input element that has its type attribute set to "file".</returns>
        public static string FileBox(this HtmlHelper htmlHelper, string name, object htmlAttributes) {
            return htmlHelper.FileBox(name, new RouteValueDictionary(htmlAttributes));
        }
    
        /// <summary>
        /// Returns a file input element by using the specified HTML helper, the name of the form field, and the HTML attributes.
        /// </summary>
        /// <param name="htmlHelper">The HTML helper instance that this method extends.</param>
        /// <param name="name">The name of the form field and the <see cref="member">System.Web.Mvc.ViewDataDictionary</see> key that is used to look up the validation errors.</param>
        /// <param name="htmlAttributes">An object that contains the HTML attributes for the element. The attributes are retrieved through reflection by examining the properties of the object. The object is typically created by using object initializer syntax.</param>
        /// <returns>An input element that has its type attribute set to "file".</returns>
        public static string FileBox(this HtmlHelper htmlHelper, string name, IDictionary<String, Object> htmlAttributes) {
            var tagBuilder = new TagBuilder("input");
            tagBuilder.MergeAttributes(htmlAttributes);
            tagBuilder.MergeAttribute("type", "file", true);
            tagBuilder.MergeAttribute("name", name, true);
            tagBuilder.GenerateId(name);
    
            ModelState modelState;
            if (htmlHelper.ViewData.ModelState.TryGetValue(name, out modelState)) {
                if (modelState.Errors.Count > 0) {
                    tagBuilder.AddCssClass(HtmlHelper.ValidationInputCssClassName);
                }
            }
    
            return tagBuilder.ToString(TagRenderMode.SelfClosing);
        }
    }

    Reviewed by Daniel Magliola. Thank you!

  • I’ve been looking for ages for the perfect music for coding. I’ve asked around and tried new age, Mozart, Bach, and other academic music. I’ve tried instrumental soothing music and instrumental electronic music. Nothing worked until I started to expand my original coding music: Indiana Jones and the Last Crusade.

    Yes, I used to code to the music of Indiana Jones and the Last Crusade and I loved it. I started to try others and I’ve found I like coding to these albums:

    I’m looking for more. There’s a clear pattern: instrumental and fast. It has to be of movies I’ve seen. When I listened repeatedly to Indiana Jones and the Last Crusade when I was a teenager I would recreate the whole movie in my head. I don’t do that anymore but the music still carries some subconscious meaning. I’ve tried with music of movies that I haven’t seen and it doesn’t work. And some don’t work and I don’t know why. These songs work as isolated songs, but not the whole album:

    All by Vangelis of course. Star Wars music kind of works, but only some songs. I still have to sit down and select them (6 albums, lot of work). I remember other music like Apollo 13 also worked, but I don’t have it anymore.

    What do I mean by work? It seems that music speeds me up. It makes me work faster, concentrate more and enjoy myself more. It makes me not want to stop, like watching a good movie. What do you listen to? Any other movies with great coding music?

    Reviewed by Daniel Magliola. Thank you!

  • Image taken from http://www.artlebedev.com/everything/defendius/

    I was writing this long post about how to use rewrite rules to make Apache query itself and serve various sites through the same SSLed virtual host using only one IP. After about four hours of struggling with it I thought I was done but then while writing this article I found out I was wrong. Something was not working as expected. Did I face another 4 hours of Apache struggling? (more…)

  • This has been mentioned thousands of times on the interwebs, but in case there’s at least one person reading this that didn’t know it, I’m explaining it again. Using hyperlinks in a piece of text doesn’t mean it has to stop being proper, readable English (or any other language). For example, imagine the phrase:

    It was a nice movie, click here to read more about it.

    Read it again. Now close your eyes and imagine someone reading it out loud. It doesn’t make any sense, does it?

    Hyperlinks already carry the meaning that there’s more information behind them. No need to repeat it with “to read about it”. And they also carry the information about being clicked, so no need to say “click here”. And in some interfaces you don’t click, and I can think of already two cases:

    • People using the keyboard and only the keyboard to navigate. They are more than you think. I myself would be doing it much more if it wasn’t so hard on so many broken web sites.
    • People using a phone, like the iPhone. You don’t click, nothing clicks. It’s called tapping.

    For computers “click here” doesn’t provide any proper meta-data. There are services that extract a lot of information about links. Google being one example. Let’s analyze what would happen to Google if you do it correctly, like:

    It was a nice movie.

    That was short, wasn’t it? Half the size and no-nonsense, but I digress. Google would index that link as a “nice movie” and that’s good because you are adding information to the web, you are expressing your opinion and when people search for “nice movie” they are more likely to find the movie you pointed to. Maybe you are the only one believing that’s a nice movie, but when lots of people link to it as a “nice movie”, Google will catch that.

    Also, imagine that your page gets turned into plain text, or printed, or spoken, or whatever:

    • It was a nice movie, click here to read more about it.
    • It was a nice movie.

    Which one makes more sense?

    Now, we can take it a step further. Something else you can do to make your text more readable, more robust and nicer overall is to do more or less proper attribution. I’m not talking about academic proper attribution, I’m taking about simple things. I’ve recently found this sentence in the Stack Overflow article Advice for Computer Science College Students:

    I’ve read an article from Joelonsoftware.com a few years agohttp://www.joelonsoftware.com/articles/CollegeAdvice.html

    which I promptly edited, thanks to my karma earnings, to be:

    I’ve read the article Advice for Computer Science College Students from Joel on Software a few years ago.

    Aside from the proper period at the end of a sentence, do you see how and why my version is more readable, contains much more information (while being shorter on text on the screen) and can resist being turned into text, speech or braille? So, next time you write something, please, remember that even if you are using a computer, you are still writing a proper language.

    Sometimes the links are so important that you want them to get to a text or spoken version. In that case, imagine how you would write it if you were speaking or writing with a pen on paper:

    I really like Joel on Software, which you can read on http://joelonsoftware.com.

    which you can then later enhance for the web:

    I really like Joel on Software, which you can read on http://joelonsoftware.com.

    Now there’s extra information in there. The URL is there three times, one in text, two in hyperlinks. But the text is not longer and it’s not harder to read (unless you pick up hyperlink colors badly) and it gives the user more places to link, machines that look for context information more to pick up from. It’s a win-win.

    Reviewed by Daniel Magliola. Thank you!

  • When you create an ASP.NET MVC project it comes with a controller called AccountController that manages logging in, logging out, registering, changing password and so on. Since usernames and passwords are dead I converted it into OpenID and I’m just pasting it here for everybody to use.

    I’m using the DotNetOpenAuth library which you have to download, put in your project and refer. The difference between what I’m pasting and the example provided by DotNetOpenAuth is that I’m actually storing the user in the membership database, like the original AccountController.

    My work is based on the on the blog post Adding OpenID to your web site in conjunction with ASP.NET Membership. I really had to put a couple of hours on top of that, so I consider it worth it to post it. Scott Hanselman also provides useful information for integrating OpenID. I’m using the jQuery OpenID plug-in but I’m not going to post my views. They are really trivial and left as an exercise to the reader.

    I’m not using any extra tables, I’m storing the OpenID identifier (the URI) in the field for the username. This has the advantage of not requiring any other fields but the disadvantage that you can have only one identifier per user. There are some unfinished parts but since you are likely to customize them anyway, I don’t feel too guilty about not finishing yet. If you find a bug, please, let me know.

    (more…)