January 2005 - Posts

I just started doing some work with Python for the first time, it seems like a nice language but I'm still too new to it to make any real judgments.  Parenthetically, when did Python overtake Perl as the cool dynamic programming language on the block?

Over the course of evaluating some of the Python IDE's and struggling through the first days of the new programming language, I started to wonder if the success of .Net, and to some extent the debate about statically typed and dynamically typed languages, is really all about IntelliSense. 

I mean of course the CLR and the .Net framework are world class bits of engineering, and I imagine the verifiability of statically typed languages is truly useful under some requirements. But for large majority of programming tasks, having your editor tell you the type of the third argument to the function you want call is where the true value of statically typed languages and the .Net Framework is at.
Posted by swein | 4 comment(s)
I took a brief look at the Avalon CTP tonight.  And really, all I want to know, is where is the speech recognition support? It appears that managed support for the Text Services Framework is baked into the System.Windows.Input namespace, and that there's plenty of support for tablet input, but nothing for speech recognition. This is terribly disappointing.
Posted by swein | 2 comment(s)
Filed under:

I got my first bit of wiki graffiti today, spam I would be able to understand, but this was a simple defacing of the site.

 

It's a good thing, for the turds who did it at (198.54.202.242 and198.54.202.242 and 217.210.97.5), don't live anywhere near me.

 

 

Posted by swein | 1 comment(s)

For some of us coders who suffer from RSI, programming by voice is something of a holy grail. There are a fair number of false starts, and aborted attempts. It's a hard problem, the people who are most likely to want it, and be willing to work on a solution, are the same people who are unable to do so.

Here's my contribution, IdentifierCache, an experimental add-in for Visual Studio.Net to provide an identifier cache, based on the idea of the Emacs module cache-pad.

User Guide
('Camel' | 'Hungarian') <dgndictation>

The phrase "Camel word count" will produce wordCount, and if the add-in is active, will add wordCount to the Identifier Cache

Joined Under <dgndictation>

The phrase "Joined Under word count" will produce word_count, and if the add-in is active, will add word_count to the Identifier Cache

Pascal <dgndictation>

The phrase "Pascal word count" will produce WordCount, and if the add-in is active, ...

Dots <dgndictation>

The phrase "Dots word count" will produce word.count, and if the add-in is active, ...

[ 'identifier' | 'insert' [ 'ID' ]] <n>

The phrase "identifier 3", will insert the third identifier, in the screenshot below that's ReadLine

likewise "insert 3" or "insert ID 3" will do the same.

Non Voice

additionally, if you right-click on selected text, a menu option is presented to add the text to the cache.

 

Posted by swein | 2 comment(s)
Filed under:
Updating from my last post I've incorporated some code from Chris Sells XmlSerializerPreCompiler to help diagnose serialization problems with the configuration class.


Imports System.Configuration
Imports System.Xml.XPath
Imports System.Xml.Serialization
Imports System.Xml
Imports System.Text
Imports System.Text.RegularExpressions
 
Namespace Config
  Public Class XmlSerializerSectionHandler
    Implements IConfigurationSectionHandler
 
    Public Function Create(ByVal parent As Object, _
    ByVal configContext As Object, _
    ByVal section As System.Xml.XmlNode) As Object _
    Implements IConfigurationSectionHandler.Create
 
      '-- get the name of the type from the type= attribute on the root node
      Dim xpn As XPathNavigator = section.CreateNavigator
      Dim TypeName As String = xpn.Evaluate("string(@type)").ToString
      If TypeName = "" Then
        Throw New ConfigurationException("The type attribute is not present on the root node of " & _
        "the <" & section.Name & "> configuration section ", section)
      End If
 
      '-- make sure this string evaluates to a valid type
      Dim t As Type = Type.GetType(TypeName)
      If t Is Nothing Then
        Throw New ConfigurationException("The type attribute '" & TypeName & _
        "' specified in the root node of the the <" & section.Name & "> configuration section " & _
        "is not a valid type.", section)
      End If
      Dim xs As XmlSerializer = New XmlSerializer(t)
 
      '-- attempt to deserialize an object of this type from the provided XML section
      Dim xnr As New XmlNodeReader(section)
      Try
        Return xs.Deserialize(xnr)
      Catch ex As Exception
        Dim s As String = ex.Message
        Dim innerException As Exception = ex.InnerException
        Do While Not innerException Is Nothing
          s &= " " & innerException.Message
          innerException = innerException.InnerException
        Loop
        Throw New ConfigurationException( _
        "Unable to deserialize an object of type '" & TypeName & "' from " & _
        "the <" & section.Name & "> configuration section: " & s, _
        ex, section)
      End Try
    End Function
 
 
    Public Shared Function SerializeObjectToConfigXML(ByVal configObject As Object) As String
      Dim sb As New Text.StringBuilder
      Dim sw As New IO.StringWriter(sb)
      Dim typeName As String = configObject.GetType.FullName
      Dim asmName As String = configObject.GetType.Assembly.GetName.Name
 
      Try
 
        Dim xs As XmlSerializer = New XmlSerializer(configObject.GetType)
        Dim xsn As New XmlSerializerNamespaces
        xsn.Add("", "")
 
        Dim xtw As New Xml.XmlTextWriter(sw)
        xtw.Formatting = Xml.Formatting.Indented
        xtw.WriteRaw("")
        xs.Serialize(xtw, configObject, xsn)
 
        Dim s As String = sb.ToString
        s = regex.Replace(s, "(<" + configObject.GetType.Name + ")(>)", "$1 type=""" + typeName + ", " + asmName + """$2")
        Return s
 
      Catch ex As Exception
        Debug.WriteLine("Error, unable to serialize " + typeName)
        Debug.Indent()
 
        Debug.WriteLine(ex.Message)
        Dim innerex As Exception = ex.InnerException
        While Not innerex Is Nothing
          Debug.WriteLine(innerex.Message)
          innerex = innerex.InnerException
        End While
        Debug.Unindent()
        ' HACK: Pull our assembly base file name from exception message
        Dim regex As regex = New regex("File or assembly name (?<baseFileName>.*).dll")
        Dim match As match = regex.Match(ex.Message)
        Dim baseFileName As String = match.Groups("baseFileName").Value
        If baseFileName = "" Then
          sb.Append("If you still need additional information to diagnose this problem,").Append(vbNewLine)
          sb.Append("add the below to your app.config, which may let you examine the intermediate files produced by the serializer").Append(vbNewLine)
          sb.Append("and rerun this method").Append(vbNewLine)
          sb.Append("<system.diagnostics>").Append(vbNewLine)
          sb.Append(vbTab).Append("<switches>").Append(vbNewLine)
          sb.Append(vbTab).Append(vbTab).Append("<add name=""XmlSerialization.Compilation"" value=""4""/>").Append(vbNewLine)
          sb.Append(vbTab).Append("</switches>").Append(vbNewLine)
 
          sb.Append("</system.diagnostics>").Append(vbNewLine)
          Debug.WriteLine(sb.ToString)
          Exit Function
        End If
 
        Dim outputPath As String = IO.Path.Combine(IO.Path.GetTempPath(), baseFileName + ".out")
        Console.WriteLine((New IO.StreamReader(outputPath)).ReadToEnd())
        Console.WriteLine()
 
        Dim csPath As String = IO.Path.Combine(IO.Path.GetTempPath(), baseFileName + ".0.cs")
        Debug.WriteLine("XmlSerializer-produced source:\n" + csPath)
        Return "Error. See debug output"
      End Try
    End Function
    Public Function CreateConfigSectionDecl(ByVal ConfigObject As Object) As String
      Dim sb As New StringBuilder
      sb.Append("<section name='")
      sb.Append(ConfigObject.GetType.Name)
      sb.Append("' ")
      sb.Append("type='")
      sb.Append(Me.GetType.FullName)
      sb.Append(", ")
      sb.Append(Me.GetType.Assembly.GetName.Name)
      sb.Append("'/>")
 
      Return sb.ToString
    End Function
  End Class
End Namespace

Posted by swein | 1 comment(s)

Yet another update the last configuration section handler you will ever need.

Every time I get started with a custom configuration section, I struggle to get the XML correct. This updated class provides two methods that output the correct strings.

        Dim x As New config.XmlSerializerSectionHandler

        Debug.WriteLine(x.CreateConfigSectionDecl(New MyConfig))

        Debug.WriteLine(x.SerializeObjectToConfigXML(New MyConfig))


Nearly all this code is taken or adapted from Jeff Atwood's entry on the topic

Imports System.Configuration

Imports System.Xml.XPath

Imports System.Xml.Serialization

Imports System.Xml

Imports System.Text

 

Namespace Config

 

    Public Class XmlSerializerSectionHandler

        Implements IConfigurationSectionHandler

 

        Public Function Create(ByVal parent As Object, _

        ByVal configContext As Object, _

        ByVal section As System.Xml.XmlNode) As Object _

        Implements IConfigurationSectionHandler.Create

 

            '-- get the name of the type from the type= attribute on the root node

            Dim xpn As XPathNavigator = section.CreateNavigator

            Dim TypeName As String = xpn.Evaluate("string(@type)").ToString

            If TypeName = "" Then

                Throw New ConfigurationException("The type attribute is not present on the root node of " & _

                "the <" & section.Name & "> configuration section ", section)

            End If

 

            '-- make sure this string evaluates to a valid type

            Dim t As Type = Type.GetType(TypeName)

            If t Is Nothing Then

                Throw New ConfigurationException("The type attribute '" & TypeName & _

                "' specified in the root node of the the <" & section.Name & "> configuration section " & _

                "is not a valid type.", section)

            End If

            Dim xs As XmlSerializer = New XmlSerializer(t)

 

            '-- attempt to deserialize an object of this type from the provided XML section

            Dim xnr As New XmlNodeReader(section)

            Try

                Return xs.Deserialize(xnr)

            Catch ex As Exception

                Dim s As String = ex.Message

                Dim innerException As Exception = ex.InnerException

                Do While Not innerException Is Nothing

                    s &= " " & innerException.Message

                    innerException = innerException.InnerException

                Loop

                Throw New ConfigurationException( _

                "Unable to deserialize an object of type '" & TypeName & "' from " & _

                "the <" & section.Name & "> configuration section: " & s, _

                ex, section)

            End Try

        End Function

 

 

        Public Shared Function SerializeObjectToConfigXML(ByVal configObject As Object) As String

            Dim sb As New Text.StringBuilder

            Dim sw As New IO.StringWriter(sb)

            Dim xs As XmlSerializer = New XmlSerializer(configObject.GetType)

            Dim xsn As New XmlSerializerNamespaces

            xsn.Add("", "")

 

            Dim xtw As New Xml.XmlTextWriter(sw)

            xtw.Formatting = Xml.Formatting.Indented

            xtw.WriteRaw("")

 

            xs.Serialize(xtw, configObject, xsn)

            Dim s As String = sb.ToString

            s = System.Text.RegularExpressions.Regex.Replace(s, "(<" + configObject.GetType.Name + ")(>)", _

            "$1 type=""" + configObject.GetType.FullName + ", " + configObject.GetType.Assembly.GetName.Name & """$2")

            Return s

        End Function

 

        Public Function CreateConfigSectionDecl(ByVal ConfigObject As Object) As String

            Dim sb As New StringBuilder

            sb.Append("<section name='")

            sb.Append(ConfigObject.GetType.Name)

            sb.Append("' ")

            sb.Append("type='")

            sb.Append(Me.GetType.FullName)

            sb.Append(", ")

            sb.Append(Me.GetType.Assembly.GetName.Name)

            sb.Append("'/>")

 

            Return sb.ToString

        End Function

 

 

    End Class

End Namespace

Posted by swein | 2 comment(s)
More Posts