Code Improvement

Welcome to my blog!

Thursday, 28 January 2010

2010 Goals

2010 will be a great year and I’m sure that my life will change dramatically. I have a whole bunch of ideas and things I want to do.  Here is a list of my “professional goals”.

Become an expert with ASP.NET MVC.

Ever since I first heard of ASP.NET MVC, I knew I should become proficient in it. But I can’t control the type of project I’m working on, so I neglected to do my homework and stay up to date.

Get some more experience with web design (CSS, XHTML)

A big gap to fill. I’ve made some progress but still not able to do it efficiently. I will probably pick up some books and try to design web site from scratch just for gun.

Write a jQuery plugin.

I have some ideas of plugins that haven’t made it to general release. This year, I will definitely launch one to have a real experience with launching an open source project and responding to feedback.

One contribution to an open-source project.

Something else than the jQuery plugin mentioned earlier. I have made some “improvement” to BlogEngine.Net and maybe I will submit them some changes I’ve made.

At least 100 blog posts and 100 feed reader.

95 posts to go and around 50 more readers. Completely feasible. I also picked some tips while I had a complete lack of posts for some month and I am now ready to apply them.

GTD

I need to finish Getting Things Done and try it for some months. A goal that I really need to complete this year.

Get back in the shape of my life.

I took some weight since the wedding in October 2009 and I can now see how it affect my health. So I am ready to take care of this again. It may not looks like a professional goal but I’m sure It will have a big impact in the end.

 

Technorati Tags: ,,,
Del.icio.usDigg It!DZone It!StumbleUponTechnorati


Saturday, 23 January 2010

Understanding $.proxy on jQuery 1.4

One of my great resolution of the year is to learn by teaching. Today I watched the Day 9 videos of the 14 days of jQuery. In one of them, Paul Irish talked about $.proxy() and I did not totally understood what was going on.

The jQuery API definition is : Takes a function and returns a new one that will always have a particular scope. Well, I could read this all day long and I am sure It couldn’t be clearer without an example.

Here is the problem the “proxy” function is trying to solve.

 var me = {
            name: "Sebastien",
            blogging: function () {alert(this.name + " is blogging") }
        };

$(function () {
    me.blogging(); //will display : Sebastien is blogging
    $('#clickMeButton').click(me.blogging); //will display : is blogging
});

 

As we can see, on line 7, the function is called inside me (now that I think of it, this instance name is not perfect). But when called as the button click handler, the this keyword is now representing the button. And as the name property is not set on the button, nothing is displayed. Easily provable with :

$('#clickMeButton')[0].name = "Button"; 
$('#clickMeButton').click(me.blogging); //will display :Button is blogging

This could be awkward if not the desired behaviour. Let’s see how the jQuery team resolved that problem.

$(function () {
	me.blogging(); //will display : Sebastien is blogging
	$('#clickMeButton').click($.proxy(me, "blogging")); //will display :Sebastien is blogging
});

By calling the proxy method with the instance and the desired function, the context is now set to that instance. Resolving that particular problem. The method takes the instance and the name of the function as a string or could also be called by using :

$('#clickMeButton').click($.proxy(me.blogging, me));

I hope It helped you understand $.proxy(). I can already see where I can apply this knowledge right now.

 

Technorati Tags: ,
Del.icio.usDigg It!DZone It!StumbleUponTechnorati


Wednesday, 20 January 2010

AlternativeTo.Net review

AlternativeTo is a web site that suggests alternatives to a given application based on user recommendations. For example : TeamCity will have Hudson and CruiseControl and Windows 7 will have Windows Vista and Windows XP as an alternative. The web site is divided into 2 main category: desktop and mobile and can be further divided between OS (Windows, Mac, Linux or Online for the Desktop section and IPhone, Win Mobile, Android, Blackberry and S60 for the Mobile section).

The first things that came to my attention is the ease of use and the quality of presentation. It’s just easy to find what you need to. It really is that interesting  and I admit I return to them often when I’m in need of an alternative software. They have release their beta version on March 2009.

Great job guys!

PS: I have no relation whatsoever with AlternativeTo. I just find the concept interesting.

Technorati Tags: ,
Del.icio.usDigg It!DZone It!StumbleUponTechnorati


Tuesday, 19 January 2010

SEO tips I have used to improve my search engine visibility

I’ve been across a couple of ways that you can increase your search engine visibility. I’m not an SEO expert. I’m merely exposing what I’ve learn in the last months. If you don’t know, I had a drop of 50% of traffic from search engine when moving from Wordpress to BlogEngine.NET. Mostly due because of me. I have now deployed my blog with a lot of improvements on keywords, titles and descriptions. But there is some other ways your site or blog can be affected. Here are some tips I’ve used to optimize my search engine visibility.

Subscribe to Google Webmaster tools or other search engines and submit your sitemap

Creating a sitemap for Google is like telling Google everything you have on your website. Some page may not be accessible via normal crawling so it’s a way of telling Google everything that should be indexed.

Check your website with an SEO analyser

This will help you see your site with another eye. The best online analysers I’ve found are Website Grader web site and SEOmoz. Both are good looking and provide useful tips to increase your web site traffic. If you are using IIS, another tool to check out, is the SEO toolkit.

Launch Without Comments (and Add Them Later)

I’ve taken this advice from the 21 Tactics to Increase Blog Traffic post and it’s not as bad as it seems. I, myself, did fall for this one. Many times I’ve not subscribed to a blog, because of its lack of comments.

One h1 tag by page and use the headings tag wisely

Many people think it is not as important as it appears, but I think the h1 tag is utterly important. The h1 tag should be used to put emphasis on the content of the page. I’ve used them primary to contain a relevant title for the page. Use h1 to h6 tags wisely to properly separate the content of the page, like a book. Think about reader without a visual browser (usability).

Remove broken links

Removing broken links prove to search engine that you care about your content and their will re-crawl your site. It also means that you care about your readers and it’s a good thing. Other that with the SEO toolkit, you can use the W3C Link Checker to find any broken links. 

Provide great content

Probably the greatest advice ever. Your site is nothing if you don’t have great content that is relevant. I’ve found this Blogsessive post to be interesting. And if you need to become a better writer, check out The Day You Became A Better Writer.

Use the description meta tag

Don’t forget to add a description meta tag. Did you ever where the description under a link from the list of results from a Google search came from? Providing accurate description will help ensure that the user won’t be disappointed when visualizing your web page.

Verify the length of the description and title meta tags

To avoid your tile being cropped by search engines, you should have titles that have less than 64 characters including spaces and more than 5 characters. The description should be between 25 and 150 characters according to the SEO toolkit.

Use the ALT attribute on images and an accurate filename

Search engines cannot see images. If you want them to know what the image is about, you need to add an ALT attributes to your images. Even better, name your image to reflect what they really are.

 

Del.icio.usDigg It!DZone It!StumbleUponTechnorati


Monday, 18 January 2010

2009 Retrospective

2009 has been a big year. A lot happened. Professionally and in my life in general.

What went well

Reading other books than technical books

I have been reading a lot of books that had nothing to do with the technical aspect of my job, but with other challenges in mind. I’ve read about business development, learning process, design (not software design) and project management. I’ve also came in contact with the Pragmatic Thinking and Learning book which gave me a lot of great tools to learn more effectively.

Agile

I’ve been working with an Agile Team for half a year now, going back where I really belong. I liked the experience and hope we (the team) can get even more benefits from this methodology this year. I’ve also assisted to some of the conferences of the Agile Tour 2009 which was a fantastic event.

Web Development and Javascript

I’ve always been a developer with a little knowledge of web design but no deep knowledge. I’ve always had design supplied to me and been able to hack through it and get thing done. This year, I’ve gone deeply in web design and CSS, so deeply that I now really hate browsers differences :). And I’m now an expert in Javascript, thanks to jQuery. Seriously, I made really big improvement on this side.

