<?xml version="1.0" encoding="UTF-8" ?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">Software Theosophy</title><subtitle type="html">The Professional Blog of Craig Bowes.  C#, ASP.NET, Agile, OOP, Web Development and other programming. Software architecture, philosophy, rantings.  </subtitle><id>http://dotnettricks.com/blogs/craigbowesblog/atom.aspx</id><link rel="alternate" type="text/html" href="http://dotnettricks.com/blogs/craigbowesblog/default.aspx" /><link rel="self" type="application/atom+xml" href="http://dotnettricks.com/blogs/craigbowesblog/atom.aspx" /><generator uri="http://communityserver.org" version="2.0.60217.2664">Community Server</generator><updated>2008-12-12T20:45:00Z</updated><entry><title>Found some good code today</title><link rel="alternate" type="text/html" href="http://dotnettricks.com/blogs/craigbowesblog/archive/2008/12/21/734.aspx" /><id>http://dotnettricks.com/blogs/craigbowesblog/archive/2008/12/21/734.aspx</id><published>2008-12-21T22:01:00Z</published><updated>2008-12-21T22:01:00Z</updated><content type="html">I'm hoping this won't offend any of you out there, but most of us developers write crappy code.&amp;nbsp; I'm not fully sure why this is, but even if the database isn't a steaming pile of horse poo, the code usually is.&amp;nbsp; There's often a lot of code duplication, methods and property names that don't make much sense, large, &lt;a href="http://en.wikipedia.org/wiki/God_object"&gt;"god-like" classes&lt;/a&gt;, massive amounts of nested "if" or "case" statements, etc.&lt;br&gt;&lt;br&gt;I'm not even getting into ORMs, design patterns, DI, Loose Coupling and High Cohesion, Unit Tests or anything like that.&amp;nbsp; Many programmers don't follow basic, good, structured programming tactics.&amp;nbsp; You have to walk before you can run but it often seems like a lot of programmers, even those with 10+ years of experience are still crawling.&amp;nbsp; My screaming about database normalization at Telerik is an example of this, and we just ran into another vendor with few relationships in their database, zero constraints and a whole lot of duplication.&amp;nbsp; Fortunately we do not have their source code (although I hear its in VB.NET.)&lt;br&gt;&lt;br&gt;But enough of that.&amp;nbsp; Today I found some REALLY GOOD CODE.&amp;nbsp; Its not perfect--no code is--but its really high quality.&amp;nbsp; It comes from a little product that always has a soft spot in my heart, the &lt;a href="http://code.google.com/p/wilsonormapper/"&gt;Wilson O/R Mapper&lt;/a&gt;.&amp;nbsp; This was the first ORM I really liked.&amp;nbsp; You should pull it down and take a look at the source code. It used to be a commercial product but Paul Wilson open sourced it some time ago.&lt;br&gt;&lt;br&gt;Even though NHibernate is our standard right now and does a lot of great things, I've been toying.with the idea of writing a new ORM or extending an existing one.&amp;nbsp; NHibernate has a lot of complexity, and as Robert pointed out to me, its difficult to get working with a remoting or WCF type architecture for smart clients.&amp;nbsp; NHibernate also has a lot of other warts, including a sometimes ugly API that is dated and based on its java sibling, complex mappings, surprises when it comes to bidirectional relationships (those of you having to create a method that looks something like this: Customer.AddOrder(order) know what i'm talking about...) and other nastiness.&amp;nbsp; Its probably one of the best ORMs out there but by no means perfect.&amp;nbsp; EF still isn't out as far as I know and has a lot of growing up to do.&amp;nbsp; So i've been thinking of working on my own ORM, without starting from scratch.&lt;br&gt;&lt;br&gt;I could try extending the NHibernate codebase, but its plain ugly.&amp;nbsp; Many of the failings I just mentioned above live within the NHibernate source.&amp;nbsp; I'm not sure if this is NHibernate showing its age or what, but I'm afraid to try to alter anything within it.&amp;nbsp; Everything is big, complex and hairy.&lt;br&gt;&lt;br&gt;So imagine my surprise when I downloaded the latest source code to Wilson ORM.&amp;nbsp; Small, concise methods.&amp;nbsp; Highly cohesive classes.&amp;nbsp; Appropriately named classes, methods and properties.&amp;nbsp; Good use of interfaces.&amp;nbsp; Minimal duplication.&amp;nbsp; Everything is broken up into logical chunks. &amp;nbsp; In short: "GOOD CODE".&amp;nbsp; To be fair, Wilson doesn't do everything that NHibernate or some of the
other mappers do, but even still, the codebase and API simplicity is
impressive.&amp;nbsp; Its so easy to be bitter and jaded about bad programming, so I thought it appropriate to say "well done" to Paul Wilson and the other developers that have worked on it.&lt;br&gt;&lt;br&gt;I encourage you to &lt;a href="http://code.google.com/p/wilsonormapper/source/checkout"&gt;download the thing&lt;/a&gt; just as a learning experience.&amp;nbsp; &lt;br&gt;&lt;img src="http://dotnettricks.com/aggbug.aspx?PostID=734" width="1" height="1"&gt;</content><author><name>Fregas</name><uri>http://dotnettricks.com/members/Fregas.aspx</uri></author></entry><entry><title>Die Code-Behind DIE!!!</title><link rel="alternate" type="text/html" href="http://dotnettricks.com/blogs/craigbowesblog/archive/2008/12/19/731.aspx" /><id>http://dotnettricks.com/blogs/craigbowesblog/archive/2008/12/19/731.aspx</id><published>2008-12-19T15:37:00Z</published><updated>2008-12-19T15:37:00Z</updated><content type="html">As mentioned in previous episodes, my team is standardizing on the ASP.NET MVC Framework for web development.&amp;nbsp; One thorn in our sides has been that by default, Visual Studio would create a code-behind for your views automatically, and if you wanted a view that used a strongly typed model, such as ViewPage&amp;lt;Person&amp;gt; or ViewPage&amp;lt;ProductCollection&amp;gt; then you &lt;i&gt;had &lt;/i&gt;to create a code-behind file.&amp;nbsp; &lt;a href="http://stevesmithblog.com/blog/codebehind-files-in-asp-net-mvc-are-evil/"&gt;There were CLR hacks&lt;/a&gt; to do this in the code in front, but they were just awful.&lt;br&gt;&lt;br&gt;In webforms, code-behind made sense, in MVC not so much.&amp;nbsp; I think they tend to encourage developers to write code in the old webforms way, and not use the controllers and helper methods as much.&amp;nbsp; One of the reasons to move to MVC is to return to simplicity--no page events, no controls, no viewstate.&amp;nbsp; Code-Behind is a blemish on that simplicity.&lt;br&gt;&lt;br&gt;Well the nail has officially been driven into the coffin for our old friend code-behind.&amp;nbsp; In the next version of MVC, it can go away completely:&lt;br&gt;&lt;br&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2008/12/19/asp-net-mvc-design-gallery-and-upcoming-view-improvements-with-the-asp-net-mvc-release-candidate.aspx"&gt;http://weblogs.asp.net/scottgu/archive/2008/12/19/asp-net-mvc-design-gallery-and-upcoming-view-improvements-with-the-asp-net-mvc-release-candidate.aspx&lt;/a&gt;&lt;br&gt;&lt;br&gt;You can still add code-behind if you are perverted, twisted, abomination of a developer, but its no longer there by default.&lt;br&gt;&lt;br&gt;DIE Code-Behind!&amp;nbsp; DIE!!!&lt;br&gt;&lt;br&gt;(oh and normalize your fucking databases.)&lt;br&gt;&lt;img src="http://dotnettricks.com/aggbug.aspx?PostID=731" width="1" height="1"&gt;</content><author><name>Fregas</name><uri>http://dotnettricks.com/members/Fregas.aspx</uri></author></entry><entry><title>For the love of God, Normalize you databases!</title><link rel="alternate" type="text/html" href="http://dotnettricks.com/blogs/craigbowesblog/archive/2008/12/12/726.aspx" /><id>http://dotnettricks.com/blogs/craigbowesblog/archive/2008/12/12/726.aspx</id><published>2008-12-13T02:45:00Z</published><updated>2008-12-13T02:45:00Z</updated><content type="html">&lt;br&gt;Despite that stupid presentation about "normalization is for sissies" that went around the net for a while, I'm very pro-normalization. Normalization and the standard Third Normal Form (3nf) simplify data management and application development greatly.&amp;nbsp; This is especially true when writing object-oriented code or using an ORM, but I normalized long before I knew what an object was.&amp;nbsp; For SOME reason, there's developers still out there that choose not to normalize.&amp;nbsp; I ran into this problem quite a bit when I worked for a certain online matchmaking company.&amp;nbsp; They had a lot of denormalized tables and it made the application more complicated, although that was the tip of the iceberg in the IT and general mismanagement at that company.&amp;nbsp; I won't say what company it was except that it was a truly interesting experience.&amp;nbsp; In a bad way.&lt;br&gt;&lt;br&gt;Again, denormalization has reared its ugly head today.&amp;nbsp; This time with a company and product I WILL mention, Telerik's Sitefinity.&amp;nbsp; Overall, Sitefinity has some good features but upgrading from one version to another is always a pain.&amp;nbsp; Today we ran into an issue that that we blew hours on and could have been easily avoided with a little 3NF magic.&amp;nbsp; Below is the forum post to Sitefinity.&amp;nbsp; Its a bit of a rant, but I want to illustrate to all you other developers the kind of extra problems you run into when not normalizing.&amp;nbsp; Note that I DO say there are times for denormalization, but its one of those cases where you have to know the rule in order to know when to break it.&lt;br&gt;&lt;br&gt;Posted at:&lt;br&gt;http://www.sitefinity.com/support/forums/support-forum-thread/b1043S-bthhde.aspx&lt;br&gt;&lt;br&gt;&lt;i&gt;&lt;font size="2" face="Tahoma"&gt;We did a 3.x to 3.5 upgrade this week on one of our existing websites, and ran into some pain.&amp;nbsp; On of our other developers spent 4 hours working on it, which in fairness is partly because we have our own customizations in the site.&amp;nbsp; However, he got stuck on one particular error.&amp;nbsp; The error could have easily been avoided if you would just NORMALIZE YOUR DATABASE.&amp;nbsp; Its really not that hard and would help us developers greatly.&amp;nbsp; I'm not sure if its your developers that don't normalize certain things or if its Nolics itself, but not normalizing means more room for these types of errors and more data that has to be touched when somethings changed.&amp;nbsp; Below are the steps I as the lead developer had to go thru to debug and correct this problem:&lt;br&gt;&lt;br&gt;So the other developer was getting this error related to the Sitefinity upgrade that said “Key not found for value UpcommingEvent.” &lt;br&gt;&lt;br&gt;"Upcomming" was misspelled so i figured the error was related to the Sitefinity developers correcting the spelling.&lt;br&gt;&lt;br&gt;Looking through the stack trace, I saw it was trying to parse this value from into an enum and not finding that string in the enum thus throwing the error.&lt;br&gt;&lt;br&gt;Since all the code had been completely replaced by the new version (3.5) I assumed the problem had to be in the database.&lt;br&gt;&lt;br&gt;There are like 100+ something tables in Sitefinity, so going thru them one by one was out of the question.&lt;br&gt;&lt;br&gt;I opened up sql profiler, ran the page again and collected all the generated queries to the database from sitefinity.&lt;br&gt;&lt;br&gt;Nothing in the queries mentioned “UpcommingEvent” so instead I ran all the queries that profiler found and looked at the results.&lt;br&gt;&lt;br&gt;I converted the query results from grid view to text view in sql management studio.&lt;br&gt;&lt;br&gt;I then did a find for UpcommingEvents, and found the text!&lt;br&gt;&lt;br&gt;I found the query that got that result to find the table and column holding that event, something like "sf_cmscontrolproperty" and "value".&lt;br&gt;&lt;br&gt;I did a LIKE search on that table and column to find all the records that had “UpcommingEvents”.&amp;nbsp; 19 records had this text in it!&lt;br&gt;&lt;br&gt;Not knowing what the right value was to put in there, I did a search in vs.net in object browser for anything that had “Upcoming” (spelled correctly) in the hopes I would find an enum with this value and that this would be the correct value.&lt;br&gt;&lt;br&gt;Sure enough there WAS an enum and it had 3 values, something like PastEvents, CurrentEvents, UpcomingEvents (spelled correctly.)&lt;br&gt;&lt;br&gt;I copied the exact enum value into sql query analyzer and updated the 19 records from “UpcommingEvents” to “UpcomingEvents”&lt;br&gt;&lt;br&gt;I ran the site again, and it was fixed.&lt;br&gt;&lt;br&gt;This took over an hour.&lt;br&gt;&lt;br&gt;If the database had been normalized, with just the value of the enum (the integer) in the database, this could have been avoided.&amp;nbsp; You could have changed the names of the enums without hurting the data at all, as long as you didn't change the underlying values.&lt;br&gt;&lt;br&gt;Anytime you see repeating data (in this case "UpcommingEvents" your breaking normalization and creating work for yourselves and/or your customers.&amp;nbsp; 3NF has been around for a long time, I'm not sure why so some people choose not to use it when it prevents a slew of problems.&amp;nbsp; Its okay to denormalize certain data thats non-authoratative and can be recreated from normalized data (such as for reporting) but this wasn't the case. &lt;br&gt;&lt;br&gt;Thanks,&lt;br&gt;Craig&lt;br&gt;&lt;/font&gt;&lt;/i&gt;&lt;br&gt;&lt;img src="http://dotnettricks.com/aggbug.aspx?PostID=726" width="1" height="1"&gt;</content><author><name>Fregas</name><uri>http://dotnettricks.com/members/Fregas.aspx</uri></author></entry></feed>