personal comments edit

If Joel can do it with FogBugz, I can try and do it with my blog. That “it” being to post a picture of the day.

metro
entrance

This is one of many metro entrances in Bilbao, Spain, home of the Guggenheim Bilbao. As I stated in a previous post, Bilbao is full of interesting design touches like these cool entrances.

Strangely enough, we never went in the metro in Bilbao because everything we wanted to see was within walking distance or a short bus ride.

comments edit

Branching
Diagram I can’t believe I didn’t notice this when he first published it (I only saw an internal email on it), but Steve Harman wrote this excellent guide to branching with CVS, complete with an easy to follow diagram.

He created these guidelines for the Subtext project, but they can just as easily apply to any project using CVS as an example of a sound branching policy. Keep in mind that for many branches you may encounter in the wild, you are typically done at Step D. However, in some cases you may want to continue making experimental changes on the same branch (rather than creating a new one), in which case (as the diagram points out), you continue repeating steps B through E.

If anybody out there has some constructive feedback, I am sure Steve would love to hear it. Afterwards, I will try and incorporate this into my Quickstart Guide to Open Source Development With CVS and SourceForge. Happy branching!

comments edit

In this post, I plan to give out some rough code I hope you find useful. But first, an introduction. Occasionally, in the search to compress more into less space, web designers will create a form in which the text inputs double as labels. For example, this is a login control I wrote for a recent project.

Login Control

Usability Issues:\ In my mind, this idea making the standard text box perform the double duty of being a label has several usability problems. First of all, in a large enough form, if the user starts filling in data, and then realizes after the fact that he or she made a mistake, the user no longer has any context of what each field represents except the mistaken information they typed. Believe me, it happens.

Secondly, notice that the password textbox displays the word “Password”. Well what happens when the user starts typing his password? With a normal text input, it is there for the world to see. If you use a standard password text input there, then how would you display the label text? It would look like ********.

A compromise\ However, it is important to give the client what they want, and what do I know about web design? So I created a control named TextBoxLabel that helps resolve some of the usability issues. I need to give some credit to Jon Galloway who showed me one implementation of this idea that spurred me to try and iterate on it and make it even better.

Requirements

  1. When the control receives focus, I want the user to be able to begin typing immediately. Originally, I cleared the textbox, but I found that simply selecting its contents works just as well and has the added benefit that you can still see the label when you give the control focus. Also, if you clear the field when it receives focus, you’ll run into problems in pages that automatically give focus to the first text input, since the field will be cleared before the user has a chance to read it.
  2. When a control loses focus, and its contents are blank, I want to make sure we re-populate the label. Some implementations use the javascript property textInput.defaultValue to do this, but I found one flaw in this approach. What happens if you use this control to edit an existing record. The default value will be the current value, not your label value. To resolve this, I use a custom attribute, “label”. Of course, if you clear the text input, perhaps you do want the original value and not the label value. In my case, that was not the desired behavior.
  3. In order to help maintain context, I made sure to add the title attribute to the textboxes. It’s a tiny improvement, but by highlighting a textbox with the mouse, a tooltip will show the user the label for the textbox.
  4. Finally, if the text input is a password input, I wanted to be able to display the label text in the control, but as soon as the control gets focus, I want to switch to a password mask text input. I accomplished this by having two text inputs and using javascript to switch between the two.

Demo\ I built a very simple demo you can play around with to see the control in action. Pay attention to how the password input changes to a text mask when you start typing in there.

