Y
HN Search
Hacker News Search
new
|
comments
|
top
|
jobs
Measter
searching PlanetScale…
1.
▲
2.
▲
3.
▲
4.
▲
5.
▲
6.
▲
11 ms
·
121.
▲
by
Measter
3y ago
That optimization isn't specific to Option, it works for any enum.
122.
▲
by
Measter
4y ago
Additionally, something that is forgotten now that structured programming won so hard, and so little assembly is hand-written, is that it's possible to return to different places. As in, in case A return to address F, but in case B r
123.
▲
by
Measter
4y ago
> Jai for example offers a special keyword, so the code is written one way (AOS) but the memory layout is converted into SOA. I believe Zig has a stdlib function that allows you to do this, and I'm pretty sure there's also a Ru
124.
▲
by
Measter
4y ago
In addition to what BurntSushi said, it's worth thinking of the interaction as `&mut T` allows unsynchronized mutation. Because it's guaranteed to be unique, nothing else in the program can access the data behind the referen
125.
▲
by
Measter
4y ago
I would disagree. Rust's borrow checker and other static analysis are more akin to the safety guards on a table saw. For 95% of situations they're just protect you by catching your mistakes, but there are times when the guard make
126.
▲
by
Measter
4y ago
I hate that (nightly) Rust lets you do this: #![feature(fn_traits)] #![feature(unboxed_closures)] struct If; impl<T, F, V> FnOnce<(bool, T, F)> for If where T: FnMut() -> V,
127.
▲
by
Measter
4y ago
That is actually valid Rust, and it works exactly as you said: https://play.rust-lang.org/?version=stable&mode=debug&editio...
128.
▲
by
Measter
4y ago
> [...] but I don't like how lifetime arguments are mixed with template arguments [...] It does make sense if you think of lifetimes as being part of a type system. Almost all lifetimes are generic (aside from 'static), so it k
129.
▲
by
Measter
4y ago
It matters for two reasons I can see: * Is this function monomorphised for each type passed in or is the argument passed in as a trait object? If the latter, does it implicitly fall back to monomorpisation if the trait is not Object-safe(e.
130.
▲
by
Measter
4y ago
One thing you've missed here is that `let mut` is two different things: `let` is the keyword for creating a new binding, while `mut` is part of the pattern that `let` binds to. For example, you can pattern match a tuple and make one va
131.
▲
by
Measter
4y ago
> rust The first break in this bootstrap chain is mrustc, which is 11 stable versions back. Hope you've got a couple days if you need the latest stable release of rustc.
132.
▲
by
Measter
4y ago
> Opening a file is often done in creation, and `file:5` is a perfectly valid filename, so it's a bit debatable for a default. It gets even more fun on Windows! Giving a filename of `foo:5` can result in a file called `foo` with an
133.
▲
by
Measter
4y ago
You have to use the `-g` command line option: `code -g <file>:<line>`
134.
▲
by
Measter
4y ago
> The trouble with explicit casting is if the code is refactored to change the underlying integer type, the explicit casts may silently truncate the integer, introducing bugs. That depends on how the casting is provided. For the C-style
135.
▲
by
Measter
4y ago
But that logic falls apart with languages such as Rust, where a lot of expressions start with a keyword.
136.
▲
by
Measter
4y ago
The borrow checker does allow that, though, as long the uses don't interleave and the references created correctly. As long as `f` is not used between `a`'s creation and last use, and `a` comes from `f`, it's valid for that
137.
▲
by
Measter
4y ago
> Can you show me a "valid program" that Rust rejects? #[derive(Debug)] struct Foo { a: i32 } fn thing(foo: &mut Foo) { match foo { f @ Foo { a } if *a > 5 => {
138.
▲
by
Measter
4y ago
I also used Rust, though I only went up to chapter 21 in Part 2. I completely skipped the basic data structure implementations. I had no interest in implementing basic stuff like vectors and hashmaps, because it's not relevant to the p
139.
▲
by
Measter
4y ago
I can't compare with Java, but I can for C#. With Rust I find that I have much more confidence that I understand what the code is doing primarily due to the borrow checker and how Rust enforces unique vs shared access vs ownership. Jus
140.
▲
by
Measter
4y ago
Another alternative would be the use of a string interner, with the tokens storing the interner ID. Advantages would be that the token type can stay small and Copy, while not having a lifetime to carry around. Disadvantages would be the ove
141.
▲
by
Measter
4y ago
I ran into a borrow check error on code like this[0]: enum Inner { A(i32), B(i32) } enum Outer { Foo{ field: Inner } } fn do_foo(val: &mut Outer) { matc
142.
▲
by
Measter
5y ago
I do the same as drstewart, because there's nothing I can realistically do, and getting myself worked up will only make my life worse. And to answer your assertion, I live within 5km of the largest naval port in western Europe, which i
143.
▲
by
Measter
5y ago
As I recall, it wasn't just that unsafe was being used, plenty of libraries use unsafe, but that there were multiple examples of unsafe being used with provable soundness issues when it was possible to do the same with safe code and no
144.
▲
by
Measter
5y ago
I've not kept up with C#, but does it have something akin to Rust's string continuation? In a Rust string literal a backslash followed by a newline causes the backslash and all following whitespace to be removed. So, for example:
145.
▲
by
Measter
5y ago
Mine would be my DM42, which is a SwissMicros remake of the HP42. I do have a few others within reach, but I do like my RPN, so that's what I go for first. I'd love a mechanical calculator, though.
146.
▲
by
Measter
5y ago
Here's my experience with Windows 10's updating: Every now and then, when I shut the PC down for the night, it updates itself first. Sometimes it finishes up on bootup, delaying startup by a minute or so. That's it.
147.
▲
by
Measter
5y ago
The `write` function here comes from the `Write` trait[0]. This isn't the unbuffered write API, it's just the write API. What it's writing to could be a `File`, or it could be `StdOut` or a `Vec<u8>`. It also doesn'
148.
▲
by
Measter
5y ago
Not even calculators agree on this. Here's a picture of my Casio fx-83ES and fx-83GT calculators giving different answers to "8/2(2+2)": https://i.imgur.com/SsKUQrE.jpg Both answers are completely, 100%
149.
▲
by
Measter
5y ago
The most common issues are with ownership, lifetimes, and the borrow checker. If the person is an experienced C or C++ programmer they'll probably have an easier time as you need some understanding of ownership and lifetimes to correct
150.
▲
by
Measter
5y ago
I've been thinking along similar lines for a little while. For me, it's not about mutation, but unrestricted mutation. When a unique reference (&mut T) exists then the only possible way to even look at the data is through th
More ›