Re[15]: FileIOPermission, доступ к файлам в каталоге
От: Lloyd Россия  
Дата: 22.10.08 09:02
Оценка: 1 (1) +1
Здравствуйте, _FRED_, Вы писали:

_FR>>…Посмотри сам…


_FR>Кстати, пост в тему: When to use Type Inference


* It does not reduce type safety. This doesn't allow for any late binding, type unsafe functions or the like. It simply lets the compiler chose the type for you.


Указание типа тоже "does not reduce type safety"

* It will actually increase type safety in your code. The best example of this is the foreach statement on non-generic IEnumerable instances. These foreach statements are all technically unsafe because the compiler must do a cast of the Current member under the hood. This declaration looks no different than the type safe generic version of IEnumerable. Using var will force you to write an explicit cast.

foreach (SomeType cur in col)

foreach ( var cur in col.Cast<SomeType>())


И чем это лучше?

* Maintains the principles of DRY. This is mostly true for cases where you have an explicit constructor on the RHS.


С этим согласен. Если справа есть указание имени типа, то DRY. Если нет, то repeat-а нет, а следовательно аргумент в этом случае не применим и надо указывать тип.

* For some types, this is a requirement in order to use the type (anonymous types for instance). I'm a big fan of consistency and since I must have some instances use type inference, I'd like to use them everywhere.


С этим не поспоришь.

* Makes refactoring easier. I re-factor, a lot. I constantly split up or rename types. Often in such a way that refactoring tools don't fixup all of the problems. With var declarations I don't have to worry because they just properly infer their new type and happily chug along. For explicit type cases I have to manually update all of the type names.



Порождает неконтролируемые изменения. Скорее недостаток, чем достоинство.

* Less typing with no loss of functionality.


Несмешно. Особенно если использовать resharper.

Вывод: приведенные аргументы скорее не в пользу пункта 1 (Whenever it's possible), а за пункт 2 (Only when it's absolutely clear what the type is). Т.е. собственно за то, что я и предлагал.
... << RSDN@Home 1.2.0 alpha 4 rev. 1111>>
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.