David Redding on Abstract Factory Pattern

At first I thought “that isn’t a factory!” but that is because the entire post wasn’t there in RSS.

My buddy David Redding has what could be the funniest explaination of the Abstract Factory Pattern that I’ve ever read.

He also mentions the Ann Arbor DotNET Developers meeting coming up on January 10th. It will be awesome to have an expert on Windows Workflow in town. If you are in the Ann Arbor area, stop by at 6pm and see Matt Winkler.

On : Downcasting is a Code Smell

I almost always tend to agree with Jeremy D. Miller over at CodeBetter.Com. This time, I still agree with him. I agree so much that I am wondering if he is joking or was having a bad day and posted this in frustration.

Jeremy, of course Downcasting is a code smell. It does all the bad things that you said it does. I thought that this was a given. I see code like this and I immediately assume that the person who wrote it either 1. was in too much of a hurry to take pride in their work, or 2. had no idea how to program using good OO concepts.

When I run into code like this I usually get VERY frustrated. It is never fun to run into ugly code. It is more frustrating to run into code that could be so much better with just slightly more than trivial understanding of the underlying libraries. I guess this is exactly what I wrote on with respect to System.Data over a year ago. Not the downcasting part, but rather just good use of the supplied interfaces instead of always using the concrete class.

It was downcasting that inspired me to write those posts over a year ago. I was working with a project which was using the DAAB from EntLib 1.0. DAAB returns IDbConnection and it was being Downcast to SqlConnection everywhere it was using in this project. I cursed a bit. Then I realized that all of the code was in my hands, and I went about cleaning it up. It was not difficult. That was something I COULD take pride in. Stupid, yes. Maybe a waste of time, but now I know that the next time I go into that module I won’t be disgusted by what I see.

Visual Studio 2003 web projects

If you use subversion for version control, you are probably aware of the .svn issues.

I feel like Studio 2003 is Developing Old School. I’ve fully embraced 2005. Now I can hear you developers that are ten and twenty years older than me talking about programming with buttons and switches and the graduation to teletype and finally dumb terminals. While I haven’t experienced that first hand, I can say that I can still develop with notepad or vi with the best of them.

Still, stepping back to Visual Studio 2003 after a full year of 2005 just feels old.

OK, the point is, that I am doing this. I’ve run into the well known .svn issue, and after some searching I think I’ve come up with a better fix than I’ve seen suggested yet.

My fix:
1. Close the project file.
2. Open in a text editor such a gvim or notepad2.
3. Change the value of the ProjectType attribute to “Local” from “Web” under the /VisualStudioProject/VisualBasic node.
4. Open the new project file in visual studio.

It turns out that the web project is just a class library project with a remote target. Why MS feels compelled to continue to abstract this for developers is beyond me. Developers should have a deep understanding of filesystems, both local and remote. If they do not, then purhaps they need additional training, or should consider a different career.

Mono is here to stay.

I couldn’t agree less with the idea that Mono is dead. That is the nice way that I say that I think someone is so dumb that they should not be allowed to write and communicate their opinions with others. I’m talking to you Neil McAllister. Mono is here to stay. I refuse to type the title or subtitle of the article to which I am referring.

Open sourcing Java under the GPL has no benefits compared to the state of Mono. At least half of the points regarding Microsoft and patents in the article are addressed on the Mono website under the Licensing FAQ. Neil McAllister is worse than the slime of the Open Source community that is Bruce Parens. Bruce just makes very stupid comparisons of closed source to the abomination of slavery. Neil just flat out lies. Alright, I retract that. Neil is not worse, he is equally low slime.

