Skip to content

Conversation

@18thday
Copy link
Contributor

@18thday 18thday commented Dec 25, 2025

No description provided.


// Чтобы сложение выполнялось в int64_t, приводим a и b к этому типу
// static_cast<новый тип>(переменная)
return static_cast<int64_t>(a) + static_cast<int64_t>(b);
Copy link
Contributor Author

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') {
Copy link
Contributor Author

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; // текущий символ больше не пробел — выходим
}
Copy link
Contributor Author

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]);
Copy link
Contributor Author

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;
Copy link
Contributor Author

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);
Copy link
Contributor Author

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
Copy link
Contributor Author

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);
Copy link
Contributor Author

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;
}
Copy link
Contributor Author

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
Copy link
Contributor Author

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);
Copy link
Contributor Author

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)) {
Copy link
Contributor Author

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);
Copy link
Contributor Author

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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

некорректная реализация аналогично FindLastElement

Copy link
Contributor Author

@18thday 18thday left a 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants