Do you think that ASP.NET WebForms is a bad practice? [closed]
I'm working on an industrial project build with ASP.Net WebForms. We seriously think about switching our application into an ASP.NET MVC.
It will take us some time, so do you think ASP.Net WebForms is a bad practice and the time spent on switching to MVC will be gain later?
WebForms, if coded with proper design patterns and practices, are perfectly fine. I would only invest in switching to MVC if one of the following is true:
The current performance is severely deficient. In this case, a re-write might be unavoidable, and switching to MVC (which may force a proper separation of concerns upon you) could be a good choice.
You are expecting to perform a major upgrade which will be impossible due to the current solution being in an unmaintainable state. In this case, switching is again a reasonable option.
In general, you can have well-written and poorly-written applications in both WebForms and MVC (though as I said MVC makes it slightly more difficult to write poor applications.) If you have an acceptably performing and maintainable WebForms application, don't waste your dollars converting it.
I am an MVC enthusiastic.
When WebForms came out I was the only one saying "the emperor has no clothes", because I didn't understand how ViewState would scale, and the nightmare of sending JS instructions from code-behind to the front end. It's a crappy way of trying to bring the old WinForms methodology to the web world, and MVC is a real bless in terms that it's a far better way to do web development.
Having said that, as @dlev said, you should migrate your app to MVC only if you have a real justification in terms of poor legacy codebase and/or long-term plans that make the migration time pay off.
The best things about WebForms are:
- You can get an application up and running very quickly
- Can build an application with relatively little knowledge of the web and HTTP
If you plan on making an application that will be active for a while, and you don't mind learning a little more about the web, then I think MVC is a better way to go.
Switching an existing project is different because there's work - and uncertainty - up front. If this project will still be developed in the future I suggest doing the migration, but doing it piecemeal: you don't have to convert all the existing pages at once. You can create new pages and flows with MVC, keep the old ones in WebForms, and change them one by one. You can even render MVC partial views inside WebForms pages, and WebForms controls inside MVC views (without viewstate, which means controls without server-side interaction).
I've done this on a big project and it was very successful: we didn't end switching all the WebForms pages, because some of these were never touched. The moment a page needed work then it was time to convert it as well.
You may also want to look at Webforms MVP (Model-View-Presenter). http://webformsmvp.com/
It is a nicer way to do Web Forms so that the logic can be easily unit tested etc. It might be a good compromise if you cannot switch over completely.
The other thing to consider is, do your project timelines have enough flexibility to allow for the extra time it's going to take you to learn MVC to a level that means you can do this project right? If you learn as you go there's a risk you'll want to go back and fix that code you wrote at the start which now makes you cringe.
One other thing is your existing app is presumably deployed & has been in use for X amount of time? That represents X amount of time of bug fixes & usability testing by the users (even if they don't realise that's what they've been doing). You're now going to throw all that out & generate a whole load of new bugs. Granted, some of the fixes & lessons learnt from the old app can be carried over. But you need to take this into account before you do any sort of complete rewrite.
Simon
精彩评论