Framework Design Guidelines 2nd edition
От: Сергей Тепляков США http://sergeyteplyakov.blogspot.com/
Дата: 26.06.09 14:05
Оценка: 116 (5)
Статья:
Krzysztof Cwalina, Brad Abrams. Framework Design Guidelines, 2nd edition
Автор(ы): Krzysztof Cwalina, Brad Abrams

Framework Design Guidelines, Second Edition, teaches developers the best practices for designing reusable libraries for the Microsoft .NET Framework. Expanded and updated for .NET 3.5, this book new edition focuses on the design issues that directly affect the programmability of a class library, specifically its publicly accessible APIs.


Авторы:
Сергей Тепляков

Аннотация:
Framework Design Guidelines, Second Edition, teaches developers the best practices for designing reusable libraries for the Microsoft .NET Framework. Expanded and updated for .NET 3.5, this book new edition focuses on the design issues that directly affect the programmability of a class library, specifically its publicly accessible APIs.
Re[2]: Framework Design Guidelines 2nd edition
От: SergeyT. США http://sergeyteplyakov.blogspot.com/
Дата: 29.06.09 14:29
Оценка: 22 (2)
Здравствуйте, _FRED_, Вы писали:

_FR>А не сложно рассказать про отличия от первого издания?


Ну, первое издание я не читал. Но сейчас нарыл содержание первого издания и сравнил его с содержанием второго издания. Вот что вышло.
Добавлены следующие разделы:
5.6 Extention Methods
8.4 DateTime and DateTimeOffset
8.8 Nullable<T>
9.2 AsyncPattern добавлены подразделы по EventBased Async Pattern
9.3 Dependency Properties
9.6 LINQ Support
9.11 XAML Readable Types

Содержание по ключевым пунктам осталось практически не изменным. Но книга выросла примерно на сотню страниц. Например, глава по исключениям увеличилась с 28 до 33 страниц. Т.е. либо издатель выбрал более крупный шрифт либо, что более вероятно, материал книги переработан и расширен.

После прочтения книги особенно воодушевляют беседы, подобные той, что происходят сейчас в соседней ветке здесь
Автор: jedi
Дата: 27.06.09
, т.к. глава по исключениям в этой книге особенно понравилась. Все же попытка защититься от любого исключения больше смахивает на параною, а не нормальный способ обработки ошибок.

Я ни в какой другой книге не встречал такого классного описания проблемы обработки ошибок. Вот, не поленился перебить кусок книги:

You should first decide whether the error condition represents a usage error or an execution error.
A usage error represents an incorrectly written program and is something that can be avoided by changing the code that calls your API. There is no reason to programmatically handle usage errors; instead the calling code should be changed. For example, if a routine gets into an error state when a null is passed as one of its arguments (an error condition usually represented by an ArgumentNullException), the calling code can be modified to ensure that null is never passed. In other words, usage errors can be fixed at compile-time, and the developer can ensure that they never occur at runtime.
An execution error is something that cannot be completely avoided by writing "better" code. For example, File.Open throws FileNotFoundException when it tries to open a file that does not exist. Even if the caller of the API checks whether the file exists before calling File.Open, the file can get deleted or corrupted between the call to File.Exists and the call to File.Open.
Execution errors need to be futher divided into two groups: program errors and system failures.
A program error is an execution error that can be handled programmatically. For example, if File.Open throws FileNotFoundException, the calling ode can catch the exception and handle it by creating a new file. This is in contrast to the usage error example described earlier where you whould never write code that first passes an argument to a method, catches the NullArgumentException, and in the handler calls the method with a non-null argument.
A system failure is an execution error that cannot be handled programmatically. For example, you really cannot handle an out-of-memory exception resulting from the Just-in-Time (JIT) compiler running out of memory.

Re[5]: Framework Design Guidelines 2nd edition
От: matumba  
Дата: 14.07.09 11:57
Оценка: 20 (2)
Здравствуйте, Vladek, Вы писали:

V>Откуда?


