← Home ← Back to /g/

Thread 105933435

21 posts 6 images /g/
Anonymous No.105933435 >>105933519 >>105933687 >>105933917 >>105933974 >>105935178 >>105935937
Dotted postfix match or non-dotted postfix match, in Rust and Scala
Rust proposal
https://github.com/rust-lang/rfcs/pull/3295

foo.bar().baz.match {
_ => {}
}


Scala optional dot
https://docs.scala-lang.org/scala3/book/control-structures.html#match-expressions-support-many-different-types-of-patterns

i match
case odd: Int if odd % 2 == 1 => "odd"
case even: Int if even % 2 == 0 => "even"
case _ => "not an integer"
match
case "even" => true
case _ => false


List(1, 2, 3)
.map(_ * 2)
.headOption
.match
case Some(value) => println(s"The head is: $value")
case None => println("The list is empty")


What is best, with or without dot?
Anonymous No.105933451
Why are Rustaceans like this?
Anonymous No.105933519
>>105933435 (OP)
even as a UFCS enjoyer, i hate the idea.
It's going to facilitate unmaintainable jungles.
Anonymous No.105933687
>>105933435 (OP)
Ehhh its kinda ok... ig

Feels more like a slop update that C# has been getting recently
Anonymous No.105933785 >>105933986 >>105936138
>sytax sugar
>shuffling the words around and removing one single character
I get the feeling that these anti-features only exist to make people who keep up with brand new features feel smarter than people who just prefer to use a simpler approach. Like features are voted on based on how they make you feel, not how useful they actually are.
Anonymous No.105933907
Just add the pipe operator already
Anonymous No.105933917
>>105933435 (OP)
nice good for nothing make work retardation
Anonymous No.105933974 >>105934154
>>105933435 (OP)
i saw that when it dropped (or maybe earlier, since it feels like it's been longer than 3 years).
it's a part of the larger "postfix keyword" pattern, with "await" serving as a floodgate opener (as mentioned in prior art).
it kind of makes sense. but then, if you do the same with "if", having the conditional before "if" is very awkward from a linguistical flow PoV, if you may.
but really, i'm getting old enough not to bother with syntax bikesheds anymore. i leave that to kids to endlessly debate.
Anonymous No.105933986 >>105934579
>>105933785
Anything to get your name in the papers.
Anonymous No.105934154
>>105933974
An if-expression in Rust is in reality a ternary operator when the else-branch is included.

if (condition) { (branch1) } [else { (branch2) } ]


Three operands (condition, branch1, branch2). Two operator tokens ignoring parenthesis ('if', 'else'). 'if' is prefix, 'else' is infix.

Making 'if' infix would look strange.

A popular opinion in the discussion is that if Rust had started out with only dotted postfix for 'match', it would be good. But, having both prefix and postfix (and one of them dotted) 'match', is somewhat bloated and not worth it, according to that opinion.

Also, Scala calls its syntax for 'match' infix instead of postfix. And Scala is right. How did Rustaceans confuse infix for postfix?
Anonymous No.105934579
>>105933986
Is that why a lot of Rust language development discussion moved to Zulip, and some heavily debated issues on Github were kept open but locked for new comments?

Who moderates the Rust Zulip forums?
Anonymous No.105935056 >>105935101
https://materialize.com/blog/rust-concurrency-bug-unbounded-channels/
https://media.defense.gov/2022/Nov/10/2003112742/-1/-1/0/CSI_SOFTWARE_MEMORY_SAFETY.PDF
https://bpb-us-e1.wpmucdn.com/sites.gatech.edu/dist/a/2878/files/2022/10/OSSI-Final-Report-3.pdf
https://archive.ph/uLiWX
https://archive.ph/rESxe
https://lkml.org/lkml/2025/2/6/1292
Anonymous No.105935063
Literally every rust coder has agp
Anonymous No.105935101 >>105935122
>>105935056
If rust is safe why is there a double free?
Anonymous No.105935122
>>105935101
Our findings underscore the critical importance of exhaustive CI, robust diagnostic tooling (e.g., ASAN, Valgrind, Miri), and adversarial stress testing.

In other words use C++ and trannyrust
Anonymous No.105935156
in C# this is just
foo.bar().baz switch {
_ => default
}
Anonymous No.105935178
>>105933435 (OP)
this is the stupidest shit i've seen all day it's literally the exact same amount of characters and the bottom one is objectively more readable
Anonymous No.105935937
>>105933435 (OP)
I don't know, I think I don't like this.

However, it would be interesting to have a language designed all around such postfix notation.
Anonymous No.105936138
>>105933785
>>shuffling the words around and removing one single character
You forgot that they are also adding one character. All it does is remove the necessity of the spacebar for the same amount of characters.
Anonymous No.105937162 >>105937268
How is that more readable?
Anonymous No.105937268
>>105937162
It makes more sense in context of long dot chains that are frequent in Rust.
So instead of
let temp1 = await foo.bar().baz();
let temp2 = temp1.bar();
let temp3 = match temp2 {
0..8 => foo2
x => x.bak()
}
let result = await temp3.bat()

You could do
let result =
foo
.bar()
.baz()
.await
.bar()
.match {
0..8 => foo2
x => x.bak()
}
.bat()
.await;