this post was submitted on 17 Dec 2025
429 points (96.7% liked)

Programmer Humor

27920 readers
1657 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 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] asdfasdfasdf@lemmy.world 39 points 1 day ago (1 children)

Hard disagree. Super beautiful.

[–] 30p87@feddit.org -2 points 21 hours ago (4 children)

Average Rust code:

macro_rules! sum {
    ( $initial:expr $(, $expr:expr )* $(,)? ) => {
        $initial $(+ $expr)*
    }
}

fn remove_prefix<'a>(mut original: &'a str, prefix: &str) -> &'a str

let mut up = 1;
    'outer: loop {

Hell I don't want to know what you define as ugly then.

[–] asdfasdfasdf@lemmy.world 18 points 19 hours ago* (last edited 17 hours ago) (2 children)
  1. Macro syntax technically isn't even Rust
  2. This is definitely not average Rust code.
[–] tatterdemalion@programming.dev 1 points 5 hours ago (1 children)

Sorry, I love Rust but I can't really agree with you here. They only showed a macro_rules! definition, which is definitely rust syntax. Lifetime annotations are relatively common.

I will concede that loop labels are incredibly rare though.

[–] fruitcantfly@programming.dev 1 points 4 hours ago

Loop labels are rare, but they lead to much simpler/clearer code when you need them. Consider how you would implement this kind of loop in a language without loop variables:

'outer: while (...) {
    'inner: while (...) {
        if (...) {
            // this breaks out of the outer loop, not just the inner loop
            break 'outer;
        }
    }

    // some code here
}

In C/C++ you'd need to do something like

bool condition = false;
while (...) {
    while (...) {
        if (...) {
            condition = true;
            break;
        }
    }
    if (condition) {
        break;
    }

    // some code here
}

Personally, I wouldn't call it ugly, either, but that's mostly a matter of taste

[–] wewbull@feddit.uk -3 points 16 hours ago (1 children)

What language are they then? They're not Python, JS,

[–] calcopiritus@lemmy.world 5 points 10 hours ago

You used macro_rules, which is not common at all. Most rust files don't contain any macro definition.

This code doesn't even compile. There is a random function definition, and then there are loose statements not inside any code block.

The loop is also annotated, which is not common at all, and when loops are annotated it's a blessing for readability. Additionally, the loop (+annotation) is indented for some reason.

And the loop doesn't contain any codeblock. Just an opening bracket.

Also, the function definition contains a lifetime annotation. While they are not uncommon, I wouldn't say the average rust function contains them. Of course their frequency changes a lot depending on context, but in my experience most functions I write/read don't have lifetime annotations at all.

Yes, what you wrote somewhat resembles rust. But it is in no way average rust code.

[–] flamingo_pinyata@sopuli.xyz 17 points 19 hours ago

I don't know if anyone would argue Rust macros are beautiful. If someone does they should be checked out by a doctor.
Speaking as a fan of Rust.

[–] ronigami@lemmy.world 1 points 8 hours ago

Brainfuck Cobol Perl

for a start

Definitely not your average Rust code, more like a very ugly example of it.

Also, as the syntax first put me off as well, I gave it a chance years afterwards, and have now (or rather years ago) officially joined the church of Rust evangelism.

A lot of the syntax you define as ugly makes sense when you learn it, it's just so much more explicit than a more dynamic language, but that exactly saves your ass a lot (it did for me at the very least) (I don't mean macros, macros are ugly and should be avoided if possible)