SEO

Search Engine Optimization that his. I was expected to increase visitors from the US on a website. I’ve started with no real knowledge on how Google was indexing content. So I geared myself, watched videos and read everything I could for this. It’s not always easy but it was a fun learning experience. One tool worth mentioning is the IIS SEO toolkit. The first analysis with this extensions showed me that I had a lot of problems with missing descriptions, keywords, titles, broken links, etc, on my blog, and it provided a great experience in allowing me to resolve them and understand what I did wrong.

Wedding

I’m now married. Since October 17. What an intense ride it was. And we are now waiting for our first child to be born (due February 2010).

Consulting

I’ve done some consulting work at the beginning of the year and it was really fun. Delivered on time and exactly what they wanted. Great experience. Great customer.

What could have been better

Lack of time to post on my blog and the migration to BlogEngine.

I have missed a lot of opportunity to blog and I intend to get back on track this year. I also migrated my blog from Wordpress to BlogEngine.Net this summer and seen a drop of more than 50% in traffic. I blame myself for my lack of migration strategy.

Technical Reading

I read some technical books in 2009, but not as many as the other years. In fact, aside from Clean Code, CSS Web Design and ASP.NET MVC in action, I had read no other technical book.

A contract

A situation has occurred in which I was unable to deliver a project on time. Some deadline were too thigh and a last minute change (technology switch at the last minute) made the situation goes havoc and the project was abandoned (by me).

Skullcandy headphones

I had a pair of Skullcandy headphones that broke unexpectedly. But due to the formidable warranty (complete replacement or half-price on another pair), I had sent them to be replaced in October. I’m still waiting and all my attempt to contact them has failed. The problem is that I would have been able to repair them myself and now I’ve just lost them (Update : It seems the package never arrived…).

Del.icio.usDigg It!DZone It!StumbleUponTechnorati


Wednesday, 13 January 2010

Adding a MIME map in IIS

HTTP Error 404.3 - Not Found

The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.

I got this error when trying to let user download .dwg files in IIS 7.5 but a MIME map was not created. Any uncommon files will get you this error. Fortunately, it’s very easy to do.

Open IIS and navigate to your site. Now click on MIME Type (shown below).

finding mime type in iis

Right click and select Add (or click Add… in the right-side menu). You are now presented with a dialog requesting you to enter your filename extension and the MIME type (list of possible MIME types). This will enable you to associate a file extension with a type of content.

adding a mime type

H2R77MC2M35K 

Del.icio.usDigg It!DZone It!StumbleUponTechnorati


Thursday, 05 November 2009

Back to ASP.NET WebForms and a lot of pain with the CheckBoxList

Edit : This is an old post back from november 2008 on my old blog. Since I had this problem today, I though it would be a good idea to share it again with all my readers.

Going back to standard ASP.NET Web Forms was ridiculously hard. In the last months, I have been completely blown away by the limitless (almost) possibilities of the ASP.NET MVC framework and now I find myself struggling very hard to make a single dropdownlist works the way I wanted to. The scenario was simple, in the client page, I used the value supplied by the drowdown list item to make an AJAX query and display the incoming results somewhere else in the page. That should be very easy right? Well, no. You may not know this but the value attribute of the ASP.NET CheckBoxList's items is not rendered at all.

I know that there is multiple solutions to render it, but that's not the point. I can't find a single reason to not let the developer decide if he want to display it or not. I even heard on some forum (I did not test it myself) that you cannot add a custom attribute named "value" (you can add custom attributes to any controls that will be rendered in the final html) without it to be stripped by the ASP.NET WebForms engine.

Anyway, let's see the solution to this problem.

First of all, we need to create a custom control that will inherit from the System.Web.UI.WebControls.CheckBoxList and that will implement the System.Web.UI.WebControls.IRepeatInfoUser. We use the base class CheckBoxList as we want to reuse existing behavior without implementing it ourselves. As for the IRepeatInfoUser interface, we use it because we are implementing a control that has list items.