The Code\ Unfortunately, it is difficult to present the code in a blog post because my web controls can’t be encapsulated in a single .cs file. That’s primarily because I make use of embedded resources for my client javascript (see Using Embedded Resources for Client Script Blocks in ASP.NET.

So instead, I created a simple web project that contains the controls and all supporting code files. Since I was at it, I added a few other classes I’ve written about in the past, including one control I haven’t written about. This is a small subset of our internal libraries. Over time I hope to provide more polish to some of our internal controls so I can publish more of it in this project. Here’s a listing of what you will find in this project (in addition to the TextBoxLabel control):

It’s not a lot, but it is a start. As these are controls we use internally, they aren’t necessarily the most polished and won’t work in all situations. We do not provide any warranty, liability, nor support for the controls. However, if you make improvements, feel free to let me know and I will incorporate them. You are free to use them in any project, commercial or otherwise.

The Link\ And before I forget, as I tend to do, here is a link to the code.

//TODO\ The controls do work with the ASP.NET validation controls, but not perfectly. When I say they “work”, I mean they work perfectly when client scripting is disabled. With client scripting enabled, you get some weird behavior. In part, I think this is due to how we hook into the submit event. The timing of method calls is important as the TextBoxLabel clears its value when submitting if the value is the same as the label. This makes sure that on the server side, you do NOT have to compare the value to the label to determine if it is valid. The side-effect of this approach is that if client validation prevents the form post, the textbox is now cleared. I haven’t spent any time to look into a better approach to this.

comments edit

This morning I woke up with visions of sugar code dancing in my head. It is a coding day and I was ready to sling it, only to be bowled over in stomach pain. Not sure what it was, but it was very unpleasant and wasn’t accompanied by any other symptoms like gas or otherwise.

So I put a heat pack on my stomach and went right back to sleep and just got up and am feeling somewhat better. At least I wasn’t in poor Danah’s shoes. No worshipping of the porcelain god this time.

comments edit

Christmas Lights These days I tend to find the holidays more a burden than something to look forward to. However with my family visiting us this year, I am quite excited. Maybe I’ll put up some lights like this display. The screenshot doesn’t do the video justice. It has to be seen.

comments edit

One common objection I hear to TDD and writing unit tests is that it creates a lot of extra work to develop software. And this is true, but it does not give a complete picture. TDD and writing and maintaining unit tests do take discipline and do increase the time (thus cost) of writing code. No doubt about it. However, this cost reflects the true cost of writing quality code and lowers the total cost of developing and maintaining software.

Unfortunately on many projects, management looks only at coding milestones to determine how quickly software is progressing. By milestone 1, these ten features must be implemented. What inevitably happens, assuming a tight deadline, is that developers cram and jam to get these features implemented and checked in by the milestone. They reach this milestone, and management checks these items off their project plan and record the time to completion and consider this to be the cost of developing these features.

This is completely wrong and gives a false sense of cost. Inevitably, the more time pressure a developer is to finish a feature, the more likely he or she will introduce bugs. Bugs that may not be caught much later and are much more costly to find and fix then.

Robert Glass points out in his book Facts and Fallacies of Software Engineering that Error removal is the most time-consuming phase of the life cycle. It can account for anywhere from 30 to 40 percent of the time spent coding. However this time is often booked to the task debugging and not booked back to the original feature, giving a true sense of the cost and time involved to implement the feature.

Glass also points out that 80% of the cost to implement a project is spent in the maintenance phase. I don’t know about you, but I’ve had the unenviable task to maintain a large creaky system whereby I would make a change to implement a new feature or fix a bug, and would hope and pray I didn’t break something else in some subtle manner. I would spend way more time trying to test and verify my change than it took to implement the change.

This is where I believe that unit tests ultimately provide their cost savings. They both reduce the true cost of developing a feature and reduce the Total Cost of Ownership (or TCO) of a codebase.

They reduce the true cost of software development by promoting cleaner code with less bugs. They reduce the TCO by documenting how code works and by serving as regression tests, giving maintainers more confidence to make changes to the system.

Remember, as in all writing, consider your audience. The audience for your code is not the compiler, it is the poor maintenance programmer six months from now who has to go in and make a change to the system. Sometimes that poor soul is yourself. Believe me, that person will thank you profusely if the system has sufficient unit tests.

And before I’m misquoted, I want to remind the reader that my predilection for unit tests does not mean that it is a substitute for other forms of testing.

comments edit

The Greatest Wesner writes that a couple of readers criticized him for his desire to aspire for greatness. Well obviously Wesner, you should aspire for mediocrity! In any case, one reader comments,

YOU do not get to tell if you are great or not.

And I agree that you do not get to decide if “history” or the public at large considers you to be “great” in whatever definition of that word you mean. However that misses the point entirely. Who gives a rat’s ass what the public thinks.

Visualize Greatness\ Wesner’s point is that his life is under his control, not that of others. Therefore it does not really matter whether the public sees him as great. Rather, he will strive for greatness and let the chips fall where they may. At least that’s my take on it, and you know I’m never wrong.

A valuable lesson I learned a long time ago is to behave as if you’ve reached where you want to be. You want to be a better soccer player, adopt the habits and obtain the mindset of a better player. You want to be a better developer, behave like one. This goes beyond simply visualizing your goals and has applications in many facets of life.

Business\ My first job out of college was at a very small consulting company. We wanted to grow and be a larger, well organized, well executing company. However there were times I would get frustrated at our progress and our perceived lack of professionalism. It occurred to me one day that I had to stop whining about it and start behaving as if we were already the company we strived to be. So we worked at it, became better organized, and started executing like a more professional firm (certainly with our ups and downs). We started to behave like a well run larger firm and it worked!

Relationships\ Despite all evidence to the contrary, I wasn’t exactly a ladies man growing up, and a lot of it had to do with lack of self confidence. It wasn’t till college that I started to get my “flow” going. In part this was a result of starting to behave in a confident manner as if I was already God’s gift to women. Sure enough, it had an effect. Just ask my wife about the night we met. Perhaps I was a bit too confident. ;)

