Thursday, December 06, 2007

XslCompiledTransform - Possible Memory Leak?

I just ran across an issue where the XslCompiledTransform object refused to die.  The code basically had a loop, inside of which a new XslCompiledTransform object was created and "applied" to an xml node.  This meant that for each iteration, I was reading the XSLT into memory. 

You would suspect that the object would go out of scope on the next iteration, or after the completion of the loop, or even after the method returned.  But no!  This wasn't a trivial XSLT file, either, so for every 100 iterations, my application would take on another 300MB of memory.  I was able to crash the app on my 4GB (debatable) machine in a few minutes. 

I know that doing things this way is a definite code smell, and I have learned from my mistake.  The code is now loading the transform in the constructor and using that inside the loop.  Since I'm not having to read in the XSLT all the time, the performance of the app has increased by at least an order of magnitude. 

Maybe Microsoft meant for this to happen, so I wouldn't write crappy code.  Just thought that I would share.  Has anyone else experienced this?

Wednesday, November 28, 2007

DSN Query Analyzer

The new office likes FileMaker...  No, seriously, they actually like it.  And for what they use it for, I don't really blame them. 

It didn't take long before I needed to query some data from one of the FileMaker databases.  Now, there are ways to do this from inside FileMaker, but I just wanted to run a simple query. 

Enter the DSN Query Analyzer.  It is a lightweight query analyzer clone that connects to the DSN connections set up on your machine.  It was written by a guy in the Netherlands.  You can check out his website, if you can speak the language.

One note of importance...  System DSN's do not save login information.  That would be a gigantic security hole.  So when you give the analyzer the name of the DSN to point to, you have to also pass in the login information.  Here is the syntax:

MyDSNName;UIS=username;Pwd=password

Wednesday, November 14, 2007

Sustainable Pace

One of the tenants of Agile development is the concept of "Sustainable Pace".  Let me quote the Agile Manifesto:

"Agile processes promote sustainable development. The sponsors, developers, and users should be able to maintain a constant pace indefinitely."

It turns out that this is just vague enough to leave it open to a wide array of interpretations. 

Many, believe that this means instituting the "40 Hour Work Week", where the team limits the amount of work that it will take on so that no one works more than forty hours per week.  Personally, I think that this is an ideal that is worth working toward, but is usually unachievable in the real world.  Part of "Sustainable Pace" isn't about how much you work, its about the ability to deliver functionality on a regular basis.  Forty hours may not be enough time to pull that off.

I have seen several presenters talk about sprinting and resting.  I like this approach.  Your team would work hard for a few weeks, usually working more than 40 hours in a week, and then have an "off" week.  This doesn't mean that they get a vacation once a month.  It means that they get a week where they aren't 100% committed to the iteration and can spend time on side projects to break the monotony of it all.  Apparently, this works for many teams.  I'd think that you would need a lot of management support for this kind of thing, not to mention the personal discipline to come off the iteration.   It is important that all employees have the time and backing for personal development.  That's the best way for a company to grow in its abilities and increase the value of its employees.

Tuesday, November 13, 2007

Agile Practices That are Usually Valuable

Our team is starting to look at the principles of Agile development and it won't be long before we get into the practices.  So I thought that I would share some of the knowledge that Steve McConnell bestowed upon me in his keynote address at the Microsoft Patterns and Practices Summit last week.

Steve McConnell's company Construx, has generated a report that relays their experiences with Agile practices.  The results not only come from their experience consulting and training clients ("approximately 1000 companies in the past 5 years"), but also from other published industry reports.  Steve presented the report by breaking down the practices into 3 categories:

Agile practices that are usually valuable

  • Short Release Cycles
  • Highly Interactive Release Planning
  • Timebox Development
  • Empowered, Small, Cross-Functional Teams'
  • Involvement of Active Management
  • Coding Standards
  • Frequent Integration and Test
  • Automated Regression Tests
  • Retrospectives at End of Each Release

Agile practices that have been hit or miss

  • Customer-Provided Acceptance Tests
  • Daily Stand-up Meetings
  • Simple Design
  • Test-First Development
  • 40-Hour Work Week

Agile practices that tend to be problematic

  • System Metaphor
  • On-Site Customer
  • Collective Code Ownership
  • Pair Programming
  • Refactoring

I can see at least one practice that my department is trending toward in the "Problematic" list.  This could be "problematic" going forward. :)

Anyway, I encourage you to post your reactions to this list via the comments.  I'd like to know what experiences you guys have had with these practices. Also, if you would like more information about their reasoning for placing a certain practice into a certain category, I'd be happy to oblige.

Monday, November 12, 2007

Microsoft Patterns and Practices Conference - Day Five

The last day of the conference was labeled "Applications".  This, of course, was a pretty loose title.  However, I think that this was one of my favorite days.

Keynote - Scott Hanselman

Hanselman delivers once again.  This wasn't a technology related keynote.  Instead Scott discussed how he came to be employed by Microsoft.  There must have been a lot of money involved. 

Future of patterns & practices - Rick Maguire

Rick is "the man" when it comes to the Pattern's and Practices Group, "the trusted source of application development guidance for the Microsoft platform".  Rick gave a high level overview of where the group was heading in the future.  Here are their goals for the future:

  • Simplify the Microsoft Application Platform
  • Provide solutions/guidance to your problems
  • Help you learn and grow

Evolving Client Architecture - Billy Hollis

Billy Hollis gave an interesting talk on how the types of things that we are developing is changing.  He showed that the move to SOA will force us to become better UI designers.  Right now, if our UI sucks, the users don't have a lot of choice except to use it.  In the future, some one else could build a better one on top of an exposed service.  This was a good set up for his later talk about software complexity.

Fresh Cracked CAB - Ward Bell

Ward reminds me of someone that I used to work with.  It was a good presentation on Microsoft's Composite UI Application Block (CAB), which is a windows smart client technology.  A lot of the of patterns could be converted to ASP.NET with a little work.  Ward basically showed how to use one of Microsoft's application blocks to quickly build and extend a window smart client.

Software Complexity - Billy Hollis

Billy Hollis is my new hero.  He shared some of his "outside the box" thoughts on software complexity and the need for simplicity in an increasingly complex technological landscape.  He boldly asserted that instead of making our lives simpler, Microsoft is killing us with complexity as it releases more and more technologies at a pace that no one can keep up with.  Kudos to the Microsoft employees, who had several chances to tackle him and drag him off the stage, yet some how kept their composure.  The talk can really be summed up by Billy's "Simplicity Manifesto V1.0":

  • Stop adding features
  • Make help helpful
  • Fix the bugs
  • CRUD for free
  • Hide the plumbing
  • Get better names

Thursday, November 08, 2007

Microsoft Patterns and Practices Conference - Day Four

Today's topic was "Software Factories", but it should have been titled "A bunch of stuff that you'll need VSTS to use".

Keynote - Scott Hanselman

Scott delivered a great presentation on the MVC framework that Microsoft is currently working on.  He went over the plusses of using the framework, like how it provides for clean separation of concerns and how it is extensible and pluggable. We even got a chance to see it in action in Visual Studio.  The framework won't require VSTS and will probably become a very handy development tool.

Domain-Specific Development with VS DSL Tools - Gareth Jones

This talk was about how to build a domain specific language using the graphical modeler in Visual Studio.  What it really boils down to is "How to generate a Modeling Language, using the graphical modeling language in VSTS."

Patterns of Software Factories - Wojtek Kozaczynski

Wojtek went through the Software Factories that the Patterns & Practices group has released and reported some of the common patterns that he found.  Kind of dry stuff that I won't be using anytime soon.

Building Services...Service Factory: Modeling Edition - Bob Brumfield, Ade Miller

Here, we were shown how to use a software factory to generate a modeler that will then generate some code.  Once again, this is a VSTS thing.

Web Client Guidance: Web Client Software Factory - Michael Puleio, Chris Tavares & Blaine Wastell

This was a good discussion of the P&P group's Web Client Guidance.  I've not before seen a simpler and easier to understand diagram that showed the difference between the Model View Presenter pattern and the Model View Controller pattern.  You don't need VSTS to use the guidance bits.  Expect more blog posts about this one.

Using Team Factories - David Trowbridge

Yet another Team System oriented talk.

Build your own Software Factory - Wojtek Kozaczynski, Bob Brumfield, Ade Miller

I've got to admit that this talk was way over my head.  From what I gathered, basically went through what it took to generate the software factories that they have released.  I guess there's a reason that they make the big bucks.

Tomorrow is the last day of the conference and will be dedicated to "Applications".  Scott Hanselman will give another keynote.

Wednesday, November 07, 2007

Microsoft Patterns and Practices Conference - Day Three

Today's theme was "Development", but I'm not really sure that was what we talked about for most of the day.  There were some good talks, here's more about them:

Keynote - John Lam

John Lam's presentation, for the most part, centered around IronRuby.  He ran a good code demo inside the ironruby version of irb, on mono, in a linux vm on his mac.  I know, its weird to see a Microsoft employee working off a Mac. But John was not the only presenter doing so.  There was an especially exciting demo of using Ruby to dynamically generate Silverlight objects.  Currently, this is hard to do in C#.  I think that it is really great that IronRuby is a fully open source project that accepts contributions from outside developers.  The team uses Subversion for the code repository and hosts the bits on RubyForge.

The Right Tools for the Right Job - Rocky Lhotka

Rocky started off by reminding us that Object-Oriented Design isn't dead.  He gave a in depth comparison of the strengths and weaknesses of OO, SOA, and Workflow design.  It was really enlightening to see his take that your can see aspects of OOP in all of these design architectures. 

Model Based Design - David Trowbridge

This turned out to be a demonstration of how to use the class builder, and some new modeling interfaces, to generate code.  It's a shame that we will need Team System Architecure edition to actualize any of the examples.  Maybe our team can win the lottery one day.

Dependency Injection Frameworks - Peter Provost, Scott Densmore

Have you ever wanted to know how to roll your own Dependency Injection into your application?  I thought I did.  Sure, it was very interesting.  However, if they were pitching it for my application, I'd have gone out and bought a license for typemock by the second example.  Let's just say there is a lot of work that Typemock(or other mocking frameworks) do for you automatically.

Designing for Workflow - Ted Neward

Once again, Ted delivers a great presentation, full of poignant wit.  Ted makes the argument that Workflow, as we know it in the realm of recent Microsoft tools, hasn't really been around long enough for us to declare any best practices.  Of course he offers his point of view, which left no time for the audience to chime in.

Panel: The Future of Design Patterns - Dragos Manolescu, Wojtek Kozaczynski, Ade Miller, Jason Hogg

This was strange.  They gave the guys on the panel toy guns that shot little foam discs so they could shoot each other when they were in disagreement.  They then discussed the failure of a patterns web site and debated whether we should be generating more documentation and collaboration around patterns or whether we should just build them into development tools.  I like the gun idea, no pattern or practice would truly be complete without firearms.  I think I'll try it out at our next team meeting.

EntLib Devolved - Scott Densmore

EntLib is short for Enterprise Library. Entlib is a collection of general purpose application blocks addressing enterprise scenarios. For example, there is an application block for logging.  Scott Densmore, one of the developers, gave a quick overview of the blocks and elicited feedback from those that had used it.  I have never used it, but it looks cool.

So, tomorrow's theme is "Software Factories" and the keynote is by Scott Hanselman.  It should be a very interesting day! 

Tuesday, November 06, 2007

Microsoft Patterns and Practices Conference - Day Two

Today was dedicated to Agile practices and Methodologies.  Here's a rundown of the talks.

Keynote - Steve McConnell

Steve provided a wonderful overview of the Agile methodology.  He went into a lot of detail about the agile practices and relied on his companies experiences to rate them based on how they work in the real world.  For example, short release cycle tend to work very well, while pair programming tends to be problematic. The jet lag hit me pretty hard this morning and Steve is a soft speaker, but it was really interesting.

Agile is more than monkey-see-monkey-do - Peter Provost

First off, Peter Provost is very engaging speaker that highly encourages audience participation.  I highly recommend watching one of his presentations.  This one started as a comparison of two fictitious companies and how they implemented Agile methodology. One with great success and one with terrible tragedy. It then moved onto how teams can figure out how to implement agile practices.  He also spent a good amount of time discussing how to get a team that has strayed back to the agile path.

Empirical Evidence of Agile Methods - Grigori Melnick

Grigori tried to show that there are actually people out there using agile methods.  Apparently, there isn't must documented evidence.  The topic by its very definition is pretty dry.  That's all I have to say about that.

What's new in Rosario process templates? - Alan Riddlhoover

