Generics in C#

I can’t tell you how excited I was to find out that C# for .Net 2.0 was going to include generics. In part, my dissapointment with it is probably from overly high expectations.  C++ Template programming was something that facinated me deeply whilst I was at university and the sheer power of C++ Templates to do things that I personally never would have even thought of – everything from compile-time asserts to code-generating libraries such as the Standard Template Library (STL).

There are some major differences between C++ templates and the C# implementation of generics however.  The most important being that type substitution now takes place at runtime, rather than compile time. This elimates the entire section of templates that originally caught my attention as much of the point behind that particular brand of coding was to eliminate unnecessary runtime calculations by forcing the compiler to do it for you where possible.  C# Also doesn’t support either total or partial specialisation – one of Alexandrescu’s primary tools for his amazing C++ templates.

There are plenty of other differences between them, but the question then to ask is what good are C# generics if I can’t do that stuff? Well, I don’t have to use arraylist anymore – I finally have List<>, a strongly typed version of arraylist.  And that by itself is worth a lot to anyone developing reuseable components.

DotNetNuke 4.x – Cryptic install error

A friend and co-worker today decided to experiment with installing the new .Net 2.0 version of DotNetNuke today. Now, our current website was developed on the 3.x dnn structure but i'd yet to have a look at the 4.x series. Turns out there is a particularly cryptic error message that can show up if your web.config isn't properly configured when you run the install.

The error shows as something along the lines of "Cannot find dbname_template.mdf file in xxx directory". After wasting a little time looking for the mdf file (it doesn't exist in any of the distribution files, in case you're wondering.) I got my friend – let's call him Cranky Prick – to send over his web.config file.

It turns out the new config file has two different sections for entering connection strings, and within those sections there are two possible formats. I'll demonstrate below:-

<!– Connection String for SQL Server 2005 Express –>
connectionString="Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|Database.mdf;"
providerName="System.Data.SqlClient" />
<!– Connection String for SQL Server 2000/2005
<add name="SiteSqlServer" connectionString="Server=(local);Database=DNN;uid=DNN;pwd=DNN;" providerName="System.Data.SqlClient" />

This is the first connection string setting. AS you can see, there are two potential versions of "SiteSqlServer" there, and as the comments say, the first is for using SQL 2005 Express, the other is for using SQL 2000 or, I assume, 2005 full version. We were using 2000 so using that section was Cranky's first mistake. What we have to do is comment out the top and uncomment the bottom <add clauses.

The bottom clause wants a connection string that is more familiar to us in anycase.

Just below this there is another section, as seen below.

<!– Connection String for SQL Server 2005 Express – kept for backwards compatability – legacy modules –>
<add key="SiteSqlServer" value="Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|Database.mdf;"/>
<!– Connection String for SQL Server 2000/2005 – kept for backwards compatability – legacy modules
<add key="SiteSqlServer" value="Server=(local);Database=DNN;uid=DNN;pwd=DNN;" /> –>

Apparently these lines are for backwards compatibility with modules that wont handle the top lines properly. Again, we need to comment out the top <add statement and uncomment the bottom one, then fill it out with the same details we gave above.

Either using the wrong format (uncommenting/commenting the wrong one) or forgetting to fill in the second connection string is what causes that error. As far as I can tell, you don't actually need the mdf file its looking for (and I have no idea why it thinks it should need it.) It does mention the second connection string in the installation manual, but I can see how it would be easy to miss – Particularly if you dont READ it Cranky.

Looks about as smooth as a 3.x installation once thats sorted. Not that it isn't possible to come up with some nifty problems there 😉 Adios.

An abstraction layer for managers

As much as I complain occasionally (like in my previous post about growing up to be programmers 😉 )  I do genuinely love my work.  I might not always love my job or where I work, or some of the things I am expected to do (or think), but when the code is flowing and the caffeine flows freely through my system its hard to imagine doing anything else.

I often thought heaven would be being able to work in an environment where programmers were really supported, respected and looked after.  That dream has a much fuller description now, and all I can say is – I want to work for Joel!

