Microsoft Ajax Enabled Web Site Organization Patterns

August 1, 2007

Lately I have been writing a lot of code utilizing the Microsoft Ajax framework. This means that I am writing “Ajax Services” to handle my asynchronous callbacks. Ajax Services is a term I heard from Rob Bagby which emphasizes the fact that while these services are generally in a .asmx file and the methods are decorated with the [WebMethod] attribute, they are not really web services. They are a special form of service made just for Ajax callbacks. This additional file has got me thinking lately about how I can organize the files in my web site so that it doesn’t get too cluttered.

Let me start off by saying that this post is just a diary of my thoughts and I don’t really think I have found the best solution yet. That is why I am putting this out there to see how others are approaching this situation.

Too Many Files

File Orginization In extreme cases, I can have four different separate files (6 if you count the code behind file) for just one page. Typically, you have one javascript file and one css file per website but I have found this to just be too cumbersome lately. I find that my css and js files just become too cluttered and hard to maintain. So I end up with:

  • .asmx – Contains the WebMethods for my ajax callbacks
  • .aspx – Contains the layout for my page in typically Asp.Net fasion
  • .css – Contains the style definitions for the page layout
  • .js – Contains the javascript methods which typically respond to events on my page and make callbacks to my ajax services.

So now lets look at a folder on the website which has 3 different pages – a very typical scenario.

Too many files!

This layout quickly becomes unwieldy in its own way. All of the sudden your solution explorer view of your site becomes very hard to navigate and it becomes difficult to maintain the references to all those files. Now if I have a very simple page which has no need for any ajax callbacks or custom css mixed in there, It sort of gets lost in the shuffle

Lost in the Shuffle

See how your eye can easily miss the ‘MyPage2-Simple.aspx’ page?

A Better Way?

Another idea I had was to have one folder per page which would look like:

Is this better?

This is a little better but it is still cluttered. Just for completeness, lets look at our site with only one js, css, and asmx file.

Cleaner?

While this definitely looks a lot cleaner, it also has a code smell of it’s own. Imagine what our common files (js, css, asmx) must look like. They have the code from 3 separate pages all thrown in together.

The last idea I will throw out there is to put each file type in its own folder.

Grouped Together

I also like this better than most but it breaks down pretty quickly when you have your web site organized into many folders. Do you keep the script, service, and style files in the root folders or do you have a Script, Services, and Style folder for each sub folder?

Like I said earlier, I haven’t really found a solution that I think is best. Currently, I am trying to organize my project by having each action in its own folder and within these folders I put all the extra files (style, script, or callbacks).

How do you organize your web sites? How do you non Asp.Net people organize yours?

Advertisement

My Learning Todo List

June 18, 2007

Asp.Net Alternative

All of this talk about Asp.Net being a leaky abstraction and having an overly complicated page lifecycle, I have been considering looking at some alternatives to see what all the fuss is about. I am one of those developers who has taken the time to learn a lot about the page lifecycle and am fairly comfortable with it. I don’t think this means that I should get too comfortable. I have to agree that the current model doesn’t really promote good design and separation of concerns like it should. So here is my “alternative to Asp.net” list:

Language Of The Year

I am also very interested in the trend to learn a new programming language every year. Many people have decided to choose one of the new cool languages like Ruby or Boo.  I was considering following suite until I watched this video over at YUI Theater. I realized that I have been using javascript on and off for over 8 years and I have never really stopped to learn it. So I have decided to make javascript my language for the year. Like many server side, compiled language programmers, I have never like javascript. Now that the tools for developing and debugging in javascript are improving I have decided to give it a fair shake. Visual Studio 2008 will even have intellisense for javascript! (how did this feature take this long to come about?) I think I will start my javascript journey by focusing in on javascript librarires – starting with Asp.Net Ajax and the Yahoo User Interface Library.

.Net 3.5

Lastly, there are is the huge learning opportunity that is .Net 3.5 which will become more mainstream with the release of Visual Studio 2008. I have already ready a couple of books on WPF and WCF but I also want to add:

That should keep me busy for a while. The hard part for me is not so much in the learning but in finding ways which I can apply new things to my work while still fitting in with the applications/frameworks we currently have deployed.


Codesmith 4.0 Feedback and Feature Requests

June 5, 2007