Alan gave an informative, but extremely slow paced presentation on the new features found in the next version of Visual Studio Team System.
It looks like they have a replacement for Caliber that integrates with MS Project.  Our team doesn't have VSTS, so a lot of the stuff that was demo'd won't really matter.

Lessons Learned in Unit Testing - Jim Newkirk

Now this was a good talk.  Jim is one of the original authors of NUnit and has now moved on to run Codeplex. In his talk, Jim relays 7 lessons that he has learned over his 8+ years of doing unit testing.  The lessons are listed below. 

Lesson #1 - Just Do It
Lesson #2 - Write Tests using the 3A Pattern(Arrange, Act, Assert)
Lesson #3 - Keep your tests close
Lesson #4 - Use Alternatives to ExpectedException
Lesson #5 - Small Fixtures
Lesson #6 - Don't use Setup and TearDown
Lesson #7 - Improve Testability with Inversion of Control

Some of the stuff he was talking about seems to go against what I've been learning from the internet and architecture.  I'm hoping to talk with Jim tomorrow to get some more insight.  Expect more in the future.

The Agile Security Development Lifecycle - David LeBlanc

David stressed the importance of considering security from the beginning of a project's SDLC.  He stressed that developers on an agile team need to be educated about security. "If they understand what a security mistake looks like, they are less likely to put it into the code."  He also pointed out how some of the agile practices enhance security.  For example, Peer Programming is not only effective for finding bugs but also for finding security issues.

"Yet Another Agile Talk on Agility" - Peter Provost

Peter ran this talk like an agile project.  There were 4, fifteen minute iterations where the first five minutes where used to gather issues about Agile that the audience was interested in and prioritize them.  The next ten minutes where dedicated to tackling the issues/questions based on their priority.  When the next iteration came around, we were given the ability to add new questions and re-prioritize them with the rest of the open questions.  Peter kept a count down timer running on the big screen to make sure that we stuck to the schedule.  It really drew you into the conversation and was a lot of fun.

 

Tomorrow looks like a good day.  It will be dedicated to development and the keynote speaker will be John Lam of IronPython fame.  Night, night for now kiddies.

Monday, November 05, 2007

Microsoft Patterns and Practices Conference - Day One

All this week, I and a few of my cohorts are attending a Patterns & Practices summit in Redmond.  I'll be giving a breakdown of the sessions this week and will go into more detail in future posts about the topics that I find most interesting.

Here is a quick breakdown of the topics and speakers, each followed by a brief description.

Keynote - Anders Hejlsberg

This wasn't as much a keynote address as it was a LINQ demo.  Anders is awesome and gave a great and detailed demonstration.  You can expect a lot more about this one in future posts.

A Software Patterns Study - Dragos Manolescu

This wasn't what I expected.  Apparently this guy did a survey about Patterns and how much they were used in current enterprises.  It turned out to be a plea for help from the community to help build a modern platform for collaboration on patterns.

Architecture of the Microsoft ESB Guidance - Marty Masznicky

I didn't get a lot from this talk because it was all about extensions for BizTalk, which I have zero experience with.  However, I will give the speaker credit for giving an hour long presentation with gauze stuffed into one of his cheeks.  Don't ask.  Sadly, I couldn't conjecture what ESB stood for until halfway through the presentation when the guy in front of me Googled it.  ESB stands for Enterprise Service Bus and provides a way to do a lot of stuff that should have been integrated into Biztalk by default.

Pragmatic Architecture - Ted Neward

Ted is a excellent speaker with a great sense of humor.  He spoke about our need to be able to determine the best architecture for our solutions.  Apparently, not every architecture solution is right for all applications.

Architecting a Scalable Platform - Chris Brown

This was an interesting look at building globally scalable applications.  We're talking things like Amazon.com.  Global level scalability relies on horizontal scaling. 

Grid Security - Jason Hogg

Jason gave a great talk about the Security Policy Assertion Language (SecPAL).  SecPAL was designed to address security for large scale applications, such as computing grids.  The security rules are easily read as English sentences with a restricted grammar.  You can find out more here.

Moving Beyond Industrial Software - Harry Pierson

Harry talked about the Industrial age's influence on modern programming.  Just as the Industrial age has given way to a new information age, so our programming methodologies must give way to something more practical.  The main point of his talk was that things that are simple and empower the users will be the applications of the future.

Well kids, that's all for now.  See you tomorrow.