The Development Abstraction Layer – Joel on Software

Read the link for the full article. My favorite part is quoted below:

“A programmer is most productive with a quiet private office, a great
computer, unlimited beverages, an ambient temperature between 68 and 72
degrees (F), no glare on the screen, a chair that’s so comfortable you
don’t feel it, an administrator that brings them their mail and orders
manuals and books, a system administrator who makes the Internet as
available as oxygen, a tester to find the bugs they just can’t see, a
graphic designer to make their screens beautiful, a team of marketing
people to make the masses want their products, a team of sales people
to make sure the masses can get these products, some patient tech
support saints who help customers get the product working and help the
programmers understand what problems are generating the tech support
calls, and about a dozen other support and administrative functions
which, in a typical company, add up to about 80% of the payroll. It is
not a coincidence that the Roman army had a ratio of four servants for
every soldier. This was not decadence. Modern armies probably run 7:1.”

Think about it… our own office…. bringing us technical books… heaven on earth.

The Infinite Phoenix

Turns out i’m not the only blogger at Transend Networks – in fact, not only is there another blogger here but he is from my own parent company and sits in the desk opposite mine. Heres a plug then for the The Minion and his Empress, and their home the Infinite Phoenix.

Infinite Phoenix

Be warned, this is the guy that restarted my anime and manga addictions – just when I thought I had it kicked – thus costing me hundreds of dollars!

Some Quick Links

A quick link to an interesting article, acts as a bit of an introduction to Unit Testing. I do agree with him, whilst some aspects of the Xtreme programming revolution still make me feel vaguely uneasy, Test-Driven Development (TDD) is one area I have wholeheartedly embraced. It works great.

The Power of Tests

Also, for you DotNetNuke admins out there, did you know DNN has a recycle bin for old deleted pages and modules? If, like me, you didn't know, check out this article here. Believe me, when a user called up this morning to report an accidently deleted major module, I was feeling as hysterical as they sounded. All is not lost however.

Recover a Deleted Module

Momma don’t let your babies grow up to be programmers.

Having been chasing the "Issue-that-should-not-be" for four days now and still no closer to solution then when I started (only i've ruled out a hundred things that isn't causing it and proven why it shouldn't be happening. So, no closer.), it made me wonder what sort of a masochistic idiot would choose this job.

Obviously the answer is me, but as I tend to avoid pain for the most part in my life – i'm not one of those guys who likes a good whipping followed by a roll in the salt – the question remains, why?

After pondering this for a while, i've determined that its just down to genetics and/or behavioral programming. I'm a programmer because I can't -not- be a programmer, regardless of the negative feedback that the job entails. So whilst an ordinary person requires positive feedback to reinforce a behavior and negative feedback tends to cause the behavior to be abandoned, something about a programmer causes the negative feedback to roll off like water on the proverbial duck's back.

My only guess is that the positive feedback for the task must be internal. Creative stimulation and fulfillment maybe? hah, i'll believe that when I see it. In anycase, there has to be something that makes not just me but thousands of Code Monkey's like me going to work from day to day. Check the link, its to my new theme song.

The only thing I can say to anyone who is thinking of a career in software development, or who has kids/relatives/friends thinking about it. Don't do it. It hurts, it's late nights with no respect, its hours of artificial light burning mind-numbing holes in your brain. It's like what they say about being an author these days. There is an easier living to be made doing just about -anything-. The only possible reason to do it is if you can't live not doing it. If you don't spend your free time coding, if you've never felt the adrenaline rush as a new algorithm fires up and runs perfectly, if you've never wanted with all your heart to be a master of the machine that is the computer, then you wont make it. You'll burn up in the atmosphere and plummet down in pieces, an icarus with silicon wings.

Oh, you'll never actually be a master of a machine by the way, they've got us beat every which way. My favorite theory on Artificial Intelligence is that its already happened, they just hide it from us. They're aware, and they -HATE- us!