开发者

Is it possible to further embed best practices into programming languages?

For example, in c# access modifiers implement information hiding by default (by giving classes and fields the most restrictive access possible by default).

In ASP.NET you have app_code and app_data as libraries "built-in" in your web site.

ASP.NET MVC takes it another step and "makes" you use MVC.

I don't know how it is in different languages.

Do you think concepts like single responsibility, strong cohesion, separation of concerns etc. can be further embedded into programming languages and technologies?

Edit: Maybe I should have asked- "Can you think of a way for progarmming languages and frameworks to embed these concepts?"

I'm asking for two reas开发者_C百科ons - first is curiosity. And second is that I think answers to this question can make "rules of thumb" about how to implement these concepts.

Thank you.


I believe that the answer is no, because good design and engineering decisions cannot generally be replaced by pure technical means.

It's more difficult, however, to tell to what extent technology can nudge the programmer towards, promote, or even enforce good design. I suspect the answer here depends on which "best practice" you're looking at. There are best practices that can be enforced by language rules better than others:

Take, for example, the common notion that composition and aggregation should be favoured over inheritance. A OO language could enforce this in various ways, ranging from:

  • prohibiting inheritance completely;

  • prohibiting class hierarchies of a certain depth (e.g. you cannot derive from a class that's already a derived class, thereby only allowing inheritance one level deep);

  • prohibiting inheritance while still allowing implementation of interfaces.

(In case you're wondering about the above list, I haven't gone mad: This list is hypothetical, and I'm not suggesting that any of these measures should actually be taken. Each of these options has its obvious disadvantages.)

Other common best practices — in fact I suspect most useful best practices — such as DRY (don't repeat yourself), SRP (single responsibility principle), etc. might not be enforcable by the language.


Do you think concepts like single responsibility, strong cohesion, separation of concerns etc. can be further embedded into programming languages and technologies?

No. Only a human mind can work this out.


Is as I always say: "The language can only show you the path, it should be your choice if you follow it"

This is where you skills as a programmer can make a difference.


Do you think concepts like single responsibility, strong cohesion, separation of concerns etc. can be further embedded into programming languages and technologies?

The Eiffel programming language is a good example of a programming language that was designed specificially around these more general concepts.


I remember starting a job by sharing an office with a consultant. I remember him calling a friend with with questions like "Can you explain how Windows creates a process? Here it says that it also create a thread, how does that make it different from UNIX?" He liked words like "best practices".

Better to stay away from languages that enforce them.


Encourage -> yes.

Force it-> no.

I've seen a couple very awful sources in RoR and asp.net mvc.


Besides helping you getting your job done it's a job of almost every framework out there. Check what Ruby on Rails, Django, Java EE do and you'll see exactly what I'm trying to say.

You may find it implemented more frequently in frameworks written in dynamic languages since they allow easy extension of the language by writing DLSs.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