Y
HN Search
Hacker News Search
new
|
comments
|
top
|
jobs
pansa2
searching PlanetScale…
1.
▲
2.
▲
3.
▲
4.
▲
5.
▲
6.
▲
18 ms
·
241.
▲
by
pansa2
2y ago
> Proposing syntax as noisy as […] is just another sign the designers don't get it. Are you objecting to the use of `\(…)` here instead of `{…}`? Because of the extra character or because of the need to nest parentheses?
242.
▲
by
pansa2
2y ago
> Readability counts Almost all Python programmers should be familiar with list comprehensions - this should be easy to understand: parts = [... if isinstance(item, Interpolation) else ... for item in template] Instead the exa
243.
▲
by
pansa2
2y ago
> Five years is a very long time in technology. But it's not a long time in the OP's field of science. Unfortunately despite a strong preference for Python in the scientific community, the language's design team seem to
244.
▲
by
pansa2
2y ago
I think for someone with a basic knowledge of both languages, the Ruby version is more understandable than the Python. It's a combination of basic Ruby features, whereas Python's `match` statement is much more obscure - it isn
245.
▲
by
pansa2
2y ago
The original code does the same! All the real work is inside `convert` and `format`, it just adds another layer of complexity on top. The ideal version has the same behaviour and shows that the extra complexity is unnecessary.
246.
▲
by
pansa2
2y ago
Yes there is, when it compiles source code to bytecode.
247.
▲
by
pansa2
2y ago
I don’t think I’ve ever used % formatting in Python - what makes it safer than `format`?
248.
▲
by
pansa2
2y ago
IMO it's much closer to the ideal way to write the function, which would be something like: fn stringify(item) => item.is_a(String) then item else item.value.convert(item.conversion).format(item.format_spec)
249.
▲
by
pansa2
2y ago
> I would still use pattern matching for branching and destructing, but I’d put it in a helper Yeah, using a helper function makes things much clearer. To be honest though, I'm not a huge fan of using either `isinstance` (which is
250.
▲
by
pansa2
2y ago
Ah, yes - good point!
251.
▲
by
pansa2
2y ago
> It’s starting to feel like a language designed by committee, which it basically is. That's exactly what it is. It's just that they use the word "council" instead of "committee".
252.
▲
by
pansa2
2y ago
IMO comprehensions like `[x**2 for x in range(4)]` would be better written as `[for x in range(4): x**2]`. That would make the mapping between a comprehension and the equivalent loop much clearer, especially once you use nested loops and&#x
253.
▲
by
pansa2
2y ago
Your example is interesting - `join`, a generator expression and a ternary, and Python requires us to write all of them inside-out. It's a shame we can't write that in a more natural order, something like: def f(template):
254.
▲
by
pansa2
2y ago
> This is how Python has always been. Nah, idiomatic Python always used to prefer comprehensions over explicit loops. This is just the `match` statement making code 3x longer than it needs to be.
255.
▲
by
pansa2
2y ago
Putting aside template strings themselves for the moment, I'm stunned by some of the code in this PEP. It's so verbose! For example, "Implementing f-strings with t-strings": def f(template: Template) -> str:
256.
▲
by
pansa2
2y ago
Recent versions of CPython do have an experimental JIT compiler. I'm not sure how widely-used it is, though. https://peps.python.org/pep-0744/
257.
▲
by
pansa2
2y ago
> most interpreted code uses a JIT native compiler at this point I suspect most JavaScript code is JIT-compiled - but most Python, Ruby etc is interpreted (via bytecode).
258.
▲
by
pansa2
2y ago
This isn't a "party trick" with `global`, it's a fundamental hole in the type system: class C: def __init__(self) -> None: self.i : int | list[int] = 0 def foo(self) -> None:
259.
▲
by
pansa2
2y ago
> not sure if these are checked at compile-time, run-time, or both It looks like Koto only checks types at run-time. That means its type annotations are essentially shorthand for something like Python's `if not isinstance(...): ra
260.
▲
by
pansa2
2y ago
It says Coffeescript and Moonscript influenced Koto's syntax, which is a little worrying. IMO those languages are a little too flexible and sail too close to ambiguity - very small changes to code can sometimes radically change its m
261.
▲
by
pansa2
2y ago
> It seems every scripting language does duck/dynamic typing (as far as I can tell this applies to Koto). It looks like Koto supports type hints - not sure if these are checked at compile-time, run-time, or both. > I don’t und
262.
▲
by
pansa2
2y ago
> However error case looks to be try catch which is a deal breaker Wren uses coroutines ("fibers") for error handling, which is unusual. But yes, ultimately it does seem to be equivalent to try-catch.
263.
▲
by
pansa2
2y ago
Wren is dynamically-typed, though
264.
▲
by
pansa2
2y ago
> parameters should be contravariant Always? In that case, do you know why Dart has a `covariant` keyword [0], which makes function parameters covariant? [0] https://dart.dev/language/type-system#covariant-keyword
265.
▲
by
pansa2
2y ago
> > For function parameters, doesn't it depend on how the parameter is used? > I don't think so, but maybe there's specific circumstances I don't know of? I don't know specific circumstances either, but
266.
▲
by
pansa2
2y ago
> So don't do this then? Don't do what? - Don't write unsound code? There's no way to know until you run the program and find out your `int` is actually a `list`. - Don't assume type annotations are correct? Th
267.
▲
by
pansa2
2y ago
> Whoa there - those are very different claims! I suspect that the stronger claim is true - but even the weaker claim would invalidate the article's statements that "existing programming languages have little or no subtyping&
268.
▲
by
pansa2
2y ago
> existing programming languages have little or no subtyping [...] If you remember the fad for Object Oriented Programming I was under the impression that even today, most code is written in an object-oriented style (or at least, writt
269.
▲
by
pansa2
2y ago
> function returns should be contravariant I'm not very familiar with these relations, but shouldn't function returns be covariant ? `String => Cat` is a subtype of `String => Animal`? > Function parameters should
270.
▲
by
pansa2
2y ago
> 100 = 3*4*...*50*50*...99 You can’t replace 2*100 with 50, it has to be 4*50. But there’s no reason you have to divide by 2 at all - why not replace 2*99 with 6*33?
More ›