Neil seems to think that Java is just as good as the CLR (the runtime which runs .NET and Mono applications.

…recent releases of Java have done much to close the gap. Why go over to the dark side when established, mature technology is already available?

I’ll quickly point out that words like ‘dark side’ should immediately trigger the readers FUD detector. This type of illogic is no different than the FUD that Microsoft marketing once propagated which said that closed source was less than secure and written by uneducated teenagers.

What is worse is to realize that Neil believes that Java has done much to close the gap. He obviously has not spoken to anyone who has used both technologies. With Mono and .NET I have the choice of using C#, VB.NET (I can still use the ms compiler and run my code on mono), Iron Python, Boo, F#, and countless other languages. With Java I can choose to program in Java, or… well maybe Groove. Sorry, JPython doesn’t work with modern JVM. Now consider all of the features of all of those languages and compare. Java has TONS of catching up to do.

On this point I’d like to comment that I hope Java catches up and blasts past .NET. It will only mean that Microsoft will be forced to do the same. A healthy game of competitive leapfrog could be very great for developers using both technologies.

Another licensing issue which I would like to pull directly from the Mono licensing faq is just why Mono is NOT licensed GPL. Mono uses an interesting mix of licensing. The compiler and tools are licensed under the GPL. Runtime libraries are licensed under the LGPL. The class libraries are licensed under MIT X11. This means that I don’t have to worry about the GPL unless I am modifying the compiler. I can write software, even closed source, and I can link to the LGPL Mono runtime. I can ship my software closed source, along with an open source mono runtime. With Java under the GPL, technically any software linking to the java libraries must also be GPL. I am not a lawyer but does this means it is illegal to use the GPL version of Java with closed source software? It sounds like it.

The Mono class libraries are licensed under the MIT X11 license for exactly this reason. From the Mono Licensing FAQ:

Originally, the class libraries were released under the terms of the GNU Library GPL (LGPL). The problem with the GNU LGPL is an outdated wording related to “derived works”. A derived work of the library must be covered by the same license as the library itself. This definition was fine before object oriented frameworks existed, but with the introduction of object oriented frameworks, different people disagree whether some code that uses object-oriented inheritance is an instance of a “derived work”.

This is completely ignoring that a high number of the best Linux desktop applications are written in C# and run under Mono. F-spot is the iPhoto application for Linux. Tomboy is sticky notes merged with a desktop wiki. Banshee is quickly becoming an alternative to iTunes for syncing audio with an ipod and does things like transcoding from lossless codecs that iTunes does not do.

On the commercial front, Mainsoft actually uses Mono and IKVM to sell an application that helps people take their ASP.NET applications and run them on a J2EE webserver. At this point the line between Mono and Java is getting blurred. IKVM is an awesome bridge. All those existing Java libraries are accessible from Mono and visa-versa.

It is a shame that ComputerWorld would publish such an uninformed piece, but sensationalism sells.

I hate frameworks too

Y E S !!!!!

As usual I couldn’t agree with Oren any more. Of course I read the Joel article when it was released 15 months ago. It is just as true now as it was then. Honestly, I have zero use for the Enterprise Library as a whole. What does it do for me? It doesn’t help me with good design (and architecture, but I hate the “arch” word) like Castle’s Windsor helps me. It doesn’t help me with Database abstraction like NHibernate or Castle’s ActiveRecord. I already have logging with log4net. So what does Enterprise Library do for me? Caching, Configuration, Instrumentation? mmm… Maybe. I’m not sure. I’d rather just enable an NHibernate Cache. For Configuration, Windsor does a lot of this for me. Instrumentation. OK. I’ll investigate the Instrumentation block. I think the Enterprise Library team could learn a lot from Castle.

putty and screen

I’ve been using screen in Linux or Unix (Tru64) since around 1996. I left it for a number of years and didn’t start using screen regularly again until sometime in 2004. Since then I’ve been trying to learn more and more about screen’s endless feature set.

My favorite thing has more to due with a my use case for screen with putty. I’ve found it extremely useful to set my “Remote command” to “screen -U -x -R” in putty. This reconnects to a running putty session without disconnecting any other connected sessions. This setting is in putty under Connection->SSH.

Now I can ssh to a remote system using 2 or 3 putty instances and get the same screen session and have each different putty session in a different screen window. I can even split the screen windows in one session, and have them separate in another session. I’ve been using this for at least a year and it has very positively affected my productivity.

Other great putty tips include using Consolas (sorry, its only available to vista users or Visual Studio users) at 8pt for a font and using the putty -load command line to start a saved session. I type win-R putty -load myhost more than I should. Before I did the screen thing I set putty’s scrollback setting to 20000 lines. I like to minimize with the keyboard by pressing alt-space n, so I enable “System menu appears on ALT-Space”. Today I heard a complaint that putty closes the window and you don’t see what happened, but I’ve never experienced this because I always have the “warn before closing window” option.

This tip is the newest one to me, and I wish I had found it sooner. Under Window->Selection the behavior of double clicking a word is set. Double clicking URLs doesn’t normally work in putty, so you have to go change the character class of colon, question mark, and ampersand. Change the class to 2 and now when you double click a url it will be highlighted entirely!

I use port forwarding a ton, but I’m not going to explain it here. It has been explained before in many places. Use google.

Visual Studio 2005 – another day, another bug.

FIX: Error message when you use the debugger in Visual Studio 2005 to debug an MFC class library application: “Managed Debugging Assistant ‘LoaderLock’ has detected a problem in ‘‘”

I liked Visual Studio 2005 a WHOLE lot more when I wasn’t running into its bugs. Right now, I can’t debug my application. So what am I to do? Resort to pre-debugger techniques? I don’t even remember those. printf littering? log4net for no reason but debugging. This was supposed to be a trivial app to be written in one hour.

Another day, another bug.

.NET Command Line Options – Mono.GetOptions

I actually write .NET Command Line applications for Windows. I write little tools, that maybe would be usually be written in VBScript by a sysadmin, but since I was a sysadmin and AM a C# guy, I write in the latter. One thing that Microsoft seems to ignore (at least until PowerShell) is the command line and easy programming for the command line. I’ve never seen an equivalent to getopts in any MS Shell, or any API.

Mono implements a getopt library called Mono.GetOptions which works very nice on the Microsoft Platform as well. Just install Mono and copy the Mono.GetOptions.dll from C:\Program Files\Mono-1.2\lib\mono\2.0 or C:\Program Files\Mono-1.2\lib\mono\1.0 depending on which framework version you are targetting. I typically treat this dll as I do any third party dll as part of my project. In my case that means place in a lib directory and keep it under version control. I would prefer the Linux approach of no binaries under source control, but that doesn’t seem to be the standard on Windows projects.

Add the reference within your project to the lib/Mono.GetOptions.dll

The library works by extending Mono.GetOptions.Options and marking member with attributes.  The library includes many helpers, including the ability to automatically generate help messages.

class Options : Mono.GetOptions.Options {
  [Mono.GetOptions.Option(1,"Display this help message", 'h', "help")]
  public override Mono.GetOptions.WhatToDoNext DoHelp()
    return base.DoHelp();

The OptionAttribute has a number of default constructors.  In this case the arguments are maxOccurs, shortDescription, shortForm, longForm.  This allows the help to be displayed if you call Options.ProcessArgs with -h or -help.  See the source for more constructor forms: OptionAttribute.cs

To actually allow these options to be processed, you must call Options.ProcessArgs as I stated above.  You can play with options using this simple program:

    class Program
        static void Main( string[] args )
            Options lOptions = new Options();
            lOptions.ProcessArgs( args );


If you do this much and test by invoking with -h or -help, you will notice that there are some other options displayed in the output.  -help2 shows a couple of GetOptions debug and verbose options -~ and -. respectively.
  You will also see a message about using some assembly Attributes if you have not already added them.

[assembly: Mono.About( "This program does stuff." )]
[assembly: Mono.UsageComplement( "nonoptarg1 ... [nonoptargn]\nDo Stuff with nonoptarg1" )]
[assembly: Mono.Author( "Jay R. Wren" )]
[assembly: Mono.AdditionalInfo( "With no args this progam does stuff." )]
[assembly: Mono.ReportBugsTo( "jrwren@xmtp.net" )]

These assembly attributes work with the library to output usage information along with the normal System.Reflection.{AssemblyTitle,AssemblyCopyright,AssemblyDescription,AssemblyVersion} attributes.


Program - Copyright c MyCorp - MyDiv 2006

Usage: Program [options] nonoptarg1 ... [nonoptargn]
DoStuff with nonoptarg1
  -h -help     Display this help message
     -help2    Show an additional help list
     -usage    Show usage syntax and exit
  -V -version  Display version and licensing information

With no flags, the current users known host putty registry keys will be listed.

Please report bugs to <jrwren@xmtp.net>

Depending on your application you can use Options members such as:

[Mono.GetOptions.Option("debug level",'d',null)]
public int DebugLevel = 4;
[Mono.GetOptions.Option("warning level",'w',null)]
public WhatToDoNext SetWarnngLevel(int warningLevel)
  return WhatToDoNext.GoAhead;

And now you can simply access the Options.DebugLevel and Options.WarningLevel members. They will be set if the -d and/or the -w options were used on command invocation.

Further examples can be seen in the mcat sample from Mono subversion.

Castle had a birthday

Sometime last week Hammett posted links to a history of Castle in honor of its two year birthday.

I love history.

Reading about how castle sprung(punny?) from the Microkernel Pattern was interesting. I often forget that Castle started from Apache Avalon.

Early implementations of “Avalon Castle” could probably be found in CVS or SVN some place if you looked hard enough.

I find explainations of design decisions helpful to understanding a project.

Only 2 months later the Rails ActionPack inspired “Castle on Rails” was born. I think back to what I was doing then, and I realize I was still learning C# and messing with Web Services.

Just 2 days later(Nov 18th) the “Castle Project” was born.

And a few days later the concepts were introduced. Now that I think about it, Castle Project started much like TurboGears. Take the best of breed of some things and enhance them. ActiveRecord is just enhanced and simplified NHibernate. MonoRail’s default view engine is an enhanced NVelocity. Brail is boo, but enhanced for web views (whitespace matters less).

Thanks to everyone developing Castle, especially Hammett and Ayende. Their blog posts have helped me the most.