Tuesday, March 29, 2005

Finally a hybrid that doesn't suck?

It's not like I hate the environment or anything (please, all I do in the summer is camp and mountian bike), it's just that hybrid cars are, well, sloooooow. I'm a car enthusiast and I've tweaked my Subaru WRX wagon to put it over the 350hp mark. It's a 4-cylinder turbo wagon that goes 0-60 in 4.9 seconds. That's respectible. Gas milage is 21mpg so that kinda sucks, but it isn't horrible. It's better than most SUV's on the market today (and I still have 4WD). I love my car. I just love cars.

I never thought these hybrid cars would really take off until two things happened. #1 - they were really fast. #2 - you can modify them. I admit #2 is not as important to most people, but I don't know many people who don't like power in their vehicle.

I came across the Lexus GS 450h today and it looks like Lexus has finally answered my #1 complaint about hybrids.

This new hybrid powertrain is unique to the GS 450h. It features a 3.5-liter V6 engine teamed with a high-output electric motor that, when combined, will produce "substantially" more than 300 horsepower, according to Lexus vice president of marketing Mark Templin. Lexus claims that this hybrid will be quicker than the new V8-powered GS 430, yet it should achieve fuel economy similar to that of a compact sedan with a 4-cylinder engine.

Only time and test driving will tell, but I think car manufacturers are moving in the right direction with these hybrids.

Sunday, March 27, 2005

Happy Easter!

Growing up Catholic (and 12 years of Catholic school!) I remember Easter as being a pretty big religious holiday. When me and my sister were kids, my mom used to make us cute little Easter outfits to wear to church. My sister was a little more into the cute dresses than I was but I do remember loving to wear those cool white bonnets with the long ribbons down the back. They also flew like frisbies if you threw them hard enough.

After Mass we used to go over to my Nona and Nono's (mom's parents) house and we'd have an Easter egg hunt. Nona would fill those plastic colored eggs with money and hide them in the yard. And I'm not talking dimes and nickels here, I'm talking paper money... $5, $10, even sometimes $20! The entire family used to participate, not just the kids (who wouldn't!). Though I do vaugely remember the kids got a head start.

One year, we all come back onto the patio and while opening our eggs and counting our money we see Nona hovering around us like she's looking for something. My mom asks her what she's looking for and she says that there's still a $20 egg out there somewhere. Now let me give you a little background on Nona's yard. Nona is one of the best gardeners I know (even today). She used to have beautiful tropical plants everywhere. She lived in Palos Verdies, CA overlooking the ocean and Catalina island. Her backyard looked like the Italian island of Iscia where she was from (off the Almafi coast). The yard was big. Real big. Real lush. Nona didn't make a treasure map. Whoops. We all looked for an hour and no money egg anywhere (though I do remember recruiting some more snails for my snail army). A couple years later while gardening, Nona finds the egg and the semi-decomposed $20 bill. But even the liquor store wouldn't take it when she tried to buy her lottery tickets. Great memories.

Although I'm not very religious now, Easter Sunday is still a day to spend with family eating and drinking (and drinking and drinking). This weekend has been really fun so far. My honey, Alan, is Jewish so he was very facinated with the whole Easter egg decorating. Friday was his first time. See, I usually go for an art deco look which basically involes throwing the eggs in as many colors as possible and then putting as many hideous stickers on them as I possibly can. Quantity, not quality, baby. Alan, on the other hand, took so much care in designing his eggs (all two of them). I do have to say that his were definate masterpieces. Of course, I had to break the news to him that my dad was just going to crack them open and eat them. But it was fun.

Later this afternoon we're heading over to mom's. Typically my mother makes enough gormet food to put Martha Stewart to shame. If 8 people are coming, she'll make food to feed at least 25. Now when we were kids we usually had some kind of roast or ham on Easter. When we got older the tradition changed to going out to a nice big brunch. This year Nona wanted to take it back home and cook. This year we're making rabbit. Yes, we're cooking up cute little easter bunnies and eating them. And if that's not enough, were also roasting a cute little lamb to go with the easter bunnies. My mom would never let Nona make this dish on Easter when we were kids because of the obvious freak-out factor, but we used to raise rabbits and I LOVE LOVE LOVE rabbit. And the way my Nona makes it is amazing. I can't wait!

I know my family is not normal, but we all love eachother very much and that's what these religous holidays mean to me nowadays... getting together with the people you love most in this world and having a good time. HAPPY EASTER EVERYONE!

Sunday, March 20, 2005

Podcasting to Fame

Carl's in the news about podcasting! If you haven't seen the DNR or Monday's shows you're definately missing out on some awesome podcasts. Carl's now setting up a customizable podcast called The Daily Commute. I can't wait to try this out.

Friday, March 18, 2005

Come to DevTeach 2005 in Montreal!

