6 ms·
This is exactly what I think too. Sum types are so powerful, I feel a lot safer in Python + mypy with sum types (`from typing import Union`) than anything with
by gnulinux 4y ago
This is exactly what I think too. Sum types are so powerful, I feel a lot safer in Python + mypy with sum types (`from typing import Union`) than anything with C++ [1] even though C++ has a significantly more complex type system (it's type system is TC) and Python is as type-unsafe as a language can get. C++ made this odd choice as if any complex type system is better than a simple type system. When I was a younger software engineer, I agreed with this choice but now I completely disagree. I think next generation of software engineers will see that Turing completeness is a bug, and that the whole thing about software safety is finding weak features that are just powerful enough to be useful. If you don't believe me, go look at a language like Agda. You do not need Turing completeness: function application, sum types, primitive/structural recursion/corecursion are just about everything you need as a programmer and everything else that gives you a Turing complete language is extraneous.
[1] unless you liberally use `union`s everywhere which is very unidiomatic C++, but can be done if desired.
- aw1621107 4y ago> even though C++ has a significantly more complex type system (it's type system is TC) For what it's worth, Python's type hints are also Turing complete (https://arxiv.org/abs/2208.14755 https://arxiv.org/abs/2208.14755, discussed on HN at https://news.ycombinator.com/item?id=32779296 https://news.ycombinator.com/item?id=32779296)
- deleted 4y ago[deleted]
- School-Cotton 4y agoRust’s type system is also Turing complete: https://sdleffler.github.io/RustTypeSystemTuringComplete/ https://sdleffler.github.io/RustTypeSystemTuringComplete/
- pharmakom 4y agoC++ has std::variant though?
- OnlyMortal 4y ago… and boost::variant if you’re either using an old code base or want to use boost serialization.
- dureuill 4y agoYes, but: - nobody uses it in the ecosystem. As outlined in the article, a lot of value of Option/Result is derived from their pervasiveness in the Rust ecosystem. C++ is far from this - the ergonomics of it are terrible: no pattern matching, structural variants instead of named variants (yes you can emulate that with wrapper types but meh), lambda-oriented matching means you cannot as easily do things like early returns, statement-oriented language limits the usefulness anyway, lack of combinators, and for error handling specifically, lack of `?` operator - performance is dubious. I had very steep and unexpected performance cliffs when lambda inlining started to fail for some reason. Having sum types be a language construct guarantees we're not relying on things like lambda optimisation here.
- blub 4y agoVariant types where one has to use objects as types don’t come up that often in API design or data structures in my experience with mobile and system programming on e.g. Linux. I think I’ve genuinely had to use them only a few times. Error types are probably the most popular incarnation of that. There’s several libraries available and they will be part of the C++ standard. This is a case of the Rust community overselling a minor feature as a game-changing novelty.
- 3836293648 4y agoYou clearly haven't tried using variant types properly then. Sure, `std::variant` is pretty unergonomic, but they really are game changing. Most of my types are variant types
- blub 4y agoMost of your types? Well that certainly deserves congratulations and I hope someone will take advantage of the opportunity. I think you misunderstood me though if you say I haven’t used them properly. I just didn’t need them or find them that useful because it rarely happens that I want to model a type which has several states. Specific variant types like std::optional or the Result-equivalents are useful, but not that game changing either. They’re nice I suppose. I wonder what kind of software you write that such low-level coding idioms make a big difference to the end result. Or what do you mean by game changing?
- Sparkyte 4y agoYou can just make your python modules out of another language. I am not sure why code has to be big. Break it down and make it executive, not very friendly in terms of threads but if you're writing an API you are writing it for Linux which is vastly safer for threads than Microsoft or Mac. https://developers.redhat.com/blog/2017/11/16/speed-python-using-rust#why_does_it_matter_for_a_python_developer_ https://developers.redhat.com/blog/2017/11/16/speed-python-u...