Better HN
topnewbestaskshowjobs
Log inSign up

sizediterable

672 karma · joined Jan 29, 2020 (6y ago) · 78 submissions

Submissions

comment 5y ago · link · parent

Most of my experience is with mypy and TypeScript.

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

Python is experimenting with a novel approach where objects have two reference counts, one exclusively for the owning thread and another for all other threads, improving performance when most of the increments/decrements are done by the owning thread.

https://lwn.net/Articles/872869/

comment 5y ago · link · parent

ah, makes sense!

comment 5y ago · link · parent

People like to bring up reference cycles a lot as if it's always a deal-breaker, but for short-lived processes it kind of seems like a non-issue. Anecdotally, we've seen Instagram get overall gains by disabling GC in Python (which will still do reference counted cleanup).

comment 5y ago · link · parent

A Rust team alum has actually written a bit about the topic:

https://without.boats/blog/notes-on-a-smaller-rust

https://without.boats/blog/revisiting-a-smaller-rust

comment 5y ago · link · parent

This seems to be for the `async-task` crate. My question was about `async_std::task` in particular since it doesn't have cancel-on-drop behavior.

comment 5y ago · link · parent

In the first `async_std::task` example, we see that `JoinHandle::cancel` is an async function. I'm curious what would you do if you didn't care whether or not the cancellation succeeded and didn't want to await the cancellation. Would you wrap the cancellation in a task?

comment 5y ago · link · parent

Non-template-based code generation. So many tools depend on interpolation and concatenating strings together resulting in terrible-looking and error-prone code. What you want is an API for building and manipulating a concrete syntax tree-like structure. Bonus points if the nodes have type information, which would make things like codemods even more powerful.

HHAST and LibCST are notable examples in the right direction.

comment 5y ago · link · parent

I also wonder how this might relate to "viewpoint adaptation" as defined in Pony https://tutorial.ponylang.io/reference-capabilities/arrow-ty...

comment 5y ago · link · parent

This kind of reminded me of how in Rust you can split a slice type into sub-slices, except in that case you are actually allocating space for those sub-slices. This leads me to wonder if this is possible in a zero-cost way using const generics, where you only need to store the pointer to the backing data, and the index range/length is known at compile time, e.g. Slice<T, Start, Length>.

41.

View Types for Rust(smallcultfollowing.com ↗)

2 points · by sizediterable · 5y ago · 2 comments

comment 5y ago · link · parent

Sorry if it's a bit sensationalized. I wanted to give some color as to why this release might be interesting and took this tweet I saw at face value https://twitter.com/rbranson/status/1455923426359578631

comment 5y ago · link · parent

Also: https://github.com/microsoft/TypeScript/pull/46429. Anders is on a roll!

44.

Amazon Time Sync Service(aws.amazon.com ↗)

128 points · by sizediterable · 5y ago · 88 comments

comment 5y ago · link · parent

I'm less familiar with OCaml and don't know off the top of my head. Doing a quick search I was only able to find references to type declaration variance [0], though I learned that Java also supports use-site variance too [1]

[0] https://blog.janestreet.com/a-and-a/

[1] https://blog.jooq.org/tag/use-site-variance/

comment 5y ago · link · parent

I think most languages define variance at type definition level, notable exceptions being Kotlin which supports both [0][1] and Flow. But yeah, TS doesn't support (variable-)declaration-site variance which I didn't realize you were asking in my previous answer.

[0] https://kotlinlang.org/docs/generics.html#variance

[1] https://kotlinlang.org/docs/generics.html#declaration-site-v...

comment 5y ago · link · parent

I think variance can be simulated by typing the private field as an existing covariant/contravariant/invariant type

  class CovariantFoo<T> {
    private phantom!: T
  }

  class ContravariantFoo<T> {
    private phantom!: (_: T) => void
  }

  class InvariantFoo<T> {
    private phantom!: (_: T) => T
  }
(inspired by Rust [0])

[0] https://doc.rust-lang.org/nomicon/phantom-data.html

comment 5y ago · link · parent

I forgot about OCaml (since I normally associate it with the more sophisticated typing stuff). I don't know if I'd completely count Go since interfaces only apply to methods, not fields

comment 5y ago · link · parent

Oh cool, hadn't realized this. Also thanks for your great work! I'm rooting for some of your exploratory PRs!

comment 5y ago · link · parent

From https://luau-lang.org/typecheck

> 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

TS: https://tsplay.dev/mZaL1N

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

Given the URL I was thinking that this would be hosted on a service that could run Github gists as single-page-apps. Unsurprisingly something like that actually kind of exists:

https://gist.run

comment 5y ago · link · parent

> Beartype brings Rust- and C++-inspired zero-cost abstractions

> 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

I think it's not discussed enough how things like language features shape how library APIs are formed. People usually seem to only consider the question "how would I use this feature?" and not "how would the standard library look like with this feature?", which is surprising given how much builtin libraries affect the pleasantness of a language (OK not that surprising since people usually talk about features added to existing languages that already have a standard library.)

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

[2] https://koka-lang.github.io

[3] https://github.com/ocaml-multicore/effects-examples

comment 5y ago · link · parent

Fixed, my apologies

comment 5y ago · link · parent

An algebraic effects library: https://github.com/digital-fabric/affect

He has great taste!

comment 5y ago · link · parent

Does anyone know of if the issues brought up by njs in this thread still apply? https://trio.discourse.group/t/structured-concurrency-in-rub...

comment 5y ago · link · parent

> the last time I did html we were still using tables

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:

https://flexboxfroggy.com

https://cssgridgarden.com

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

Preferably you'd preserve the best aspect of StackOverflow; others being able to learn from others questions. I don't know what the best way to achieve that would be. Recording the sessions and making them public would probably be uncomfortable on both sides. Perhaps incentivize the expert to do a short write-up on the problem and solution in some way.

comment 5y ago · link · parent

I'm optimistic that this will be less painful as more of the Python ecosystem becomes async-friendly. We have `aiohttp` as a suitable replacement for `requests`, and major libraries like Django (not ORM yet), Flask, FastAPI, SQLAlchemy now have async support as well.

comment 5y ago · link · parent

Yeah, it's unclear to me whether you'd have to "join" to get the result from an operation, or if you can have some form of "await" expression
123