开发者

In a strongly-typed world, why isn't ASP.NET MVC's fragile dependency on naming conventions frowned upon? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

Since forever, strongly-typed objects have been a foundation of object-oriented programming. Fast-forward to 5 minutes ago, when working with the Entity Framework and MVC3, I was forced to add this to my Web.config:

<connectionStrings>
    <add name="_MY_EXACT_CLASS_NAME_DbContext" connectionString="Data Source=blahblah.../>
</connectionStrings>

Great, My entire application depends on an arbitrarily-chosen name in an XML attribute. Is this really what modern programming looks like? Misspelling a class name is a serious offense, one the compiler leads us directly into fixing, but in this case, I'll just get a runtime exception message. If Mr. aforementioned exception message in a good mood, he'll point me toward Mordor, and I'll trudge off toward another Mount Doom of wasted debugging hours to destroy the invisible One-Typo-To-Rule-Them-All.

The same goes for Controllers:

routes.MapRoute("BE_CAREFUL","{controller}/{action}/{id}",
            new { controller = "ONE_FALSE_MOVE_AND",
            action = "BUT_I_SWEAR_IT_SAID_BUILD_SUCCEEDED" }
);

It seems like things come and go in waves. Strongly-typed objects had their day in the sun, and now we're all girl-next-door over the anonymous "var". I'll admit, being coy about your type stirs up a lot of sexy scenarios - especially knowing you don't have to do any setup work - but here's The Actual Question:

How do the forefathers of object-oriented programming feel about our "advancement" of their art by adding a bunch of wishy-washy, do-sorta-whatever anonymous constructs while at the same time creating fragile dependencies on naming conventions?

For all we know, MVC4 might suddenly require that all names be preceded by exactly 4.7 spaces followed by lolcat ASCII art. Why? Because yes, that's why. Take a moment and marvel at the fact that you just witnessed the birth of a naming convention. Obviously, this is seriously solid foundational material for a flagship framework.

So, if there's one thing I want my entire codebase to both functionally and philosophically depend on, there's nothing more mission-critical to the mathematic logic of programming than..... Microsoft's® English-Language Naming Conventions!

</sarcasm>
</griping>

<!-- resume enjoying all of MVC's amazing features, after eating any humble 开发者_开发知识库pie served up in the comments -->


My entire application depends on an arbitrarily-chosen name in an XML attribute.

This is called "coding by convention" or "convention over configuration" ... you pick a few things that need configuration, and then everything else just "falls into place". Like using razor and having _layout.cshtml in /views/shared. Or like using razor and having mySpecialController with ActionResult Index and /views/mySpecial/Index.cshtml ... those are just a way of letting the convention work for you.

Since forever, strongly-typed objects have been a foundation of object-oriented programming. Strongly-typed objects had their day in the sun, and now we're all girl-next-door over the anonymous "var".

var variables are just a shorthand to make things slightly more readable, the compiler still strongly and statically types things at compile time. Consider the difference here:

foreach (var c in Customers) { /* do stuff */ }
foreach (CustomerDataItem customerDataItem in Customers) { /* do stuff */ }

As you can see, the first one says "get a item c from Customers" and the second one says the same thing but good lord man I've already written two more lines of code while you're still typing the long one. Granted, with ReSharper that advantage disappears, however ...

For all we know, MVC4 might suddenly require that all names be preceded by exactly 4.7 spaces followed by lolcat ASCII art. Why? Because yes, that's why.

har.

How do the forefathers of object-oriented programming feel about our "advancement" of their art by adding a bunch of wishy-washy, do-sorta-whatever anonymous constructs while at the same time creating fragile dependencies on naming conventions?

Ok, so this was mostly just frustration, but I'll bite. The guys that started wanted simpler code (BASIC, COBOL look up what those mean) and so they want things to be easier and more math-y. That's where things are moving (LINQ is set math, and higher order calculus; also see F# and Python)

So they would LOVE what we're doing now. Getting away from procedural code (algebra) and moving into set-oriented logic (adv calculus). Also see Event Handlers ;-)


So .. having said all that: I've been in your shoes. I've asked those questions. I've studied at the feet of masters. I love where the languages are going.

In your next life, I want you to learn node.js. I want you to learn async evented processing, and I want you to understand how things don't rely on ANSI-C anymore. We've made a lot of progress in this industry, and things are looking up. Things are looking up every day. I love where we are, and I think it's the right thing for our industry.

Cheers, and HTH.


My answer: "because of the advancements in automated testing".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