-
Notifications
You must be signed in to change notification settings - Fork 5
[F]unctions
Our main problem seems to be that we are improving methods, but we are confused about the goals.
Functions should have a small number of arguments. No argument is best, followed by one, two, and three. More than three is very questionable and should be avoided with prejudice.
[F1]: Слишком много аргументов
Функции должны иметь небольшое количество аргументов. Лучше всего, когда аргументов вообще нет; далее следуют функции с одним, двумя и тремя аргументами. Функции с четырьмя и более аргументами весьма сомнительны; старайтесь не использовать их в своих программах.
Output arguments are counterintuitive. Readers expect arguments to be inputs, not outputs. If your function must change the state of something, have it change the state of the object it is called on.
[F2]: Выходные аргументы
Выходные аргументы противоестественны. Читатель кода ожидает, что аргументы используются для передачи входной, а не выходной информации. Если ваша функция должна изменять чье-либо состояние, пусть она изменяет состояние объекта, для которого она вызывалась.
Boolean arguments loudly declare that the function does more than one thing. They are confusing and should be eliminated.
[F3]: Флаги в аргументах
Логические аргументы явно указывают на то, что функция выполняет более одной операции. Они сильно запутывают код. Исключите их из своих программ.
Methods that are never called should be discarded. Keeping dead code around is wasteful. Don’t be afraid to delete the function. Remember, your source code control system still remembers it.
[F4]: Мертвые функции
Если метод ни разу не вызывается в программе, то его следует удалить. Хранить «мертвый код» расточительно. Не бойтесь удалять мертвые функции. Не забудьте, что система управления исходным кодом позволит восстановить их в случае необходимости.
This wiki document contains a lot of information, please take your time and read these carefully.
If you run into any trouble, you may start by understanding how this works.
Be sure to read the CONTRIBUTING guidelines before reporting a new issue or open a pull request.
If you have any questions about the Heuristics for "Clear Code" usage or want to share some information with the our community, please go to one of the following places: