| ▲ | dieselgate an hour ago | |||||||
Didn’t see it mentioned in the article but isn’t leading with if-statement called a “guard clause”. I like that pattern but it’s just general best practice I thought. | ||||||||
| ▲ | mahboi 40 minutes ago | parent | next [-] | |||||||
Guard clauses are things that return early for trivial or problematic cases. Like https://en.wikipedia.org/wiki/Guard_(computer_science)#Flatt... They're one of those good practices that look like bad practice to everyone who just got a CS degree. Seems ex-students are unsettled by asymmetry or want to minimize the number of return statements. | ||||||||
| ||||||||
| ▲ | woadwarrior01 an hour ago | parent | prev [-] | |||||||
Swift explicitly has a guard statement for this. Rust's let .. else { ... } is also very similar. https://docs.swift.org/latest/documentation/the-swift-progra... | ||||||||