Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Issues like this are another reason Python should have a native switch...case control flow instead of trying to cram it into a chain of elifs or a dict. In other languages, calling a switch on an enum will cause the type checker to ensure that all cases are handled or that there's a default case. I see there's a PEP out to push this functionality into elifs, but it still seems inelegant to me.


The `match` statement, slated for the next version of Python (3.10), is rather comprehensive. Don't think we could reasonably expect much more than this to be retrofitted into an old language [0]

https://www.python.org/dev/peps/pep-0622/#exhaustiveness-che...

https://www.python.org/dev/peps/pep-0634/

[0] Trivia: Python is older than Linux!


Very exciting for experienced developers missing this from other languages, but I predict the growing spec of Python is leading it away from the "my first language" crowd in future.


I'm so excited for match to become a thing. Honestly, exhaustiveness had kept me from using Python for some work that I'd have otherwise loved to use it! I enjoy FP and some of the other benefits of Ocaml, which is what I use for programs where Mypy can't give me what I need. But at the end of the day, I'm just not as nimble with it, and I can just see the python in my head so much easier.


Yet python never needed a case statement. It used to be simple to write and read language, unlike so many others.

Cramming in new statements just to check Enums types properly sounds... well wrong... The types don't do anything except make code harder to read. But I know that unpopular opinion here... I guess I just like old simple Python more.


Curious what other languages you're fluent with? I found once I'd grokked a language with `match` (Rust), I missed it when writing Python afterwards.


In my professional career I've worked mostly with C++, PHP and Python and these are probably ones I'm most fluent with. But also done tone of Perl, Delphi, VB and C# back in the day. Strange mix.

However I also think that how you look at the language greatly depends on what actual projects you have been working on and with whom plus personal taste. I've been mostly in finance and accounting and personally love code that is very easy to "read" (definition of readable code seems to vary per person).

Example: C++ has so many things crammed into it that I don't see the value of it for doing stuff that are not high frequency trading. It is like using a sledgehammer to drive a nail in the wood.


Looks like you haven't had much immersion in functional languages - the ones you list are all quite an imperative flavor. If you're interested in sampling some other styles of language I suggest the book "Seven languages in seven weeks"


... I never done LISP in professional life but I have learned it and used it for side projects. I've read SCIP and found that everything said there can be applied to most programming languages. I don't understand what you're comment is supposed to imply? That I don't understand match cos I didn't write first reddit version?

I've spent 25 years discovering languages and concepts in computer science. I've even played with Smalltalk, Ada and some Algol variant. Even wrote COBOL for short while. What's your point?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: