Michael H. Pedersen
Michael H. Pedersen

Reputation: 199

Development speed - Compiling mvc web application "on the fly"

Moving to mvc 4 recently I'm wondering if there's way to speed up those "change a comma and update browser to see if it works" type of situations during developement.

Having programmed professionally for more than 10 years now I've gotten into certain habits. For one I've been using mainly asp.net web site projects, webforms, which allows me to make changes to the code-behind, ctrl+s, alt-tab to browser, hit f5, and see the results. Sometimes, but not always, it'll recycle the application, destroy my session, and send be back to the login page.

Working on a learning-by-doing mvc 4 project I'm getting slighly frustrated with the compilation cycle - I guess mostly because it's not what I'm used to.

As an example, let's say we're writing an Action to handle file moving and copying.

string rootpath = HostingEnvironment.MapPath("~/uploads");
string targetpath = HostingEnvironment.MapPath(Path.Combine(rootpath, TargetDir.Substring(TargetDir.LastIndexOf("/"))));

This compiles fine, but when tested it throws an exception because "rootpath" is already absolute and cannot be mapped again. Changing the code to

string rootpath = HostingEnvironment.MapPath("~/uploads");
string targetpath = Path.Combine(rootpath, TargetDir.Substring(TargetDir.LastIndexOf("/")));

also compiles fine and probably actually works. However you have one of those "what was I writing" moments and change it to

string rootpath = HostingEnvironment.MapPath("~/uploads");
string targetpath = Path.Combine(rootpath, Path.GetDirectoryName(TargetDir));

For now all's good.

Compared to developing with web site projects, the steps of code change, wait for compilation, refresh browser, login, test functionality (and repeat) seems to take much longer than before. Is there any way to speed up these types of trial-and-error situations? Or am I simply going about it wrong?

Upvotes: 0

Views: 368

Answers (1)

Davide Icardi
Davide Icardi

Reputation: 12219

I suggest a completely different approach. Use unit test.

The great advantage of MVC is that basically all code can be unit tested (controllers, models, ...). In this way at each change you just run a single or a set of unit test (keyboard shortcut like Ctrl+R, Ctrl+L or similar keywords are your best friends for maximum speed :-) ).

Only at the end you will run the complete project to see the final output.

Of course other then speed up develpment/debug time you will also benefit of a full suite of tests that can be very useful during development (for a better design of your code) and for regression test.

Upvotes: 2

Related Questions