Lucy :3
link
fedilink
52M

Does that random ‘true’ at the end of the function have any purpose? Idk that weird ass language well

Maven (famous)
creator
link
fedilink
142M

It’s the default return. In rust a value without a ; at the end is returned.

Lucy :3
link
fedilink
-72M

That honestly feels like a random, implicit thing a very shallow-thought-through esolang would do …

Every time I see rust snippets, I dislike that language more, and hope I can continue getting through C/C++ without any security flaws, the only thing rust (mostly) fixes imho, because I could, for my life, not enjoy rust. I’d rather go and collect bottles (in real life) then.

xigoi
link
fedilink
English
132M

A lot of languages have this feature. Including ML, which is where Rust took many concepts from.

Ephera
link
fedilink
English
4
edit-2
2M

That honestly feels like a random, implicit thing a very shallow-thought-through esolang would do …

Nope, you’re far from the truth there. Most functional programming languages have this feature, but it’s also definitely not shallowly-thought-through, as it’s essentially an extension of how maths works.

Basically, in most cases when you see braces { } (excluding things like for-loops and imports), you can think of them as an expression, where the whole brace-scope will evaluate to just one value, similar to how “3+5” evaluates to a value. That one value is this last value at the end of the brace-scope.

So, to give a very simple example:
{ 3 + 5 } / 4 evaluates to
{ 8 } / 4, so then the whole brace scope evaluates, which gives us
8 / 4 and that’s then
2.

In maths notation, you know that as (3+5)/4, with parentheses instead of braces.
Within this simple example, they do the exact same thing (and Rust does also allow you to use parentheses for this purpose).

Where braces and parentheses differ, is that braces allow you to write multiple statements within them, so in theory, you could do:

{
    let x = 3;
    x + 5
} / 4

Obviously, this is where this simple maths example largely stops making sense, but in real-world programming, there’s a lot of use-cases for this.

It does take some getting-used-to, when you’re coming from hardcore procedural languages like C/C++, but yeah, it’s really not new for anyone who knows maths.

worst take of the week

Create a post

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.
  • 1 user online
  • 79 users / day
  • 166 users / week
  • 604 users / month
  • 2.27K users / 6 months
  • 1 subscriber
  • 1.66K Posts
  • 36.6K Comments
  • Modlog