I'll be speaking at DevTeach 2005 this year in beautiful Montreal June 18-22. If you missed out last year, you should definitely consider it this year. I had a blast and those wonderful Canadians are so hospitable. I'm very excited to be coming back. Check out my sessions topics here and here. I'm doing a two parter with Nick Landry (aka Mobile Man) on designing distributed apps for multiple user interfaces. These sessions are going to be very "how to" focusing on a lot of different issues developing usable enterprise information systems. I can't wait!

DataSet Debugger Visualizer for VS 2003!

I don't know how I missed this one. This is probably my most favorite VS 2003 add-in to date. Anyone doing database development in .NET is probably using the DSWatch add-in. This add-in lets you select a dataset variable while in the debugger and presents a form with an XML representation of the dataset's data (as well as a datagrid).

Well say goodbye to DSWatch and hello to the XML Visualizer! This add-in rocks! Among the cool features it lets you view the schema of your dataset as well as the row versions. It also works on DataViews or any XML serializable type! Who needs to wait for Whidbey? Get this now!

Thursday, March 17, 2005

My Singleton Answer

In my previous post I asked a question about using the singleton pattern for application-wide services that were stored in an object repository. With the help of the commenters, I decided not to implement the singleton pattern in this situation because since the services were only accessed via shared members on the object repository there is no need to force the service classes into the singleton pattern. This also makes them easier to extend (inherit).

That said, the discussion led to the question about how to implement lazy initialization of shared members in a thread-safe manner. I mentioned I was using double-checked locking, but someone pointed me to this interestering article and this discussion. I decided to test out double-checked locking versus just locking before the read in my distributed app (basically just created a remoted unit test) and I observed no difference in performance really. The test was just the "give me a warm and fuzzy feeling" test so I didn't write any performance counters or anything. But just measuring speed of the calls with 40 concurrent threads calling the components 100 times I only saw between a 1 and 10 milisecond average difference in speed. This is really nothing to me so I'm going to go with the easier, safer pattern of locking the whole shee-bang:
Private Shared m_service1 As ExtendedService
Private Shared _syncRoot As New Object

Public Shared ReadOnly Property Service1() As ExtendedService
  Get
    SyncLock (_syncRoot)
      If (m_service1 Is Nothing) Then
        m_service1 = Factory.CreateExtendedService()
      End If
    End SyncLock
    Return m_service1
  End Get
End Property

Wednesday, March 16, 2005

Singleton Question

I've been going back and forth trying to decide whether or not to use a Singleton pattern for a specific situation and I've decided I need community input. In my application I have a global "object repository" which is basically just a single point of entry for application-wide services. Some objects are expensive to create and only used in certian situations but what they all have in common is that there only needs to be one instance of each service for my entire application since they are all thread safe (I hope! :P). The object repository itself contains only shared (static) readonly properties used to access the application services and has no instance methods itself. The services need to have an inheritable class hierarchy to support different application's needs.

My question is then, since I only access these objects from the ObjectRepository, do I gain anything by creating the base services as extendable (inheritable) singletons or should I just access them as shared members directly? Now what gets a little trickier is that the application is a server-side application and objects are activated as single-call objects, so depending on the load on the server the application service objects may not be around and may need to be created on the next round if the aspnet worker process is recycled, right? Anyways, I've got the system scaling really well not using the singleton pattern and just accessing the services as shared members of the ObjectRepository, but I'm just curious if using the singleton pattern in this situation will be more performant. Of course, since I need to have the services inheritable, if I go with the singletn pattern I will have to maintain the pattern on all the sub-classes so code maintenance has a weigh-in factor here as well.