Codesmith is a product that I have considered purchasing multiple times in the past. It seems to be the code generations suite that has the best community built around it and I think that is a very import aspect of any software I purchase. Every time I download the trial of Codesmith, my trial expires before I find a compelling reason to purchase the product.

Well, the other day I received a free licence for Codesmith 4.0 professional so I decided to use it on a project I am working on. After spending a couple of days with the product there are many features which I feel are missing or need some improvement. Some of them seem so glaring that I plan on following up with support to make sure I understand the functionality and the documentation correctly. It is also possible that the scenarios that Codesmith is meant to target are just not what I am trying to use it for. It seems that Codesmith is very well suited for walking through database structures and generating stored procedures or some sort of custom data layer, but that is not really what I want to use it for.

Background

First I want to explain what I am attempting to use code generation for. Basically, I am generating an asp.net website based on configuration in a database. I already have a separate app that is used to input the configuration parameters and now I am trying to use Codesmith templates to generate the website. So here is the basic structure of my project:

I have created a base class for all the templates which includes some properties and functionality that will be common to all the code templates in this project. I created this class in Visual Studio and so it is in a re-usable dll. I also have other classes in this assembly which are used to hold common configuration parameters and such.

I plan on making three template files (.cst) for each aspx page I am generating. One for the code behind(.cs), one for the markup (.aspx), and one “master” template that will call the other two templates.

In the end, I will be writing my own client which will use the Codesmith API to run the templates and generate the website.

Visual Studio Integration

With visual studio integration being a feature, I assumed that this would allow you to view, edit, and run your code templates inside of Visual Studio. I was expecting an experience where I can open Visual Studio, choose “New Codesmith Project” or “Add Codesmith template” to an existing project and then begin editing both the .cst file as well as the .cs code behind file. Well, the only visual studio template that is provided is a “Add Codesmith project” which simply adds a Codesmith project (.csp) to your project. This features helps you manage code generation as part of your build process. And when it comes to editing and running your code templates, they still open up in Codesmith Studio which is external to Visual Studio. This wouldn’t be so bad except the development experience in Codesmith Studio is nowhere near as nice as Visual Studio. The intellisense only seems to work part of the time, the code formatting is not very configurable, and it just feels a lot more like editing in notepad than it does a development IDE.

Reading through the feature request at the Codesmith forums lead me to believe that I am not alone in my frustrations with the Visual Studio integration. I have seen other products do a much better job of leveraging the fact that I am comfortable and much more productive in Visual Studio. Codesmith Studio should only be for developers who do not have Visual Studio.

Assembly References

As I mentioned earlier, I want to use a common assembly to hold some base and utility classes for my templates. There is one problem though, if you want to use any external assemblies, they must be in one of three places:

  • The GAC
  • The Visual Studio PublicAssemblies Folder
  • The Codesmith Addins folder

So this basically means that I have to finish developing my external assemblies BEFORE I begin developing my code templates or I can just copy my assembly manually over to one of the folders above every time I make a new build of it. Well, that may not be so bad except for the fact that the Codesmith Studio holds on to the assembly once you use it in a template so I can’t replace it in the file system until I completely close Codesmith Studio. This is annoying to say the least.

I do not know how the Codesmith engine works under the hood, but I assume it is doing some sort of build which results in a .Net assembly or something very similar. I think it would be ideal if you could just have a Codesmith visual studio project type which would result in an assembly which could be referenced in other visual studio projects. This would really open up tons of new scenarios for sharing templates across applications as well as with the community. Having the templates in a assembly package would also make using the Codesmith API much easier. Instead of having to point the CodeTemplateCompiler to a .cst file, I would like to be able pass it an instance of a CodeTemplate class which it can then operate on.

Code Behind

I realize intellisense is probably a very hard feature to implement but whenever I use a product has it implemented but it only works sometimes, this almost makes me wish it weren’t there at all. If you can’t count on a feature, then it is more of an annoyance than a help. The code behind model seems like it is something that was just tacked on to Codesmith and is not really supported all that well. For starters, I can’t figure out how to add a .cs code behind file to the Codesmith Explorer window. If I right click, there is not “new C# file” option and if I try to rename another file to a .cs extension it complains that it is not a valid extension. The only way I have been able to add my own code behind files into the Codesmith explorer is to create a blank cs file and move it into the same folder as my template using windows explorer. Then it shows up in the Codesmith explorer. Maybe my experience as an Asp.Net developer pushes me towards the code behind model because it seems that Codesmith templates are more geared towards the inline classic asp type model of coding.

