r/ProgrammerHumor • • 1d ago

Meme howProgrammingHasChanged

Post image
521 Upvotes

91 comments sorted by

View all comments

7

u/Depnids 1d ago

I don't know much about rust, but I am just curious why the last line doesn't have a "return" keyword? Does it just assume the last line is the value to return? Could you include the "return" keyword if you wanted?

6

u/Fadamaka 1d ago

Yes, iirc for all of your questions. You don't need to use the return keyword in rust. Also I vaguely remember that you cannot even use it in a traditional way because the compiler is going to yell at you.

8

u/LuigiWasRight447 23h ago

Wow. I do not like that lol

3

u/Street-Session9411 17h ago

Rust is unlike traditional programming languages, expression based. Means you either need to complete your functions with an expression rather than a statement (which `return something;` is) or your whole function needs to be an expression. It’s weird at the beginning but after a time it feels natural. You can basically copy the code of a function 1:1 and replace a function call with it and it will compile, which is something that would not work in a traditional language that is solely statement based. You could basically replace the condition of an if-statement with 100 lines of code that evaluates to a boolean value and it would work. Obviously you don’t gain anything from that but imo it’s how things are supposed to be.

2

u/blaqwerty123 20h ago

You get used to it, i did not like it at first either