-
Notifications
You must be signed in to change notification settings - Fork 33
Уразаев Руслан #23
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?
Уразаев Руслан #23
Conversation
| int64_t Addition(int a, int b) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| } | ||
| return (int64_t)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.
c-style cast не уместен, static_cast
| int count_repeat = 1; | ||
|
|
||
| std::string tmp; | ||
|
|
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.
зачем все эти пустые строки?
| if (array[i] == prev_ch) { | ||
| if (array[i] != ' ') { | ||
| ++count_repeat; | ||
| } |
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, неудобно листать большой блок кода ниже
| ++count_repeat; | ||
| } | ||
| } | ||
| else { |
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.
и else убрать поскольку он станет лишним и уйдет уровень вложенности
| } | ||
| } | ||
| else { | ||
| 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.
отсутствют пробелы вокруг бинарных операторов
| } | ||
| } | ||
| else { | ||
| double x = (double)(-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.
снова C-style каст
| if (a == 0) { | ||
| if (b == 0) { | ||
| if (c == 0) { | ||
| std::cout << "infinite solutions"; |
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.
В данном случае излишняя вложенность, поскольку это особые случаи корректнее будет делать короткие ветки или ветки с return
| } | ||
| else if (D > 0) { | ||
| double x1 = (-b - std::sqrt(D)) / (2.0*a); | ||
| double x2 = (-b + std::sqrt(D)) / (2.0*a); |
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.
нет пробелов вокруг бинарных операторов
| throw std::runtime_error{"Not implemented"}; | ||
| } | ||
| if (values == nullptr || !size) | ||
| return 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.
местами используется с { местами без
| return end; | ||
| } | ||
|
|
||
| for (const int *p = end - 1; p != begin - 1; p--) { |
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.
декремент должен быть префиксным и указатель у типа, следуем сигнатуре функции
| return sum; | ||
| } | ||
|
|
||
| for (size_t i = 0; i < length; i++) { |
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.
инкремент должен быть префиксным
| std::memset(digits, '0', sizeof(digits)); | ||
|
|
||
| for (size_t i = 0; i < 4; ++i) { | ||
| uint8_t byte = *(reinterpret_cast<uint8_t*>(&value) + i); |
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.
на каждом шаге делается каст, хотя можно было вынести это выше
| uint8_t byte = *(reinterpret_cast<uint8_t*>(&value) + i); | ||
|
|
||
| for (size_t j = 0; j < 2; ++j) { | ||
| uint8_t code = (byte & (0b1111 << (j * 4))) >> (j * 4); |
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.
сложно к восприятию
|
|
||
| void PrintMemory(double /* write arguments here */) { | ||
| throw std::runtime_error{"Not implemented"}; | ||
| void PrintMemory(double value, bool is_big_endian = false) { |
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 int вызывать функцию которая выполняет действия над данным указателем без дублирования кода
| for (int i = 15; i >= 0; --i) { | ||
| std::cout << digits[i]; | ||
| } | ||
|
|
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.
зачем этот миллиард пустых строк? пустые строки обычно используются для выделения логики, логику получения бит в digits и логику вывода, но не каждую строчку
| throw std::runtime_error{"Not implemented"}; | ||
| } | ||
| if (begin >= end) { | ||
| return nullptr; |
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.
возвращается nullptr можно объединить условия, так как это все некорректные указатели
| if (*p == prev_char) { | ||
| ++prev_seq_len; | ||
| } | ||
| else { |
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.
лучше else убрать и воспользовать в условие выше continue
|
|
||
| count = max_seq_len; | ||
|
|
||
| return const_cast<char*>(max_seq); |
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 должна возвращать const в данном случае это UB если пришел изначальный const, поэтому в данном случае должно быть две версии функции с const и не const и уже в неконстантной версии можно вызывать константную и снимать константность с помощью каста, это корректное было бы использование
| } | ||
|
|
||
| data.sd = std::sqrt(data.sd / values.size()); | ||
|
|
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.
неэффективное решение в два прохода
|
|
||
| bool operator<(const StudentInfo& lhs, const StudentInfo& rhs) { | ||
| return std::tie(rhs.mark, lhs.score, rhs.course, lhs.birth_date) < std::tie(lhs.mark, rhs.score, lhs.course, rhs.birth_date); | ||
| } No newline at end of file |
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 аргумента, можно и друг под другом для удоства, строка уже слишком длинная
| return; | ||
| } | ||
|
|
||
| std::vector<int> filtered; |
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.
это излишне
| } | ||
| } | ||
|
|
||
| vec = filtered; |
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.
это не эффективноерешение, если у нас много значений и все подходят, вместо просто проверки мы получаем перевыделение памяти, и если будет не int, а более тяжелый тип тоже долго
| @@ -0,0 +1,27 @@ | |||
| #include <vector> | |||
|
|
|||
| auto FindAll(const std::vector<int>& vec, bool (*f)(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.
auto в данном случае излишне, так как возвращаемый тип не длинный и по типу было бы понятно что возвращаются позиции, а сейчас ничего не понятно
| if (f(vec[i])) { | ||
| res.push_back(i); | ||
| } | ||
| } |
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.
Два прохода, а если передана тяжелая функция предикат, не эффективно
| } | ||
| } | ||
|
|
||
| return std::make_pair(min, max); |
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.
примерно 3 лишних пустых строки
|
|
||
| auto MinMax(const std::vector<int>& vec) { | ||
| if (vec.empty()) { | ||
| return std::make_pair(vec.end(),vec.end()); |
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.
нет пробела после запятой
| res.push_back(vec[i + 1]); | ||
| } | ||
| } | ||
|
|
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.
два прохода не нужны
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.
- не уместно используется C-style каст
- местами используется постфиксный декремент инкремент вместо префиксного
- разный стиль кода местами
- неуместные лишние пустые строки
- дублирование кода
- часто неэффективные решения
- const_cast UB
No description provided.