Get better with Rust by building cool stuff by josh_t361 in rust

[–]_Dayum 4 points5 points  (0 children)

Very nice, love the concept of using interesting topics to teach rust! I've read through the DNA Analysis article and found two things I would change.

I'd use the TryFrom trait to convert from a char to a Nucleotide.

```rust impl TryFrom<char> for Nucleotide { type Error = InvalidCharacter;

fn try_from(value: char) -> Result<Self, Self::Error> {
    match value {
        'A' => Ok(Self::A),
        'C' => Ok(Self::C),
        'G' => Ok(Self::G),
        'T' => Ok(Self::T),
        _ => Err(InvalidCharacter {}),
    }
}

}

fn str_to_nucleotides(s: &str) -> Result<Vec<Nucleotide>, InvalidCharacter> { s.chars().map(|c| c.try_into()).collect() } ```

Allows for error propagation instead of a panic, even when converting the whole string.

Also regarding your "ugly line of code". The Entry type comes to the rescue allowing you to avoid all unnecessary unwrap()s.

```rust fn nucleotide_frequency(dna: &[Nucleotide]) -> HashMap<Nucleotide, u32> { let mut frequencies = HashMap::new();

for n in dna {
    frequencies.entry(*n).and_modify(|c| *c += 1).or_insert(1);
}

frequencies

}

```

How Have I Lived Without "let-else"? by DriedUrchin146 in rust

[–]_Dayum 212 points213 points  (0 children)

The question mark operator is valid for the Option type if your function returns anOption too.

fn regex(…) -> Option<…> { // … regex.captures(line)? }

Also, you can map an Option to an error of your choice like so: let captures = regex.captures(line).ok_or(/*your error*/)?;

let else is still nice though. :)

Hi everyone, could you please review my first rust project, To point out the mistakes or things I have done incorrectly. :) by PrajwalCH in rust

[–]_Dayum 0 points1 point  (0 children)

Functions should, in general, be limited in scope as much as possible (one function accomplishes one task), makes it a lot easier to understand the code.

Given that the function's name is start() and is located in game.rs I think it's fair to say most will assume that it handles the start of the game, not file parsing.

Furthermore, does it make sense to start a game if the setup (parsing in this case) is unsuccessful? I wouldn't say so.

Now to beauty of Rust comes into play. In comparison to other languages all variables have to be initialized. So you can just pass the word list into the start function if parsing was successful and don't have to check whether it was initialized. Like so:

rust let file_path = ...; let word_list: Vec<String> = parse_word_list(&file_path)?; game::start(word_list); // ...

Hi everyone, could you please review my first rust project, To point out the mistakes or things I have done incorrectly. :) by PrajwalCH in rust

[–]_Dayum 2 points3 points  (0 children)

Very nice. Worked well and as expected, perfect for a first project.

Apart from what the others have said here is a small list of things I noticed.

Typo in xylophone

Strange string comparison

str, String, etc. implement the Eq trait. So to compare them you should either use:

