Thibaut Van Spaandonck’s blog

Some stuff about Web and .NET development
RSS icon Email icon Home icon
  • People & Business Development on HTML5 Gallery

    Posted on September 2nd, 2010 Thibaut No comments

    My latest web project, People & Business Development, has recently been selected by HTML5 Gallery, a website that showcases exemplary HTML5 websites with the objective that their implementations serve as a reference for web developers. It also features a dedicated page with the description, rating and suggestions of improvements so that webmasters of the showcased websites can perfect their creations.

     

    HTML5 Gallery

     

    HTML5 Gallery

     

    HTML5 Gallery being a popular website, the impact on People & Business Development’s visits has been dramatic, as well as its ranking in Google (ended up at the 2nd place for some keywords).

    Analytics

    Think I’ll put some interest in CSS galleries too ;)

    Share/Save/Bookmark

  • Visual Studio “collapse solution” extension

    Posted on September 2nd, 2010 Thibaut No comments

    Have you ever been annoyed by the expanded projects and items in Visual Studio, and lost so much time in collapsing them all manually ? Sure you do, especially if, like me, you have the track active item option checked (which highlights the current opened file in the solution explorer, resulting in automatic expanding of the parent project and namespaces). Wouldn’t it be great if you could right-click on the solution and select “collapse solution” ? You ain’t dreaming ;)

    First, click on Tools and select Extension Manager :

    Extension Manager

    Then, select Online Gallery in the left pane, start typing collapse in the search box and select the Collapse Solution extension. Restart Visual Studio and you’re done !

    Collapse solution

    Enjoy ;)

    Share/Save/Bookmark

  • Getting Visual Studio 2010 search back

    Posted on August 16th, 2010 Thibaut No comments

    If you already worked using Visual Studio 2010, you surely noticed the new, simplified interface and the different code profiles that you can choose after the installation. As a result, you’ve got a bigger area to code and the toolbars are kept to the minimum (at least if you chose the code only profile like me).

    But the thing is that I’m addicted to the search box and it’s gone (maybe due to my config, but surely others had the same case)… Here’s how to get it back :

    • Step 1 : check that you’ve enabled the standard toolbar. To do this, right click in the toolbar area (top of the IDE) and select Standard

      VS2010 Standard Toolbar
    • Step 2 : go to the customize options of the standard toolbar by clicking on the little arrow at the rightmost of it.

      VS2010 Standard Toolbar customize option
    • Step 3 : click on the Add command button, go to the edit pane and add the find in files and go to find combo. Then use the move down button to rearrange the commands you’ve just added. Their standard place is just before the solution explorer command.

      VS2010 Standard Toolbar customize window
    • Final tips : here are 2 simple shortcuts that will maybe make you addicted to that search box. First, moving the mouse and clicking into it to put the focus each time you want to perform a search isn’t really productive. Try [ctrl] + [:]. It will automatically put the focus into it. Then type > of [fileName] and it will list for you all file occurences starting by the name you’ve just entered. The magic behind it is the following : the “>” sign transforms the search box into a command window, and “of” stands for “open file”. An essential trick !

      VS2010 Standard open file

    Make good use of it ;)

    Share/Save/Bookmark

  • Bad smells in code by Martin Fowler

    Posted on August 9th, 2010 Thibaut No comments

    At the company I’m currently working for, there’s a big poster on the wall with the following headline : “if you see something like this, please raise your hand to improve code quality”. Below is the content of that poster – a list of things to avoid when coding – from Martin Fowler’s refactoring book.

    • Duplicated code : the same code structure in two or more places is a good sign that the code needs to be refactored: if you need to make a change in one place, you’ll probably need to change the other one as well, but you might miss it
    • Long methods : longs methods should be decomposed for clarity and ease of maintenance
    • Large class : classes that are trying to do too much often have large numbers of instance variables. Sometimes groups of variables can be clumped together. Sometimes they are only used occasionally. Over-large classes can also suffer from code duplication
    • Long parameter list : long parameter lists are hard to understand. You don’t need to pass in everything a method needs, just enough so it can find all it needs
    • Divergent change : software should be structured for ease of change. If one class is changed in different ways for different reasons, it may be worth splitting the class in two so each one relates to a particular kind of change
    • Shotgun surgery : if a type of program change requires lots of little code changes in various different classes, it may be hard to find all the right places that do need changing. Maybe the places that are affected should be all brought together into one class
    • Feature envy : this is where a method on one class seems more interested in the attributes (usually data) of another class that in its own class. Maybe the method would be happier in the other class
    • Data clumps : sometimes you see the same bunch of data items together in various places: fields in a couple of classes, parameters to methods, local data. Maybe they should be grouped together into a little class
    • Primitive obsession : sometimes it’s worth turning a primitive data into a lightweight class to make it clear what it is for and what sort of operations are allowed on it (eg creating a date class rather than using a couple of integers)
    • Switch statements : switch statements tend to cause duplication. You often find similar switch statements scattered through the program in several places. If a new data value is added to the range, you have to check all the various switch statements. Maybe classes and polymorphism would be more appropriate
    • Parallel inheritance hierarchies : in this case, whenever you make a subclass of one class, you have to make a subclass of another one to match
    • Lazy class : classes that are not doing much useful work should be eliminated
    • Speculative generality : often methods or classes are designed to do things that in fact are not required. The dead-wood should probably be removed
    • Temporary field : it can be confusing when some of the member variables in a class are only used occasionally
    • Message chains : a client asks one object for another object, which is then asked for another object, which is then asked for another one, etc. This ties the code to a particular class structure
    • Middle man : delegation is often useful, but sometimes it can go too far. If a class is acting as a delegate, but is performing no useful extra work, it may be possible to remove it from the hierarchy
    • Inappropriate intimacy : this is where classes seem to spend too much time delving into each other’s private parts. Time to throw a bucket of cold water over them !
    • Alternative classes with different interfaces : classes that do similar things, but have different names, should be modified to share a common protocol
    • Incomplete library class : it’s bad form to modify the code in a library, but sometimes they don’t do all they should do
    • Data class : classes that just have data fields, and access methods, but no real behavior. If the data is public, make it private !
    • Refused bequest : if a subclass doesn’t want or need all of the behavior of its base class, maybe the class hierarchy is wrong
    • Comments : if the comments are present in the code because the code is bad, improve the code

    Share/Save/Bookmark

  • Shuffling a collection using Fisher-Yates algorithm

    Posted on August 7th, 2010 Thibaut No comments

    Lately, I came across a situation where I needed to shuffle a collection. It’s the case when, for example, you need to display elements in a random fashion.

    This is where the Fisher-Yates algorithm comes into play. Created by 2 statisticians, this algorithm enables to generate a random permutation of a finite set and properly implemented, the shuffle is unbiased, so that every permutation is equally likely. Exactly what I was looking for !

    Below, you’ll find my C# implementation for shuffling a generic dictionary (adapting this to shuffle any other type of collection should be straightforward) :

    /// <summary>

    /// Shuffles a dictionary using the Fisher-Yates algorithm

    /// </summary>

    /// <typeparam name="TKey">Type of the key</typeparam>

    /// <typeparam name="TValue">Type of the value</typeparam>

    /// <param name="dictionary">Dictionary to shuffle</param>

    public static void Shuffle<TKey, TValue>(ref Dictionary<TKey, TValue> dictionary)

    {

        KeyValuePair<TKey, TValue>[] keyValuePairs = dictionary.ToArray();

        Random random = new Random();

     

        for (int i = keyValuePairs.Length - 1; i >= 0; i–)

        {

            int j = random.Next(0, i + 1);

            KeyValuePair<TKey, TValue> temp = keyValuePairs[i];

            keyValuePairs[i] = keyValuePairs[j];

            keyValuePairs[j] = temp;

        }

     

        dictionary = keyValuePairs.ToDictionary(k => k.Key, k => k.Value);

    }

    C ya’ ;)

    Share/Save/Bookmark

  • Book review : Learning WCF

    Posted on July 19th, 2010 Thibaut No comments
    Learning WCF

    For future challenges, I’ll have to learn WCF in deep, so I decided to start with this book. Next one will be Lowy’s Programming WCF services book, which covers WCF even more in depth. But let’s talk about the book I’ve just read (written by Michele Leroux Bustamante, Chief Architect of IDesign and colleague of Juval Lowy). I found it was a perfect book to start with WCF : introduction to SOA and its tenets, teaching of the key concepts of WCF such as contracts, bindings, hosting, instancing & concurrency, reliability, security and exceptions & faults. And to help you master these concepts, each chapter contains several labs where you can put into practice what you’ve just learnt. A very effective approach. Just note that this book doesn’t cover peer-to-peer protocols (which is done in Lowy’s book).

    Pros

    • Great book, covers a lot of ground of WCF
    • The labs really help in mastering all the concepts

    Cons

    • No cons for me. Just keep in mind that this book doesn’t cover peer-to-peer protocols

    Conclusion

    I recommend this book which will give you a strong knowledge of WCF on which you can build upon with Lowy’s book if you want to go even further.

    Share/Save/Bookmark

  • jQuery UI versus custom development

    Posted on July 17th, 2010 Thibaut No comments

    During the development of People & Business Development – my latest web project (related post) – I used the great jQuery UI library for some visual components such as the carousel or accordion. For some reasons I’ll discuss below, I also implemented those features by myself and I thought that giving my experience feedback could be useful.

    The carousel

    The landing page of the website presents the logos of the clients, which was done using jCarousel (jQuery UI). It needed somme little tweaking but was done in a reasonable amount of time. The jCarousel file contains 878 lines of code, which is quite heavy for me because I only needed a basic behavior.

    Carousel

    Considering all that richness I didn’t need and the fact that it always takes some time to adapt the library to the project, I decided to implement my own carousel for the twitter widget in the sidebar. Not only is the file way smaller (41 lines, I actually copy-pasted the code below so you can take a look at it), but it also took me less time to develop this custom version from scratch than adapting the jCarousel library to fit my project.

     

        1 $(document).ready(function() {

        2     var widgetWidth = 180;

        3     var animationSpeed = 700;

        4     var easing = "swing";

        5     var itemCount = $("#twitter_widget_list li").length;

        6     var currentItemIndex = 0;

        7 

        8     if (itemCount == 1)

        9         $("#btnTwitter_next").addClass("disabled");

       10 

       11     $("#btnTwitter_previous").click(function() {

       12         if (currentItemIndex > 0) {

       13             $("#twitter_widget_list").animate({

       14                 left: "+=" + widgetWidth

       15             }, animationSpeed, easing,

       16                 function() {

       17                     if (currentItemIndex == 0) {

       18                         $("#btnTwitter_previous").addClass("disabled");

       19                     }

       20                 });

       21 

       22             currentItemIndex–;

       23             $("#btnTwitter_next").removeClass("disabled");

       24         }

       25     });

       26 

       27     $("#btnTwitter_next").click(function() {

       28         if (currentItemIndex < itemCount - 1) {

       29             $("#twitter_widget_list").animate({

       30                 left: "-=" + widgetWidth

       31             }, animationSpeed, easing,

       32                 function() {

       33                     if (currentItemIndex == itemCount - 1)

       34                         $("#btnTwitter_next").addClass("disabled");

       35                 });

       36 

       37             currentItemIndex++;

       38             $("#btnTwitter_previous").removeClass("disabled");

       39         }

       40     });

       41 });

    The accordion

    I also used the jAccordion plugin to display the list of trainings and services the company provides (can be seen on the website here and there). The file contains 477 lines of code because you can, once again, customize a lot of things that most of the time you’ll don’t need. Integration time was very small and it perfectly fitted my needs, at least for the regular version of the website.

    For the iPhone/iPod touch optimized version, I simply couldn’t use it anymore : jAccordion sometimes creates a scrollbar into the sections that the iPhone and iPod touch won’t display. There is only one main scrollbar on those devices, resulting in a cropped content. In that case, I could either adapt jAccordion, take the time to dive into the code of the plugin or develop again a custom version from scratch. I chose the latest option, which took me 10 minutes to implement and test :

        1 $(document).ready(function () {

        2     $("div.accordion h3 a").click(function () {

        3         // Update arrow icons

        4         $("div.accordion h3 span").attr("class", "closed");

        5         $(this).prev().attr("class", "opened");

        6 

        7         // Show/hide sections

        8         $("div.accordion > div").slideUp(600);

        9         $(this).parent().next().slideDown(600);

       10 

       11         // Prevent default behaviour for href="#"

       12         return false;

       13     });

       14 });

    Conclusion

    So now you understand why I thought talking about this could be interesting as the difference between the 2 options is big. First : jQuery UI is a great library. You can do a lot of cool stuff with it, there’s plenty of documentation and the community is huge, so you’ll always find what you’re looking for.

    But in some cases (like mine), using those plugins is not always the best option. First it took me less time to develop a custom version than adapting the code of the plugin to fit my needs. Second, it’s way lighter (I got 41 lines of code instead of 878 for jCarousel and 14 lines instead of 477 for jAccordion).

    Although there’s no point comparing the amount of lines of code here (jQuery UI does provide much more options than my custom controls, so obviously code files are heavier), what should be remembered is : if you’ve got a good knowledge of jQuery, sometimes you’ll go much faster developing custom controls than using plugins, so think about it ;)

    Share/Save/Bookmark

  • Guidelines for mobile web development

    Posted on July 16th, 2010 Thibaut No comments
    Mobile Web Development Having recently completed a web project (related post) including an iPhone/iPod touch optimized version, here are some guidelines I’ve learnt and followed during that development :

    • Lightweight and concise design : we read less on mobiles than on a regular computer. Go to the point, be clear, provide fast access to relevant information. Don’t fear that visitors will be missing important information, they’ll go to the full version of the website if they’re interested in what they’ve seen.
    • No hover effects : whether it’s on menu items, links etc, don’t waste time developing hover effects. It’s a nonexistent concept on tactile interfaces.
    • Take inspiration from the GUI style of the platform : using GUI elements in which users are already familiar will make the interface easier to use. If you’re developing for the iPhone/iPod touch, you can take a look at the iPhone GUI PSD from Teehan+Lax. You can also get some inspiration from this gallery of iPhone websites.
    • Orientation detection : detect the orientation of the phone and adapt the interface accordingly. More screen width enables you to display larger images and longer paragraphs of text, improving readability on mobiles’ small screens.
    • Optimize for the phone screen resolution : when developing regular websites, you have to cope with different browsers, different screen resolutions, etc. One of the greatest things when developing for a specific mobile device is that every user has the same screen resolution and same browser. So you can tailor your interfaces to the pixel without worrying about those concerns.
    • Interfaces for fingers : there’s no mouse cursor on tactile interfaces and everything is done using the finger (at least if you’re using an iPhone/iPod touch). Keep that in mind by providing big enough buttons and add space between links to prevent errors. If you’re developing for the iPhone/iPod touch, I recommend you to take a look at the iPhone Human Interface Guidelines (official Apple documentation).

    And that’s it for this post ! Don’t forget that this is a noncomprehensive list and if you’ve got interesting guidelines to add, don’t hesitate to comment about that ;)

    Share/Save/Bookmark

  • [FR] Site Web : People & Business Development

    Posted on May 18th, 2010 Thibaut 3 comments

    Mon nouveau projet, réalisé en tant que freelance et en collaboration avec le graphiste Quentin Flamant, est le site web pour la société People & Business Development. L’objectif principal est d’assurer une présence en ligne de cette dernière, y compris dans les réseaux sociaux (tels que Twitter, Facebook et LinkedIn), afin de présenter son activité et ses services. Le surf sur mobile étant une tendance en vogue, une version optimisée pour l’iPhone et l’iPod touch a également été développée.

    Présentation de la société

    Actif depuis une dizaine d’années, People & Business Development est un bureau spécialisé en coaching, en formation et en conseil pour optimiser le potentiel humain des organisations et, en conséquence, le chiffre d’affaires. Leur liste de clients comporte des noms tels que Alstom, la Commission Européenne, Delta Lloyd Life, Securitas ou encore Gefco.

    Le site web

    Le site a été développé en ASP.NET et utilise jQuery comme librairie javascript ainsi que jQuery UI pour les composants graphiques. Des propriétés CSS 3 ont été utilisées pour embellir le site dans les navigateurs modernes sans affecter le rendu dans les navigateurs plus anciens via le mécanisme de dégradation gracieuse. En ce qui concerne le respect des standards du Web, chaque page du site passe la validation W3C XHTML 1.0 Strict.

    People & Business Development

    La version iPhone et iPod touch

    Ci-dessous, des captures d’écran de la version dédiée à l’iPhone et l’iPod touch. On notera notamment la détection de l’orientation permettant une lecture plus aisée de longs paragraphes de texte ainsi que l’intégration au menu de l’iPhone et l’iPod touch, permettant un accès direct au site web.

    Cliquez pour agrandir

    People & Business Development iPhone

    Cliquez pour agrandir

    Conclusion

    L’objectif de ce post, outre l’aspect publicitaire, est de présenter une application concrète de bon nombre de mes précédents posts, incluant :

    Bonne visite !

    Share/Save/Bookmark

  • Why you should use a CDN for your website ?

    Posted on May 3rd, 2010 Thibaut 1 comment

    What’s a CDN ?

    CDN stands for “Content Delivery Network”. It’s a system of strategically placed servers around the globe so the client can access to the requested file from the closest server.

    In this post, I’ll discuss the benefits of CDNs for Javascript libraries such as jQuery, MooTools, …

    The benefits

    Typically, you place your javascript libraries on the FTP hosting your website. CDNs allow you to host these files for you, and benefit from the following :

    • you’ll optimize the client-side experience of your visitors as the libraries will be delivered faster to them, because they’ll get the files from the nearest server
    • it falls back on other servers if ever one of them would be down
    • you’ll save the bandwidth of your webserver as it won’t be hosting those files anymore
    • you’ve got less files to maintain on your server

    How to use a CDN ?

    It’s very simple, you just have to include one or two javascript tags on every page you want to use those libraries (if you’re working in ASP.NET, you’ll typically place these tags on the MasterPage).

    Resources :

    See you ;)

    Share/Save/Bookmark