Y
HN Search
Hacker News Search
new
|
comments
|
top
|
jobs
pansa2
searching PlanetScale…
1.
▲
2.
▲
3.
▲
4.
▲
5.
▲
6.
▲
21 ms
·
271.
▲
by
pansa2
2y ago
> using the wrong language IMO this is the source of much of the demand for type hints in Python. People don't want to write idiomatic Python, they want to write Java - but they're stuck using Python because of library availa
272.
▲
by
pansa2
2y ago
The type system itself is unsound. For example, this code passes `mypy --strict`, but prints `<class 'list'>` even though `bar` is annotated to return an `int`: i : int | list[int] = 0 def foo() -> None:
273.
▲
by
pansa2
2y ago
> The inverted pyramid is almost always the correct format for your text. Do you find this conflicts with "offering an interesting story that resonates with the reader"? For example: Using inverted pyramid to describe a problem
274.
▲
by
pansa2
2y ago
> Annotations can and should be checked Unfortunately Python’s type system is unsound. It’s possible to pass all the checks and yet still have a function annotated `int` that returns a `list`.
275.
▲
by
pansa2
2y ago
> I don't think it's "wrong" per se I do. I think it only makes sense for ranges to be inclusive at the lower end and exclusive at the higher end. A slice with a negative step `-n` should contain the same elements a
276.
▲
by
pansa2
2y ago
No, it doesn't, it prints ['D', 'C']. I agree that it should be ['C', 'B'] - the way that Python handles negative `step` values is wrong.
277.
▲
by
pansa2
2y ago
> Your visualization makes sense if you always count them going from left to right. Yes - personally, I do always count them left-to-right. I don't think negative indices implies counting right-to-left. A negative step does, but
278.
▲
by
pansa2
2y ago
From Roberto Ierusalimschy himself [0]: "one of the design goals, was for Lua to be easy for nonprogrammers to use" [1] https://www.reddit.com/r/lua/comments/w8wgqb/complete_interv...
279.
▲
by
pansa2
2y ago
No - negative indexing is fine as it is. You just need to be careful about the special case of negative zero.
280.
▲
by
pansa2
2y ago
> decades of programming languages choosing 0-based index is hard to ignore Yes - many file formats also work with zero-based indices, not to mention the hardware itself. One-based indexing is particularly problematic in Lua, because t
281.
▲
by
pansa2
2y ago
It makes more sense if you think of indices as pointing between elements: 0 1 2 3 4 ----------------- | A | B | C | D | ----------------- -4 -3 -2 -1 -0 Except, of course, -0 doesn't exist. AFAIK that&#
282.
▲
by
pansa2
2y ago
AFAIK "offset" (i.e. from the beginning of the array/file/etc) is commonly used to indicate a zero-based index.
283.
▲
by
pansa2
2y ago
Not quite seamlessly, unfortunately. `l[:n]` gives you the first `n` elements of the list `l`. Ideally `l[-n:]` would give you the last `n` elements - but that doesn't work when `n` is zero. I believe this is why C# introduced a sp
284.
▲
by
pansa2
2y ago
"Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration." — Stan Kelly-Bootle
285.
▲
by
pansa2
2y ago
But you'll be called things like "catastrophically unprofessional" [1] if you choose JavaScript over TypeScript, or dynamically-typed Python over MyPy. [1] https://www.reddit.com/r/Python/comments&#x
286.
▲
by
pansa2
2y ago
> C, Go, Python, and Lua are my go-to languages because of their simplicity One of these things is not like the others! Python's complexity has been increasing rapidly (e.g. walrus operator, match statement, increasingly baroque t
287.
▲
by
pansa2
2y ago
> simplicity of Python Python isn’t simple, it’s a very complex language. And Mojo aims to be a superset of Python - if it’s simple, that’s only because it’s incomplete.
288.
▲
by
pansa2
2y ago
> I was very surprised to see that the TypeScript team didn’t choose Rust Typescript is a Microsoft project, right? I’m surprised they didn’t choose C#.
289.
▲
by
pansa2
2y ago
`player` vs `players` etc.
290.
▲
by
pansa2
2y ago
This isn't about general substitutability though, just about naming constants. If you have `case 404:` and you add a named constant `NOT_FOUND = 404`, you can't change the code to `case NOT_FOUND:` because that completely changes
291.
▲
by
pansa2
2y ago
Yeah, it was added to tick the box for people who ask "does Python have pattern matching?" If you look at the feature in detail, and especially how it clashes with the rest of the language, it's awful. For example: https:&#x
292.
▲
by
pansa2
2y ago
Any examples? The biggest change since Guido stepped down has been the addition of pattern matching, which he was strongly in favour of. Moreover, Guido is in favour of ongoing addition of major new features (like pattern matching), worryin
293.
▲
by
pansa2
2y ago
There’s always PyPy - it’s much faster than CPython and, unlike Mojo, is ready to use today.
294.
▲
by
pansa2
2y ago
> Admire simplicity That would be nice. Instead we’re seeing all these JS/Python tools written in Rust - a complex language whose complexity comes providing memory safety without garbage collection. Their authors are deliberately
295.
▲
by
pansa2
2y ago
It’s eating Python too - with Ruff, uv, and an upcoming alternative to Mypy: https://bsky.app/profile/crmarsh.com/post/3lgvhzdfrps26
296.
▲
by
pansa2
2y ago
Fair point, I was specifically referring to the CPython interpreter. I don’t know if there’s a benchmark that compares PyPy to JIT-compiled Ruby.
297.
▲
by
pansa2
2y ago
Python. At least, it was a few years ago. Both languages have added JIT compilers since then, so I’m not sure how the most recent versions compare.
298.
▲
by
pansa2
2y ago
Wikipedia says it’s more common in physics, and we mostly used it in that context (e.g. fluid mechanics) rather than pure math. It was pronounced “veck”, IIRC.
299.
▲
by
pansa2
2y ago
IIRC at university-level we used the wedge symbol [0] for cross product - not sure how common that is. https://en.wikipedia.org/wiki/Wedge_(symbol)
300.
▲
by
pansa2
2y ago
> In Ruby, every object that is instantiated is represented internally by basically three things: > * A table of instance values > * A pointer to the class of the object, used for method lookup > * A pointer to a unique c
More ›