Bill Robertson's Blog

MVC Spaghetti Code

Some professional background info first.  I started my tech career as a network technician setting up networks and hardware support.  I was interested in programming back in 1997 (actually 321 Contact magazine on a Commodore 64) and it seemed back then, web was the way of the future.  I spent a week working on an asp (classic) project and knowing c++ just couldn’t stand the unstructured syntax for rendering the pages.  I left IT to go back to grocery stores.

I’ve been on this MVC project for 6 weeks now. I making progress and learning exactly what it behind the idea.  Simply put, your Controllers are the CodeBehind for your pages.  Rather than have one code file for each page, you have one code file for a plethora of “Views”.  I really don’t care.  A View is simply a page and changing the name doesn’t mean squat.

I am going with it and working within the framework they provide, but had to post how ugly this code was.  Remember, I avoided classic asp because of the slaughtering of readability.

alt

I just wanted to alternate the style on table rows.  I admit the <%= ip.AttemptedCount %> is worlds better than <% Eval( “AttemptedCount”) %>. The “.ToShortDateString” is better than googling (or binging) the string format codes.  But seriously, this is the default formatting for the code.  I’m confident there is a more readable way to do this.

I want to also add that intellisense is the greatest developer tool created by Microsoft and even that is failing in this situation.  I'd almost rather turn off the validation for this type of logic when it is inside a funky script block.  I highly tout intellisense and has enabled me to become a better developer around self discovery of code and sure beats the hell out of looking in a book, which is where I started before the web really took off.

You can lecture me about HtmlHelper extension methods, and I’ll accept that, but seriously, this doesn’t seem to be that crazy of an idea: let’s alternate the style on the table rows.

I’ll take any advice to make this more readable, but why abandon the entire idea of server controls.  Extracting this type of functionality is what makes server controls so much better than dryly rendering basic html.

Comments

gerry lowry said:

Bill, you have some interesting ideas.

Try asking questions and answering too

at forums.asp.net; specifically the asp.net mvc

section:  http://forums.asp.net/

You'll find many other useful areas are covered:

http://forums.asp.net/ as well as a lot of mvc

learning material at  http://www.asp.net/mvc/

in general and http://www.asp.net/mvc/learn/

in particular.

Regards,

Gerry (Lowry)

# November 20, 2009 2:45 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)