I am a big fan of compilation errors. I find it much easier to fix than runtime errors. I am currently using the ASP.NET MVC framework, and I find that it has a lot of typo space that the compiler will not catch.
For example, if I want to return a Data view from an Index action.
public ActionResult Index() { return View("Data"); }
can be easily mistaken
public ActionResult Index() { return View("Dats"); }
and will not throw an error until I run this action.
Has anyone come up with a method for checking these kinds of things at compile time? I came up with two possible solutions:
- Create a static class with all action names as constants and use names for names. I would have a coding rule that says use only constants. The weakness of this, if I change the name of the view, I have to update the class.
- Lots of unit tests to make sure that every action of the controller returns a valid
ActionResult and runs them anytime I make changes.
What process was implemented to manage this risk? Are there any additions or frameworks that mitigate this problem?
source share