For me, I’m not necessarily striving for greatness. Greatness is a very vague term. I would prefer well-liked and well-respected. That would do nicely. Just remember, it’s not wrong to strive for greatness or other goals, just behave in a manner of one who has achieved the goals.

comments edit

In his post Unit tests are the new documentation Scott sees unit tests as an undue burden much like documentation. Documentation, typically written after the fact, inevitably falls sway to the laws of entropy and becomes hopelessly outdated.

On one level, I do agree that unit tests are the new documentation, but I would add new and improved! Unit tests are a great way to provide code samples to document how an API is to be used. Though agile proponents point out that the code (when well written) is the documentation, well named methods and variables only tell you what it does and what they are used for, but not how to use it. There are several ways that I see unit tests as better than your traditional documentation.

Unit Tests Are Closer To The Code\ First of all, unlike traditional documentation sitting in a binder or word doc on the corporate network, your unit tests are typically in a project within the same solution the unit tests test. It is even possible to place the unit tests within the code being tested, but I personally avoid this approach. So it isn’t as close to the code as the code itself, but it is far closer than a word doc sitting on the network somewhere.

Unit Tests Are Hard to Ignore\ Once you’ve adopted unit testing and made it a habit, having unit tests get out of synch with your code is hard to ignore. For one thing, unlike documentation, unit tests compile. If they don’t compile, well you know they are out of date. Secondly, if the unit tests compile, but do not pass, then you know they are out of date. Documentation doesn’t provide any sort of notice.

Unit Tests Are Written As You Go\ The holy grail of documentation is to write it as you go, but you rarely see that in practice. However in places I have worked that have adopted Test Driven Development, I have not seen this same problem with unit tests. Unit tests are written as you develop. It becomes part of the development process. In part, once a developer sees the value in unit tests, it is not hard to integrate it into his/her programming style.

The Question of Discipline\ Many who question or are unfamiliar with unit testing assume that it requires a lot of discipline and will be the first thing to fall out during tight deadlines. But this isn’t necessarily true when TDD is adopted as good software practice. It doesn’t require much more discipline than using source control. These days, I hardly realize source control requires any discipline at all because it is so well integrated into my work style. But if you think about it, it really does take discipline to do it properly. Especially if you employ branching. Likewise TDD does take some discipline, but it becomes second nature. And the benefits are worth it. Documentation, though providing some benefits, requires much more discipline to keep in synch.

comments edit

Sam Gentile is preaching and I am in the choir. I’ve talked about the benefits of unit testing and refactoring in the past, but Sam makes this great point.

BDUF makes a huge gamble that all the business and development people can think of all the X’s up front in the “requirements” stage. In my 22 years of software development, I have very rarely seen that this is the case, Why? Many the aspects of design of software and the problem are completely unknown until one begins to write the test or the code. Code speaks to you. It tells you which way to go. Often we need to learn what its saying, upgrade our original understandings. Thats why Red-Green-Refactor works so well. You think a bit, write a test, write some code, and then refactor it based on the new learnings that you have made while doing it.

This is in response to the critics of refactoring and TDD who suggest that software developers simply spend more time thinking about the code up front in order to produce better code. But as Sam points out, what use is better code if it does the wrong thing?

