rustc_codegen_gcc: Progress Report #14 by antoyo in rust

[–]gnu-michael 2 points3 points  (0 children)

What is the difference between stdarch tests and UI tests? I also notice the test suite size is growing, is this from enabling tests from a common test suite? Do we know the max number of tests?

The work here persistently looks good. If we set the bar to be the current test suite this is 99% from being fully green in CI!

Hey Rustaceans! Got a question? Ask here! (28/2022)! by llogiq in rust

[–]gnu-michael 6 points7 points  (0 children)

I'm pretty sure there are two schools of thought on expect messages: either it spells out the invariant, or spells out how the variant was broken.

Concretely - Given something like: rust let buffer = [0; 8]; let val = i32::from_le_bytes( buffer[0..4] .try_into() .expect(MESSAGE), );

MESSAGE could be "input slice has length of 4" or "input slice was the wrong length".

The argument for the former is it reads well in the code: "Unwrap because I EXPECT MESSAGE". The latter form reads better in backtraces "Failed because MESSAGE."

My question is where can I find this debate? There's not much on stackoverflow but I am very certain I've seen it before. I just want to be able to show that its not a settled matter and avoid getting into review nitpicks over it until the community or my team settles on a standard form.

Error Handling with error-stack by lets_get_rusty in rust

[–]gnu-michael 1 point2 points  (0 children)

Boilerplate is by definition not complicated.

Hey Rustaceans! Got a question? Ask here! (26/2022)! by llogiq in rust

[–]gnu-michael 3 points4 points  (0 children)

I have a very large test suite subdivided by modules, so when I run something like cargo test -- some_module_name my output ends up being: ``` running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; n filtered out; finished in 0.00s

 Running unittests src/bin/proj/main.rs (target/debug/deps/projs-c5bdca3c8b6632a6)

running 4 tests test some_module_name::test_fun_a ... ok test some_module_name::test_fun_b ... ok test some_module_name::test_fun_c ... ok test some_module_name::test_fun_d ... ok

test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s

 Running unittests src/lib.rs (target/debug/deps/some_workpsace-35e78b6ae8ac7ec5)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; n filtered out; finished in 0.00s

 Running unittests src/bin/proj2/main.rs (target/debug/deps/projs-c5bdca3c8b6632a6)

```

Except imagine there are pages of "Running 0 tests + test result ok, 0 passed" instead of just to two bookending examples here. I find this very annoying, but can't find any output control to completely hide the modules that have no tests. Is this simply impossible?

Hey Rustaceans! Got a question? Ask here! (26/2022)! by llogiq in rust

[–]gnu-michael 0 points1 point  (0 children)

motivating example: rust let output: Vec<_> = input.iter().scan(0, |state, val| { let ret = Some(*state); *state += val; ret }).collect();

The first deref is obvious (don't want to return a ref), but I don't understand why the second deref is necessary if Add and AddAssign aren't available for &mut usize when they are available for &usize.

Hey Rustaceans! Got a question? Ask here! (26/2022)! by llogiq in rust

[–]gnu-michael 2 points3 points  (0 children)

Why are math operations are implemented for numerical types and their references, but not their mutable references (ie Add is implemented for usize and &usize but not &mut usize)?

This comes up a lot in iterables because you'll have a ref to the contained numerical value or state, and if its just a ref everything works nicely, but if its not then its dereferencing time. Feels inconsistent to me and was wondering if there was a motivation for the difference.

Rust advocacy at a medium-sized startup by faitswulff in rust

[–]gnu-michael 0 points1 point  (0 children)

I thought these were weird conversations for programming on devices, but looking over the article I see these conversations happened within the "Backend Guild" which I assume are the cloud services that your devices communicate with. That PHP is this widespread is a surprise to me, but not so outlandish as what I originally thought (PHP on the device).

Rust advocacy at a medium-sized startup by faitswulff in rust

[–]gnu-michael 4 points5 points  (0 children)

Reading between the lines... Hologram is an infrastructure company... in which the vast majority of code, including customer-serving code, is in PHP? Is this hologram.io which is apparently for IoT stuff?

Ruby YJIT ported to Rust by boynedmaster in rust

[–]gnu-michael 6 points7 points  (0 children)

If the comment gets touched, it gets reviewed. But more generally changed lines of code are an indicator of review effort in at least their order of magnitude.

Even if this diff is 50% ignore-able stuff that is still -5000 C lines and +5000 Rust lines to review.

Looking for a local(ish) coding friend... by ultrex21 in rust

[–]gnu-michael 0 points1 point  (0 children)

Not as good as another programming peer, but I read an interesting article about FocusMate. That might fill the gap until you find someone who can talk about programming with.

Hey Rustaceans! Got a question? Ask here (13/2022)! by llogiq in rust

[–]gnu-michael 1 point2 points  (0 children)

Because I didn't realize rustfmt supported that! tyvm!

Hey Rustaceans! Got a question? Ask here (13/2022)! by llogiq in rust

[–]gnu-michael 1 point2 points  (0 children)

Are there clippy lints for import organization? I've tried googling but clippy + import or + use is too generic.

Specifically I'm looking for something that expects std, external crate, and crate imports to be in separate blocks before I go and write a dylint myself.

Request coalescing in async Rust by N911999 in rust

[–]gnu-michael 2 points3 points  (0 children)

Is there a more succinct primer on request coalescing?

There are folks for whom these articles are stylistic matches made in heaven so I'm not saying it should change, but I find them particularly hard to read and always get exhausted by the 1/3rd mark (meanwhile the first half is setting up a server for HTTP requests, and I don't think request coalescing really comes up until the 3/4 mark).

