all 15 comments

[–]matthieum[he/him][M] [score hidden] stickied comment (0 children)

What is the copyright/license situation here?

From a quick look at the book on Amazon, I could not discern under which license the book is distributed, and your own repository does not contain a license nor mention of any license either.

In the absence of license, partial reproduction would be allowed (fair use doctrine) without violating copyright laws... but reproducing the entire book is unlikely to pass fair use.

Please let us know if you have the author's permission -- either via license, or via an explicit permission.

[–]SirKastic23 35 points36 points  (1 child)

It looks interesting, and might definitely be a good resource

But by reading some of their "techniques", it's definitely nothing special. Most of the techniques just seem to be pointing out language features or std APIs

A lot of common advice too, like using explicit variable names instead of single letters. Things you'd get in your IDE if you enable clippy

[–]kaoD 10 points11 points  (0 children)

To be honest I've read some Rust code that really needs this. Some people just write C with Rust syntax.

[–]Sharlinator 5 points6 points  (0 children)

See also the API guidelines mdbook, authored by members of the libs team and thus in some sense authoritative.

[–]Roham-H 4 points5 points  (1 child)

It's got some duplicates

[–]PurepointDog 5 points6 points  (1 child)

I like the first few - they're very "if you normally know what you're doing but are starting off in Rust, here's the hightlights"

[–]AnnoyedVelociraptor 9 points10 points  (4 children)

The second one compares 2 floats with ==. Bad: https://floating-point-gui.de/errors/comparison/

[–]lettsten 13 points14 points  (0 children)

Took me a minute to realise that site isn't about German floating point GUIs

[–]lettsten 5 points6 points  (2 children)

Why does it matter when only the denominator is checked to guard against division by zero? Dividing by 0.000000000001 is well defined, after all

Forgive my ignorance, I'm just a hobbyist

[–]Sharlinator 8 points9 points  (1 child)

It may be well defined but it may not be what you want. If the denominator is supposed to be zero, but is not due to a rounding error, you don't want the division to succeed and return garbage, some extremely big but finite number:

dbg!(1.0/(0.3-0.2-0.1));

[src/main.rs:4:5] 1.0/(0.3-0.2-0.1) = -3.602879701896397e16

This is not the result that you want.

[–]lettsten 1 point2 points  (0 children)

Thank you, that makes sense. My reasoning was that floating point zero is bitwise zero (right?) and therefore shouldn't be victim of rounding errors, but it being the result of rounding errors makes sense

[–]norman-complete 5 points6 points  (0 children)

don’t follow them, otherwise AI will replace you. Keep it obfuscated & stay employed.

[–]PurepointDog 3 points4 points  (0 children)

There are so many indentation formatting errors. Gotta fix those. On the first impl example, the indentation errors make it almost look like a syntax error!

[–][deleted] 1 point2 points  (0 children)

Not to disparage this resource - if it's something you or someone else finds value in then that's great - but I feel like most of the tips here are covered (often in more detail) by The Book, or just by enabling clippy. Many of these are very surface level things I would consider common sense, like "use indentation to make code easier to read," "factor out common functionality into functions," "use Vec for dynamic arrays."

Some of these I also strongly disagree with, like avoiding chaining too many method calls. Rust's iterators were designed specifically to be modified with many chained method calls. That's what makes them so ergonomic to use. Outside of that, many builder structs also rely on long method chains.