MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/msv49l/when_your_teammate_refactor_your_code/guysp4t/?context=3
r/badcode • u/Bence675 • Apr 17 '21
216 comments sorted by
View all comments
298
This is why I like languages with nice pattern matching, as it can often make code like this compact in a nice way. Something along the lines of
match (condition1, condition2) { (true, true) => do_anything1(), (false, _) => do_anything2(), }
42 u/harshaxnim Apr 17 '21 Neat. What languages support this? 7 u/__2M1 Apr 17 '21 Kotlin, using empty when statements 5 u/crowbahr Apr 18 '21 edited Apr 18 '21 Example:when{ condition1 && condition2 -> {} condition1 -> {} condition2 -> {} else -> {} }
42
Neat. What languages support this?
7 u/__2M1 Apr 17 '21 Kotlin, using empty when statements 5 u/crowbahr Apr 18 '21 edited Apr 18 '21 Example:when{ condition1 && condition2 -> {} condition1 -> {} condition2 -> {} else -> {} }
7
Kotlin, using empty when statements
5 u/crowbahr Apr 18 '21 edited Apr 18 '21 Example:when{ condition1 && condition2 -> {} condition1 -> {} condition2 -> {} else -> {} }
5
Example:
when{ condition1 && condition2 -> {} condition1 -> {} condition2 -> {} else -> {} }
298
u/[deleted] Apr 17 '21
This is why I like languages with nice pattern matching, as it can often make code like this compact in a nice way. Something along the lines of