Hanselman has it pegged when it comes to language

I get a lot of crap for being a VB programmer.  People who think it is cool to be smarter than someone else like to point out that they code in C# (though it was Java last year and C++ the year before) and I keep writing programs that work in whatever language best suits.  Why?  I learned how to program, not how to program in X language.  I recommend it for everyone - I recommend it in the book, and Scott Hanselman says it better than I ever could.

When programming (that is, expressing your intent to the computer) you should select a language that matches up with the program you're trying to solve. Every language is, in a way, a Domain Specific Language.

Regardless of what your language of choice is, you might be someone who says all languages eventually become, or try to become Lisp, or you might think Visual Basic is the best or that PHP is God's Language, you should learn a new language every year. I code, and have coded, for many years in C#, and before that C++, but it's important for me in my personal development to remember why I learned Haskell and Lisp (I suck at Lisp) and Smalltalk, and why I return to them occasionally for a visit.

This year, I'm learning Ruby. Does that mean my team is moving to Ruby?  Probably not, but it does mean I'm learning Ruby this year because I believe in sharpening the saw. You might be too busy sawing to sharpen, but I'd encourage you - no matter what brand or type of saw you use - to remember that there are other folks out there cutting wood successfully with a different kind of saw. Maybe they know something that you don't.

The man is a genius.  Pay attention.  Learn a new language every year.  If VB is your language this year, may I suggest a good book.  For the record, I am learning Ruby too ...

Just finished watching the PDC Keynote

Weird not seeing Bill there.

Anyway, everything old is new again, again.  Microsoft Azure is Hailstorm with a little more structure around the standards of XML Web services.  Even has an SDK.  With the advent of REST and the strong strides made in reliability, security and transaction support it made sense to try it again.  However, as Steve Wallace pointed out on Twitter, you still have issues of 1)Trust and 2) Not Built Here Syndrome.  This will be a hard sell.

What am I talking about?  Azure is the new Software as a Service offering from Microsoft.  It is a 'cloud computing' (read: bunch of machines that use the Internet) environment where applications can easily be hosted with managed scalability.  You write an app, you put it on Azure, and then subscribers can get to it.  Like XBox marketplace, but for enterprise consumers.

Credit to Microsoft for doing what they said they were gonna do.  I remember at TechEd 2002 when Bill said that Software as a Service was the future and that they were going for it all the way home and back, I thought "nah".  But I was wrong.  They made a plan, and stuck to it, and here we are.

PDC attendees can register for Azure at azure.com after noon PDT.

Paul Vick at PDC

I can't make it to PDC this year due to a project commmittment, but if you are there be sure to drop by and say "hi" to Paul Vick.  He is doing a talk on the future of VB this year, and it is sure to be something I should be at ... oh well.  Anyway, I guess I'll just have to live with the video.  This is the description from microsoftpdc.com

Hear language architect Paul Vick and specification lead Lucian Wischik discuss the future direction of the Visual Basic language. Learn about the new capabilities of the next version of the language, including additional LINQ features, syntax simplifications, and a host of other improvements. Also gain insight into possible future features, including meta-programming and scripting.

If you are at PDC, be sure to check him out, cheer loudly, and report back here with the scoop!  Here is the channel 9 link:

http://channel9.msdn.com/pdc2008/TL12/

I'm sure it will be a great presentation!

Detail

In Jujutsu, details matter. The Bansenshukai Ninjutsu jujutsu curriculum is made up of a 30 part kata of maneuvers from American Jujutsu in the Crawford system. It's the basic stuff you see in an MMA fight, really. Mount reversal, guard break, side mount, key lock, arm bar, arm bar, juji gatame ... you get the idea.

What astounds me is how much the details matter. Fo instance, in step 4 of the drill Tori is in side mount and Uke breaks an arm bar and grabs for a scarf choke. Tori goes to gaidon and get a vertical arm bar. Uke's arm is laying against the back shoulder and chest of Tori, and Tori has both hands to get the lock. In BSSKN, we use the palm grip (palms together, thumbs interlocked, fingers folded over back of hand) and tonight Sensei reminded me to use the knife edge of the inside of the forearm to get the lock. Just put that bone right on the top of the tricep.

That makes all the difference.

It is simpler to just grab the elbow joint with the hands. In fact, you can just hit it with a fist and break the elbow joint if you want. But putting that edge there just puts Uke in an inordinate amount of pain right away, and who doesn't want to end a fight faster?

So next time you train, work out the details. It's not just a fight, it is a set of techniques, and blending them will take time. Focus on the techniques now so them come naturally later.

Dates and nothingness

Sounds like a metaphysical post, but it isn't. In working with an object for which I needed a last change date, I set the DateTime variable value to Nothing in the constructor.

Dim lastReset as DateTime = Nothing 

But when I check for IsNothing() later in the code the check always fails due to the fact that the Nothing value for the DateTime (a value type in .NET) is actually MinValue. To make sure that it wasn't Nothing I would avtually have to compare to MinValue:

If lastReset <> Date.Minvalue Then DoSomething() 
 
 

Well, I was sure that .NET 2.0 fixed this with Generics and I was right. This is what happens when you do to much designing and not enough coding, I guess. The new Nullable object type can be Of DateTime, so that this now works:

Dim lastReset as Nullable(Of DateTime) = Nothing 
'… 
If IsNothing(LastReset) Then DoSomething() 
 
 

From a pragmatic programming perspective, this isn't a big deal. From a solid code perspective it is a rather large deal. If I say Nothing, I want NOTHING in there. I don't want the MinValue in there. I want Nothing in there. Then I want to see if the value is still nothing later.

Generate a managed class for WMI instrumentation

So,I need a list of services from a remote machine for an application I am building for Wendys.  I wrote a boatload of System.Management code to do it, liike something like this:

   1:  Public Function ListServices() As Dictionary(Of String, String)
   2:    co = New ConnectionOptions()
   3:    co.Username = My.Settings.Username
   4:    co.Password = My.Settings.Password
   5:    co.Impersonation = ImpersonationLevel.Impersonate
   6:    scope = New ManagementScope("\\" + IPNumber + "\root\cimv2", co)
   7:    Dim result As New Dictionary(Of String, String)
   8:    Dim mc As New ManagementClass("Win32_Service")
   9:    Dim oc As ManagementObjectCollection
  10:    Dim query As New ObjectQuery
  11:    query.QueryString = "SELECT * FROM Win32_Service"
  12:    Dim mos As New ManagementObjectSearcher(scope, query)
  13:    oc = mos.Get
  14:    For Each item As ManagementObject In oc
  15:      result.Add(item.Item("DisplayName"), item.Item("State"))
  16:    Next
  17:    Return result
  18:  End Function 
  19:   

 

Then what did I learn?  Lo and behold, there is a Tool To Do This.  I hate it when that happens!  Just pass in the WMI namespace and it will generate all the class code you can eat.  (Win32_Battery made me 2800 lines of code).  Check it out here on MSDN.

Coding for Patterns

With the deployment of the gold release of ASP.NET MVC, the topic of patterns are hot and heavy again, and I am getting reader emails about “What pattern do I use for this or that”.  I answer when I can, but it needs to be understood that The Gang Of Four were writing for a pretty broad kind of software development, and a lot of their thoughts only peripherally apply to the world of business programming.

Most of us write programs that accept data from some source – usually a user – and then deliver it to some source – usually a report.  This is not what The GoF had in mind when they wrote Design Patterns.  In fact, you’ll notice that even Model View Controller – the pattern behind the ASP.NET MVC – is Martin Fowler’s; it isn’t even in Design Patterns.

Speaking of Fowler, he is a great author to check out when making decisions about a pattern for the data-driven applications usually built by VB.NET programmers.  I strongly recommend his Patterns of Enterprise Application Architecture.  The Object-relational structural patterns, especially, define a lot of the thought that needs to go into object-oriented applications persisting to a relational database.

What patterns do I use?  I believe in single abstraction of the domain.  I think that you need significant separation between the database and the domain and application layer, but to wrap ever single little thing in interfaces is a waste of time for 80% of stovepipe applications.  In general, using Fowler’s terminology, I use a lazy mapper model.  The domain objects (like person or organization) call data objects that relate directly to tables in order to gather or persist information.  If it is a really big application, I will go ahead and go to that next level of abstraction and implement that separated interface that I generally do not like.

A final note – design patterns are not ‘philosophical constructs of programming.’  They are real, important, significant and weighty contributors to software design.  If you are not designing your software, you should be and it is tough if not impossible to design without an approach and the approach is defined by the pattern.  Please don’t allow the hackers on a team to direct the flow away from a sensible approach.