Conclusion

I hope all of this ranting makes you think I hate Codesmith. On the contrary, I think it is a pretty cool product that has a very wide variety of applications. I guess I am just spoiled by Visual Studio. I am a big believer that when you create tools for a development platform like .Net or Visual Studio, you should make things work just like they were always part of the platform. For example, if you are writing APIs, they should conform as closely as possible to the BCL standards as far as naming etc. Codesmith essentially introduces a new file type into my development arsenal: the .cst template file. Having to use these files outside of Visual studio when I am trying to integrate them with a project that is being developed inside of the Visual Studio IDE just feels wrong. I would love to hear from the Codesmith team as to what their plans are beyond version 4.0


Child Collections in Asp.Net Custom Controls

May 23, 2007

I have been developing custom web controls for many years now and I am just now getting comfortable with many of the advanced features afforded by the rich System.Web.UI.WebControls namespace. One feature I have implemented many different times over the years is having a web control which contains a list of sub items. For example, the Asp.Net GridView’s collection of Columns or the DropDownList’s collection of ListItems.

<asp:GridView ID="grid" runat="server"> 
    <Columns> 
        <asp:BoundField /> 
        <asp:ButtonField /> 
    </Columns> 
</asp:GridView>

There is so many things going on it a control like this that just seem like magic. How are the child items persisted in ViewState? How does the control know how to parse the child items? What if the whole world were a power ranger?

StateManagedItem

I have created a couple of classes that really simplify the process of creating lists of child items. The first of which is the class StateManagedItem. This class is the base class for all the objects which you wish to use as "Child Items" (like grid view columns or list items).

In order to manage state in Asp.Net, you have to implement the IStateManager interface. This interface allows objects to participate in the process of saving and retrieving things from ViewState. In order to generalize the whole process, I needed on other method to set an item as "Dirty" so I created the following interface:

public interface IStateManagedItem : IStateManager 
{ 
    void SetDirty(); 
}


So now we have the base interface for all state managed items. So here is the what the base class definition looks like:

public abstract class StateManagedItem : IStateManagedItem

This class provides it’s own ViewState for items to save their state in which essentially allows "Child Items" to save their state just like custom web controls do. To illustrate this concept, lets create an example class called Appointment which will hold information about a calendar appointment.

public class Appointment : StateManagedItem

The definition for this class is very simple. Here is how the properties are implemented:

public DateTime? Start 
{ 
    get 
    { 
        object o = ViewState["Start"]; 
        return o == null ? null : (DateTime?)o; 
    } 
    set { ViewState["Start"] = value; } 
}

If you are familiar with using ViewState to store web control properties, this syntax should look fairly familiar. That that is all there is to our child item.

StateManagedCollection

The next helper class is a base class for the collection of items. In our example, we need a collection of Appointments. For this purpose, I have created a StateManagedCollection<T> class which can be used to hold the child items.

public abstract class StateManagedCollection<T> : IList<T>, ICollection<T>, IEnumerable<T>, IStateManager, 
    IList, ICollection 
    where T : class, IStateManagedItem, new()

If you are not familiar with generics and generic constraints, this is basically a list class which requires the child items to be a class (not a struct), derive from IStateManagedItem, and to have a default constructor.

So to create our list of Appointments, all we need to do is the following:

public class AppointmentCollection : StateManagedCollection<Appointment> 
{ 
}

That is it as far as the AppointmentCollection class goes. It doesn’t require any more code.

Sample Control

So lets finish the example by creating a custom control which displays a list of Appointments. First we will derive from Composite Control:

[ParseChildren(true), PersistChildren(false)] 
public class AppointmentControl : CompositeControl

Note the ParseChildren and PersistChildren attributes, these are required to tell Asp.Net how to parse the markup inbetween the start and end tags of your control. This is part of the "Magic" I mentioned earlier.

Next, make a member of the class which is an AppointmentCollection:

private AppointmentCollection appointments = null;


And a public property to access that collection:

[ 
    Mergable(false), 
    PersistenceMode(PersistenceMode.InnerProperty), 
] 
public AppointmentCollection Appointments 
{ 
    get 
    { 
        if (appointments == null) 
        { 
            appointments = new AppointmentCollection(); 
            if (base.IsTrackingViewState) 
            { 
                appointments.TrackViewState(); 
            } 
        } 
        return appointments; 
    } 
}