public class CheckBoxListFixed : CheckBoxList, IRepeatInfoUser
{
    void IRepeatInfoUser.RenderItem(ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
    {

    }
}

 

Inside the RenderItem method we will use the HtmlTextWriter to output all the wanted html.  So we want to create an input of type checkbox:

writer.WriteBeginTag("input");
writer.WriteAttribute("type", "checkbox");
writer.Write(">");
writer.Write(Items[repeatIndex].Text);
writer.WriteEndTag("input");

 

This will render only basic checkboxes.

<table id="checkboxList" border="0">
    <tr>
        <td><input type="checkbox">1</input></td>
    </tr>
    <tr>
        <td><input type="checkbox">2</input></td>
    </tr>
    <tr>
        <td><input type="checkbox">3</input></td>
    </tr>
    <tr>
        <td><input type="checkbox">4</input></td>
    </tr>
    <tr>
        <td><input type="checkbox">5</input></td>
    </tr>
<table>

 

With no IDs or attributes. Let's add those to each checkbox.

writer.WriteBeginTag("input");
writer.WriteAttribute("type", "checkbox");
writer.WriteAttribute("name", UniqueID + this.IdSeparator + repeatIndex.ToString(NumberFormatInfo.InvariantInfo));
writer.WriteAttribute("id", ClientID + this.ClientIDSeparator + repeatIndex.ToString(NumberFormatInfo.InvariantInfo));
           
if (Items[repeatIndex].Selected)
    writer.WriteAttribute("checked", "checked");

System.Web.UI.AttributeCollection attrs = Items[repeatIndex].Attributes;
foreach (string key in attrs.Keys)
{
    writer.WriteAttribute(key, attrs[key]);
}
writer.Write(">");
writer.Write(Items[repeatIndex].Text);
writer.WriteEndTag("input");
 

We have also added the "checked" to each checkbox. Now we are ready to insert the "missing" value attribute. Adding the following line will resolve the problem.

writer.WriteAttribute("value", Items[repeatIndex].Value);
 

Complete control code :

namespace yourNamespace
{
    public class CheckBoxListFixed : CheckBoxList, IRepeatInfoUser
    {
        void IRepeatInfoUser.RenderItem(ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
        {
            writer.WriteBeginTag("input");
            writer.WriteAttribute("type", "checkbox");
            writer.WriteAttribute("name", UniqueID + this.IdSeparator + repeatIndex.ToString(NumberFormatInfo.InvariantInfo));
            writer.WriteAttribute("id", ClientID + this.ClientIDSeparator + repeatIndex.ToString(NumberFormatInfo.InvariantInfo));
            writer.WriteAttribute("value", Items[repeatIndex].Value);
            if (Items[repeatIndex].Selected)
                writer.WriteAttribute("checked", "checked");
            System.Web.UI.AttributeCollection attrs = Items[repeatIndex].Attributes;
            foreach (string key in attrs.Keys)
            {
                writer.WriteAttribute(key, attrs[key]);
            }
            writer.Write(">");
            writer.Write(Items[repeatIndex].Text);
            writer.WriteEndTag("input");
        }
    }
}

 

And here is a bonus : How to use this control in my code?

Supposing the control isn't in another library and that you cannot add it to your toolbox, you can always use the Register directive inside your aspx file.

<%@ Register TagPrefix="yourPrefix" Namespace="yourNamespace" %>

Next, you can declare your control with the format

<tagprefix:CheckboxListFixed runat="server" id="yourID" />

Del.icio.usDigg It!DZone It!StumbleUponTechnorati


Thursday, 05 November 2009

Pragmatic Thinking & Learning – Book review

I have enjoyed it so much that I had to sent an email to Andy Hunt (the author) to tell him how much I appreciated his effort to write this wonderful book.

I have just finished reading Pragmatic Thinking and Learning a few moments ago and I believe it's a wonderful book.

Thank you!

I haven't had much interest in reading computer related book so much as this one for a long time. I have a strong interest in the content you provided and will begin to apply what I can right now. Starting by re-reading the book and doing a Mind Map to be sure I picked all the interesting stuff.

Excellent!  If you have a chance, please post some happy comments like these on amazon.com.  It really helps.
Good luck, and all the best!
/\ndy

 

 

This book is about the process of learning and thinking. How the brain works. But with an programmer point of view.  Andy Hunt start by showing the Dreyfus model of skill acquisition which is describing the different type of skill level and how you go between them. Just for the info, the Dreyfus model has 5 levels : Novice, Advanced Beginner, Competent, Proficient, Expert. He describe each level in detail and how to recognize it. And most importantly, how to act accordingly.

He also describe the R and L mode (left brain and right brain) and how to improve the flow between them. This is how you can remember think without thinking.

There is also a lot of the content dedicated to various method to “refactor” your brain. Each one is focused on being a better learner or to think more efficiently. Morning pages, mind map, SQ3R, etc.

I even had to apply some techniques described right away. Doing a mind map of what I’m trying to figure out or when I’m trying to absorb knowledge has helped me tremendously. It’s been almost a month now and I see some improvements.

I like to learn something new everyday and care a lot of the quality of what I am learning. So, it’s the reason I must give 4.9 star out of 5 (and yes, I will post a review on Amazon Mister Hunt).

Del.icio.usDigg It!DZone It!StumbleUponTechnorati


Thursday, 08 October 2009

ASP.NET MVC Request Handling Poster

niceposter If you need to visually look at what happens on an ASP.NET MVC request, look no further. Steve Sanderson has created a poster that will help me better understand the request pipeline. I have been looking for a long time for a resource like this, I’m a visual learner (I think) and seeing the plumbing visually is just great.

Thanks for Steve Sanderson for sharing his Request-Handling Pipeline Poster.

Del.icio.usDigg It!DZone It!StumbleUponTechnorati


Wednesday, 07 October 2009

My opinion about Duct Tape Programmer

duct-tape As everyone else, I have been following the discussion about the Duct Tape Programmer post that Joel Spolsky has written. If you haven’t read it yet, go read it and be objective.

 

Simple is better, less is better

I agree with him, really! Not totally, but the essence of what I believe is written there. It’s all about simplicity. I want my code to be simple. If I need to figure out what it’s doing, I will refactor it until I can understand it easily. And I will never consider the use of a framework or another piece of technology if I really don’t need it. Adding things for fun or for learning purpose can be fun, but it’s not the most important aspect of software development.

I just want to stay away from complicated stuff. Simpler is better. Less is better. If there is a way to accomplish a task easily without a grandiose architecture, then I’ll do it.

And don’t forget that the ultimate goal is to ship it!

 

TDD

But, I refuse to let TDD down. I don’t know why everyone else is talking about Joel hatred concerning unit testing (am I to only one not reading his blog religiously?) but I need to put my feet here and give my opinion about TDD in this context. TDD allow me to write simple code. Just what is needed and nothing else. I don’t think it slows me down. I don’t think it gave me a lot more speed on my productivity, but it sure as hell helped me a lot in making things simple. But! Yes It could slow down dramatically a new team that has never done any sort of unit testing. Why not, you need to think a lot more of how you are going  to do things and it’s not easy to get out of the “write and forget about until we test” state of mind.

 

TDD and 100% code coverage

One of the aspect of unit testing that can be a problem is the 100% code coverage mark. Most people are trying to test everything and will put a lot of effort in it. Why should it be important to cover every single line of code. Not everything should be tested. Automatic property in C# should not be tested. Use your judgement.

Del.icio.usDigg It!DZone It!StumbleUponTechnorati
Tags: | Categories: Agile
E-mail | Permalink | Comments (0) | Post RSSRSS comment feed