And this point is crucial. When you wrote the code, it may well be doing the right thing. But somewhere down the line, some biz dev guy is going to realize what he sold the client is completely different than what he told you. Now your correct code is incorrect and you don’t have the safety net of unit tests to help you refactor the code to now correct thing. This, Virginia, is how the real world works.

comments edit

I haven’t confirmed this myself, but I believe Scott when he says that the latest version of RSS Bandit changed some of the keyboard settings. In particular he states that to mark a post as read changed from CTRL+M to CTRL+Q.

The reason I didn’t notice is that I am using customized keyboard settings. It isn’t too hard if you use my (unsupported) keyboard setting tool for RSS Bandit.

I wrote up a two-part article about how keyboard settings are implemented, but the only part you really need is part 2 in which I describe a quick and dirty tool for modifying keyboard settings.

This tool simply provides a GUI for modifying the ShortcutSettings.xml file (an embedded resource file available with the source code) and making a copy of it to the following directory: C:\Documents and Settings\YOUR_USER_NAME\Application Data\RssBandit\ShortcutSettings.xml. Once there, new installations shouldn’t override your custom keyboard settings.

comments edit

In case you were wondering, this is where my wife and I will be spending our New Years Eve this year. Some of the highlights of the expansive line-up include John Digweed, Christopher Lawrence, The Crystal Method, Miguel Migs, Muytaytor and Black Eyed Peas (though they seem a bit out of place, they are a hot ticket).

This is one of them big-fangled parties, taking up six blocks in downtown Los Angeles. Yeah, there will be a lot of people (maybe even too many), but this particular party has sentimental value since it is the party my wife and I met at in 2001/2002. We’ll make sure to ride the ferris wheel.

In part, I post this to make Jayson jealous.

comments edit

Apparently I am quite sensitive to jet lag. My wife has been cheerful, upbeat, and energetic, while I’ve come very close to biting the heads of little babies and throwing my own feces on the wall. Yeah, it’s that bad.

In this dazed catatonic state, I’ve found my mind to be a blank slate. Not the good kind of blank slate which implies a fresh start. No, I am talking about that dreary empty slate that means I am bereft of ideas. Tap on my head and you hear an endless echoing inside.

The end result is that I am suffering (and “suffering” is not too strong a word my friend) from Bloggers Block. My friend Jon tells me he has five unfinished posts and notes for at least 50. I checked my notes and I have about zilch ideas waiting in the wings.

The best way to beat writer’s block is to write. Anything. So there you have it. I am making you, the reader, suffer through this mindless drivel, so I can remove a block. Interesting content will follow in the future. One hopes.

comments edit

Upon returning from any vacation, I usually have a great desire to upload all my pics to Flickr and give each one a detailed, witty, interesting description. About five pictures into the process, I grow fatigued and give up on the whole process. So what if the picture is named DC32101?

Also, with jet lag, it makes it difficult to focus. So rather, I’ll post a link to the pics on Flickr for those of you who enjoy that sort of thing.

Palacio
Real For the rest of you, I’ll post some highlights. We started the trip off in Madrid. We were only here for one day and didn’t get to see much. That wasn’t a problem for me since I lived around here for three years already. To the left is a picture of the royal palace at night.

While in Madrid we also visited Torrejon de Ardoz, the place where I lived back in the day. Not much to look at, but it has sentimental value for me.

Leon
Parador Our next stop was in Leon where we stayed in a magnificent Parador. A parador is a government-owned hotel, often in a converted historical building such as a castle, monastery, etc… I think the one we stayed on was a converted palace or castle. Apparently it also served as a jail during the civil war.

The parador has its own cathedral attached and an internal cloister. It was really beautiful inside and out and the best part was that we were able to explore on our own. It really felt as if we were staying inside a museum exploring ancient nooks and crannys.

Guggenheim From Leon we headed over to Bilbao, home of the very famous Guggenheim Bilbao museum designed by Frank Gehry. From what we learned, the inspiration for the design is a Salmon. It is hard to tell from this picture, but the museum has the shape of a very large fish. Its outer walls are made of titanium sheets and must have given the construction teams and engineers nightmares with its odd angles and shapes.

