There’s no place like 127.0.0.1
I think I need one of these (available now at ThinkGeek for only $49.99).
Refactoring to Patterns
A great catalog of refactorings are available at Industrial Logic. These are from Joshua Kerievsky’s book, which will be published in July 2004.
Fantastic stuff here…
Singletons are not evil
Scott Densmore has an interesting post regarding singletons and why he thinks they are evil. I’d like to go through his points one by one and add my thoughts:
Singletons frequently are used to provide a global access point for some service.
Unfortunately, I tend to agree with this. However, this does not make the Singleton pattern evil. Using a singleton in this way could easily be compared to using global variables. Using a singleton for this is no different than having a class with a bunch of static members on it.
Singletons should be used to control creation, not access. A singleton should *not* be used as a global object just because you can. I find it hard to dismiss a pattern simply because some people dont use it how it was intended to be used.
Singletons allow you to limit creation of your objects.
Scott states that this is true (as it is), but thinks that this is a violation of the Single Responsibility Principle, since a class should only be concerned with its business responsibilities.
Most of the issues around singletons revolve around the terminology. After all, isnt the Singleton property/method *really* just a Factory Method.
I agree that you could use a factory or builder object to do this for you, however, this method doesnt allow you to create one and only one instance.
Singletons promote tight coupling between classes.
This one I have to agree with. The way around this is to use a factory method, however, then you dont get the private constructor that the singleton really should have.
Singletons carry state with them that last as long as the program lasts.
As they should. The idea behind a singleton is that you need one and only one instance of an object.
As with any design pattern, the singleton is good when it is used wisely. Unfortunately, what happens a lot of the time is that a pattern is thrown into something without looking at the other options. Before implementing a singleton is not a bad idea to ask yourself, would it be wrong to have another instance of this class in the system?
Let me leave you with this to chew on… If singletons are evil and should be avoided at all costs, how would you suggest to handle things in the framework such as HttpContext? I personally find HttpContext.Current to be an absolute godsend. Without it, I would probably end up having to corrupt my class interfaces with properties or method parameters that will allow me to access HttpContext.
VS.NET 2005 May CTP now on MSDN
Visual Studio .NET 2005 (May Community Technical Preview) is now available on the MSDN subscriber download site.
I only saw it under the Developer Tools node in the treeview and not on the front page, so make sure you check there as well.
It’s a 3.32GB DVD ISO, so make sure you have some time to pull it down.
Enjoy!
Your daily cup of WTF
Alex Papadimoulis has started providing his “Daily cup of WTF” at http://thedailywtf.com (rss).
For those who arent familiar with this, he takes coding things that make you go “WTF” and provides them as a laugh to the rest of us. For example: the wonderful IsTrue(boolean) function.
Subscribed…
Id give almost anything to be able to do this…
Recently, David (my boss) used the power of the internet to purchase a brand new motorcycle from a gentleman in New Jersey. On Friday, David flew to New Jersey to start a cross country trip to bring this bike back to Boise.
To see the heart of America, David has made it a point to stay off of the main highways, sticking more to the old state routes. By the way, so far it appears that he’s only laid the bike down once (on a muddy dirt road in Kansas).
David has been posting entries and pictures to his weblog about his journey (and his sore ass). Definately fun reading, considering that almost every day has involved rain.
The Big Unit shows perfection
Earlier tonight, Arizona Diamondbacks pitcher Randy (”Big Unit”) Johnson threw a perfect game. For those that are unfamiliar with exactly what this is, a perfect game is one where the pitcher allows no one to get on base (either with a walk, base hit or error). 27 batters up, 27 batters out…
Perfect games are so uncommon; this is only the 17th perfect game to be recorded in MLB history. Johnson also became the oldest pitcher to ever throw a perfect game.
Even though Im not a D’Backs fan, this is an unbelievable achievment. Congratulations, Randy…
Oh, and think blue… :=)
MTCodeBeautifier and C# keywords
When using Sean Voisen’s MTCodeBeautifier to colorize C# code, you may notice that the keywords this and base may not get properly colorized.
This is due to an omission in the CSharp hfile. To resolve this, add “.”, to the $self->{delimiters} line in HFile_csharp.pm and rebuild your entries.
Example:
$self->{delimiters} = [".", "~", ... ];
Hopefully, Sean can work this in to the next release.
XmlResolver Goodness
Today I was looking through the best way to transform some XML documents using XSLTs from a database instead of from a file system.
Typically, this would be no problem, via the following simple code:
XslTransform xsl = new XslTransform(); Stream strm = SomeMethodToLoadTheXslFromTheDatabase(); XmlTextReader rdr = new XmlTextReader(strm); xsl.Load(rdr);
Now, the snag happens when you do an xsl:import or xsl:include in your XSLT. In this case, the XslTransform will try to load the specified file from the filesystem, which is obviously not what we want.
I started to panic a little bit while reading the MSDN documentation when all of the sudden, the XmlResolver class came to my rescue. The XmlResolver class resolves external XML resources named by a URI.
To resolve my problem, I ended up subclassing XmlUrlResolver and overriding the GetEntity method. The GetEntity method maps a URI to an object containing the actual resource. You’re supposed to return a Stream out of it. The only changes to the original code is passing an instance of this custom Resolver to XslTransform.Load().
class MyResolver : XmlUrlResolver { public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn) { string doc = Path.GetFileName(absoluteUri.AbsoluteUri); Stream strm = SomeMethodToLoadTheUriFromTheDatabase(doc); } } XslTransform xsl = new XslTransform(); Stream strm = SomeMethodToLoadTheXslFromTheDatabase(); XmlTextReader rdr = new XmlTextReader(strm); xsl.Load(rdr, new MyResolver(), null);
This is a great little class to remember if you ever need to do something like this… Enjoy!
Quitting Tobacco, cont’d
Just thought I would post a little blurb to talk about my progress with quitting tobacco.
Originally, I was planning on using the Nicoderm CQ patch. I used the patch for two days, but it started burning everytime I put it on. So, after two days of the patch, I had a decision to make: either start chewing again, or quit cold turkey…
I decided that since I had already made the decision to quit, the only thing to do would be to bite the bullet and see my decision through.
So, Im pleased to say that I’ve made it since Wednesday, May 5th (12 days) with absolutely no nicotine at all. Of course, there are still occassional cravings (mostly after meals), but a stick of Extra Polar Ice gum takes care of those pretty quick.



