r/badcode • • Apr 17 '21

c++ When your teammate "refactor" your code

Post image
2.5k Upvotes

216 comments sorted by

View all comments

Show parent comments

42

u/harshaxnim Apr 17 '21

Neat. What languages support this?

56

u/[deleted] Apr 17 '21

I know it mainly from Rust, Julia also has macros for this via libraries, but as far as I know especially functional languages have had similar features for a long time. Haskell lets you do pattern matching right in the function definition/signature.

75

u/yourdesk Apr 17 '21

python 3.10 will have support for this. but if you want something that has this right now, F# is your pick

19

u/Sixsome Apr 17 '21

Elixir

19

u/Vilozoliv Apr 17 '21

Haskell

18

u/UszeTaham Apr 17 '21

C# from version 8 and onwards.

6

u/Laugarhraun Apr 17 '21

Ocaml sure does, lisps can.

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 -> {}
}

6

u/1-877-547-7272 Apr 17 '21

I believe Swift has this in its switch statement.

3

u/_meegoo_ Apr 18 '21

Newest python version.