-
Notifications
You must be signed in to change notification settings - Fork 33
Гущин Андрей #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Гущин Андрей #25
Conversation
…5 into development
…5 into development
Added a newline at the end of the file for consistency.
|
|
||
| // Чтобы сложение выполнялось в int64_t, приводим a и b к этому типу | ||
| // static_cast<новый тип>(переменная) | ||
| return static_cast<int64_t>(a) + static_cast<int64_t>(b); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
лишний каст, достаточно явно кастовать только один операнд, второй будет неявно преобразован, необходимо использовать данную возможность языка и не писать лишний код
|
|
||
| // идем по массиву пока не выйдем за него | ||
| // и пока текущий символ не конец строки, конец строки по условию это '\0' | ||
| while (read < size && array[read] != '\0') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
много лишних комментариев, невозможно читать код
| unsigned char c = static_cast<unsigned char>(array[read]); | ||
| if (!std::isspace(c)) { | ||
| break; // текущий символ больше не пробел — выходим | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
проблемы с отступами
| while (read < size && array[read] != '\0') { | ||
| // в cppreference указано, что isspace должно принимать безнаковый символ, | ||
| // поэтому преобразуем текущий символ из char в unsigned char | ||
| unsigned char uc = static_cast<unsigned char>(array[read]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
данное преобразование произойдет неявно, это лишний каст
| double C = static_cast<double>(c); | ||
|
|
||
| // Дискриминант | ||
| double D = B * B - 4 * A * C; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
модет тогда стоит назвать discriminant переменную?
| // 4) четвертый случай: a неравно 0, то есть уже само квадартное уравнение | ||
| double A = static_cast<double>(a); | ||
| double B = static_cast<double>(b); | ||
| double C = static_cast<double>(c); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
это лишние переменные, достаточно было бы 4.0 в дискриминанте или каст одного из значений у слагаемых по месту использования
|
|
||
| // третий случай: a == 0, b != 0 → b*x + c = 0 | ||
| if (a == 0) { | ||
| double x = -static_cast<double>(c) / static_cast<double>(b); // x = -c / b |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
лишний каст
| double root2 = (-B + sqrtD) / (2 * A); | ||
|
|
||
| double x1 = static_cast<double>(root1); | ||
| double x2 = static_cast<double>(root2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double переменные кастуем к double. это сильно
| } | ||
| if (x2 == -0.0) { | ||
| x2 = 0.0; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
в C++ 0.0 строго определен, что за -0.0 ?
| throw std::runtime_error{"Not implemented"}; | ||
| } | ||
|
|
||
| // в случае пустовго массива возращаем 0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
программисты умеют читать код ниже
| continue; // пропускаем пустую функцию | ||
| } | ||
| // вызываем i-ю функцию с числами a и b, кладем в v | ||
| double v = mathOperations[i](a, b); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
что за v ? удобнее вызывать функцию ниже, непосредственно в месте использования
| @@ -1,6 +1,29 @@ | |||
| #include <stdexcept> | |||
| // для случая (nullptr, nullptr) | |||
| int* FindLastElement(std::nullptr_t, std::nullptr_t, bool (*)(int)) { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
зачем, если функция ниже дублирует данную возможность
| // Перегрузка для const int*. | ||
| // Снимаем const, чтобы переиспользовать логику из версии для int*. | ||
| const int* FindLastElement(const int* begin, const int* end, bool (*predicate)(int)) { | ||
| return FindLastElement(const_cast<int*>(begin), const_cast<int*>(end), predicate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
это UB, некорректно снимать константность с изначально константного объекта, корректно можно было сделать наоборот, из функции которая принимает изменяемые объекты вызвать константную версию и снять константность с результата
| // поэтому здесь будем использовать его, | ||
| // временно снимаем const, чтобы вызвать существующую логику | ||
| const char* FindLongestSubsequence(const char* begin, const char* end, size_t& count) { | ||
| char* result = FindLongestSubsequence(const_cast<char*>(begin), const_cast<char*>(end), count); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
некорректная реализация аналогично FindLastElement
18thday
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@GushchinAndrei1 общие замечания к коду
- миллион лишних static_cast, даже double переменные кастуются к double явно
- комментариев столько, что невозможно читать код
- UB const_cast
No description provided.