I'm a big fan of compilation errors. I find the a lot easier to fix than runtime bugs. I currently using the ASP.NET MVC framework and I find it has a lot of room for typos that the compiler won't catch.
For Example if I want to return the view Data
from the Index
action.
public ActionResult Index()
{
return View("Data");
}
can easily be mistyped
public ActionResult Index()
{
return View("Dats");
}
and will not give an error till I run that action.
Has anyone devised a method of checking these sorts of things at compile time? I've come up with two possible solutions:
- Creating a static class with all action names as constants, and using that for view names. I would have a coding rule that says only use the constants. The weakness with this if I change a view name I have to update the class.
- Lots of unit tests just to make sure every controller action returns a valid
ActionResult
and running them anytime I make a change.
What process have y'all implemented to help manage this risk? Are there any add-ons or frameworks that mitigate this issue?