[deleted]
Can you name any widely-used programming language(s) that has a short-circuit AND that returns on the first non-true result but not a short-circuit OR that returns on the first non-false result?
11–20 of 82 posts
[deleted]
Can you name any widely-used programming language(s) that has a short-circuit AND that returns on the first non-true result but not a short-circuit OR that returns on the first non-false result?
Alternative title: Why a CS degree is worthwhile even if you're a web developer.
If you want to get good at clarifying conditionals, take an electronics class and revel in the Karnaugh maps.
I transferred midway through my undergraduate degree, and was surprised to discover that Karnaugh maps weren't taught at my destination school - they are such an intuitive and straightforward mechanism for whittling down complex logic into its simplest form.
If you want to get good at clarifying conditionals, take an electronics class and revel in the Karnaugh maps.
Cool to see De Morgan's Laws used at a high level. But the real takeaway: rewrite your conditional until it makes sense.
Or conversely that it is better to write affirmative conditionals rather than negative conditionals. I always find reading the affirmative ones much easier, as I have always found working in positive logic easier than work with negative logic circuits.
if(a) {
if(b) {
if (c) {
// Do something.
}
}
}
Into: if(!a) {
} elseif(!b) {
} elseif(!c) {
} else {
// Do something.
}Earlier quoted context omitted.
Or conversely that it is better to write affirmative conditionals rather than negative conditionals. I always find reading the affirmative ones much easier, as I have always found working in positive logic easier than work with negative logic circuits.
Except where writing negative conditionals are clearer. For example turning: if(a) { if(b) { if (c) { // Do something. } } } Into: if(!a) { } elseif(!b) { } elseif(!c) { } else { // Do something. }
if (a && b && c) {
// Do something.
}As for the refactoring, that might be a good choice (I myself prefer positive boolean methods) but it's not a logic lesson.