News for hackers. Stuff that matters.
Re:Python's Type Checking Renaissance by nynx on Tuesday January 26, 2021 @10:50AM (#25917162)
People who use dynamically-typed languages are finally realizing that having to simulate a type-checker mentally is a bad idea.

Also, many statically-typed languages do not take advantage of the flexibility a good type-system can provide. For example, C, C++, Java.

Re:Python's Type Checking Renaissance by rscho on Tuesday January 26, 2021 @11:54AM (#25918103)
Contra: (some) people doing exploratory programming in the small e.g. scientists don't want to have to deal with the type checker.

Type systems like Haskell add a lot of value, but you have to really know the language to make good use of it. I mean, just IO handling requires planning ahead. Small dynamic languages allow one to keep simple things simple. There's value in that too.

Re:Python's Type Checking Renaissance by mumblemumble on Tuesday January 26, 2021 @10:19PM (#25923839)
When I'm wrangling data, it's not necessarily that I don't want to have to deal with the type checker. It's that I have yet to see a statically typed language whose type system is designed to help solve the kinds of problems I have when I'm wrangling data.

The distressing example that nags at me here is how the headline feature of Apache Spark 2.0 is that they Greenspunned a dynamic typing mechanism into it. And, in doing so, realized improvements in ergonomics, performance, and memory consumption. Understanding why and how is an instructive lesson.

The most promising typing system for arbitrary data wrangling that I've seen so far is the one that's built into a Python package called Dagster. It seems reminiscent, as best I can tell, of dependent typing. (Although I haven't actually spent any time with a dependently typed language, so that could be a misunderstanding on my part.) The actual checks are done at run time, of course, but I don't see any particular reason, aside perhaps from the complexity involved, why a similar mechanism couldn't be implemented as a static type check.

Re:Python's Type Checking Renaissance by wk_end on Wednesday January 27, 2021 @01:15AM (#25924903)
What are the sorts of problems you have when wrangling data that type systems don't help with? I'm not a data scientist, but I'm a type system guy, and I'd like to learn about ways that type systems are failing users. I took a very quick peak at Dagster and the Google results for "apache spark 2.0 dynamic typing" (are you talking about "Datasets"?) and nothing immediately jumped out as a clear sort of elucidation of what you're saying.
Re:Python's Type Checking Renaissance by snicker7 on Wednesday January 27, 2021 @01:38AM (#25925024)
In data science, types change all the times. E.g. when dealing with tabular data, the columns (which might be used as type parameters) change frequently. In Julia, for example, see DataFrames.jl vs. TypedTables.jl for some trade-offs.

In general, type annotations are useful if you know the business requirements beforehand. Data science is exploratory, where type annotations can be a form of premature abstraction. Languages with traits (e.g. Scala) might be a decent compromise.

Re:Python's Type Checking Renaissance by wk_end on Wednesday January 27, 2021 @05:31PM (#25935027)
It sounds like the structural typing in Typescript might help a lot here - you don’t need to formally define any types for a record, the language just infers and tracks fields/types for you. I don’t know what the current state of data science is for TS though.
Re:Python's Type Checking Renaissance by rowanG077 on Wednesday January 27, 2021 @03:26PM (#25933478)
But now you are talking about type annotations and not static typing. You can have static typing without any type annotations
Re:Python's Type Checking Renaissance by bluejekyll on Tuesday January 26, 2021 @12:08PM (#25918321)
Everything comes with trade offs. But I’d argue that one of the primary reasons folks avoid types is that it requires additional learning.

I’m speculating here, but as a software engineer who’s dealt with many different languages, I (personally) find types to increase my productivity, because it reduces errors at runtime. This is a huge benefit, and because I’ve spent a lot of time learning the target language’s type system, it doesn’t come at the cost of productivity, and like I said, I find it to improve my downstream productivity.

I’ve read that scientists have had significant mistakes in their findings in papers due to bugs, which I know is anecdotal, but it seems like adopting typed languages would reduce those errors and increase confidence in studies.

I wonder if they were able to recognize the downstream benefits of types, if they would shrug them off as irrelevant to their work.

Re:Python's Type Checking Renaissance by visarga on Wednesday January 27, 2021 @01:50AM (#25925098)
I read about a guy who wanted to reproduce a neural net and he worked at it for a year only to find it missed a +1 in one place. Being a neural net it still worked but not as good. I don't think this kind of error would have been caught by a type system.
Re:Python's Type Checking Renaissance by bluejekyll on Wednesday January 27, 2021 @03:48AM (#25925770)
It depends. Off by one errors are common, but the context is important. Some languages for example prefer integrators to indexing, and if ‘a’ was an index that might have been avoided.

Languages with algebraic data types also allow you to express state in ways that can make it easier to identify state changes, possibly making the missing increment more obvious.

Some languages will warn when variables are being used or modified in scopes where they are referenced but not used.

But, even with all this, yes bugs will still happen.

Re:Python's Type Checking Renaissance by rscho on Tuesday January 26, 2021 @01:00PM (#25919067)
It's true that many papers have mistakes, but the reasons for that go further than types, the main one being the prevalence of uneducated spreadsheet warriors.

I definitely agree that if you're making a big custom model you should use a typed language. But indeed, that requires a lot of learning, so the investment has to be worth it. The problem is often that scientists don't program all day, so remembering language intricacies is hard. Dynamic languages that can have their whole syntax written on a postcard make things much easier from that pov.

Re:Python's Type Checking Renaissance by jolux on Tuesday January 26, 2021 @08:16PM (#25923087)
Haskell syntax would probably fit on a postcard too. I think type systems are orthogonal to syntactic complexity.
Re:Python's Type Checking Renaissance by jgwil2 on Tuesday January 26, 2021 @09:35PM (#25923592)
Right, the problem is that the semantics of statically typed languages are far more complex (since the program text conveys more information).
Re:Python's Type Checking Renaissance by sillysaurusx on Tuesday January 26, 2021 @09:33PM (#25923578)
It’s not that it requires additional learning. It requires additional time when writing code. A nontrivial amount of time that isn’t generally worthwhile for me.
Re:Python's Type Checking Renaissance by jen20 on Tuesday January 26, 2021 @09:45PM (#25923651)
I tend to find the opposite - writing Python with or without type annotations is both more time consuming and a more fraught endeavour than writing Go, TypeScript or even Rust.
Re:Python's Type Checking Renaissance by abnry on Tuesday January 26, 2021 @10:03PM (#25923749)
I suspect that is the case if you have written a lot in a typed languages. There may be both context switching and literally no issue dealing with types if you have mastered them.
Re:Python's Type Checking Renaissance by rsrsrs86 on Wednesday January 27, 2021 @09:34PM (#25937387)
Oh, I find that Haskell and Elm are much quicker to write code because I spend much less time on little programming mistakes and refactorings are much safer
Re:Python's Type Checking Renaissance by KMag on Tuesday January 26, 2021 @10:59PM (#25924087)
Most static type checkers prove (to the limits of the soundness of the type system) that the types of the values at run time will always be compatible with the operations performed on those values. For these checkers, any program that's not provably sound (to the limits of the type system soundness) will be rejected. In other words, most static type checkers answer "is this definitely correct?"

However, it's possible to have a more lenient static type checker that only looks for cases where you're guaranteed to get an illegal operation at runtime. They answer the question "is this definitely wrong?"

For instance, if we have:

  def f(x):
      g(x)
      h(x)

  def g(x):
      x.a()

  def h(x):
      x.b()
If we're doing whole program analysis and there's no type that has both a() and b() methods, then f is guaranteed to call a non-existing method at one place or the other.

This sort of "this is clearly wrong" type checking is much less intrusive than the more common "I'm not positive this is correct" type checking.

If you're not doing whole-program analysis, then you may restrict the type search to the types imported into the transitive closure of the module and its dependencies. This makes type checking slightly more intrusive by sometimes forcing more module imports, but it's still much less intrusive than common type checkers.

Re:Python's Type Checking Renaissance by yawaramin on Tuesday January 26, 2021 @11:59PM (#25924476)
> However, it's possible to have a more lenient static type checker that only looks for cases where you're guaranteed to get an illegal operation at runtime. They answer the question "is this definitely wrong?"

If you're thinking about Erlang's Dialyzer, almost everyone I've heard talking about it says that it's difficult to understand and doesn't provide as much confidence as a regular type system would.

Re:Python's Type Checking Renaissance by cozzyd on Wednesday January 27, 2021 @12:43AM (#25924739)
right, but for languages that support monkey-patching, this is going to be hard. e.g.:

  setattr(type(x),sys.argv[1],x.a)
or

  setattr(type(x), 'b' if halts(sys.argv[1]) else 'c',x.a)
Re:Python's Type Checking Renaissance by UncleMeat on Wednesday January 27, 2021 @11:21AM (#25930102)
Yes, static analysis of highly dynamic languages like javascript or ruby is tremendously difficult. Sound results are nearly impossible because you need to havoc so frequently. But if you permit some error and ask for a little extra help from developers in cases outside normal style for a language you can still do a pretty good job.
Re:Python's Type Checking Renaissance by KMag on Wednesday January 27, 2021 @02:07AM (#25925178)
Presumably, you'd have an escape hatch in the from of specially formatted comments to annotate each questionable call site. My understanding is that even strong proponents of monkey patching feel it should be used sparingly.
Re:Python's Type Checking Renaissance by ardy42 on Tuesday January 26, 2021 @02:04PM (#25919835)
> Contra: (some) people doing exploratory programming in the small e.g. scientists don't want to have to deal with the type checker.

Which in at least some cases means ignoring bugs. Pretty much every system I've worked on that used a language that didn't to type checking (or was too forgiving about it) has had runtime bugs because of type incompatibility or type coercion issues.

Re:Python's Type Checking Renaissance by rscho on Tuesday January 26, 2021 @02:46PM (#25920259)
> Which in at least some cases means ignoring bugs

Indeed, but simplicity is the name of the game for exploratory programming. It's difficult to explore using languages requiring a lot of ceremony.

But then, that's when the time and funding constraints come in and prevent rewriting in more type sound languages. Which is why we end up with buggy python (if speed not an issue) or buggy C (if speed is an issue).

There are alternate paths. For example, APL tries to be terse enough that you can have the whole thing on a single screen. That's another attempt at bug prevention.

For example, I do my data wrangling in J.

Re:Python's Type Checking Renaissance by jjnoakes on Tuesday January 26, 2021 @09:12PM (#25923466)
> languages requiring a lot of ceremony

Some statically-typed languages don't require a lot of ceremony.

Re:Python's Type Checking Renaissance by jshen on Tuesday January 26, 2021 @09:39PM (#25923612)
Is it a bug if it never happens? Another way to say it, would you pay money to prevent a problem you don’t have?
Re:Python's Type Checking Renaissance by ardy42 on Wednesday January 27, 2021 @09:34AM (#25928708)
> Is it a bug if it never happens? Another way to say it, would you pay money to prevent a problem you don’t have?

Let me rephrase that: Is it a bug if I don't know about it? Another way to say it, would you pay money to prevent a problem you're not (yet) aware of?

Saying the bugs "never happen" is basically saying "I always write bug-free code."

I feel languages that don't have type checking (or where it's sloppy), force developers perform semi-automated testing (i.e. unit tests to catch type issues) when they could have systematic, fully-automated testing (for type issues, at least)

Re:Python's Type Checking Renaissance by jshen on Wednesday January 27, 2021 @11:12AM (#25929996)
Right, but some people are doing data wrangling by themselves with python in a jupyter notebook. These aren’t production systems, and static type checking slows you down without adding much value.

That’s all I’m saying, the data analyst that has some edge case “bug” that never gets executed probably shouldn’t pay the upfront overhead cost of type checking.

Re:Python's Type Checking Renaissance by cheriot on Tuesday January 26, 2021 @10:14PM (#25923805)
Is having buggy, unused code lying around a good thing?
Re:Python's Type Checking Renaissance by jshen on Tuesday January 26, 2021 @10:24PM (#25923865)
It’s not always bad, and dealing with it has a cost. The cost is not always worth. It may be worth it most of the time, but not always.
Re:Python's Type Checking Renaissance by stosto88 on Tuesday January 26, 2021 @08:33PM (#25923206)
Agreed. I am essentially an Excel Poweruser on steroids with the way I use Python.
Re:Python's Type Checking Renaissance by socialdemocrat on Wednesday January 27, 2021 @02:50AM (#25925455)
Utilizing a type checker when you want is very different from being forced to use it. Statically typed languages create a lot of complexity from being entirely dependent on types being correct in a static sense rather than at runtime.

With type checkers for dynamic languages, a lot of the arguments in favor of static languages disappear.

Re:Python's Type Checking Renaissance by pansa2 on Wednesday January 27, 2021 @03:27AM (#25925667)
> Statically typed languages create a lot of complexity from being entirely dependent on types being correct in a static sense rather than at runtime.

Python’s type annotations aren’t checked at runtime, though - they’re also entirely static. So you either have to:

- Write code that’s as pedantically correct as in a traditional statically-typed language (e.g. by using `mypy —-strict`), in which case you’d be better off using a language that supports AOT-compilation, or

- Be prepared for cases where the runtime type doesn’t match the annotation. This is unacceptable - I hate the idea of code that tells lies.

Re:Python's Type Checking Renaissance by gypsyharlot on Wednesday January 27, 2021 @04:34AM (#25926108)
You're entirely forgetting the benefits.

1) Scientists, hobbyists etc. can be super productive with Python while disregarding types.

2) Software developers can write serious applications with type checking.

Statically typed languages exclude group that benefit from 1).

Re:Python's Type Checking Renaissance by pansa2 on Wednesday January 27, 2021 @04:45AM (#25926179)
A language that tries to satisfy both of these groups won’t be ideal for either of them.

Python should aim to be perfect for group 1. There are many other languages that will always be a better choice for group 2.

Re:Python's Type Checking Renaissance by gypsyharlot on Saturday February 06, 2021 @03:51AM (#26045235)
I disagree. You can spend 90% of your time doing e.g. data science, and then one day you need to integrate with a DB or make a cross-platform desktop GUI application, as an example. Should you learn C++ (it takes a decade to become a very mediocre C++-developer), or Java to write a desktop GUI application?

No, there isn't "always" a better choice for group 2.

- Most software isn't CPU bound, so that defies "always" in your argument

- You need libraries get things done

What language would you always pick for group 2? Or would you pick a different one for each task, spending an order of magnitude more time learning them?

Re:Python's Type Checking Renaissance by lmm on Wednesday January 27, 2021 @05:03AM (#25926299)
> Statically typed languages create a lot of complexity from being entirely dependent on types being correct in a static sense rather than at runtime.

Nonsense. It's very easy to use a runtime cast if and when you want to, even in Haskell. You're in control of exactly where typechecking doesn't happen.

In contrast, in a dynamic language with optional typechecking you have basically no guarantees. Even if 99% of your codebase is typechecked, you have no idea what errors might be lurking in the other 1% or how far they might propagate, since a type error can show up essentially arbitrarily far away from its actual cause. It's the worst of both worlds - you pay all the costs of a static type system but get hardly any of the benefits.

Re:Python's Type Checking Renaissance by antihero on Wednesday January 27, 2021 @04:47AM (#25926185)
I think this is a pretty old-school mindset. For instance, with strict TypeScript the overhead once you get used to properly typing things is minimal - most things are inferred, and it actually empowers you to code faster as you have guard rails and great autocomplete; the issues are more likely due to poor/non-existent types.
Re:Python's Type Checking Renaissance by konjin on Wednesday January 27, 2021 @02:39AM (#25925383)
>People who use dynamically-typed languages are finally realizing that having to simulate a type-checker mentally is a bad idea.