So let me show you what I mean. Should I do this (what I'm doing now):
Public Class MyBaseService1

 Public Sub New()
  Initialize()
 End Sub

 Private Sub Initialize()
  'do initialization stuff
 End Sub

 Public Sub TemplateMethod()
  HookMethod1()
  HookMethod2()
 End Sub

 Protected Overridable Sub HookMethod1()
  'do default stuff
 End Sub

 Protected Overridable Sub HookMethod2()
  'do more default stuff
 End Sub
End Class


Public Class MyExtendedService1
 Inherits MyBaseService1

 Public Sub New()
  MyBase.New()
 End Sub

 Protected Overrides Sub HookMethod1()
  'do different stuff
 End Sub

 Protected Overrides Sub HookMethod2()
  'do more different stuff
 End Sub
End Class


Public Class ObjectRepository1

 Private Shared m_service1 As MyExtendedService1
 Private Shared _lock As New Object

 'Use lazy initialization because this 
 ' class is rarely used and expensive to create.
 Public Shared ReadOnly Property Service1() As MyExtendedService1
  Get
   If m_service1 Is Nothing Then
    SyncLock (_lock)
     If m_service1 Is Nothing Then
      m_service1 = New MyExtendedService1
     End If
    End SyncLock
   End If
   Return m_service1
  End Get
 End Property

End Clas
Or would it be better to implement this pattern?
Public Class MyBaseService
 Protected Shared _Instance As MyBaseService
 Protected Shared _Lock As New Object

 Protected Sub New()
  Initialize()
 End Sub

 Public Shared Function GetInstance() As MyBaseService
  If _Instance Is Nothing Then
   SyncLock (_Lock)
    If _Instance Is Nothing Then
     _Instance = New MyBaseService
    End If
   End SyncLock
  End If
  Return _Instance
 End Function

 Private Sub Initialize()
  'do initialization stuff
 End Sub

 Public Sub TemplateMethod()
  HookMethod1()
  HookMethod2()
 End Sub

 Protected Overridable Sub HookMethod1()
  'do default stuff
 End Sub

 Protected Overridable Sub HookMethod2()
  'do more default stuff
 End Sub
End Class


Public Class MyExtendedService
 Inherits MyBaseService

 Public Shared Shadows Function GetInstance() As MyExtendedService
  If _Instance Is Nothing Then
   SyncLock (_Lock)
    If _Instance Is Nothing Then
     _Instance = New MyExtendedService
    End If
   End SyncLock
  End If
  Return DirectCast(_Instance, MyExtendedService)
 End Function

 Protected Overrides Sub HookMethod1()
  'do different stuff
 End Sub

 Protected Overrides Sub HookMethod2()
  'do more different stuff
 End Sub
End Class

Public Class ObjectRepository
 Private Shared m_service1 As MyExtendedService

 'Use lazy initialization because this 
 ' class is rarely used and expensive to create.
 Public Shared ReadOnly Property Service1() As MyExtendedService
  Get
   If m_service1 Is Nothing Then
    m_service1 = MyExtendedService.GetInstance()
   End If
   Return m_service1
  End Get
 End Property

End Class
I mean, I really don't see the advantage of this pattern for my situation but maybe I'm missing something? Thanks in advance!

Monday, March 14, 2005

Can't we all just get along?

Here's a great post from Rick commenting on the absurd .NET language "war" that seems to be going on. It's not really a war, it's just a bunch of Microsoft platform developers bickering and wasting time. This is more ridiculous than the religious war of Java versus .NET. At least the argument with Java is an argument about an entire architecture - OS, Languages, and Tools. Who cares if you wrote your code in C# or VB.NET? It runs on the same damn framework! Like Rick, I come from a VFP background (talk about being neglected) so I'm not really bothered when someone tells me that VB.NET is not a "real" language because I know it is and they are probably just saying that because they don't have a date for Saturday night. Unlike Rick, however, I'm more comfortable with VB.NET because it just seems closer to the Fox programming style I've been used for so long. I think VB-only people are being too sensitive and C#-only people shouldn't knock a language just because it lets you do lose-typing (actually one of the things I like about VB, but that's another post), or isn't "pure" or whatever. Gimme a break. A business isn't going to care what language you program in, they care if the project is done on time, to spec, and works!

Things that make you go "hmmmm...."

I'm not sure if I like this car or not. My friends would either think I'm totally cool or a total weirdo... wait, they already think that.

Thursday, March 10, 2005

GOTCHA: Cancelling a control's validating event in MDI apps

Okay, this is the first time I ever noticed this one and I think it's either a bug or pretty damn retarded. Alright, say you have an MDI application with two child forms call 'em Form1 and Form2, each with a text box on them. You open the forms from your MDI container form like normal (probably from a Main Menu's click event):
Dim frm as New Form1
frm.MdiParent = Me
frm.Show()
Now on Form1, you are handling the TextBox1's validating event and are cancelling the event (probably based on some condition):
Private Sub TextBox1_Validating(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating

   'If some condition blah blah blah
   e.Cancel = True

End Sub
When you run your application, open Form1 and trigger the event, the focus remains in the TextBox1 as expected... until.....

Now you want to open Form2 while Form1 is still open (a perfectly valid use case for an MDI application). BUT, once Form2 opens, even though the form is activated, no control can receive focus on Form2. It basically renders Form2 useless and in a user's eyes it looks like the form is not responding. WHAT!? Why in the world is the Textbox1's Validating event being raised at all on Form1 once Form2 is active? This has got to be a bug or it is just plain retarded. I fail to see why you would ever want this behavior. This is not a problem if the application is not an MDI application. In that case the event will not be raised if the form is not active.

I can't figure out how to prevent the Validating event from being raised, however, I did find a work-around. You can use this check in the handler to avoid running your handler code:
Private Sub TextBox1_Validating(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating

  If Me.MdiParent.ActiveMdiChild Is Me Then
   'If some condition blah blah blah
    e.Cancel = True
  End If

End Sub
This is moderately painful because I have to search my app for "_Validating" and add this line to all the handlers. If anyone's got a better idea I'm all ears.

The VB MVPs are pissed...

I happen to agree with Carl on this one, but I also don't have million line legacy applications to maintain either. If I did I'd probably kill myself. Fact is, all the things I love about programming come directly from learning something new and cool. I prefer to solve my business problems with the best solutions and right now that's VB.NET. Sorry.