Skip to content

Гущин Андрей#25

Open
18thday wants to merge 60 commits intopsds-cpp:mainfrom
GushchinAndrei1:main
Open

Гущин Андрей#25
18thday wants to merge 60 commits intopsds-cpp:mainfrom
GushchinAndrei1:main

Conversation

@18thday
Copy link
Contributor

@18thday 18thday commented Dec 25, 2025

No description provided.

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"};
} No newline at end of file

// в случае пустовго массива возращаем 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