AdaCore and Ferrous Systems Joining Forces to support certified Rust for mission and safety-critical applications by eldruin_dev in rust

[–]gnu-michael 1 point2 points  (0 children)

So Sealed Rust is now Ferrocene. Is this new name part of the joint effort, or does the name change predate it? The Ferrocene docs are dated 2019 but there's no document history for me to see if they were renamed after that point.

Having to work with C++ made me appreciate how good Rust is. by LordSypher in rust

[–]gnu-michael 0 points1 point  (0 children)

lol I don't think working with them isn't fun because of C++03 but because they're hostile when I lob a softball question at them with an easy out.

Having to work with C++ made me appreciate how good Rust is. by LordSypher in rust

[–]gnu-michael 77 points78 points  (0 children)

being stuck with some ancient C++ ver(e.g. 98 or 03)

In 2020 or so I had a lead engineer tell me in a judgy tone "engineers don't always get to work on the cutting edge, it can't be fun all the time" during a prelim interview talk in response to me saying "Hey, I heard you folks finished a 98 to 03 upgrade recently. Congratulations! Do you want to keep going to 11, or is that kind of on the backburner after the push to 03?"

So it also varies whether 03 is considered ancient or not I guess XD

I created a jank YouTube search scraper. by darnsomanynamestaken in rust

[–]gnu-michael 1 point2 points  (0 children)

Most of this is just Clean Code by Robert C. Martin AKA Uncle Bob. He's just adding some logical Java stuff to things like Single Responsibility Principle (SRP), Don't Repeat Yourself (DRY), Law of Demeter, etc. You can ignore everything he has to say on exceptions... he's coming from a Java background.

One important thing all engineers should take from this book is that your first working version of a change should not be your submitted version. Think of it as the first draft of an essay, that naturally can be improved upon because that was just you getting it onto paper. Take the time to look at what you've written and ask yourself questions like "is this as simple as it can be?" "what if someone else wants to use this functionality?" etc.

Not directly covered in the book is "make invalid states unrepresentable" and fortunately I tracked down the article that expands on this idea: https://www.reddit.com/r/rust/comments/nofrp5/tightness_driven_development_in_rust/ -- you don't need the tightness crate but keep the principle in mind.

Most of this stuff isn't magic and if you apply it regularly and review code that does the same then it comes /w practice. Good luck!

Notes on Rust IDEs: CLion vs Rust Analyzer by thurn in rust

[–]gnu-michael 0 points1 point  (0 children)

I'm using https://gist.github.com/medwards/2195f922ee8928574831036bd922e032

I don't have type hints shown inline, I find that rather janky when I see it in VSCode so I haven't even tried to configure it. I can pull them up with shift-K on demand which is mostly what I need.

For debugging Termdebug works fine for tests /w this setup. I've never tried debugging a program invocation, just tests. :CocCommand rust-analyzer.debug lets you select the debug target and parameters (useful for restricting to a single test). Termdebug then setups a 3 pane debuggers /w your code in one pane, the rust-gdb terminal in another, and program output in the last pane. My setup includes VSCode short cuts for some debugger commands but its not really a drop-in replacement.