What was most interesting to me was to learn that before this museum was built, Bilbao was a pretty industrial city with very little of interest to tourists. However, with the introduction of a beautifully designed museum, the entire city became devoted to design in some way or another. Everywhere we looked we found interesting touches of design such as the entrances to the metro.

Sagrada Familia
Barcelona Our last stop was the lovely city of Barcelona located in the Catalunya region of Spain. Though as one graffiti sign reminded us, “Catalunya is not Spain”. Catalunya sees itself as a fairly independent entity and Barcelona is its capital.

The architecture in Barcelona was dominated by a single great architect, Antonin Gaudi. It seemed that nearly every significant building in the city was either by Gaudi, or a disciple of Gaudi. His most famous work is the unfinished cathedral, Sagrada Familia. It was intended to be a project that would be left to future generations to finish, and construction continues to this day.

Ronaldinho The highlight of our trip (at least for me) was our fantastic seats at the FC Barcelona game. In the pic on the left, you can see how close to the action we were. That’s a picture of Ronaldinho actually missing a penalty kick. No worries, as he had another opportunity later that he converted during their 4 to 1 win over Racing Santender.

FC Barcelona is clearly the pride of Barcelona, especially after their recent 3 to 0 dismantling of Real Madrid, Barcelona’s perennial arch-nemesis.

comments edit

Alright. Enough about vacations, it’s time to get back to work, so let’s dig our teeth into the dispose pattern again. In a recent post, I wrote up a potential error I saw in the Framework Design Guidelines.

In a follow up on Brad Abram’s blog, Joe Duffy confirms that if they neglected to mention something about chaining a dispose call to the base class, that would indeed be a book bug/omission. He then points out how in the typical pattern, not chaining the dispose call could end up being very bad and difficult to track down.

To my second question, he points out that in general, it is not a good idea to call a virtual method from your Finalize method, but they made an exception for the Dispose pattern because it is carefully controlled. Virtual calls during destruction are not as dangerous as virtual calls during construction, which in general is a no no.

So suffice to say, the general (potential) enhancement to the Dispose pattern I suggested with the additional virtual methods for clarity won’t introduce any new problems. It’s really a matter of style and a question of whether or not it makes the code more readable or not. That is for you to decide.

comments edit

This post about crosswalk countdowns and icons reminds me of the crosswalk icon in Bilbao.

As I mentioned in my highlights from Spain post, Bilbao seems to have embraced design since the Guggenheim was built. One example of this is their crosswalk lights. Not only is there a countdown, but the crosswalk icon itself is animated, showing a person walking. However, as the countdown gets closer to zero, the animated figure starts to run, not walk.

Cool!

comments edit

Well my wife and I arrived back from Spain tonight after a grueling series of flights. Is it just me or has this heightened security environment we live in today given airport staff a crutch to be completely rude and uncommitted to decent service? Is it not possible for security and service to go together hand in hand? It is certainly something we strive for as software developers.

Complaining and bitching aside, we had a great trip and I’ll be sure to bore you with some more detailed stories and photos later. Posting vacation photos on a blog is the modern equivalent of those old three hour slideshows your parents used to bore your neighbors with after a long vacation.

And here we see yet another picture of a stained glass window. Notice the colors, that pretty much look like the last 132 previous slides of stained glass windows.

One nice surprise is that while I was gone, my ad-sense earnings were higher than average. Perhaps I should take more vacations.

comments edit

Lynx Welcome!

Just going through various stats on my blog today and noticed that last month, there were 57 visits to this site using Lynx.

Lynx?

Are you serious?

Does looking at this site via Lynx make my ass look big?

Lynx, for the unitiated, is a text based browser designed to allow mainframes to present a browsing tool to its users. It is the first web browser I ever used back in college. You ain’t ever navigated the web till you’ve done it in a text browser.

So to you Lynx users, I should mention that we now have these newfangled 32-bit processors that are capable of running browsers that can render and format text and images. They’re really a hoot!

All kidding aside, my understanding is that people still use Lynx for accessibility reasons. For example, blind people can have the site read to them with a Stephen Hawking like voice. That’s pretty sweet.

comments edit

Map of Spain The missus and I are pretty much packed and ready to go. We have to be at the airport at 5 AM. Yes, that is AM as in early morning (or late at night depending how you look at it).

