BottleIT - October 2007

Negativity

by Peter Hancock 25. October 2007 02:49

One of the things that I look for in a developer is openness.  When a new technology is released, I like to see an instant "hmm, this could work" thought process, rather than a "it'll never take off" attitude.  Same for a new way to approach an existing solution.  An openness to change is an acknowledgement that things can be improved.  An openness to new technology reflects a belief that it could solve some problems that existing technologies have, or it could provide some opportunities that existing technologies don't.  The immediate negative response reflects to me a closed mind.  My current openness test is Silverlight.  (It used to be Ruby)

"What do you think of Silverlight?" is my current test question.

It's surprising the number of people who dismiss this entirely - because it's from Microsoft!  I usually follow up with "What does it do?" It replaces Flash. Oh.  Ok.  So you have a deep knowledge then to make that judgement?  What's scary is that often they don't even realise the bigotry that is occurring, and worse, peers look up to some of these people as mentors and guides.

So why does this bug me?  Because I'm responsible for ensuring a high quality technology solution.  One that meets the customers needs, one that meets my company's needs, and one that can be delivered as rapidly as possible.  In order to make a decision, I want people around me who can make educated choices on a way forward, not a choice based on software house bigotry, or the "not invented here" syndrome, or even worse, the "that's the way we've always done it" excuse.  The negative response to an alternative immediately predisposes that individual away from the alternative - even when it could be the "perfect" solution to the problem.

But how do you deal with this?  One way that I've found useful is to actually highlight the issue up front.  "So you won't even consider this option because it's open source?" Another technique is to confront them with their own lack of knowledge - "So why specifically won't it work?".  My third favourite technique is to paraphrase...  "So, using Sourcesafe is the only option because that's all our developers are able to learn?"  Unfortunately, all these questions are negatively stated - perhaps that's my personal reaction to the negativity around me in these situations.  I'm open for alternatives...

So... what do you think of Silverlight?

... and why?

Currently rated 3.3 by 3 people

  • Currently 3.333333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

General

Naming Methods

by Peter Hancock 22. October 2007 22:25

One of the yukky areas of code that we deal with is legacy code.  Whether it be taking old asp code and bringing it up to 3.5 asp.net, or C# code that has evolved beyond recognition, we all end up dealing with it.  My pet technique now with advent of refactoring tools like Resharper is to rename methods to reflect exactly what they do.

So - the 172 line validateUser method becomes, ValidateUserShowErrorLockedOutStatusLastLoginAndAccessPrivileges(username, password)

Why is this good?  Well, if I *can't* refactor it into smaller methods because it's all so inextricably intertwined, at the least, I'm highlighting this fact, and telling the next poor person who wanders along, just what the function does.  And when you review the code later for targets to refactor - this one suddenly sticks out - just because of the name.

My all time favourite though was...

CalculateFeeOnPortfolioForBrokerageTransactionSubscriptionAndApplyFeeToAccountAndRollFeeUpToGLAndPrintTransactionStatememtAndIfEndOfYearPrintFeeSummary()

Seriously.

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Software development

Autogenerating constants from a database

by Peter Hancock 1. October 2007 20:02

I’ve frequently worked on projects that use a factory to create objects that have been persisted to a database.  The type of object is stored in an integer in the database and there is a corresponding #include file to enumerate the types of objects that can be created sorta like this…

enum Products
{
    Espresso = 1,
    Latte = 2,
    Long_Black = 3
};

and can write code like

if(productType == Products::Latte) // Ignore the switch on type, just go with the argument here…
    Product::ServeWithMilk();

The problem of course, is with our product list, we have over 30, and are adding them at a fairly regular clip. This means we need to

INSERT INTO Product VALUES (4, ‘Flat White’)

and then add to the enum Product enum as Flat_White = 4. Given the concept that we should update once only, the following script can be used to automatically generate the include file…
declare enumCursor cursor fast_forward for
 select typeId, productName
   from Product
declare @enumVal AS VARCHAR(10)
declare @enumName AS VARCHAR(50)
declare @line AS VARCHAR(80)
print ‘/** ‘
print ‘  * Product type cursor is autogenerated from sql’
print ‘  */’
print ‘enum ProductType’
print ‘{’
open enumCursor
 fetch next from enumCursor into @enumVal, @enumName
 while @@fetch_status = 0
 begin
  set @line = ‘    ‘ + replace(@enumName, ‘ ‘, ‘_’) + ‘ = ‘ + @enumVal

  fetch next from enumCursor into @enumVal, @enumName
  if(@@fetch_status = 0)
   set @line = @line + ‘,’
  print @line
 end
close enumCursor
deallocate enumCursor
print ‘};’

Save the script as a generateProducts.sql, and use osql to call it as a pre-build step…

osql.exe -E -dCoffeeApp -h-1 -oProductEnum.h -n -i  generateProducts.sql -b

This is not all that difficult to do, and keeps the database and the include files in sync.  What amazes me about this though is that in four of the seven organisations I’ve recently worked at, nobody has actually done it.  The other thing that has really surprised me has been the resistance to my changes to implement it this way.  Not from managers - who haven’t actually cared all that much, but by the senior developers in the group!  Quite remarkable really.  I guess they don’t like handing over that manual control…

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Software development

Recent posts

Recent comments