Why would a language NOT use Short-circuit evaluation?

Reasons NOT to use short-circuit evaluation: Because it will behave differently and produce different results if your functions, property Gets or operator methods have side-effects. And this may conflict with: A) Language Standards, B) previous versions of your language, or C) the default assumptions of your languages typical users. These are the reasons that VB … Read more

Fastest way of finding the middle value of a triple?

There’s an answer here using min/max and no branches (https://stackoverflow.com/a/14676309/2233603). Actually 4 min/max operations are enough to find the median, there’s no need for xor’s: median = max(min(a,b), min(max(a,b),c)); Though, it won’t give you the median value’s index… Breakdown of all cases: a b c 1 2 3 max(min(1,2), min(max(1,2),3)) = max(1, min(2,3)) = max(1, … Read more

How do I conditionally check if an enum is one variant or another?

First have a look at the free, official Rust book The Rust Programming Language, specifically the chapter on enums. match fn initialize(datastore: DatabaseType) { match datastore { DatabaseType::Memory => { // … } DatabaseType::RocksDB => { // … } } } if let fn initialize(datastore: DatabaseType) { if let DatabaseType::Memory = datastore { // … … Read more