Friday, September 07, 2007

Being a better developer

I know what you're saying, "Yo Mack!, why you no post?"  Well, that's a tough one to answer.  Let's just say that I'm lazy. 

Today I'll be responding to the uber blog meme on what I will do over the next 6 months to become a better programmer.  I know a lot of folks don't like "list" posts.  To them I say, just be glad I'm not numbering them.

Pick up a new OS - I feel that this is very important as more and more of our user base is moving from Windows to something else.  I have chosen Linux, Ubuntu specifically.  I chose this over a Mac for several reasons.  It's more accessible to me, it appeals more to my techy/nerdy side, and we all know what happened to Mac at the end of Jeepers Creepers

Learn a cross platform language - Once again with the cross platform thing. Here I'm going with Ruby. It is elegant and has a lot of great features.  Microsoft if also writing a .Net version, IronRuby, that will be useful in Silverlight development.  I'm hoping to create a few cross platform applications, not web apps, that will actually be useful.  I'll let you know how it goes.

Linq, Linq, Linq - Seriously folks, this is where its at.  I've been taking the LinqPad Challenge for the last couple of weeks and plan to continue for the next few months. It's great, I'm actually getting a handle on Linq to SQL queries.  Let's take the challenge together, shall we?

Presentations - I am admittedly the worst presenter/public speaker that I can imagine.  Miss South Carolina has me beat, hands down.  However, I find a way to do it anyway.  Presenting increases your communication skills, boosts your confidence and is a great way to trick your peers into thinking that you actually know what you're doing.  I'm planning on doing some research on presenting skills and applying them more often. I'm even looking into doing a screencast or two.

GTD - I'm a big proponent of Life Hacking.  So I'm going to continue finding great ways to save time.  I can tell you from personal experience that hacks like Merlin Mann's Inbox Zero can really save you time and peace of mind.

This isn't a comprehensive list, but it is stuff that I think is important.  What things will you be doing to become a better developer over the next few months?  I'll check in with you next year.

Friday, June 01, 2007

Spell Check in PowerShell

If you are like me, you do a lot of work in simple text editors. I'd take a sleek, versatile and fast Notepad2 over a bulky Word instance any day. So have you ever typed in a word and it looked funny? Did you spell that correctly? Well, you could open up Word and wait for it to come up and then use it's spell checker. Or, you could bring up a browser and use one of many sites that will check. My machine runs at a speed somewhere between sloth and slug. So if I don't already have one of those apps open, I'll use up my squirrel sized attention span and forget why I opened them in the first place.

I always have a PowerShell instance running. Wouldn't it be cool to test my funny looking word with a script. I'd used the NETSpell library on one of my previous projects and thought that it would be easier to access than Google's api. So what I ended up with was a good example of how to wrap a PowerShell script around an existing class library.

Here's the script:

###############################################################
###
### Spell.ps1 - Allen Mack 6/1/2007
###
### This script takes the first argument passed to it and
### runs it through the NETSpell spell checker.
###
###############################################################

[System.Reflection.Assembly]::loadfrom("c:\Program Files\NetSpell\bin\NetSpell.SpellChecker.DLL") Out-Null

$checker = New-Object NetSpell.SpellChecker.Spelling
$checker.Dictionary.DictionaryFolder = "c:\PowershellScripts"

$word = $args[0]

$result = $checker.TestWord($word)

