Похожие чаты

Hi, i wrote this line of code, but i'm not

sure how to refactor it to make it more readable and/or concise

if (((curveType == CurveType::ENVELOPE || curveType == CurveType::LFO) && points.size() >= 1) || (curveType == CurveType::GRAPH && points.size() >= 2)) {

is there a way to do the same boolean operations but a bit nicer to read?

6 ответов

5 просмотров
artemetra 🇺🇦-[less active] Автор вопроса

no, i only have 2 cases - either the configuration i have is valid or it isn't and that code validates it

bool isEnvelope = (curveType == Envelope) bool isLFO = (curveType == LFO) bool has1Point = (points.size >=1) bool isGraph = (curveType == Graph) bool has2Points = (points.size >= 2) IF ( (isEnvelope || LFO) && has1Point) || (isGraph && has2Points) ) { //... }

artemetra 🇺🇦-[less active] Автор вопроса
Mihai
bool isEnvelope = (curveType == Envelope) bool isL...

not sure if it's "the c++ way",, from one perspective it's readability but from the other it's redundant code, i most likely won't use those statements again

Depends on what you want to do, and how much of it. This could be more concise, especially if you have more options in the enum: bool hasEnoughPoints(CurveType ct, int pNum) { switch (ct) { case CurveType::ENVELOPE: case CurveType::LFO: return pNum >= 2; case CurveType::GRAPH: return pNum >= 1; default: return false; } }

artemetra 🇺🇦-[less active] Автор вопроса
Avihay B
Depends on what you want to do, and how much of it...

thank you! i currently don't have more options in the enum, and it's highly likely i won't have any more, but i'll take your suggestion into consideration

Похожие вопросы

Обсуждают сегодня

Здравствуйте! Есть вопросы по ПК: 1.1. Безопасно ли запускать программы, которым я не доверяю, в виртуальной машине под KVM+qemu? (x86_64) 1.2. То же самое при использовании ...
Pavel
5
Hi everyone! I have a two-folded message to share today. First: updates and news, as we are being asked for those. We still want to go like we did the last 6 years: we w...
Marten | Unibright.io
31
У меня вопрос, а какой уровень оптимизации ставить при сборке на i5 4 ядра 16G ddr3 ОЗУ и видюха Geforce GTX 970?
Sir Jiga
18
Guys, what’s the most expensive part of your budget for your business/startup/app/website?
Ice Kream
18
Скажите, можно ли как-то "переместить" динамический массив из одной переменной в другую? Скажем, переместить из TList<> в TArray<>. Именно переместить, а не скопировать. Если ...
Eugene Krasnikov (ᴊɪɴ x)
37
Happy Friday and happy CartesiWeekly! This week on the list: 🪲 Bug Buster Update 🎥 Erick de Moura’s interview with Ornella from Web3TV 👽 Thriving Cartesi alien 🇧🇷 SBRC hackat...
Nida | Cartesi - Never DM first or ask for funds!
1
Oh.... Admins at the main TG is already muted me. How many months Sir you muted me? Or forever if you are here @Janevietani @JohnnySonic
Charles Dar
28
комрады, че-та лыжы не едут var tmpFont: TFont; begin tmpFont:= TFont.Create; try case rgFontColor.ItemIndex of 0: tmpFont.Color:= clWindowText; 1: tmpFo...
Ed Doc
34
Вот еще криповенькая штука. uMain.pas(517,3) Warning: Case statement does not handle all possible cases И ЧО? 😂
Александр (Rouse_) Багель
20
Интересно, нет ли какого-то способа получить из dll не адрес самой метки, а адрес со смещением?
The Bird of Hermes
54
Карта сайта