Magic strings in code are a no-no
Why?
Ok let's say you have a connection string "MyConnection" in
config.. and all throught your code you refer to it as
"MyConnection", then if you ever need to change it you will have to
do a search/replace on the string...
Ok .. so what's the problem ?
What if you have a class called VerifyMyConnection ...
search/replace will change the name of that class too .. that's BAD
!
So .. wherever possible use constants instead of
strings
In MVC you might want to write
@Html.ActionLink("Home", "Index", "Home")
in one of your views, this is really brittle code, if you change
the name of that method on your controller your code will fail
!
Also there are TWO parameters with value "Home", looking at it
.. which is which ? .. one is the name of the controller .. one is
the link text ..
So.. add a nuget reference to https://nuget.org/packages/Mvc3
Futures
it will
allow you to write
@Html.ActionLink((HomeController a) => a.Index(), "Home")
Ok, there is 'slightly' more processing overhead involved in
parsing the lambda expression (so far this has proved to be
neglible),
but it's far more maintainable and a lot more
'intention-revealing' !!
Note that there is now only one param "Home" which is the link
text :-)
Note this works fine with Async Controllers in MVC