I'd say that the pool of python developers has been swamped by a tsunami of former java/c# developers who don't understand the first thing about what made python good and are demanding they get everything they were used to in their old languages in python.

It's a rather sad state of affairs, but it's been great for cashing out on a language I learned in my off time at highschool in the 00s, especially since I have my name as a contributor before I turned 18.

Re:Python's Type Checking Renaissance by oblio on Wednesday January 27, 2021 @04:26AM (#25926040)
Or you could look at it as Python growing up and being used for long lived projects with tens and hundreds of developers of varying skill levels, where you need to do things such as... safely refactor large amounts of code quickly.
Re:Python's Type Checking Renaissance by pansa2 on Wednesday January 27, 2021 @04:59AM (#25926270)
Maybe it’s “growing up”, but I agree that Python has definitely changed its focus. It has pivoted towards the handful of companies with “projects with tens and hundreds of developers“ at the expense of the millions(?) of people using it for much smaller projects.

As part of the latter group, I don’t consider this change in focus to be a good thing.

Re:Python's Type Checking Renaissance by oblio on Wednesday January 27, 2021 @07:06AM (#25927209)
> It has pivoted towards the handful of companies with “projects with tens and hundreds of developers“

Handful of companies? Small and medium businesses, according to most definitions, can have up to 100 employees, and they generally make up to 90% of the businesses in most countries. If these small and medium businesses are writing Python apps, it's far from inconceivable that they will at some point have tens of people working on a project.

You make it sounds like you need to be a company with 1 million employees in order to have a big project.

And I don't see how these changes impact the "millions (?)" using Python for small projects. Python type checking is optional.

Re:Python's Type Checking Renaissance by konjin on Wednesday January 27, 2021 @05:08AM (#25926332)
Indeed, I've moved to Guile as my small scripting language.

It has much better integration with the gnu user space, and much like pythons early days if you know C you can write extremely performant code. The fact that I can write a DSL for every problem is a benefit I didn't know I wanted until I no longer had to monkey patch objects.

Re:Python's Type Checking Renaissance by pansa2 on Wednesday January 27, 2021 @07:50AM (#25927581)
> I've moved to Guile as my small scripting language.

I have been using Lua as an alternative to Python. It's much closer to my ideal level of language complexity - and I think overall it's better designed than Python, although it's certainly not perfect. The implementation of the interpreter is significantly better as well.

Re:Python's Type Checking Renaissance by konjin on Wednesday January 27, 2021 @04:28AM (#25926062)
Yes, I already said a tsunami of developers who do not know how to use python.
Re:Python's Type Checking Renaissance by oblio on Wednesday January 27, 2021 @06:29AM (#25926944)
As opposed to the many Python gurus writing short scripts? :-)
Re:Python's Type Checking Renaissance by konjin on Wednesday January 27, 2021 @07:18AM (#25927309)
Yes.

Python is glue.

If you build a stick bridge with just glue you sound like the type of person who ate most of it.

Re:Python's Type Checking Renaissance by slifin on Tuesday January 26, 2021 @12:19PM (#25918480)
As a Clojurian I just run static analysis

It can be nice to use an optional type/spec system to help with that but not required

Re:Python's Type Checking Renaissance by flohofwoe on Wednesday January 27, 2021 @05:57AM (#25926682)
I'm a fan of static typing (but not necessarily overly strong typing) myself, but one big reason why I use Python next to statically typed languages is to write quick and dirty cross-platform-scripts where the sloppy duck typing comes in handy. Want to throw vastly different things into a single array (sometimes not even knowing what type those things are)? No problem, it just works.

This type of quick'n'dirty throw-away coding would be a lot less convenient if Python would force a strong static type system on me.

