Y
HN Search
Hacker News Search
new
|
comments
|
top
|
jobs
dbaupp
searching PlanetScale…
1.
▲
2.
▲
3.
▲
4.
▲
5.
▲
6.
▲
17 ms
·
151.
▲
by
dbaupp
7y ago
Ownership/affine typing does allow modelling that, within a single program. For instance, the type representing a handle to the external resource can have limited constructors and limited operations, that will enforce single threaded m
152.
▲
by
dbaupp
7y ago
There's a good argument to be made that Rust is safer in multithreaded scenarios than the JVM or .NET. Rust statically prevents inappropriate unsynchronized accesses for arbitrary APIs (for instance, the compiler will emit an error whe
153.
▲
by
dbaupp
7y ago
Speaking of performance and streams, it seems streams are not even byte streams: they are bit streams (rdb and wrb).
154.
▲
by
dbaupp
7y ago
That's close to one approach (generate a float in [1, 2) by setting the mantissa with a constant explonent of 1, and subtract 1), another is to generate a 32 or 64 bit integer and multiply by 2^-32 or 2^-64. I think both of these can g
155.
▲
by
dbaupp
7y ago
I'm not entirely sure how that relates to my comment... However, I think that approach is conceptually very similar to "FP Multiply" (using floating-point arithmetic) or "Integer Multiplication" (using fixed-point a
156.
▲
by
dbaupp
7y ago
Generating a random float always takes that into account: for instance, the samples will be less than 0.01 only 1% of the time. A method that just interpreted a uniformly random bit pattern (that is, integer) as a float would only be useful
157.
▲
by
dbaupp
7y ago
In N-bit unsigned arithmetic as we have here, -bound = 2 N - bound (and similarly for 32-bit) and the unsigned modulo operator "knows" that. In essence, that is a tricky way to compute 2 N % bound, to work-around not able to rep
158.
▲
by
dbaupp
7y ago
That results in many rejections when the inclusive limit is a power of two (or slightly larger). For instance, for [0, 4], one has to reject 38% of the time, and this gets closer to 50% as the limit increases. This requires doing more sampl
159.
▲
by
dbaupp
7y ago
I've got no idea. One would have to understand the code fairly deeply to tell that. For instance, are the volatile reads/writes meant to be atomic ones (which could be done safely) or are they truly volatile?
160.
▲
by
dbaupp
7y ago
Yeah, that's fair. I think there's a strong argument that bounds checking satisfies the "don't pay for what you don't use" rule (although one could say that every slicing having to carry around its length, doub
161.
▲
by
dbaupp
7y ago
Hm, I'm not sure I understand. I don't think I was the one to call bounds checking an abstraction in this thread.
162.
▲
by
dbaupp
7y ago
This is taking zero-cost abstraction to the extreme, and I think waters down the concept to the point that it almost isn't useful. One can argue that any feature is a zero-cost abstraction for the exact set of trade-offs it has (in the
163.
▲
by
dbaupp
7y ago
You're essentially right. The grandparent may be meaning that they're using a lot of raw pointers (which requires unsafe), and raw pointers means less aliasing information, and so less precise optimisations. This can affect bounds
164.
▲
by
dbaupp
7y ago
Rust allows multiple mutable non-overlapping slices. They cannot be constructed by direct array[i..j] slicing, but there is a variety of convenience functions for it. Sequential: https://doc.rust-lang.org/std/primitive.
165.
▲
by
dbaupp
7y ago
Swift takes this approach: monomorphisation is an implementation detail/optimisation. In languages like Rust and Swift where values don't have a uniform representation (that is, not always a pointer), this takes a lot of infastruc
166.
▲
by
dbaupp
7y ago
Python extras are pretty much equivalent to cargo "features": https://doc.rust-lang.org/cargo/reference/manifest.html#the-... The article mentions a few places that use cargo "features" for exa
167.
▲
by
dbaupp
7y ago
I think it is better to not think of ; (or lack of ;) as an "active" return: it isn't like the `return` keyword. If the last statement/expression in a block is an expression not followed by ;, the block evaluates to that
168.
▲
by
dbaupp
7y ago
Indeed, hence me saying "things that use {}" (like struct {} and trait {}), not "after {}". :)
169.
▲
by
dbaupp
7y ago
As others have said the principal is: no semicolons after things that use {}, semicolons after everything else.
170.
▲
by
dbaupp
7y ago
In my experience, Option/Optional/Maybe of a type T comes up a lot less than the type T itself. That is, needing "not a valid object" is a rarer than only requiring objects that are always valid. Those construction exact
171.
▲
by
dbaupp
7y ago
Another way to address that problem is to not default initialise at all. There's then no need to worry about a default value for pointers, or about NaN vs. 0.0 for floats. In addition, null doesn't always give a segfault, as I
172.
▲
Module Counts
(modulecounts.com)
2 points
by
dbaupp
7y ago
|
0 comments
173.
▲
by
dbaupp
7y ago
They have to go via the atomic types or it is undefined behaviour. One can use a very weak ordering (such as Relaxed) to require little or no "physical" synchronisation by the CPU. Like C++, Rust atomics offer a range of levels of
174.
▲
by
dbaupp
7y ago
Interior mutability via atomic values ( https://doc.rust-lang.org/std/sync/atomic/index.html ) works great for the first one, and, indeed, some sort of atomicity/synchronisation is required even in languag
175.
▲
by
dbaupp
7y ago
Tracing GCs usually don't have any recording of the number of pointers to a value.
176.
▲
by
dbaupp
7y ago
Rust traits are similar to features in many different languages: Swift protocols, Haskell type classes, Scala traits (when used as implicit evidence), even Go interfaces (in an approximate order from most to least similar). It's not th
177.
▲
by
dbaupp
7y ago
Yes, those value classes are still heap/GC allocated objects. Value types are a generalisation of `int`, `long`, `float` (etc), where values are stored inline, not allocated on the heap. For instance, a `Pair<long, double>` that
178.
▲
by
dbaupp
7y ago
The 'push -f' suggestion could instead recommend 'push --force-with-lease' to be less error prone in case one is accidentally pushing to a concurrently modified branch. Also, unless the diagram is confusing with the alig
179.
▲
by
dbaupp
7y ago
There is a useful distinction between "properties" and "functions" that appears in some languages: properties exist in memory and so can be addressed. This is particularly important for "systems"/low-level
180.
▲
by
dbaupp
7y ago
The lower value is of type &String because the argument to filter is of type &(String, String) and the pattern match needs to propagate the &. The reference is only valid for the body of the filter closure (that is, it is &&
More ›