672 karma · joined Jan 29, 2020 (6y ago) · 78 submissions
comment 5y ago · link · parent
If your Python code relies a lot on dynamic dict objects instead of classes you'll have a rougher time. You have to use `TypedDict` which is not very expressive and syntactically verbose. This could be considered a good thing since you'll be pushed to use things like `NamedTuple`, `dataclass`es, or (a third-party extension) `attrs`. Most JS/TS code is probably using plain objects rather than `Map`s. The TypeScript syntax for expressing object types is extremely expressive, though annoyingly `Object.keys` and `Object.entries` are not precisely typed (For legitimate soundness reasons. Object types are "inexact", whereas in Flow you can express both "exact" and "inexact".)
mypy supports union types, but not intersection types, unlike TypeScript. The closest you can get is creating a `Protocol` (i.e. interface) that extends multiple `Protocol`s, but this can be cumbersome.
mypy's generics are strictly worse, both syntactically and expressively. In mypy you can express both co/contra-variance explicitly, whereas in TypeScript variance is implied by the readonly-ness of an object's properties and variance of its methods.
Both mypy and TypeScript have `Any`/`any` types, but only TypeScript has the safer `unknown` type. You can kind of use `object` in mypy for this purpose.
Both have a "bottom" type, "NoReturn" and "never", respectively.
mypy has decent support for classes and subclass type-checking. TypeScript doesn't truly understand sub-class relationships nor even prototypal inheritance.
Both are very configurable in terms of the strictness checks, but mypy's flags are more poorly documented and it requires more work to increase the level of strictness. Enabling "strict" in TypeScript enables most of what one would want.
Anecdotally, I would say TypeScript has better control flow analysis. With mypy you have to cast a lot more often.
The TypeScript ecosystem is much stronger. Most new packages have types as do major packages (located in DefinitelyTyped repo). Python's typing ecosystem is fairly poor. There are barely any packages in Typeshed and a lot of new packages are still untyped.
TypeScript has a dedicated team at Microsoft working on it with a public roadmap and milestones, though big features only come around one or twice a year. Python's type ecosystem is more design by committee. A lot of conversation happens over mailing lists, monthly video calls, and a yearly conference. Since there are multiple Python type checker implementations, there isn't a single unifying vision. The core mypy team is employed by Dropbox, who has them spending most of the time migrating the giant monorepo from Python 2 to Python 3.
The TypeScript team is fairly decent at fixing true bugs between releases, but a lot of "bugs" are really feature requests that tend to become long-standing Github issues. On the other hand, last I checked, there are still some long-standing bugs in mypy that haven't been fixed (as not to spread FUD, I will say that they tend to be very edge-casey and more for power users).
Note that there are multiple type checkers for Python at this point with varying capabilities, but they share the same syntax and basic types since they're built into the language runtime. I expect Pyright (also from Microsoft) to come out ahead as more people start using the Pylance VSCode extension. mypy's editor/IDE support is not great, based on my VSCode experience. I haven't tried it with PyCharm.
comment 5y ago · link · parent
comment 5y ago · link · parent
comment 5y ago · link · parent
comment 5y ago · link · parent
HHAST and LibCST are notable examples in the right direction.
comment 5y ago · link · parent
comment 5y ago · link · parent
41.
View Types for Rust(smallcultfollowing.com ↗)
2 points · by sizediterable · 5y ago · 2 comments
comment 5y ago · link · parent
comment 5y ago · link · parent
44.
Amazon Time Sync Service(aws.amazon.com ↗)
128 points · by sizediterable · 5y ago · 88 comments
comment 5y ago · link · parent
comment 5y ago · link · parent
[0] https://kotlinlang.org/docs/generics.html#variance
[1] https://kotlinlang.org/docs/generics.html#declaration-site-v...
comment 5y ago · link · parent
class CovariantFoo<T> {
private phantom!: T
}
class ContravariantFoo<T> {
private phantom!: (_: T) => void
}
class InvariantFoo<T> {
private phantom!: (_: T) => T
}
(inspired by Rust [0])comment 5y ago · link · parent
> Luau’s type system is structural by default
I think that makes it the second (production-ready) language to have a primarily-structural type system, after TypeScript/Flow(/and Closure to some extent) for JS. I wonder if it will follow in their impressive footsteps or if it will tread new territory.
One of the things that Flow gets right that TypeScript doesn't yet support is switching to nominal type-checking between class instances. In TypeScript you can assign an instance of one class to an instance of another as long as they have compatible fields. Compare:
Flow: https://bit.ly/3jZx4rB
TypeScript doesn't have any understanding of prototypes or prototypal inheritance, which is a big gap considering that it's a fundamental aspect of JS.
I'm really hoping Luau will come to do the right thing with tables and prototypes. Perhaps it already does, but unfortunately there doesn't seem to be a Luau playground to try in the browser.
comment 5y ago · link · parent
> Thanks to aggressive memoization and dynamic code generation at decoration time, beartype guarantees O(1) non-amortized worst-case runtime complexity with negligible constant factors.
I don't think the author(s) understands what "zero-cost abstraction means". O(1) is not O(0). Also let's not forget that memoization incurs a memory cost.
comment 5y ago · link · parent
One of the things I'm excited to see is the cap-std project for Rust [0] given what Pony [1] has demonstrated is possible with capabilities. I'm also hoping that languages like Koka [2] and multicore OCaml [3] will demonstrate interesting ways to design APIs around algebraic effects.
[0] https://github.com/bytecodealliance/cap-std
[1] https://www.ponylang.io/discover
comment 5y ago · link · parent
He has great taste!
comment 5y ago · link · parent
comment 5y ago · link · parent
I know the OP probably meant using tables for things like centering elements and doing page layouts (no longer needed since we have flexbox and grid respectively). But for those reading this that don't know any better, you should still use tables for content that is semantically tabular like displaying data. This makes the content more accessible to people using screenreaders.
Speaking of which, Flexbox Froggy and Grid Garden are fun and addicting ways to learn:
And the Axe extension is a great way to learn about modern accessibility best practices:
https://chrome.google.com/webstore/detail/axe-devtools-web-a...
comment 5y ago · link · parent