Y
HN Search
Hacker News Search
new
|
comments
|
top
|
jobs
dbaupp
searching PlanetScale…
1.
▲
2.
▲
3.
▲
4.
▲
5.
▲
6.
▲
46 ms
·
421.
▲
by
dbaupp
9y ago
One can look at Option<T> as an interface/base class that can be satisfied by a T or by (). Indeed, in Java-style languages, one occasionally sees implementations that have an Option abstract base class, with two subclasses, Some
422.
▲
by
dbaupp
9y ago
One example is something like enum A { B, C }: a function might have a precondition that it requires an A::B, and crashes/misbehaves when given an A::C. In Rust, this can be seen in Option::unwrap (requires a Some, panicking if given a
423.
▲
by
dbaupp
9y ago
And, most people can't : most places, only ~half the year will be cold enough to have snow/ice.
424.
▲
by
dbaupp
9y ago
The acronyms are different, but at runtime they're pretty much the same: the only difference is the Swift compiler inserts the clones that a Rust programmer has to do manually (that is, Swift retain/releases are atomic too).
425.
▲
by
dbaupp
9y ago
It won't when using architecture specific instructions like AVX512.
426.
▲
by
dbaupp
9y ago
The String and Vec objects live on the stack in the same way, but they contain pointers to heap data. I think the grandparent was trying to get at the fact that &str etc don't force things onto the heap nor do they keep things on t
427.
▲
by
dbaupp
9y ago
Rust's borrow checker makes writing to captured variables okay and safe, e.g. this is a bit unconventional, but it works: let mut sum = 0; (0..10).for_each(|i| sum += i); println!("{}", sum); // 45 Having
428.
▲
by
dbaupp
9y ago
> I'm not special at all, anyone living in a rural area ends up with a pickup You are special (i.e. part of the minority). Somewhere between 60 and 80% of people live in cities/urban areas in the US. As you said yourself, a tr
429.
▲
by
dbaupp
9y ago
When JS is a compiler target, that truck will generally only be used if the source language excludes all those edge cases, i.e. the value is guaranteed to be an integer.
430.
▲
by
dbaupp
9y ago
I don't think adding indirection is what the parent was thinking of. It's more like storing the Option<T> Some vs. None bit in its own separate bitvector along with a packed vector of Ts. This layout, due to padding, may be
431.
▲
by
dbaupp
9y ago
That's true, and does mean one has to drop down to C/C++-style pointers and manual layout when the default enums don't work. However, that's somewhat orthogonal to the semantics about what they can express, especially fo
432.
▲
by
dbaupp
9y ago
The cost being compared here is the 'if x.is_none()' or 'if x == null' check, not what happens after it.
433.
▲
by
dbaupp
9y ago
One can express the states more clearly with a slightly upgraded Option/Optional/Maybe, i.e. a full sum-type/enum. For instance, that function could be, in Rust syntax (but the same thing works in Haskell, OCaml, Swift, ...):
434.
▲
by
dbaupp
9y ago
I think in practice it isn't a higher cost: a lot of code in languages with nullable pointers also has a pile of unnecessary dynamic checks (e.g. checking arguments aren't null).
435.
▲
by
dbaupp
9y ago
Deallocating/RAII is not memory safety. Leaking all memory is, in fact, a tried-and-true way to get memory safety (GC'd languages are semantically doing this: GC is "just" an optimization), since it means problems like u
436.
▲
by
dbaupp
9y ago
My understanding is that the latest RFCes touching that syntax (not sure if they're implemented) have it overloaded with traits, and I would guess/hope that it's possible to implement those traits in a way that is fallible (e
437.
▲
by
dbaupp
9y ago
As the sibling says, catching panics isn't as reliable as Result for error handling, and, anyway, the parent was slightly wrong: the standard library types like Box and Vec abort on allocation failure, not panic.
438.
▲
by
dbaupp
9y ago
The allocation most built in to the language is https://doc.rust-lang.org/std/heap/trait.Alloc.html and that returns a Result. Some std APIs like Box and Vec do just panic/abort on allocation failure (althoug
439.
▲
by
dbaupp
9y ago
(You missed a zero: 8×16×2×200 = $51k.)
440.
▲
by
dbaupp
9y ago
And, similarly, what about vs. clang static-analyzer?
441.
▲
by
dbaupp
9y ago
http://gifpop.io/ does a pretty good job using lenticular printing.
442.
▲
by
dbaupp
9y ago
I do think it (optionally) provides a busybox-esque single-binary interface, but I do not know whether this also translates into a busybox-esque command-line interface.
443.
▲
by
dbaupp
9y ago
https://github.com/uutils/coreutils is a long way along.
444.
▲
by
dbaupp
9y ago
It is useful. I'm focusing on the effect on code generation: the compiler relies on that rule to deduce that x and y are not null. The special case for n==0 makes it harder for the compiler to deduce the non-null-ness and thus harder f
445.
▲
by
dbaupp
9y ago
The rule is memcpy(x, y, n) is undefined if x or y are null. Making it defined if n is zero is a special case inside that rule.
446.
▲
by
dbaupp
9y ago
You've phrased the result of the UB in a way that disguises the benefit: your complaint is adding a special case, and for an arbitrary memcpy(x, y, n) call, the compiler would have to provide it isn't in this special case (i.e.
447.
▲
by
dbaupp
9y ago
That's not my point. A general built-in checking scheme that handles all the variations of linked lists and trees will likely have to have quite a few nobs to tweak for the various trade-offs one might want to make, and will likely hav
448.
▲
by
dbaupp
9y ago
You've missed a far more fundamental question: how does this interact with aliasing XOR mutability? That's the core reason why back pointers are hard: they result in complicated relationships between things, in that an &mut po
449.
▲
by
dbaupp
9y ago
Do you have any thoughts on how it might even begin to be possible to do back pointers safely, in ways that don't already exist in Rust? I find it very confusing that you often complain about Rust's complexity, and then also compl
450.
▲
by
dbaupp
9y ago
They're on multilane, high-speed roads (meaning a bridge/tunnel or traffic lights are the only actually safe solutions).
More ›