Где-то в интернете 4ebooks.org/2009/06/03/framework-design-guidelines-conventions-idioms-and-patterns-for-reusable-net-libraries-2nd-edition.html
Re[3]: Framework Design Guidelines 2nd edition
От: FlevelEx Россия  
Дата: 09.08.09 00:03
Оценка: +2
Здравствуйте, SergeyT., Вы писали:

ST>Только судя по качеству книг, изданных издательством Вильямс в последнее время, не известно, это хорошая новость или нет


Судя по переводу названия, уже известно

«Принципы разработки инфраструктуры проектирования: соглашения, идиомы и шаблоны для повторного использования библиотек .NET»

Re[4]: Framework Design Guidelines 2nd edition
От: SergeyT. США http://sergeyteplyakov.blogspot.com/
Дата: 29.06.09 16:43
Оценка: 64 (1)
Здравствуйте, jedi, Вы писали:

J>Очевидно, что здесь идет речь о ExecutionEngineException (с сообщением "out of memory"), а не об OutOfMemoryException. JIT compiler не должен бросать OutOfMemoryException, если он это делает, это мега-глупость.


At one end of the spectrum, an OutOfMemoryException could be the result of a failure to obtain 12 bytes for implicitly autoboxing, or a failure to JIT some code that is required for critical backout. These cases are catastrophic failures and ideally would result in termination of the process. At the other end of the spectrum, an OutOfMemoryException could be the result of a thread asking for a 1 GB byte array. The fact that we failed this allocation attempt has no impact on the consistency and viability of the rest of the process.
The sad fact is that CRL 2.0 cannot distinguish among any points on this spectrum. In most managed processes, all OutOfMemoryExceptions are considered equivalent and they all result in a managed exception being propagated up the thread. However, you cannot depend on your backout code being executed, because we might fail to JIT some of your backout methods, or we might fail to execute static constructors required for backout.
Also, keep in mind that all other exceptions can get folded into an OutOfMemoryException if there isn't enough memory to instantiate those other exception objects. Also, we will give you a unique OutOfMemoryException with its own stack trace if we can. But if we are tight enough on memory, you will share an uninteresting global instance with everyone else in the process.
My best recommendation is that you treat OutOfMemoryException like any other application exception. You make your best attempts to handle it and ramain consistent. In the future, I hope the CLR can do a better job of distinguishing catastrophic OOM from the 1 GB byte array case. If so, we might provoke termination of the process for the catastrophic cases, leaving the application to deal with the less risky ones. By threating all OOM cases as the less risky ones, you are preparing for that day.
Christopher Brumme


P.S. Это все из той же Framework Design Guidelines.
Re[5]: Framework Design Guidelines 2nd edition
От: MozgC США http://nightcoder.livejournal.com
Дата: 13.07.09 14:25
Оценка: 12 (1)
Здравствуйте, Vladek, Вы писали:

MC>>Скачали, будем читать

V>Откуда?

Ищите в гугле и в торрентах. Тут модераторы уже удалили ссылку.
Re: Framework Design Guidelines 2nd edition
От: existen  
Дата: 08.08.09 05:26
Оценка: 10 (1)
Эта книга выйдет на русском языке в издательстве Вильямс в конце этого года

http://shtonda.blogspot.com/2008/11/2008-net-platform-windows.html#comments
Re[6]: Framework Design Guidelines 2nd edition
От: Sinclair Россия https://github.com/evilguest/
Дата: 30.06.09 07:19
Оценка: +1
Здравствуйте, jedi, Вы писали:

J>Один-в-один то, что я написал в той ветке. Пытаемся обработать, не получилось — извините.

Не совсем. Брюмме советует обрабатывать "лёгкие" случаи, считая, что катастрофических вовсе не бывает.
То есть вот так писать — нормально:
try
{
  buffer = new byte[1024*1024*1024];
} catch (OutOfMemoryException)
{
  // not enough address space to get a large chunk; fallback to the iterative algorithm:
    buffer = new byte[1024*1024];
    useSlowHashing = true;
}

