Friday, September 02, 2011

Raising Our J-Score

I follow Joel Spolsky's Blog, which I find very useful and pithy.  Joel is a former Microsoft programmer, now CEO and programmer.  Joel published a blog way back in the Halcyon Days of 2000 entitled "The Joel Test: 12 Steps to Better Code"

So how do we stack up?


The Joel Test
1.  Do you use source control?
     Not yet.  We make file-system copies.  Our score:  0
2.  Can you make a build in one step?
     Depends.  My code is usually a yes, others, not a chance. Our score is a generous  .5
3.  Do you make daily builds?
     Not really.  Our score:  0
4.  Do you have a bug database?
     Nope  Our score: 0
5.  Do you fix bugs before writing new code?
     We try, but without a bug database, it's often hard to tell. I'm going to be very generous and say yes.  Our score 1.
6.  Do you have an up-to-date schedule?
      What's a schedule?  Our score:  0
7.  Do you have a spec?
     Real programmers don't need no stinkin' specs! That's a no, by the way.  Our score: 0
8.  Do programmers have quiet working conditions?
     What did you say?  It's too noisy in here!  Our score: 0
9   Do you use the best tools money can buy?
     Mostly.  Being a state agency, buying anything is challenging.   I'll say "yes".  Our score: 1
10 Do you have testers?
     Do programmers and users count?  No?  Then no.  The only thing harder than buying stuff is hiring people.  Our score:  0
11.  Do new candidates write code during their interview?
      Nope.  Our score: 0 
12.  Do you do hallway usability testing?
       No.  Our score:  0

Joel says "A score of 12 is perfect, 11 is tolerable, but 10 or lower and you've got serious problems. The truth is that most software organizations are running with a score of 2 or 3, and they need serious help, because companies like Microsoft run at 12 full-time. "

We scored a pathetic 2.5.  But there's hope!  I spend some time today investigating source control, and am confident that we will, kinda, sorta, start using it soon.  We're going with Mercurial , an open source distributed source control management tool.

If you've not looked at it, it is a command-line code repository.  If you are not using source control at all, look at this tutorialthis blog post, and this tutorial.  These sites will bring you up to speed.

Next in my sites, bug tracking!

That's Generic!

So you are creating a small config file and think "Gee, it would be nice to use the auto-serialization feature of  dot net"

So you wrap the serialization and deserialization routines as shared (static for you c# guys) functions, and throw a  _ in front of your class, and viola!

But, what if you are doing two, three, 48, 72 small serializable objects?  Ah, the power of object orientation!  Yes folks, object orientation makes this cake.  I created an abstract base class which contains the code I need to repeat for each small class.


Imports System.IO
Imports System.Xml.Serialization

Public Class AbstractSerialzationClass(Of t)
    Private Shared _ErrorOccured As Boolean = False
    Private Shared _ErrorText As String = ""
    Shared Function Deserialize(ByRef anObject As t, _
ByVal FileNameString As String) As Boolean

        _ErrorOccured = False
        If File.Exists(FileNameString) Then
            Try
                Dim aStreamReader As New StreamReader(FileNameString)
                Dim x As New XmlSerializer(anObject.GetType)
                anObject = CType(x.Deserialize(aStreamReader), t)
                aStreamReader.Close()
            Catch ex As Exception
                _ErrorOccured = True
                _ErrorText = "Unable to deserialze '" & FileNameString & "'." & ex.Message
            End Try
        Else
            _ErrorOccured = True
            _ErrorText = "XML File -'" & FileNameString & "' was not found"
        End If
        Return _ErrorOccured
    End Function
    Shared Sub Serialize(ByVal FileNameString As String, ByVal InObject As t)
        _ErrorOccured = False
        If File.Exists(FileNameString) Then
            If File.Exists(FileNameString & ".old") Then
                File.Delete(FileNameString & ".old")
            End If
            File.Copy(FileNameString, FileNameString & ".old")
            File.Delete(FileNameString)
        End If
        Try
            Dim aStreamWriter As New StreamWriter(FileNameString)
            Dim x As New XmlSerializer(InObject.GetType)
            x.Serialize(aStreamWriter, InObject)
            aStreamWriter.Close()
        Catch ex As Exception
            _ErrorText = "Unable to Serialze Annotation object to file named '" & FileNameString & "'.  " & ex.ToString
            _ErrorOccured = True
        End Try
    End Sub
    Public ReadOnly Property ErrorOccured() As Boolean
        Get
            Return _ErrorOccured
        End Get
    End Property
    Public ReadOnly Property ErrorText() As String
        Get
            Return _ErrorText
        End Get
    End Property
End Class


Now to use this in a class, all I've got to do is this

 Public Class foo
    Inherits AbstractSerialzationClass(Of foo)
end Class


Much neater!