views:

530

answers:

8

This is a question I have had rattling around in my head for some time. I had a chat with a guy the other night who told me he would not be using the navigational framework because he could not figure out how it works with MVVM. As much as I tried to explain that patterns should be taken with a pinch of salt he would not listen.

My point is this, patterns are great when they solve some problem. Sometimes only part of the pattern solves a particular problem while the other parts of it cause different problems. The goal of any developer is to build a solid application using a combination of patterns know how and foresight.

I feel MVVM is becoming the one pattern to rule them all. As it is not directly supported by .Net some fancy business is needed to make it work. I feel that people are missing the point of the pattern, which is loosely coupled, testable code and instead jumping through hoops and missing out on great experiences trying to follow MVVM to the letter.

MVVM is great but I wish it came with a warning or disclaimer for newbies as my fear is people will shy away from silverlight development for fear of being smacked with the mvvm stick.

EDIT: Can I just add as an edit, I use and agree with MVVM as a pattern I know when it is and isn't feasible in my projects. My issue is with the encompassing nature it is taking, as if it HAS to be used as part of development. It is being used as an integral feature and not a pattern, which it is.

EDIT 2: Thanks for all the comments so far, one issue that is surfacing from this is something I have not thought about until now. Is the introduction of richer more advanced frameworks for GUI/RIA development showing a weakness in RAD development for this generation. That is, is there a lack of code design and pattern knowledge being taught along with these frameworks? I once asked for a book on just C# (Before Pro C# & the .Net framework was popular) and was told why would I want to know C# minus winforms/asp.

Sure there are plenty of books/KB on these subjects but are people using them, beyond the superstars and very good programmers?

+3  A: 

Actually I've used MVVM quite effectively with Navigation Applications with the Windows Phone 7 framework using commands and messaging. But if someone tells you that you can use every feature of Silverlight without adding some code to the code-behind, then they are fooling themselves. Use the pattern where it helps and make sense, and go "off-pattern" when a particular feature requires something custom.

babernethy
+1, I agree with your view and it is the view I take.
DeanMc
+1  A: 

Why can't you?

And no, MVVM is just one of many patterns and frankly, not even amongst the most popular ones. What is hurting Silverlight's development is a) Flash b) not being Flash c) being Microsoft centric d) learning curve.

Plus the fact WPF doesn't really seem to have caught on doesn't much help.

Serapth
I wouldn't say WPF hasn't caught on, anyone who thought it would replace winforms overnight is naive. You say MVVM is not a popular pattern, do you belive that? In terms of WPF/Silverlight I think it is the most popular.
DeanMc
I don't know... what do you consider overnight? WPF was released in 2006, thats not exactly 'overnight'.
Serapth
Working for a large multinational my view is that WPF wont take off until large corporations move way from IE 6/7 and windows 2000/nt which could be a while, but of course this is an argument for another topic.
DeanMc
Sorry for -1 but I totally disagree. As DeanMc pointed out, MVVM is probably the most popular presentation pattern. And I fully believe that if one wants to create a medium scale silverlight/wpf application it is unavoidable to use mvvm. Flash is not hurting Silverlight. Silverlight is hurting Flash.
Przemek
+1 I am not putting MVVM down, it has its roots in older patterns that are just as successful and also, in theory follows good practice. It is its learning curve and lack of integration that I feel is hurting development.
DeanMc
@dean: if you don't put it down, I will. You are multiplying the amount of code required to display a model. It is a valid pattern, but it seems like the "nuclear" option that you reach for when you have no other choice. The problem is that the way WPF databinding is built, you don't really have any other option. A framework that requires large amounts of boilerplate to get anything done is poorly designed, but apparently the concern of having designers work on the same codefile was more important then designing a good api for developers. What I find amazing is how few people complain about it
Matt Briggs
@ matt, good arguements and very valid points +1
DeanMc
+1  A: 

Someone has problems figuring out how to use navigational framework with MVVM => Someone doesn't use navigational framework => MVVM is killing navigational framework => MVVM is killing Silverlight development.

Would you say there are few flaws with this chain of reasoning?

PL
No no, you misunderstand my point. My point is that people are using MVVM and shying away from things that are not MVVM friendly out of the box. The navigational framework was just an example of something that needs to be "played with" to get to work with MVVM.
DeanMc
+2  A: 

I'm using MVVM for a Windows Phone 7 app. I really like the idea of it but there's too many hacks, wordarounds and 3rd party tools needed to get it running.

Things are getting better with every release of Silverlight but I still think the technology is "bleeding edge".

vidalsasoon
This is my feeling on it. I suppose the frustration comes from hacking code waiting for the next release for integration purposes, that is of course if the SL team decide to integrate MVVM into silverlight at all.
DeanMc
+3  A: 

Assuming your question applies to WPF as well, I sort of wonder if the problem isn't just the massive learning curve of WPF/Silverlight, before it even occurs to you to try out MVVM. Think about all the new things that need to be learned with WPF (and I assume Silverlight): XAML, dependency properties, attached properties, routed events, routed commands, static resources, dynamic resources, styles, data templates, control templates, databinding, etc., etc. etc. Then take the fact that Microsoft released this technology with an incomplete set of, at least with WPF, badly skinned controls, and you have a recipe for frustration and the inescapable feeling that you are dealing with a technology that is "not ready for prime time". I mean, before the WPF Toolkit came out, there wasn't even a proper DataGrid control.

Once you understand all these things, MVVM is yet another hurdle, but I don't think it's the main impediment to people jumping on the WPF/Silverlight bandwagon. That said, it would be nice if Microsoft would get behind it the way it has gotten behind ASP.NET MVC. As it stands today, you have to download and use third-party tools, like MVVM Foundation and MVVM Toolkit (which, incidentally, have a lot of overlap and should be combined into a single project).

So, I agree with you to a point, but I think most of the challenges involved with MVVM are probably due to the lack of support from Microsoft, and the inherent complexity of WPF/Silverlight, not due to any flaw in the MVVM pattern itself.

DanM
That could very well be it. WPF/Silverlight are by nature complex. I wonder then if the issue may be that there is not enough emphasis on patterns and code design for newbies. Its all flashy no structure in the books I've read on silverlight.
DeanMc
@DeanMc, comment upvoted so hard. The emphasis is always on what the platform can do for you and not what to do with the platform (and how to do it).
nlawalker
Cheers, Good to know people think the same way.
DeanMc
+4  A: 

So, here's something that I think a lot of new MVVM developers forget - the pattern is there to help you, not the other way around. Building software in this manner tends to make your life easier as your project gets larger, but if it's completely getting in your way for a specific task, take a step back and ask, "In this specific scenario, is MVVM helping me here?" You're allowed to "cheat" a bit from time to time if it makes your life easier.

Paul Betts
+1 I second that opinion
Przemek
+1 I agree, see my edit for more on that subject.
DeanMc
+1  A: 

While Microsoft has introduced commands in Silverlight 4, I agree with DanM that Microsoft need to do more to help developers understand when patterns should be used.

This might help with the learning curve becuase for many companies that can’t or won’t use third party tools there is a lot of plumbing code you have to do yourself to use the MVVM pattern (see my blog post http://www.arrangeactassert.com/how-to-implement-mvvm-inotifychanged-and-icommand-in-a-silverlight-application).

Jag Reehal
+1  A: 

Great answers here, by the way. Good discussion and an important one to have. There is no doubt that learning Silverlight can be intimidating for new developers, and the MVVM framework will no doubt compound that.

However, I do agree that someone not understanding it isn't a dig against the framework. I still have developers who tell me that inversion of control/dependency injection is too confusing to learn, but does that make these invalid patterns? The fact the so much proven, "in the field" software relies on those concepts tells me they are sound even if complicated to grasp at first or understand.

Then again, learning a foreign was tough when I started, but once I pushed through, now I can speak it comfortable and wonder why it was so hard to begin with.

I guess the trend that scares me the most is this notion that for some reason complicated, enterprise applications should be easily built by beginner developers who either can't or won't grasp complex concepts. That's what it really boils down to. You don't have doctors saying, "Help, make this brain surgery easier so any one can do it." It's specialized. Building great software is also specialized, that's why consultants command good payment for their services: it's the value they provide in understanding the right way to architect and develop solutions.

If you are making an asteroids game, a fantasy game, a media site, a YouTube knock-off, etc, then you probably don't need MVVM and it is overkill. If you are building a small site with a few forms and graphs then build it how you are comfortable and be done with it.

If you are building a large, complex site that is composed of multiple, dynamic modules, moves thousands or millions of records and requires scaling to massive concurrent users, then you can't expect the design to just pop out after thumbing a few pages of a book or skimming a few sites. Software like that is complicated, with a lot of moving parts, and rqeuires a firm grasp of architecture.

What amazes me is people presumably building these more complex applications who still don't get building these more complex applications. Is there someone experienced on the team? Do you have an architect to stub out the framework that you can consume?

I mean really, the example just tells me the problem isn't MVVM, it's the developer. "Avoiding Navigation because of MVVM?" REALLY? What's MVVM got to do with it? Write the navigation pieces, and let the view models live inside the pages. Why does my navigation have to drive from a view model?

Come one. If it's that complicated I think it has nothing to do with the pattern, and everything to do with the developer just not understanding development. Don't blame the pattern. Maybe they need to stick to simpler applications. In my experience, people who come to understand the pattern understand software well enough that they know when and when not to use the pattern.

I know there are many movements to boil it down and make it simple for the "average consumer" but I think this is like trying to say, "Calculus is the wrong way to find the area under a curve because it's too tough to learn." While MVVM isn't as complex as Calculus, building complex software is a complex endeavor and I don't think you are ever going to simplify it or boil it down to a simple formula (nor should you). If you struggle with MVVM, please, don't use it - find something simpler and easier. If your project is complex enough to use it and you still don't grasp it, please hire someone who does, have them plumb it out and learn from them.

No, I don't want Microsoft telling me what pattern to use nor do I feel it is their responsibility. I'm a professional and it's on my shoulders to invest the time to learn and understand what I'm building so I can build it the best way for the customer. Microsoft doesn't necessarily know what my customer does or needs, so how can they possibly tell me what pattern to use? Projects like Prism are great because they are a compromise: they provide guidance and share "best practices" of how something can be done, without forcing that implementation on the developer.

Jeremy Likness