If Python is used for "real projects" with more than a few thousand lines of code, worked on by a team, static typing totally makes sense. But there are a lot of everyday tasks where this just gets in the way.

Re:Python's Type Checking Renaissance by raverbashing on Wednesday January 27, 2021 @02:08AM (#25925185)
The annoying part about (traditional) type checking is having to do it all the time

But the optional Python annotations? I was skeptical, but I began to see the value in it, especially in interfaces/APIs for external consumption, or more complicated areas.

But yeah don't ask me to type hint a "private" function that's only a couple of lines long and used in specific cases

Re:Python's Type Checking Renaissance by BiteCode_dev on Tuesday January 26, 2021 @11:50AM (#25918037)
It's a trade off. You don't want to write all your types for quick scripts, data analysis and small web sites.

As a trainer, experience teaches me that it's also much easier for beginners.

Now, types are nice to have for bigger code bases, but that doesn't mean there is no place for a language with optional typing.

Re:Python's Type Checking Renaissance by smlckz on Tuesday January 26, 2021 @11:58AM (#25918175)
There is Hindley-Milner type inference. Don't need to type types in most cases. See, for example, OCaml.
Re:Python's Type Checking Renaissance by rscho on Tuesday January 26, 2021 @02:50PM (#25920298)
Type inference does not mean untyped. Arguably, getting a type error when you didn't write a single type hint makes things even more confusing if you are not an experienced programmer.
Re:Python's Type Checking Renaissance by wool_gather on Tuesday January 26, 2021 @12:45PM (#25918853)
That comes with its own tradeoffs: increased compile time and more effort needed to create error messages that are helpful to the user.
Re:Python's Type Checking Renaissance by GeorgeWBasic on Tuesday January 26, 2021 @08:27PM (#25923150)
Ocaml is probably the fastest compiling language I've ever used.
Re:Python's Type Checking Renaissance by jgwil2 on Tuesday January 26, 2021 @09:39PM (#25923614)
> more effort needed to create error messages that are helpful to the user.

Well, sure, but that's a tradeoff for the developers of the language to consider. As a user, there are already plenty of statically typed languages to choose from with many person-hours put into just that.

Re:Python's Type Checking Renaissance by erik_seaberg on Tuesday January 26, 2021 @09:54PM (#25923711)
I want to offload as much work as we possibly can to the compiler. My brain will always be millions of times slower.
Re:Python's Type Checking Renaissance by dan_quixote on Tuesday January 26, 2021 @09:42PM (#25923632)
Is it really that burdensome for novice programmers? Maybe it's just been too long for me to remember the pains...but I'd expect most novices to heavily use primitive types which shouldn't be that hard to grok.
Re:Python's Type Checking Renaissance by d0mine on Wednesday January 27, 2021 @01:40PM (#25932042)
> People who use dynamically-typed languages are finally realizing that having to simulate a type-checker mentally is a bad idea.

It cuts both ways. Some days type advocates recognize why their type language is not their host language i.e., there is a such a thing as too much types.

If you believe types can express anything, and more over they are the best at expressing it then why do you need the host language, why not to program using just types.

There is no silver bullet. Types won't make your code bug free.

What programming language do you know that uses types to express most tests?

Re:Python's Type Checking Renaissance by oivey on Wednesday January 27, 2021 @02:27AM (#25925315)
I’ve found that enforcing types users (including myself) can use with my code is a bad idea. Informal specifications are simpler and enable massive code reuse. Inheritance in OOP was meant to SRN able code reuse in static languages, but has largely failed. In OOP, library interoperability can only be achieved if all developers know a common set of subtypes that satisfy all cases, which can never be true. The granularity of trait systems is better, but still suffers from the same issue.
Re:Python's Type Checking Renaissance by jgwil2 on Tuesday January 26, 2021 @09:41PM (#25923627)
What is so bad about Java/C++?
Re:Python's Type Checking Renaissance by valenterry on Tuesday January 26, 2021 @10:26PM (#25923869)
They can't even describe simple problems without using escape hatches (ignoring C++'s crazy templates).

Example: Everyone in your system has a role. There are 3 kind of roles: User, Moderator, Admin

They have different attributes. All of them have a name, but only moderators and admins have dedicates areas of responsibility. And only moderators have a subset of at least one allowed permission (e.g. "edit posts" and/or "delete posts").

You can't really denote this in a way that the Java compiler understands it at the use site. E.g. an action is executed and you want to see if it is allowed. So you want to check the kind of role and if the attributes/permissions match the action or not. The compiler doesn't support this well at ala.

Re:Python's Type Checking Renaissance by jgwil2 on Tuesday January 26, 2021 @10:44PM (#25923975)
So the problem is that the type system does not give you the type of the caller of a method? Does e.g. Haskell support this?

(As an aside, I think one solution in Java would be to use the command pattern and pass an object (ModeratorCommand, etc.) to whatever code is processing your actions, so it can type check the command.)

Re:Python's Type Checking Renaissance by valenterry on Wednesday January 27, 2021 @03:56AM (#25925822)
It's more that you simply can't define your datastructure correctly.

> Does e.g. Haskell support this?

Sure, and it is not certainly not the only language. E.g.:

    data Role = User String | Moderator String [Area] NonEmpty Permission | Admin String [Area]
I'm not even saying that this is the best way of modeling it - but with Java you unfortunately can't really define it.

> (As an aside, I think one solution in Java would be to use the command pattern and pass an object (ModeratorCommand, etc.) to whatever code is processing your actions, so it can type check the command.)

The problem stays the same though: how do you know what kind of command it is that you just received? You cannot safely "match" on the command in the same way you can in other languages, because the compiler doesn't know that there are only exactly 3 types of commands.

Re:Python's Type Checking Renaissance by jgwil2 on Wednesday January 27, 2021 @09:05AM (#25928379)
Okay, so it's union types plus pattern matching that are missing (among other things I'm sure). Thanks, that's helpful.

> You cannot safely "match" on the command in the same way you can in other languages, because the compiler doesn't know that there are only exactly 3 types of commands.

Perhaps the visitor pattern? Command processing receives an object and calls its command method, which knows what permissions it has.

I guess the fact that I have to keep saying "patterns" is a hint that some flexibility is missing. Still, I'd rather have Java/C++ static types than nothing at all.

Re:Python's Type Checking Renaissance by dwohnitmok on Wednesday January 27, 2021 @03:48PM (#25933726)
Yes the visitor pattern is a valid encoding of algebraic datatypes. Very heavyweight (imagine if booleans were all encoded with the visitor pattern) but nonetheless valid.

https://blog.ploeh.dk/2018/06/25/visitor-as-a-sum-type/

Re:Python's Type Checking Renaissance by lmm on Wednesday January 27, 2021 @05:08AM (#25926328)
No sum types, no HKT (which means no practical way to handle effects), no ability to handle records generically (i.e. no typeclass derivation). Just imagine something super basic like: take a JSON structure that's a "patch" to an existing domain object, merge it in place, and for each field type there's a given way of merging it and a possible kind of error that can occur; gather up all those errors and report them together. That's trivial in Python and impossible in Java/C++.
Re:Python's Type Checking Renaissance by rational_indian on Tuesday January 26, 2021 @11:14AM (#25917494)
Better late than never.
Re:Python's Type Checking Renaissance by kashif on Tuesday January 26, 2021 @11:20AM (#25917580)
Java is not a good type system at all - Haskell is.
Re:Python's Type Checking Renaissance by nesarkvechnep on Tuesday January 26, 2021 @11:30AM (#25917728)
That's what the OC said.
Re:Python's Type Checking Renaissance by kashif on Tuesday January 26, 2021 @11:39AM (#25917850)
Ah my bad. I misread that.
Re:Python's Type Checking Renaissance by SAI_Peregrinus on Tuesday January 26, 2021 @11:33AM (#25917768)
They listed those three as examples of languages that don't take good advantage of having static typing.