How do you deal with new C # features so that they do not lead to poorly written code?

Several functions were introduced in C # 3.0, which made me difficult, such as object initializers, extension methods, and implicitly typed variables. Now in C # 4.0 with things like a dynamic keyword, I'm getting even more worried.

I know that each of these CAN functions will be used in appropriate ways BUT , in my opinion, they make it easier for developers to make bad coding decisions and therefore write worse code. It seems to me that Microsoft is trying to gain market share by making coding simple and undemanding. Personally, I prefer a language that is strict and makes more demands on my coding standards and forces me to structure things in an OOP way.

Here are some examples of my problems for the functions mentioned above:

Object designers can execute important logic that is not exposed to the consumer. This is under the control of the developer of the object. Object initializers take this control and allow the consumer to make decisions about which fields will be initialized.

EDIT: I did not appreciate that you can mix the constructor and the initializer (my bad one), but this is starting to look messy for me, and so I'm still not sure if this is a step forward.

Providing developers with extensions of built-in types using extension methods allows everyone to start adding their favorite pet methods to the string class, which can lead to a confusing set of options or require more protection for coding standards from weeds from them.

, .

?

+5
9

, , .

, :

Person p1 = new Person("Fred");
p1.Age = 30;
p1.Height = 123;

Person p2 = new Person("Fred")
{
    Age = 30;
    Height = 123;
};

, 'var'. , , , , :

var p1 = new Person("Fred");
Person p2 = GetPerson();

, . .

- , .NET , IEnumerable, ICollection String. String.IsNullOrEmpty() , .

, , , : .

+5

# 3.0, , . , , , , , . .

, - . , , , , . .

VS 2008 , .NET ( "" > "" ). .NET 2.0, - .NET 3.5. , , .

, , vars . # . - var . , int Person . , ; , var; .

+2

, :

, .

, . . , - , ,

VB . [++] .

, , , . - . foreach , , . .

+2

, - . , .

"var" . , , , , , "".

. , .

+1

- . , - .

" " - , , . - , , . .

Linq . , . , , .

, , , , .

0

var , . . , .

0

, Microsoft , . , LINQ. , : 1) , 2) , .

, , .:)

0

, "var" intializers , . , .

, , , . , , . , , # . , .

0

?

. .

-3
source

All Articles