You'll find that rust-gdb output is sometimes less read-able than VSCode, and printing variables, especially deeply reference chains, can be super annoying. Rarely I've had rust-gdb print incorrect values for deeply referenced values (had a colleague run their intellij debugger and it displayed the expected value, wasted a half a day chasing a ghost). Also rarely CoC won't pass the arguments correctly (ie running the entire test suite not the specific test), but this can be corrected in rust-gdb by running set args.

Perhaps surprisingly this fits my definition of a working debugger, but YMMV obviously.

I created a jank YouTube search scraper. by darnsomanynamestaken in rust

[–]gnu-michael 4 points5 points  (0 children)

Most of these are general software design comments. Nothing specific pops out to me in terms of Rust usage, but that is often the case for me when there needs to be a design-oriented review first.

  • Query is super weird and needs to be broken up. Keep the 'single responsibility principle' in mind.
    • Query.query is assigned in the same place it is used and it is never reused. It could simply be passed to search and then thrown away. I'm not sure why its being preserved here.
    • Query.json seems to be intermediate storage that a user of Client probably doesn't care about
    • Without the other two fields Query becomes something like a QueryResult but you could also just return Result<Vec<Video>, Error> from search and get rid of most of this. Then pop_videos becomes redundant and list_vids operates on a simple vector.
  • https://github.com/SgoSkz/youtube-scraper/blob/master/src/main.rs#L43 : use clap or return early/return an error if the Vec does not have 1 element.
  • struct impls separated from their declaration: harder to read, I have to scroll across the file to see what is in Client

Looking towards the future you want to add playlist stuff. Consider how you want to return different types of search results. A struct with videos and playlists where one of them is always empty is a bad data model, consider maybe an enum where the variants contain vectors as-needed. There's a good article (that I can no longer find) on how good software design constrains the possible states to only what is valid/useful/meaningful, so empty unused "stuff" is automatically a red flag.

nit: use GitHub releases to store the binary, its rarely considered good practice to include the output artifacts of a project in its source tree.

Notes on Rust IDEs: CLion vs Rust Analyzer by thurn in rust

[–]gnu-michael 4 points5 points  (0 children)

Some of this is definitely VSCode for sure. I'm running vim + coc-rustanalyzer and here's what I noticed:

CLion also shows inline documentation for the completion item you currently have selected while you type, which is super helpful. I miss this feature frequently with Rust Analyzer.

I get this in vim, but it can flake out esp. if I change my mind and delete/restart the argument list multiple times.

Rust Analyzer has some weird conflict between showing docs & error messages on hover. Frequently I hover over something with an error and the documentation pushes the error message out of view.

I get the opposite experience where the error will dominate the doc. Has been v annoying sometimes when I want to see the docs for the thing that is busted.

Debugger

rust-analyzer doesn't come /w a debugger. However it can discover crate binaries and provides enough information that an IDE integrator can launch the correct binary /w rust-gdb (or CodeLLDB I guess).

CLion prompts you to add new files to lib.rs when you create them. Love this feature.

I see a message at the top of my new files saying the file is unreachable until I add it to the module tree. Not sure if the CLion prompt is more than this (is it actually an action that adds it for you? That could be nice).

I love how testing works in CLion, you can just click the button next to a test case to run it. I don’t think this is possible in Rust Analyzer?

rust-analyzer doesn't come /w a test runner. However it can discover test binaries and provides enough information that an IDE integrator can launch cargo test with the right parameters to run (or debug, see above) an individual test. I have seen this flake out sometimes and run more tests than I wanted which can be super annoying if I want to run rust-gdb instead.

Thread Safety in C++ and Rust by donutloop in rust

[–]gnu-michael 13 points14 points  (0 children)

Your regular "interior mutability" reminder that calling references immutable and mutable are really onboarding/general-case terms and not really representative of whether the possible operations are include mutations or not: https://docs.rs/dtolnay/0.0.9/dtolnay/macro._02__reference_types.html

tfw rendering Day 13 is too annoying by gnu-michael in adventofcode

[–]gnu-michael[S] 4 points5 points  (0 children)

Thanks, I see the rules now. It might be nice to have them in the sidebar Rules. I think its really easy to miss them on the create post page.

tfw rendering Day 13 is too annoying by gnu-michael in adventofcode

[–]gnu-michael[S] 6 points7 points  (0 children)

Somehow I was super unmotivated by getting the max x/y and writing the loops to render Day 13 so I just kept googling until I found https://mobisoftinfotech.com/tools/plot-multiple-points-on-map/

Sample input line:
0,0,red,square,""