r/ProgrammerHumor • • Oct 13 '26

Meme howProgrammingHasChanged

Post image
676 Upvotes

108 comments sorted by

View all comments

Show parent comment

10

u/shizzy0 Oct 13 '26

Rust. Great language. Can be abused though.

9

u/no_brains101 Oct 13 '26

That is one of the most horrific fibonacci's I have ever seen.

12

u/shizzy0 Oct 13 '26

I’m sure a C++ template enthusiast has more delights to show you.

5

u/no_brains101 Oct 13 '26

I'm sure someone could make it more horrific in rust too, I just haven't seen it yet.

4

u/BastetFurry Oct 14 '26

Perl has entered the chat:

perl -E'$b=1;$b+=$a=$b-$a for 1..pop;say$a'

Execute with the n-th Fibonacci you want to get at the end, ie:

perl -E'$b=1;$b+=$a=$b-$a for 1..pop;say$a' 10
55

2

u/no_brains101 Oct 14 '26

I know 0 perl but this actually almost makes sense. Why is pop the end though what is pop, and IDK what say is, doesnt for do the for action for the thing? Do you really have to spell it out and then say it? And that compound assignment thing is wild. But I kinda see the fibonacci in this. If you asked me what this did, I would say fibonacci.

1

u/BastetFurry Oct 14 '26

The pop at the end hands back the last element of an array, without an argument it defaults to @_, an array given as the caller argument, which in this case is the command line. Perl is full of these shortcuts.

1

u/no_brains101 Oct 14 '26 edited Oct 14 '26

Oh I see. (and then say is just print?)

I don't see an array though, for just repeats until the end condition is met, storing in a and b, theres no array I don't think?

Edit: OH the array is the ARGUMENTS and pop is grabbing the last one.

2

u/BastetFurry Oct 14 '26

No array for the calculation, no.

Just abusing the fact that @_ contains all caller arguments. And calling the main "function" puts all command line arguments into that built-in array.

0

u/donaldhobson Oct 15 '26
fn fib(n:isize)->isize{
    if n<2{return n;}
    let mut c=0;
    for i in 0..1<<(n-2){
        if i&(i<<1)==0 {c+=1;}
    }
    c
}

4

u/Gaxyhs Oct 14 '26

that looks like what an IL for assembly would look like if assembly was made by oracle instead of java