views:

1857

answers:

13

I just went through some MVC tutorials after checking this site out for a while. Is it just me, or does MVC View pages brinig back HORRIBLE flashbacks of Classic ASP spaghetti code with all the jumping in and out of HTML and ASP.NET with yellow delimiters everywhere making it impossible to read? What ever happened to the importance of code/design separation?? I was really sold on the new technology until the tutorials hit the View page development section.

Or am I missing something? (And don't say you can use the template to help because it's jsut moving the spaghetti to another location - sweeps it under the rug - it doesn't fix the problem)

+19  A: 

see Jeff's post (http://www.codinghorror.com/blog/archives/001155.html) which echoes your question, and Rob Conery's response (http://blog.wekeroad.com/blog/asp-net-mvc-avoiding-tag-soup/)

In summary, ASP.NET MVC gives developers the choice of shooting themselves in the foot, although it's certainly possible to do it cleanly. As such, it is suited for developers who are comfortable with web development and have a clean style, but it is not for the developers who want Widgetized behavior a la winforms without having to delve too deeply into the markup.

Jimmy
Excellent links - I hadn't seen them yet.
le dorfier
+3  A: 

The difference is that in MVC the only thing that the view is doing is rendering the display. All of the business logic, I/O handling, and model-related code is found in the controllers and model classes. The amount of code found in the view is relatively small and compact -- and you can abstract it out into user controls (partial views) if it is commonly used.

Personally, I like the extra control I have over the view. Most of my time with webforms seemed to be spent trying to work around the default assumptions that were made (and the name mangling introduced by master/child pages) that made it difficult to do much of anything client-side.

EDIT: I forgot to mention the ability to create HtmlHelper extension methods that lets you move a lot of the stuff into the backend as well. All in all, between the controllers, models, and extension methods it adds up to a lot more code that is easily testable in MVC that in either classic ASP or ASP.NET WebForms.

tvanfosson
In theory that's correct, but I think the MVC views still allow unrestricted embedding of code, so it's still up to the developer to do it properly.
chaiguy
The same mechanisms to embed code in MVC views are available in webforms, too. As the saying goes, "you can write Fortran in any language." It takes discipline to write good code. The extra testability in MVC is worth, IMO, the temptation.
tvanfosson
+1  A: 

This was mentioned at PDC, they did mention it was a bit too "classic asp" like with all the <%=. But they also did mention that they will be adding standard ASP.Net tagging and controls.

The entire direction for them is to get a stable release, then make it easier to work with.

PDC Video: http://mschnlnine.vo.llnwd.net/d1/pdc08/WMV-HQ/PC21.wmv

Tom Anderson
So there will likely be a "MVP 2.0" which will be leaps ahead?
pearcewg
+1  A: 

It is about seperation of concerns. In Classic ASP, it was a mix of business logic and presentation logic, with nasty includes thrown in for libraries.

The syntax is similar at this point, but the purpose is not. In the view, you should only be doing presentation logic. You still can put business logic in there, nothing stops you (unfortunately). It depends on the developer, which is still my biggest concern.

joseph.ferris
+7  A: 

If you don't like the default View engine, you can use another one.

As per Scott Guthrie's blog:

One of the things the team has done with ASP.NET MVC is to make sure you can use any type of "view engine" you want with it. This provides a lot of flexibility to customize the rendering engine however you want.

We are going to be investigating some more declartive view engines in the future - although nothing specifically planned just yet.

Examples of alternative View engines are NHaml discussed here, Spark discussed here and NVelocity discussed here.

Grant Wagner
+4  A: 

MVC vs. generic ASP.NET like the difference between automatic and manual transmissions. Use a manual if you want to determine which gear to use for which purposes, when to shift, and optimize for efficiency. Use the automatic if you want something that just works but may not be very well optimized, or flexible, or easy to debug (which you won't need to do as often.)

Classic ASP was a manual transmission with only second gear.

le dorfier
I'd say Classic ASP was a manual transmission with only Neutral (when things were good) and Reverse (all other times)
Mark Brackett
+2  A: 

I think the problem with the ASP.NET view engine is that there are no restrictions on what you can do, since its just a .NET language embedded in XHTML.

In contrast, take a look at the Django template engine. In the Django framework, the controllers and models are written using the full-blown Python language, but the view template engine defines a restricted language which only provides basic programming constructs (conditional, loops, etc). This restricted language resembles Python but it isn't actually Python, so it cannot invoke arbitrary code like external libraries. It can only access the model data that is passed in to the view.

Any view engine that embeds a general purpose language is going to have the problem where people abuse it and do things they shouldn't in the view. So with those engines you really need to have the due diligence to constrain yourself from doing things other than access the model data.

DSO
The django template language also imposes other limitations which are important in this context. You can't modify the state of objects. So you can't do stuff like db inserts from the templates. Which essentially forces you to use separation of concerns.
Vasil
See also StringTemplate view engine.
chaiguy
+7  A: 

Finlay Microsoft is correcting his error with ASP-Classic to ASP.NET step. 70% of old asp programmers went to PHP because ASP.NET was to complex.

They tough that everything can be solved with ASP.NET drug and drop menus. And in the end everything is inside form tag! We are building big "web form" not web sites. Just look at the HTML from any ASP.NET site. Absolutely horrible!

ASP.NET MVC is the new HOPE for cleaner more organised HTML code and powerful business logic.

vladocar
Yeah ASP.NET sucked, but I'm actually pretty excited about MVC. It looks much simpler, especially when combined with a custom view engine like StringTemplate I mentioned.
chaiguy
+1  A: 

Check out the StringTemplate view engine, it looks nice and clean.

chaiguy
it DOES look nice!
Evildonald
A: 

Because the people behind MVC really liked ASP/JSP pages and want to implement it all over again. They appear to hate:

  • ViewState
  • Existing ASP.Net Controls
  • Clean Html
  • Existing User Controls
  • Postbacks

They appear to love:

  • Re-inventing the wheel
  • REST-ful urls

MVC essentially is a way of forcing a separation of code from presentation. If a developer actually cared enough, this could be easily acheived with normal Asp.Net. It is possible to punk the whole "separation" system anyway, so I don't really see the point.

That being said, there is some merit to it.. but not enough to outweigh the problems. MVC version 3 I'm sure will be awesome.

And before anyone marks me down -1, see how many MVC questions I've answered. I know what i'm talking about.

UPDATE If you are taking your separation seriously, upon looking at it, chaiguy1337 is onto a good thing. String Template looks great because it does not allow any code in your front end! In my opinion, the ASP.net MVC team dropped the ball on MVC.

Evildonald
You may know much about MVC but you obviously haven't done enough asp.net development, since you think ViewState is good. It is in the right hands. In 75% it's evil. And what in the world makes you think that Asp.net MVC creators hate clean HTML? (I'm sure I've written this before - some strange deja vu)...
Robert Koritnik
Dear Rude Robert,You must not know much about ASP.Net or else YOU would know that if you find viewstate so evil, that you can turn it off for a page or a whole application. If you also knew as much about coding as you do about being rude, you would know that any framework can be abused and that poor programmers who would make large viewstates, will ultimately end up making large cookies/session/hidden objects in the page to achieve the same result but with less security.Viewstate isn't evil, poor programming and rude flamers are evil.
Evildonald
What is more Robert, know-it-all, humourless commenters like yourself ruin StackOverflow for everyone. Have a good look at what you wrote and realise that you could have written it in a much less confrontational manner. That will make you a better "all-rounder and a great asset for any development team"
Evildonald
A: 

In classic ASP, you didn't have a choice to move business logic out of the UI layer. In ASP.Net MVC, the "spaghetti" code is isolated the UI layer, the View; 90% of your logic will be in the "M" and "C" layers, which are regular, non-spaghetti C# classes.

The View is meant to be "dumb". Nothing critical in there from a business logic perspective. It's meant to be nearly disposable.

You can paint a room messily without doing any damage to the structure. If you decide to clean it up and re-paint, you don't need to call the architect. Same with the View.

Matt Sherman
+2  A: 

After programming MVC for a while now, I'm going back to ASP.NET.

MVC is indeed a nice step forward from classic ASP or PHP, but it is a big step back compared to ASP.NET.

Many things that can be programmed with a few steps in ASP.NET need a lot more work in MVC. Making it harder to meet deadlines.

The technology has it's merits, but isn't mature yet.

Maybe in version 3.0 ...

George