Форум
C/C++
Тема
Как правильно задавать вопросы
B
I
abc
U
X
3
X
3
H1
H2
H3
H4
H5
H6
Asm
C/C++
C#
Erlang
Haskell
IDL
Java
Lisp
MSIL
Nemerle
ObjC
OCaml
Pascal
Perl
PHP
Prolog
Python
Ruby
Rust
SQL
VB
Здравствуйте, greenpci, Вы писали: G>Здравствуйте, Abyx, Вы писали: A>>>>using namespace std; это плохо G>>>я использовал его только в cpp файлах. Зметь ни во одном h файле его нет. G>>>Использовать using namespace нельзя только в headers. В cpp его даже рекомендуется использовать. Ты с этим не согласен? A>>кем рекомендуется o_O? A>>о using namespace std; хорошо написано тут - http://stackoverflow.com/a/1453605/343443 G>Та же книжка: G>[q] G>[b]Coding Standards 101 Rules Sutter and Alexandresku[/b] G>[b]59. Don't write namespace usings in a header file or before an #include[/b] G>... G>In short: You can and should use namespace using declarations and directives liberally in your implementation files after #include directives and feel good about it. [b]Despite repeated assertions to the contrary[/b], namespace using declarations and directives are not evil and they do not defeat the purpose of namespaces. Rather, they are what make namespaces usable. G>In short: You can and should use namespace using declarations and directives liberally in your implementation files after #include directives and feel good about it. Despite repeated assertions to the contrary, namespace using declarations and directives are not evil and they do not defeat the purpose of namespaces. Rather, they are what make namespaces usable. G>Namespaces deliver the powerful advantage of unambiguous name management. Most of the time, different programmers don't choose the very same name for a type or function; but on the off chance that they do so, and that the two pieces of code end up being used together, having those names in separate namespaces prevents them from colliding. (We don't, after all, want the global namespace pollution experienced by default in languages like C.) In the rare case when there is such an actual ambiguity, calling code can explicitly qualify a name to say which one it wants. But the vast majority of the time there is no ambiguity: And that is why namespace using declarations and directives are what make namespaces usable, because they greatly reduce code clutter by freeing you from having to tediously qualify every name every time (which would be onerous, and frankly people just won't put up with it) and still letting you qualify names only in those rare cases when you need to resolve an actual ambiguity. G>[/q] G>Еще в далеком 2004 году, Александреску знал о том, что Abyx и sbi на stackoverflow будут убеждать меня, что namespace in cpp after headers это зло. Поэтому он добавил "[b]Despite repeated assertions to the contrary[/b]". Может это был Сатер. У книжки два автора. A>>>>используйте #pragma once G>>>Обучен по старым книжкам. Может какой компилятор вдруг не поймет эту прагму. Я хотел сделать максимально портабл. A>>все основные компиляторы понимают. а вот <windows.h> - уже не все. G>Про виндовс понятно. Использовал его только для вывода OutputDebugString(); G>Про прагму приму на вооружение. G>@Evgeny.Panasyuk G>Я нарушил правило G>[q] G>[b]Coding Standards 101 Rules Sutter and Alexandresku[/b] G>[b]44. Prefer writing nonmember nonfriend functions [/b] G>Avoid membership fees: Where possible, prefer making functions nonmember nonfriends. G>[/q] G>мне оно сразу понравилось после си шарпа. Надоел уже этот каплинг и блоат с классами. По поводу статических методов. Они там тоже не очень в почете из-за юнит тестов, моков и прочего. Если твой статический метод использует другой клас, то по законам ТиДиДи, ты должен создать фейк. А это делается с помощью инхеританс и т.д. Так что в мире Си шарпа мои коллеги пихают все в классы кода надо и не надо. Плюс там нету замечательной изоляции cpp файлов.
Теги:
Введите теги разделенные пробелами. Обрамляйте в кавычки словосочетания с пробелами внутри, например:
"Visual Studio" .NET
Имя, пароль:
Загрузить
Нравится наш сайт?
Помогите его развитию!
Отключить смайлики
Получать ответы по e-mail
Проверить правописание
Параметры проверки …