4 ms·
I completely agree. It's _vital_ to know what a, b, doSomething and doSomethingElse actually stand for, and what is the context. This is not a technical probl
by MrPatan 11y ago
I completely agree.
It's _vital_ to know what a, b, doSomething and doSomethingElse actually stand for, and what is the context. This is not a technical problem, it's a people problem (like almost all problems).
Take this, for example:
if (userLoggedIn) {
setCookie();
if (itsANiceDay) {
tellUSerToGoOutAndPlay();
}
}
And this:
if (itsSunny && itsCold) {
putOnSunglasses();
putOnCoat();
} else if (itsSunny && !itsCold) {
putOnSunglasses();
}
They both kind of make sense! Now let's see the other way around:
if (userLoggedIn && itsANiceDay) {
setCookie();
tellUSerToGoOutAndPlay();
} else if (userLoggedIn && !itsANiceDay) {
setCookie();
}
This one is just silly. We are mixing logic about two completely different things. Nobody would do that (many people would do that, I know. Too many)
if (itsSunny) {
putOnSunglasses();
if (itsCold) {
putOnCoat();
}
}
This one seems ok. Until you wonder what happens if it rains and/or it's windy. Then you'll refactor it to a "switch/case" for clarity.
And it's all about the domain specific content! You cannot reason only about the syntax tree in isolation and come to a meaningful conclusion!
- jessaustin 11y agoThe problem with these examples is that putOnCoat() should not depend in any way on itsSunny, so there should just be two separate if blocks. We should be discussing a scenario in which one condition is a subset of the other.
- JustSomeNobody 11y agoWhy not? I've been on Rainier when it's cold and sunny.
- Jtsummers 11y agoBut it's an independent test. You'll put on your coat when it's cold, whether it's sunny or not.
- denis1 11y agoI you didn't understand what the GP said. You can certainly have a day when it is both sunny and cold, but the checks would look like this: if(isSunny){ putOnGlasses(); } if(isCold) { putOnCoat(); }
- Retric 11y agoDepends on context, in a game you might only send someone outside if it's sunny. So if it's !sunny your staying inside and you don't need a Coat.
- deleted 11y ago[deleted]
- deleted 11y ago[deleted]