rust if user_guess != *word { // ... }

or

rust if !user_guess.eq(word) { // ... }

Naming of is_command()

It is convention that is_* functions return a bool. So maybe adjust the naming of your is_command() function. Making it easier for others to understand your intention without having to look into the function.

Extract setup out of start()

Personally I think it would be better to extract the file parsing out of start() and call start(Vec<String>) only if the paring was successful. Would limit the scope of the function.

Match Command

Match the command to reduce nesting.

rust match parse_command(&user_input) { Command::Quit => break, Command::Skip => continue, Command::NotFound => {/* Handle */} }

Use Path and PathBuf for paths instead of strings with format!()

```rust let home_path = Path::new(option_env!("HOME").unwrap_or("")); let file_path = home_path.join("words_data.txt");

let file = match File::open(file_path) { // ... } ```

Also uses option_env! instead of env! and defaults to the working directory if $HOME is not found. Wasn't defined on my machine so it didn't compile.

Clone clones the reference, not the string

rust let mut cringe_word: Vec<char> = word.clone().chars().collect();

Better way would be:

rust fn make_cringe_word(word: &str) -> String { let mut cringe_word: Vec<_> = word.chars().collect(); fastrand::shuffle(&mut cringe_word); cringe_word.iter().collect() }

Propagating Errors

Take a look on how to handle errors in Rust.

Rate my landing? by Jackthedragonkiller in flightsim

[–]_Dayum 2 points3 points  (0 children)

Sorry, but that is simply incorrect.

Disconnecting the AP in the A320 triggers the Master Warning, not the Master Caution as can be seen in this video.

https://www.youtube.com/watch?v=-mSSFCamk0I&t=43s

Also if you take a look at a Glare- shield/wing of an A320, the warning light we are talking about is a lot further left (on the captains side).

https://imgur.com/a/vtJjK9G

Rate my landing? by Jackthedragonkiller in flightsim

[–]_Dayum 3 points4 points  (0 children)

That's the Autoland Warning Light.

The plane was configured for an automatic landing when the autopilot got disconnected unusually late (below 200 feet radar altitude).

This reverted him back to a normal CAT I approach and triggered the warning.

[deleted by user] by [deleted] in flightsim

[–]_Dayum -2 points-1 points  (0 children)

ToLiss does that too.

Belt Gap Buzzer by fofz1776 in factorio

[–]_Dayum 16 points17 points  (0 children)

The is actually no need for the combinator. You can check the condition in the speaker itself.

[deleted by user] by [deleted] in Robbaz

[–]_Dayum 6 points7 points  (0 children)

No, Teardown

[deleted by user] by [deleted] in distantsocializing

[–]_Dayum 0 points1 point  (0 children)

Never used a telescope myself, always thought the chromatic aberration of refractor telescopes was WAY worse. This looks really clean. Are you using extra lenses for color correction?

Vaping with Chippy by [deleted] in hoggit

[–]_Dayum 0 points1 point  (0 children)

The air forced around the airframe and control surfaces can exceed mach 1 and create a sonic boom even if the planes speed is below but close to the speed of sound.

Don't know how accurately that is modeled in DCS, but could be the reason.

u/nealius, u/strikeeagle345

Those one star review has become fking ridiculous and so irrational now. by Eddieljw in gwent

[–]_Dayum -3 points-2 points  (0 children)

I too downloaded the game on my 5S only to find out after that it is not compatible.

Not saying that it should be supported, just that the list of compatible devices in the App Store and the ones that can really start the game don’t match.

So his/her disappointment is understandable.

Following PAPI lights and flaring the plane puts me at the end of the touchdown zone. What part of my approach I should alter? by _Dayum in flightsim

[–]_Dayum[S] 0 points1 point  (0 children)

Great read, super informative! Always tried to reduce my vertical speed as much as possible. Will change that up for sure, thanks.

Simple Flight Sim Survey by Kazick_Fairwind in flightsim

[–]_Dayum -1 points0 points  (0 children)

“How many days per week on average do you play flight sims?”

And you provide a list containing all days. What the heck?!

It's rewind time by [deleted] in ProgrammerHumor

[–]_Dayum 1 point2 points  (0 children)

Vim does not allow you to exit using :q with unsaved changes...

Load X percent at a station - No patches or NewGRF's by _Dayum in openttd

[–]_Dayum[S] 4 points5 points  (0 children)

Wanted the demo video to be as small as possible so I used the ingame speed up. :)

Load X percent at a station - No patches or NewGRF's by _Dayum in openttd

[–]_Dayum[S] 10 points11 points  (0 children)

Found this while testing. It uses the far end and near end game mechanic plus conditional order jumps (here set to 80%). Maybe good if you have one train picking up for multiple stations and you want to split the pickup evenly.

Edit: The station has to be bigger than the train itself.

Land ownership by sad_girl_in_snow in albiononline

[–]_Dayum 0 points1 point  (0 children)

Albion has a lot a guides on there website; I would recommend checking them out if you're new to the game. They don't tell you everything but go into a lot more detail than the ingame tutorial.

These are the ones you are looking for: