this post was submitted on 11 Jun 2024
231 points (96.8% liked)

Programmer Humor

19589 readers
467 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] anton@lemmy.blahaj.zone 6 points 5 months ago (2 children)

Instead of

if let Some(a_) = a{
    ()
} else if let Some(b_)=b{
    ()
} else {
    dostuff 
}

you could just use

if a.isNone()&&b.isNone(){
    dostuff
}

Also if you don't use the value in a match just use _

[–] jimitsoni18@lemmy.zip 4 points 5 months ago (1 children)

Also you can use enums insteas of string literals

[–] Thelie@sh.itjust.works 1 points 5 months ago (1 children)

I'm not sure how I would go about this in an elegant way since I'm matching the string I get from a message…

[–] jimitsoni18@lemmy.zip 1 points 4 months ago (1 children)

If the message used enums for actions/procedures like SPAM_MEMES, then using enums would be more performant

[–] Thelie@sh.itjust.works 2 points 4 months ago

I think you'd be happy to know that I've gone for a bit of an overkill and used Pest to parse the commands, which automagically gets me an enum to match against in this position.

The sad part is, I haven't gotten the Media upload to work, so the project is on ice for a little while…

[–] Thelie@sh.itjust.works 2 points 5 months ago

That's a good point, thanks. Maybe I'll go without the if entirely, the (janky) code is still very much in flux ;)