if($result -eq $true)
{
Write-Output("`"" + $word + "`" is spelled correctly.")
}
else
{
Write-Output("`"" + $word + "`" is spelled incorrectly.")
Write-Output("Maybe you meant:")
$checker.Suggest($word)
$checker.Suggestions
}



The first thing to do is load the dll into memory. Next we create a Spelling object and point it to the directory where our dictionary lives. I copied the dictionary file to the same directory as the script. You could point it to the NETSpell installation directory. If the word is spelled correctly, I print out a message saying so. If the word is spelled incorrectly, I display the array of suggestions generated by the Spelling object.

Friday, March 02, 2007

Powershell FizzBuzz One-liner

I know, I know, the FizzBuzz problem isn't about the implementation. However, I've seen implementations in C#, Java, Python, Perl, Ruby, yada, yada, yada. Well, I haven't seen one in Powershell, so I'm posting it here. Not for implementation's sake, because I'm sure that there is a better way to implement it. I'm putting it here for the sake of fairness.

1..100 ForEach-Object { $str = ""; if($_ % 3 -eq 0) { $str += "Fizz" }; if($_ % 5 -eq 0) { $str += "Buzz" }; if(($_ % 3 -ne 0) -and ($_ % 5 -ne 0)) { $str += $_ }; Write-Output $str }

3/8/2008 - Thanks to Scott for pointing out a typo in the script. It's fixed now.

Tuesday, February 27, 2007

I could have died...

That's right, I could have died last weekend.  I had a high blood pressure attack on Friday night which caused tingling in my extremeties and pain in my left arm.  Now, when many people experience these kinds of symptoms, their life flashes before their eyes.  I, on the other hand, began to worry about my current level of term life insurance and how I can increase my coverage.   I'm lucky to have a brother that works in a doctor's office and he had me check my blood pressure.

I also suffer from white-coat syndrome.  Its a pre-existing condition.  That means that if I see someone in a white lab coat coming at me, my blood pressure skyrockets.  So you can only imagine what it did when I felt under-insured.  When I got to the doctor the next day, I told her what my bp was the night before and she stuck her pen in her pocket and took three steps back.  Apparently, I was lucky.  The slightest knick could have caused an explosion so violent that we would never be able to sell the house. 

On a side note, I think that I have passed the white coat syndrome to my son.  He freaks out when he sees the pharmacist at Publix, not to mention his pediatrician.

So here's the really funny part.  I had to have a Venus Dopplar scan on my arm.  Sounds impressive, doesn't it.  Well actually... no.  Its the same machine that they use to perform ultrasounds on pregnant women, goop and all.  Ask any woman whose been pregnant in the last 20 years and she'll tell you about the goop. 

I was escorted back to this little room in the back of radiology by a seemingly pleasant woman named Maria.  The name took me by surprise as I tend to think of it as having a mostly latin descent.  Maria, however, looked like she came from Khazakhstan and her dialect seemed to match.  I had to lay down and get gooped from my next down to my wrist.  My wife found this very amusing and considered it some sort of karmic payback for all the ultrasounds that she had to go through.

So then Maria says, "I poke you now,  okaaay.", in her Khazakhstanny idiom.  At the time I couldn't fathom a response.  Seriously, what are you supposed to say in these situations?  "Oh, a poking?  That sounds nice.  Thanks Maria!"  And so the poking commensed.  After about the third poke, I got up enough courage to ask, "Why are you poking me?"  Maria came back with a "I collapse your veins."  My first thought was, "What!?!", but then I thought "What?!?"  Maria went on to explain that her seemingly desctructive poking was merely a test to verify that my veins would pop back.  Of course they did, and it filled me with a sense of resiliency.  On the other hand, if they had not popped back, I could have died.  Good thing I was already in a hospital.  Of all the places to have a near death experience, I think that the hospital is at least in my top 5.

And so I made it through ok with no obvious issues and without having to use the "wand".  Once again, ask a pregnant woman. :)

Friday, February 23, 2007

IEEE defined Code of Ethics for Software Engineers

After listening to Steve McConnell's talk on the last dotNetRocks, I decided to quickly look into the IEEE Software Engineer Certification Program.  Its a little more indepth than I have time for right now and I'm not sure that I meet all the requirements for application.  However, I did stumble their Software Engineering Code of Ethics and Professional Practice.  It is aimed at making the software develop a respected profession.  I, of course, am lacking in several areas.  Here is the short version:

Software engineers shall commit themselves to making the analysis, specification, design, development, testing and maintenance of software a beneficial and respected profession. In accordance with their commitment to the health, safety and welfare of the public, software engineers shall adhere to the following Eight Principles:

1. PUBLIC - Software engineers shall act consistently with the public interest.

2. CLIENT AND EMPLOYER - Software engineers shall act in a manner that is in the best interests of their client and employer consistent with the public interest.

3. PRODUCT - Software engineers shall ensure that their products and related modifications meet the highest professional standards possible.

4. JUDGMENT - Software engineers shall maintain integrity and independence in their professional judgment.

5. MANAGEMENT - Software engineering managers and leaders shall subscribe to and promote an ethical approach to the management of software development and maintenance.

6. PROFESSION - Software engineers shall advance the integrity and reputation of the profession consistent with the public interest.