А вот так — глупость:
try
{
  s = new Socket();
}
catch(OutOfMemoryException)
{
  // execution engine failed to process the static or instance constructor call. 
    // There is not much we can do, but still I'll try to use a different approach
    s = Statics.SharedSocketForSlowCommunication;
}
... << RSDN@Home 1.2.0 alpha rev. 677>>
Уйдемте отсюда, Румата! У вас слишком богатые погреба.
Re[2]: Framework Design Guidelines 2nd edition
От: SergeyT. США http://sergeyteplyakov.blogspot.com/
Дата: 08.08.09 20:45
Оценка: :)
Здравствуйте, existen, Вы писали:

E>Эта книга выйдет на русском языке в издательстве Вильямс в конце этого года


Только судя по качеству книг, изданных издательством Вильямс в последнее время, не известно, это хорошая новость или нет
Re: Framework Design Guidelines 2nd edition
От: _FRED_ Черногория
Дата: 29.06.09 13:37
Оценка:
Здравствуйте, Сергей Тепляков, Вы писали:

СТ>Статья:

СТ>Krzysztof Cwalina, Brad Abrams. Framework Design Guidelines, 2nd edition
Автор(ы): Krzysztof Cwalina, Brad Abrams

Framework Design Guidelines, Second Edition, teaches developers the best practices for designing reusable libraries for the Microsoft .NET Framework. Expanded and updated for .NET 3.5, this book new edition focuses on the design issues that directly affect the programmability of a class library, specifically its publicly accessible APIs.


А не сложно рассказать про отличия от первого издания?
Help will always be given at Hogwarts to those who ask for it.
Re[3]: Framework Design Guidelines 2nd edition
От: MozgC США http://nightcoder.livejournal.com
Дата: 29.06.09 14:35
Оценка:
Скачали, будем читать
Re[3]: Framework Design Guidelines 2nd edition
От: jedi Мухосранск  
Дата: 29.06.09 15:41
Оценка:
Здравствуйте, SergeyT., Вы писали:

ST>A system failure is an execution error that cannot be handled programmatically. For example, you really cannot handle an out-of-memory exception resulting from the Just-in-Time (JIT) compiler running out of memory.


Очевидно, что здесь идет речь о ExecutionEngineException (с сообщением "out of memory"), а не об OutOfMemoryException. JIT compiler не должен бросать OutOfMemoryException, если он это делает, это мега-глупость.
... << RSDN@Home 1.2.0 alpha 4 rev. 1228>>
Re[5]: Framework Design Guidelines 2nd edition
От: jedi Мухосранск  
Дата: 29.06.09 16:56
Оценка:
Здравствуйте, SergeyT., Вы писали:

ST>The sad fact is that CRL 2.0 cannot distinguish among any points on this spectrum.


Ну таки сделали мега-глупость разработчики CLR, даже умная книжка это подтверждает

ST>My best recommendation is that you treat OutOfMemoryException like any other application exception. You make your best attempts to handle it and ramain consistent. In the future, I hope the CLR can do a better job of distinguishing catastrophic OOM from the 1 GB byte array case. If so, we might provoke termination of the process for the catastrophic cases, leaving the application to deal with the less risky ones. By threating all OOM cases as the less risky ones, you are preparing for that day.

ST>Christopher Brumme[/q]

Один-в-один то, что я написал в той ветке. Пытаемся обработать, не получилось — извините.

ST>P.S. Это все из той же Framework Design Guidelines.


Спасибо, уже читаю
... << RSDN@Home 1.2.0 alpha 4 rev. 1228>>
Re[4]: Framework Design Guidelines 2nd edition
От: Аноним  
Дата: 11.07.09 09:32
Оценка:
Здравствуйте, MozgC, Вы писали:

MC>Скачали, будем читать


Откуда качаем?
Re[4]: Framework Design Guidelines 2nd edition
От: Vladek Россия Github
Дата: 13.07.09 14:13
Оценка:
Здравствуйте, MozgC, Вы писали:

MC>Скачали, будем читать


Откуда?
Developers, developers, developers, developers, developers, developers, developers... © Steve Ballmer
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.