This property also must have a couple of attributes – Mergable and PersistenceMode. These basically tell Asp.Net and Visual Studio how to handle and persist this property.

To use this control, first place the proper includ directive on your page:

<%@ Register TagPrefix="web" Namespace="Web.Example.Appointment" %>

Now we can declare our control markup as:

<web:AppointmentControl id="appointmentList" runat="server"> 
    <Appointments> 
        <web:Appointment Start="1/6/2007 8:00 AM" End="1/6/2007 11:30 AM" Description="Breakfast" /> 
        <web:Appointment Start="5/12/2007 9:30 AM" End="5/12/2007 9:45 AM" Description="Meeting" /> 
        <web:Appointment Start="5/12/2007 10:00 AM" End="5/12/2007 10:30 AM" Description="Break" /> 
    </Appointments> 
</web:AppointmentControl>

I won’t go into the render code (you can download the source code to see all the gory details) but here is how the control renders:

You have 3 appointment(s)

  • Breakfast – (01/06/2007 08:00:00 – 01/06/2007 11:30:00)
  • Meeting – (05/12/2007 09:30:00 – 05/12/2007 09:45:00)
  • Break – (05/12/2007 10:00:00 – 05/12/2007 10:30:00)

You can download the full source code here. Hope this helps dispell some of the "Magic" of Asp.Net controls.

kick it on DotNetKicks.com


DelimitedList<T> – a useful utility class

May 22, 2007

There are several classes which I have written over the years which have become almost like my own personal BCL when developing .Net projects. I think most people have these classes laying around in some form or fashion. In fact, I have joined a formalized effort led by Steve Wright to make an open source version of this “Toolbox” called nToolbox. While that project is getting off the ground, I figured I might share some of the classes which have been very useful to me personally. If this topic interests you, you can read my previous post where I shared some code which I use to find Controls on an Asp.Net page.

Background

Here is the situation I kept finding myself in – I will use the case of a comma delimited list of items since it is the most common scenario:

I want to loop through a list of strings and build a comma delimited list. The code begins something like this:

string[] items = new string[] 
{ 
    "Apples", 
    "Oranges", 
    "Pears", 
    "Bannanas" 
};    

StringBuilder list = new StringBuilder();       

foreach (string item in items) 
{ 
    list.AppendFormat("{0},", item); 
}       

Console.WriteLine(list.ToString());

The problem with this is it will produce the following string:

Apples,Oranges,Pears,Bannanas,

Notice that there is a trailing comma on the end. So then I end up having to explicitly remove that last comma by either not adding it on the last iteration through the loop or by removing it after the loop has completed.

DelimitedList

So I wrote a class which will help me produce such lists but without the pain of remembering if there is a comma at the end or not. Although the DelimitedList class defaults to just having a single comma as its delimited, it can actually have any string as a delimited. I have used it in the past to delimited things by pipes ‘|’ and even line breaks which can be useful when you want one item per line.

Rewriting the same code above with the delimited list would look like this:

DelimitedList<string> list = new DelimitedList<string>();       

foreach (string item in items) 
{ 
    list.Add(item); 
}     

Console.WriteLine(list.ToString());
Now this will produce the expected string:
Apples,Oranges,Pears,Bannanas

The DelimitedList can also work on any type of object (thus the use of Generics) so you can use it with types other than strings: (just for varieties sake, I will use a delimiter other than a comma)

DelimitedList<int> list = new DelimitedList<int>("+");       

for (int i = 0; i < 10; i++) 
{ 
    list.Add(i); 
}       

Console.WriteLine(list);

This will produce the following string:

0+1+2+3+4+5+6+7+8+9

You can download the complete code for the DelimitedList class here


YUI.Net: Calendar Control

May 21, 2007

The first control I will highlight in the Yui.Net control library is the calendar. I find that I often need a client side calendar control to allow users to just choose a quick date without having to deal with the overhead brought on by the Asp.Net calendar control (ViewState, Postback, etc). When I ran across the YUI calendar I was really impressed with both its functionality as well as it customizability.

The Basics

In order to just get a basic calendar displayed on your page, you need to include two things:

1. The YahooScriptManager

<yui:YahooScriptManager ID="manager" runat="server" />

2. The Calendar Control