7. COLLEAGUES - Software engineers shall be fair to and supportive of their colleagues.

8. SELF - Software engineers shall participate in lifelong learning regarding the practice of their profession and shall promote an ethical approach to the practice of the profession.

I think that this is a great document that a lot of software development teams could adopt and reap some benefits.  I'm lucky to be on a team that already embraces most of these principals.  We are fair to and supportive of each other.  We all participate in lifelong learning and are constantly challenging ourselves.  Some of us even care about the safety and welfare of the general public.   However, like most us, I've also worked in groups where it seemed no one seemed to embody these principles.  All it generated was crappy code, shouting matches and the general weeping and gnashing of teeth. 

Friday, February 09, 2007

Interesting Text Parsing

At work this week we were getting a lot of SQL timeout errors.  We went to the DBA and he sends us a log file and explains that many of our sprocs are blocking resources.  He gave us this monster log file and left it up to us to get what we needed out of it.

Here is the basic syntax of the log file.

2006-11-17 19:03:20,733 WARNING BLOCKER -- MYDBSERVER SPID: 120, hostname MYWEBSERVER, prg .Net SqlClient Data Provider, ntlogin
2006-11-17 19:03:20,733 WARNING Blocking Buffer info: sp_executesql;1
--

This pattern was repeated ~600 times.  The log file reported on all the databases on the server, not just ours.  So, I came up with this PowerShell script to give me a list of unique stored procedures that caused a block on the SQL server.

$a = gc "blocks.txt"; 0..$a.count | % { if($a[[int]$_] -match "MYWEBSERVER") { ([regex]"ap\w*").match($a[([int]$_ + 1)]) } } | % { $_.Value } | sort -uniq

Yes, that is one line.  Thank you, PowerShell team, for giving us the ";" character.  ;-) 

The first line loads all the lines in the file into an array.

$a = gc "blocks.txt";

Then we loop through all the rows and pick out the lines that reference MYWEBSERVER.    NOTE: calling $a[$_] didn't work for me.  I had to cast $_ to an int, like so $a[[int]$_].

If the line contains the name of MYWEBSERVER, then I look at the next line and return everything that matches my regex expression, "ap\w*".  All of our sprocs have been prefixed with "ap" so this was pretty easy. 

0..$a.count | % { if($a[[int]$_] -match "MYWEBSERVER") { ([regex]"ap\w*").match($a[([int]$_ + 1)]) } }

The last step is to filter our result set to only pass through unique values.

sort -uniq

It took me about 15 minutes to write and test this.  However, next time we get a log like this, I'll be ready!

Wednesday, February 07, 2007

The death of a television giant

It has been a rough week for me, technology wise. I've had a lot of frustrating issues with my laptop. But even worse, my beloved televsion died. That's right, my 62" Panasonic CinemaView 1080i projection televsion left me to go to the great sports bar in the sky. And right in the middle of Seinfeld too. First the image flickered, then the image went away, then came the most horrible stench of burning electronics that I have ever smelled. Even now, a week later, you can still smell the subtle aroma of fried wire. Of course, this made watching the Superbowl fun. I had to bring down my kid's 20" tv/vcr combo to watch it on.

I have a demonstration image to convey the seriousness of the situation.



Clark Howard says to wait until March to buy a new tv. The prices will go down by then. So, I'm unofficially declaring the month of February as a month of mourning. On the bright side, I no longer have the warm, engulfing glow of my large screen tv to lull me into a semi-vegetative state. So I'll have more time to blog. ;)

Monday, February 05, 2007

Expand/Collapse PowerShell Commands

I was listening the Bruce Payette interview on Hanselminutes and my interest really piqued when they were discussing aliases and being able to write really terse scripts.  It got me to thinking.  Wouldn't it be cool to be able to expand all the aliased command names in a script long enough for you to work on the script.  Then, when you are ready to put it back out there, you could collapse all the command names to short aliases.

