Tuesday, May 21, 2013

Write clean code. It should be mandatory!

So I'm several months in to my latest job and into my first experience digging into other peoples code. Before this I've always been rather fortunate and created code from scratch and was able to set forth the guidelines of how it should look, etc.

This time around, I get to play with other peoples code and what I found was not pretty at all. And I don't mean pretty as in it didn't "look" nice. This code base essentially followed everything that defined "bad code". It would be a prime example of it actually. Everything from Hungarian notation, using anything but SOLID principles and useless commenting and leftover dead code scattered everywhere. And that's just the beginning. Yes, it's THAT bad. It needs major re-factoring and lots of TLC.

That being said, as a professional developer, clean code should be one of your top priorities. And just what is clean code? That in itself is a topic made for a book. Which is something that fortunately has already been written. Check out the following book and see if you can spot any of your bad habits.

Clean Code - A Handbook of Agile Software Craftsmanship

Clean code = code that's easy to follow, debug and less prone to having bugs in the first place. Make it your priority!

Wednesday, February 6, 2013

Google acquires Channel Intelligence

It's official. The company I've been working for the past 9 months has finally been acquired. By Google no less. Quite a feat for a small company. http://lnkd.in/pdNipX

Monday, February 4, 2013

Onion Architecture

If you haven't heard about the Onion Archtecture, you really should spend a few moments to check it out. If you develop code using n-tier archtectures this may just be the future...

Check out my long time friend & coworker's blog on the subject: http://www.jackpines.info/

He's got slides explaining the architecture & it's benefits over traditional layered/tiered and even has a template created to help you get started. Definitely worth the time and you may just use it for your next big project. I know I will!

Using a detailed template in a Kendo UI grid...

Just a note to myself (and this may be useful to someone else). This was using MVC3/Razor with a Kendo UI grid control. Special gotcha's in RED.

To use a detailed template in a kendo grid…

Specify the template id in the grid you are creating
   à  .ClientDetailTemplateId("roleDetailTemplate") ß
.Columns(columns =>
          columns.Bound(c => c.RoleName);
          columns.Bound(c => c.UsersInRole).Width(100).HtmlAttributes(new { style = "text-align: center;" });
       .DataSource(dataSource => dataSource
         .Read(read => read.Action("RoleSelect", "AccountAdministration"))
         .Model(model => model.Id(p => p.RoleName))))

Then script the template for the detailed view:

<script id="roleDetailTemplate" type="text/kendo-tmpl">
       .ToolBar(toolbar=>toolbar.Create().Text("Add User To Role"))
       .Columns(columns =>
               columns.Bound(ud => ud.UserName);
               columns.Bound(ud => ud.LastLoginDate).Format("{0:dd MMM yyyy hh:mm:ss tt}").Width(170);
               columns.Bound(c => c.IsOnline)
                à .ClientTemplate("\\#= IsOnline ? '&#10003;' : '' \\#") ß Must use \\# in client templates in a detailed template for this to work as just # won’t do anything.
                   .HtmlAttributes(new { style = "text-align:center;" })
               columns.Command(commands => commands.Destroy().Text("Remove")).Width(95);
       .Editable(editable => editable.Mode(GridEditMode.PopUp).DisplayDeleteConfirmation("Remove user from role?"))
       .DataSource(dataSource => dataSource
           .Read(read => read.Action("UsersInRolesHierarchyAjax", "AccountAdministration", new { roleName = "#=RoleName#" }))
           .Create(create => create.Action("AddUserToRole", "AccountAdministration", new { roleName = "#=RoleName#" }))
           .Destroy(destroy => destroy.Action("RemoveUserFromRole", "AccountAdministration", new { roleName = "#=RoleName#" }))
           .Model(model => model.Id(p => p.UserName)))
        à .ToClientTemplate()) ß IMPORTANT

Cell formatting. Reducing the size of text in a Kendo UI grid.

Here's something I ran into while using MVC3/Razor & Kendo UI by Telerik. I needed a way to minimize what was shown in the grid cells. In my case I wanted to shorten the width of a column containing email addresses. Since there aren't spaces in email addresses, word wrapping is not going to happen.

So here's how I went about it (using Kendo UI Grid (MVC Template version)):

To shorten the length of an email address displayed in a row so it will fit better I did the following (same method can be applied to shorten a paragraph or other text):

I bind my column in my grid and applied a client template.

columns.Bound(c => c.Email).ClientTemplate(string.Format("{0}...", "#= formatter(Email) #"));

I wrote a javascript function to handle the formatting:

<script type="text/javascript">
    function formatter(value) {
        return value.substring(0, 10);


Wow.. Almost 2 years have passed since my last post. A lot has changed since then too. I'm not an avid blogger but I've sure used more than a few blogs to research issues I've come across that I couldn't quite find anywhere else. Maybe I'll continue to do so, only time will tell...