<yui:Calendar id="cal" runat="server" />

On the server site, the Script manager generates the following code:

<script src="http://yui.yahooapis.com/2.2.2/build/yahoo-dom-event/yahoo-dom-event.js" type="text/javascript"></script> 
<script src="http://yui.yahooapis.com/2.2.2/build/calendar/calendar-min.js" type="text/javascript"></script> 

<script type="text/javascript" media="Screen"> 
function SetHiddenSelectedDates(type, args, obj) { 
    var txtDate1 = document.getElementById(obj.id + "_selectedDates"); 
    var selected = ""; 
    var dates = obj.getSelectedDates(); 
    for(var i = 0; i < dates.length; i++) 
    { 
        var month = dates[i].getMonth() + 1; 
        var day = dates[i].getDate(); 
        var year = dates[i].getFullYear(); 
        selected = selected + month + "/" + day + "/" + year + ","; 
    } 
    txtDate1.value = selected.substring(0, selected.length - 1); 
} 
</script> 

<link href="http://yui.yahooapis.com/2.2.2/build/calendar/assets/calendar.css" rel="stylesheet" type="text/css" media="Screen" /> 

<script type="text/javascript" media="Screen"> 
    var cal; 
    function init() { 
        cal = new  YAHOO.widget.Calendar("cal", "cal_container", { pagedate: "05/2007"} ); cal.render();cal.selectEvent.subscribe(SetHiddenSelectedDates, cal, true); 
    } 
    YAHOO.util.Event.addListener(window, "load", init); 
</script>

There are 3 things I would like to point out in this code (not necessarily in the order they appear):

First, there are the includes of the yahoo-dom-event.js and the calendar-min.js files which are hosted on the yahoo servers. YUI.Net also allows you to host the files yourself if you need access to the debug scripts or if you just prefer to store the files locally. the calendar.css file is also included which contains the default styles for the calendar control.

Second, there is the javascript initialization code in the last script block. This initializes the calendar with the default values and hooks up the event handler for the selectEvent event. This allows the calendar to store the selected dates in a hidden html field for use on the server side.

Lastly, there is the SetHiddenSelectedDates method which is responsible for taking the selected dates and storing them as a comma delimited string in a hidden html field.

The calendar control renders the following html markup:

<div id="cal_container"></div><input type="hidden" name="cal_selectedDates"></input>

This is basically just the div which will contain the calendar and the hiddent field to hold the selected dates. Notice that the name of the div is the same that is passed in to the YAHOO.widget.Calendar constructor.

Server Side Properties

public DateTime[] SelectedDates

This returns a list of dates currently selected. It achieves this by parsing through the hidden html field mentioned earlier which stores all of the selected dates in a comma delimited list. This property is read only.

public string SelectedDateString

This string maps to the ‘selected’ property of the YUI calendar configuration property. (Side note: this can get a little confusing because there is a while javascript object model which does not always map directly to the sever side .Net object model). Here is an excerpt from the YUI documentation for this property:

Sets the calendar’s selected dates. The built-in default date format is MM/DD/YYYY. Ranges are defined using MM/DD/YYYY-MM/DD/YYYY. Month/day combinations are defined using MM/DD. Any combination of these can be combined by delimiting the string with commas. For example: “12/24/2005,12/25/2005,1/18/2006-1/21/2006”

public DateTime? SelectedDate

Allows for a quick way to access the selected date for calendars which are limited to just one selection. A nullable date is used so a null can be returned if no date is selected.

public int Pages

This allows support for multiple calendars in one control which appears like:

This causes the calendar to be rendered as a YAHOO.widget.CalendarGroup rather than a YAHOO.widget.Calendar. This is an example of where I have tried to make such functionality transperant to the user.

Here is how the rest of the properties map to the YUI javascript properties:

Yui.Net Server Side Property YUI client side javascript property
PageDate pagedate
MinDate mindate
MaxDate maxdate
Title title
Closable close
UseIFrame iframe
MultiSelect MULTI_SELECT
ShowWeekdays SHOW_WEEKDAYS
MonthFormat (enum) LOCALE_MONTHS
WeekdayFormat (enum) LOCALE_WEEKDAYS
WeekStartDay START_WEEKDAY
ShowWeekHeader SHOW_WEEK_HEADER
ShowWeekFooter SHOW_WEEK_FOOTER
HideBlankWeeks HIDE_BLANK_WEEKS
NavLeftImageUrl NAV_ARROW_LEFT
NavRightImageUrl NAV_ARROW_RIGHT

In some cases I have renamed some properties to make them more Asp.Net like and changed thier types from numbers to enums to provide a better user experience.

As you can see, most of the power of this control comes from the javascript provided by Yahoo – which is why the YUI.Net is mostly a wrapper with some funcationlity added.

Technorati tags: ,


Asp.Net Controls for the Yahoo User Interface Library

April 20, 2007

I am a big fan of yahoo! and how they handle their developer resources. They release APIs for most of their services free of charge and their documentation is always top notch. One of my favorite developer resources they support is not a service but a group of javascript libraries called the Yahoo User Interface Library (YUI).

Not only do I like the library itself, but I really like the community around it. (althought they could use a better forum than Yahoo! groups.) Like I mentioned earlier, the documentation is top notch. There is also a blog and and a series of screencasts about the YUI.  And if that isn’t enough, will now host the files on their servers.

Recently, I was working on an Asp.Net project where we needed some of the functionality provided by the YUI container controls. Being the web control guy I am, I decided to make a control to make working with the panel controls easier.

Next, I realized I needed the calendar control as well so I wrote a web control for that as well.  The next thing I knew I started writing controls to wrap the basic functionalities in many of the YUI controls and I had a class library on my hands. I have recently cleaned the code up a little bit and decided to share it with the world.

Keep in mind that I am not really much of a javacript expert so the client side functionality of the controls is just the bare minimum. In fact, if anybody else out there has any feedback on how I implemented the javascript, please let me know.

Here is the basic class diagram for what I have so far.

The inheritence heirarchy for the panels, mostly mirrors that of the YUI. The Module and Overlay classes contain functionality used by the Menu, FloatPanel, and the Tooltip controls.

Architecture

The basic architecture is that each control implements an interface called IYahooControl. This interface is used by the YahooScriptManager to generate the javascript needed to initialize the controls.

interface IYahooControl 
{ 
    string LoadScript { get;} 
    YahooScript[] ScriptScriptDependancies { get;} 
    YahooStyleSheet[] StyleScriptDependancies { get;} 
}

The script manager is a non visual control that must be placed on any page which uses any of the Yahoo controls. It bascially manages all of the script references and initilization of the client side controls.

In most cases, I have tried to match the object model of the YUI javacript classes as closely as possible.  There are however, some exceptions. I decided to make some of the properties function more like most Asp.Net controls when it made sense. For example, the YUI Button control has a property called ‘diabled’ which defaults to false but Asp.Net tends to use ‘Enabled’ and defaults it to true. Most of these changes should be fairly small.

I have tried to wrap most of the panel controls into one class called FloatPanel. This control can be set to draggable and resizable which will change the actual YUI class which implements this functionality automatically.

Helper Classes

There are several classes which I consider just general utility classes which I included in the project just so I can use them in the control. I will do a seperate post in the future going through some of those classes and why I feel they are essential.

Server Side Functionality

Since the YUI controls are client side controls, they don’t really have any inherant server side functionality. I have not yet made much effort to add this functionality yet. The only exceptio is the calendar control. I added a SelectedDates property which you can use on the server side to see which dates are selected. I implemented this by added a hidden field to the form and storing the selected dates in it on the client side.  This allows me to access that on the server side when the form is posted.

Future Plans

The biggest weakness of the controls I have build so far is they don’t really provide an easy way to plug into the rich YUI eventing model. I have not yet decided how I am going to approach this so any feedback is definitely welcome. I have put the code up on CodePlex so hopefully I can generate some interest and get some other developers to contribute to the project. There is another project on CodePlex related to the YUI controls which included both the Grid and the TreeView (which I have not yet implemented). I plan on taking a look at how are two libraries can possibly work together

Documentation

I would really like to follow in the tradition of the YUI and provide good documentation but that will have to wait until a future release.


The Spice of Life

October 27, 2006

Sometimes it can be a pain to subscribe to Rss feeds which are collections of many different authors.  For instance, back in the day, I subscribed to the main MSDN feed and it was just to laborious sifting through all posts to find just what I was interested in.  Not to mention the 100 obligatory “Microsoft product [Insert Name Here] has released a new CTP” posts that happened for every release. I have since just subscribed to the authors which I found myself reading the most often.

I was relieved to find that the main feed at codebetter.com is different. Since I subscribed to their main feed, I find almost all of the posts to be at least interesting if not very helpful and applicable. Why is this?  I really don’t know.  Maybe they are focused on a smaller number of good authors.  The posts range from jmiller’s short, quick, and entertaining posts (CodingLaw! and There are two types of developers in the world) to longer, more involved posts (A Wrapper Class for Spring .NET’s Inversion of Control-Dependency Injection and Creating-an-Ad-Publishing-Application).

Browse the topics covered on this site and let me know what you think!


My Journey Through "Applications = Code + Markup" Part 2

October 10, 2006

Ok, so I haven’t been writing as often as I had anticipated about my journey through Applications = Code + Markup by Charles Petzold.  Since my last post Petzold has posted some reactions to some of the common criticisms of his book.  It is definitely worth a read.

I read through the first part of the book pretty quickly.  I would read 2 or 3 chapters while not in front of a computer and then I would find a computer and type in and run most of the samples. I thought it was important to type in the samples myself instead of just using the sample code you download from the Microsoft Press companion website so I could get used to coding in the Visual Studio Cider environment. I found this technique to be very effective in recognizing common mistakes and errors and learning how to fix them.

The pace of my reading slowed down significantly somewhere around Chapter 11: Single Child Elements or Chapter 12: Custom Panels.  Not that the subject matter wasn’t interesting, I just found it very difficult to visualize without being around a computer to try out the samples. I just kept pressing though anyway with the intention of reading those chapters slower on my second pass through of the book (yes, I intend to read the entire book twice).

Chapter 18: The Notepad Clone was also very difficult to read.  This sort of “Tying it all together” chapter is required in most programming books so I don’t blame the author for the excess of code in this chapter.

The Xaml portion of the book starts in Chapter 19. Once I reached this point, the book became a page turner. There are so many WPF mysteries that are being revealed I can’t even keep track of all of them. I found the information on Resources, Data Binding, Styles, and Templates to be fascinating.  This, in my opinion, is where the real power of WPF is revealed. I have so many things I want to try using the techniques found in these sections that I am not sure when I will find the time. After I finish this book for the first time, I am going to write down all of my ideas so I can keep them in mind during my second reading. Stay tuned.

Technorati tags: , ,

My Journey Through "Applications = Code + Markup"

September 22, 2006

 I finally received my copy of Applications = Code + Markup by Charles Petzold.  It is rare that I buy a computer book with so much anticipation and desire to just sit down and read it cover to cover.  The last time I had this feeling was with Framework Design Guidelines by Brad Abrams and Krzysztof Cwalina.  That book was awesome and I definitely read it from cover to cover.

Petzold’s book is not the first book I have read on the Windows Presentation Foundation – I have also read Chris Sells’ Programming Windows Presentation Foundation which I would say was OK but not great.

Since it will probably take me a couple of weeks to work my way through Petzold’s book, I will just blog about my thoughts along the way.

First off, I love the idea of using just code and no XAML during the first half of the book.  This really drives home the idea that you should understand what XAML eventually translates to in code. In order to truly understand a technology like WPF, you have to start from the very basics and work your way up. It is such a new programming paradigm in so many ways that somebody who has experience with Asp.Net or Windows Forms programming will not necessarily be able to transfer all of their UI knowledge to WPF that easily.

I do, however, have some immediate gripes with the book (albeit small ones).  I definitely echo the sentiments found on some of the Amazon.com reviews regarding screenshots. I immediately noticed this books lack of any screenshots or diagrams.  On one hand, this goes with the whole learning from scratch thing and I can see how the author may be using this as a way to encourage the readers to try out the examples for themselves. I just think that a book on a presentation technology could really benefit from pictures to really drive home the point.

Another very small gripe I have is also echoed on amazon.com: the fact that every code example in the book has 3 lines of code that are not necessary – The copyright notice.

//------------------------------------------- // ProgramName.cs (c) 2006 by Charles Petzold //-------------------------------------------

I could see including these in the downloaded example code, but to print them in the book is just redundant and really adds up as far as space.  Hundreds of examples * 3 lines of code = many extra pages in the book.

I am sure I will have many more good to say about this book in the long run than bad as I really enjoy Petzold’s writing style and he is definitely very knowledgeable.