Here is my first attempt:

   1:  function Expand-Command($Text)
   2:  {
   3:      $a = (alias $Text).Definition
   4:      if( $a.length -gt 0)
   5:      {
   6:          return $a
   7:      }
   8:      else
   9:      {
  10:          return $Text
  11:      }
  12:  }
  13:   
  14:  function Collapse-Command($Text)
  15:  {
  16:      $a = [string](alias | Where-Object { $_.Definition -eq $Text } | Sort-Object { Name.length })
  17:      if( $a.length -gt 0)
  18:      {
  19:          return $a.split(" ")[0]
  20:      }
  21:      else
  22:      {
  23:          return $Text
  24:      }
  25:  }
  26:   
  27:  function Expand-Script($script)
  28:  {    
  29:      $s = ""
  30:      Get-Content $script | ForEach-Object { ([string]$_).Split(" ") | ForEach-Object { $s += (Expand-Command($_) + " ") } }
  31:      return $s
  32:  }
  33:   
  34:  function Collapse-Script($script)
  35:  {
  36:      [string]$s = Get-Content $script
  37:        
  38:      Get-Command | ForEach-Object { $s = ($s -replace $_.Name, [string](Collapse-Command($_.Name))) }
  39:      return $s
  40:  }
  41:   
  42:  Collapse-Script("c:\\Dummy.ps1")
  43:  Expand-Script("c:\\Dummy.ps1")
 



So, what's going on? Let's start with the Collapse functions. The Collapse-Command function(lines 14-25) basically goes through all the aliases looking for the ones that match the command name that was passed in. Then it sorts them by their length and splits out the first available.  This way it will always pass back the shortest  command name.  In the Collapse-Script function(line 34-40), we loop through all the commands and then replace their names with the collapsed names.


The Expand-Command function(lines 1-12) acts pretty much the same as the Collapse-Command function.  The only difference is instead of searching on the alias definition, we search on the alias name.  The Expand-Script function(lines 27-32) acts a little differently than its counterpart.  It loops through all the individual lines and then through all the words, calling the Expand-Command function as it goes.


I tried to think like a PowerShell developer, not a C# developer for this one.  However, I don't think that it turned out very PowerShelly.  It is also ungodly slow.  I welcome any constructive ideas to make it better.   

Wednesday, January 24, 2007

View Office 2007 documents in Office 2003

It's only been three weeks and I have already run into compatibility issues with my version of Office and some document that I would like to open from the web.  Office 2007 uses a new file format labeled the "Open XML Format". 

According to Microsoft:

"The Open XML Formats usher in a new era of openness and transparency for Word, Excel and PowerPoint. Solution developers can take advantage of a host of new integration opportunities to connect documents to important sources of information."

If you are still using Office 2003, however, you will find that the new format isn't very open or transparent to you.  Luckily, Microsoft has published a patch for Office 2003 to make it compatable with Office 2007.  You can download it here: Microsoft Office Compatibility Pack.

My only question,  if Microsoft is so gung-ho on their new format, why didn't I get this pack via Microsoft Update?

Tuesday, January 16, 2007

Fix Visio 2003 VML code for IE7 with Powershell

I have recently been tasked with providing a lot of documentation around the applications that I am working on.  I naturally turned to Visio to help me with my dataflow and physical network diagrams.  I'm using Visio 2003 and have found that this version will export your Visio file and all of its pages as a web site.  By default all of your pages will be converted into VML.  You can also insert hyperlinks into the objects on your diagram that link to other pages.

This produces a really neat web site with built in navigation and search capabilities.  It even works in FireFox, sort of.  FireFox users see a dumbed down version without the search.  I discovered my issue when I tried to use the site in IE7.  Apparently IE7 doesn't like the way the links are built.  I found more information here.  It looks like Office 2007 will fix this. 

There is a short term fix.  You just have to replace the 'href="#"' in all the vml objects to 'style="cursor:pointer;"' for each file that was generated.  In my case, I have over a dozen files.

At the bottom of the article in the comments someone mentions that there is a utility that you can down load and install to perform the fix.  But my machine is still pissed off about the last dinky utility that I installed and only use once in a blue moon.  Powershell can do this, no sweat.  Here's the line that I used.

ls vml_*.htm | % { echo $_.Name; (gc $_.FullName) -replace("href=`"#`"", "style=`"cursor:pointer;`"") | out-File $_.FullName }



First off, I'm getting all the htm files with vml code in them.  Visio conviently labels them as vml.  Then, for each file I write out the name to the console.  You don't have to have this, but I like seeing what files were processed.  The gc command reads the file into a string and the -replace command does the replacing work.  Notice that the escape character in Powershell is "`" not "\".  Finally, the original file is overwritten with the corrected string.