Downloading a file from a remote server with network credentials

Man, was this a pain in the butt.  Seems like downloading a file from a remote PC would be easy, but 'taint.  This worked great for me,  your mileage may vary.

   1:  'First we set up all of the filenames and locations, making heavy use of app.config.
   2:  Dim filename As String = String.Format("{0}-{1}-{2}.txt", CDate(checkDate).Year.ToString, CDate(checkDate).Month.ToString, CDate(checkDate).Day.ToString + 1)
   3:  Dim RemoteFile As String = String.Format("\\{0}\{1}\{2}", My.Settings.IpNumber, My.Settings.LogDirectory, filename)
   4:  Dim LocalDirectory As String = String.Format("{0}logs\", My.Settings.ReportLocation)
   5:  Dim LocalFile As String = String.Format("{0}{1}", LocalDirectory, filename)
   6:  'Hey, check for the localdirectory
   7:  If Not Directory.Exists(LocalDirectory) Then
   8:    Directory.CreateDirectory(LocalDirectory)
   9:  End If
  10:  'Then we set up a little security
  11:  Dim myClient As New System.Net.WebClient
  12:  Dim myCreds As New System.Net.NetworkCredential(My.Settings.Username, My.Settings.Password)
  13:  'Log the fact that we are starting.
  14:  My.Application.Log.WriteEntry(String.Format("Starting download of file {0}", fileName))
  15:  'Set up the securit
  16:  myClient.Credentials = myCreds
  17:  'Now we actually try and get the file.
  18:  Try
  19:    myClient.DownloadFile(RemoteFile, LocalFile)
  20:  Catch uae As System.UnauthorizedAccessException
  21:    My.Computer.FileSystem.WriteAllText(LocalFile, String.Format("The file path to file {0} was not available at the time of this posting.", file), True)
  22:  Catch ex As Exception
  23:    My.Application.Log.WriteException(ex)
  24:  End Try
  25:  My.Application.Log.WriteEntry(String.Format("Finished download of file {0}", fileName)) 
  26:   

 

Did this as part of a project at Wendy's.  Part of the Classic Posts collection.  (heh)

Pistons

In the world of taijutsu, legs are like pistons. You let the pressure out of them to lower yourself to the ground, and increase the pressure to lift yourself up. Take Morote Gari. You drop to a sprinters stance - releasing the pressure in your knees (performed by the calves and thighs) and position yourself at the knees of uke, then increase the pressure in your knees to take uke to the mat.

Hokojutsu is the same thing. The key to moving my bulk around silently is to not place my leg, but lower it, and then lower my weight onto it. If I just place it, I thump. If I lower it, I don't. It's a totally different way of thinking.

There are a bunch of examples. When I perform Oni Kudaki, for example (in the classical way) I slide into uke with my back foot and lower by center of gravity on my pistons to take balance. Then I raise myself after I get the lock on the elbow. The legs work just like hydraulics to lower and raise my body.

Preparation

It's surprising how much preparation is a part of hensojutsu. I have been reading On Acting by Sanford Meisner, and his approach to preparation has me thinking a lot about hensojutsu and reality. Meisner says that 'acting is living truthfully under imaginary circumstances.' Admittedly, if you have one hell of an imagination you can just jump up and do what is required under the circumstances.

I don't.

So, Meisner has his students prepare. The difference is, he has them prepare for the emotion not the action. For instance, say you have a scene where your sister has died. But you are an only child. You don't know what it would feel like to lose a sibling. Well, let's get close, Meisner says. Ever lose a parent? Dear friend? Was it pretty miserable? Alright, THINK about that and say the lines.

For my 6th kyu test I have to perform hensoijutsu as Yado Nashi, or a homeless man. I originally thought to do research, and that is a good idea for the facts - where I live, how I got there, etc. For my actual preparation, though, I have to key in on emotion - hopelessness, or determination depending on my character. I have to call up something that harbors the emotion of the character as well as remember the facts. It isn't like the facts will be more true with the right emotion, but they sure will be more believable.

Bill Sempf

Husband. Father. Pentester. Secure software composer. Brewer. Lockpicker. Ninja. Insurrectionist. Lumberjack. All words that have been used to describe me recently. I help people write more secure software.

PageList

profile for Bill Sempf on Stack Exchange, a network of free, community-driven Q&A sites

MonthList