I doubt we’ll get much real solid sleep, so I probably won’t even try too hard. Besides, I am at that point before any trip where my mind is racing trying to figure out that one thing I forgot to pack. And there is always that one thing. As I step on the pain, it will suddenly spring forth into consciousness and I will curse myself for forgetting it. Whatever it may be.

Also, I am NOT bringing my computer. I am detaching from this here intarweb (though I will bring my iPod). So this blog will go radio silent for nine days unless we have spare time and happen to be in an internet cafe. I might login to delete comment spam.

P.S. While I’m gone, be sure to read some of my latest posts and let me know what you think.

**

If you start to miss me, just click on February 2004 to the right and start from the beginning as if I never left. ;)

comments edit

The Framework Design Guidelines has an illuminating discussion on the Dispose pattern for implementing IDisposable in chapter 9 section 3. However, there was one place where I found a potential problem.

But first, without rehashing the whole pattern, let me give a brief description. The basic Dispose Pattern makes use of a template method approach. I really like how they take this approach. Let me demonstrate…

public class DisposableObject : IDisposable
{
    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    //This is the template method...
    protected virtual void Dispose(bool disposing)
    {
        if(disposing)
        {
            Console.WriteLine("Releasing Managed Resources in base class!");
        }
    }
}

This disposable class implements a non-virtual Dispose method that calls a protected virtual method. According to the guidelines, classes that inherit from this class should simply override the Dispose(bool); method like so.

public class SubDisposable : DisposableObject
{
    protected override void Dispose(bool disposing)
    {
        Console.WriteLine("Releasing Managed Resources in Sub Class.");
    }
}

Notice anything odd about this? Shouldn’t this inheriting class call base.Dispose(disposing)? The guidelines make no mention of calling the base dispose method. However, just to make sure I wasn’t missing something, I ran the following code.

using(SubDisposable obj = new SubDisposable())
{
    Console.WriteLine(obj.ToString());
}

This produces the following output:

UnitTests.Velocit.Threading.SubDisposableReleasing Managed Resources in Sub Class.

Notice that resources in the base class are never released.

Also, while I applaud the use of a protected template method to implement the dispose pattern, I think it is possible to take the pattern one step further. The purpose of using template methods is bake in an algorithm consisting of a series of steps. You provide abstract or virtual methods to allow implementations to change the behavior of those distinct steps.

When I think of the steps it takes to dispose an object using the simple pattern, it consists of the following discrete step:

  • Calling Dispose indicates object is being disposed and not being finalized
  • Call into protected Dispose(bool);
  • Protected method releases unmanaged resources
  • if disposing
    • release unmanaged resources
    • Suppress finalization

So why not codify these series of steps into the pattern. The Simple Dispose pattern might look like…

public class DisposableObject : IDisposable
{
    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    void Dispose(bool disposing)
    {
        ReleaseUnmanagedResources();
        if(disposing)
        {
            ReleaseManagedResources();
        }
    }

    //Template method
    protected virtual void ReleaseUnmanagedResources()
    {}

    //Template method
    protected virtual void ReleaseManagedResources()
    {}
}

Notice that the Dispose(bool); method is now private. There are two new virtual template methods. Also note these are virtual. I did not make these abstract, since this gives the inheritor a choice on whether to implement them or not. This might seem like overkill, but it removes one more decision to be made when overriding this class. That is the goal of these patterns, to make doing the right thing automatic to the implementer.

In the previous pattern, an implementer has to remember what to do when disposing is true as opposed to it being false. Do I release unmanaged when its true? Or when its false. Certainly if you’re implementing the pattern, you should really know this down pat. But still it doesn’ hurt to make the algorithm more readable. Looking at this modified pattern, it is quite obvious what I need to do in the method ReleaseManagedResources. I probably need to add documentation to tell the overriding implementer to make sure to call base.ReleaseManagedResources().

The only open question I have with this pattern is whether or not it is safe to call base.ReleaseUnmanagedResources() from an implementing class. I need to dig into the C# specs to understand that issue fully. The issue is that from within ReleaseUnmanagedResources, you really shouldn’t touch any managed resources, because this method could be called from a finalizer thread. Is calling a method on your base class in violation of this rule?