I teach computer science to undergrads and write for The Renegade Coder. I'm most likely taking care of my daughter, watching the Penguins, or reading manga.
Location
Columbus, Ohio
Education
B.S. in CE from CWRU 2016; M.S. in CSE from OSU 2020; PhD in EED from OSU 2024
Whenever I think about why I don't like a certain way a language does something, I realize it always goes back to my love for Python. That language has ruined me. haha
No, because overloading is have same parameters with different types, but in patter matching you can have the same type and number of parameters but differs in the content. For example, here!
That's why we never have
switchin Python 😁And, the dictionary is always a better and cleaner alternative for the ugly switch.
Whenever I think about why I don't like a certain way a language does something, I realize it always goes back to my love for Python. That language has ruined me. haha
❤ for the utmost ruining lang.
Really love this pattern. I have seen various approaches to the
defaultcase that vary across languages.How would you handle a
defaultcase in this?My though is to add
|| defaultValueat the end since a failure to match any property will returnundefined. Thoughts?That would be handy using a try except:
I added the extra
defaultvariable just to make the code self explanatory.EDIT: Bad solution, look at the other comments.
You can also use defaultdict in the standard library :D
This is clean :D
This is the answer to this entire thread.
@rhymes and @pedromendes96 got it better than me 😁
Elixir :)
Pattern matching to the rescue ?
Isn't this feature called method overloading ? 🤔
No, because overloading is have same parameters with different types, but in patter matching you can have the same type and number of parameters but differs in the content. For example, here!
I quite like cond as well for certain situations as well.