Can YOUR favorite language do this?

Can YOUR favorite language do this?

def goIdle(device: Device) = device match {
case p: Phone => p.screenOff
case c: Computer => c.screenSaverOn
}

Attached: 1200px-Scala-full-color.svg.png (1200x549, 37.22K)

Yes, erlang can pattern match and use function clauses.

>Putting the computer in screensaver instead of just turning it off.

For what purpose? Also, this language is ugly to look at. What do you like about it?

Attached: 1654334816269.png (497x754, 608.47K)

Sure
fn go_idle(device: &mut Device) {
match device {
Phone => device.screen_off(),
Computer => device.screen_saver_on()
}
}

>For what purpose? Also, this language is ugly to look at.
Pajeet, you need to go back bastard bitch sir

Oh wait, you have to use device = device.super; since Rust does not have struct inheritance.
You can also use trait specialization in idiomatic Rust.

what do you use Scala for?

Spark?

Java can do it too, try to shill some other feature.
interface Device {}
class Phone implements Device {}
class Computer implements Device {}

class Main {
public static void main(String[] args) {
Device device = new Phone(); // new Computer()
String result = switch (device) {
case Phone p -> "phone";
case Computer c -> "computer";
default -> "unknown";
};
System.out.println(result);
}
}

This language is even uglier than OPs.

I came to do the sneedful.

Attached: 1654164228956.png (1920x1080, 1.64M)

>what do you use Scala for?
Literally anything that requires gigascalability. The entire modern hyper available world is built on scala-related services

satania cute

That's cool. Is it hard to learn?

Give me a use case for me to use this language

Java blatantly copying features is kinda both hilarious and sad

Say what you want, but Java is and it will always be the main language for JVM. By "copying" feature it stays relevant and it makes your fancy new language worthless. Same reason why rust will never replace c++: languages are evolving, deal with it.

OOP was a mistake.

Attached: 1654414270476.jpg (1280x720, 123.45K)

>Is it hard to learn?
Not the hardest, but definitely a brainlet filter if you want to make full use of it.
>Give me a use case for me to use this language
Let's say you want to build a personal music server (like, a self-hosted google music or Spotify)
With most languages this will start to get a pain in the ass when you get to the actual "streaming music" part, not with Scala.

Idiomatic Rust would be to not check for the platform at runtime...
#[cfg(any(target_os = "android", target_os = "ios"))]
fn go_idle() {
screen_off()
}

#[cfg(not(any(target_os = "android", target_os = "ios")))]
fn go_idle() {
screen_saver_on()
}

That's not OOP, that's procedural programming written in a "block" named Main. The object-oriented solution would use dynamic dispatch which is much better
class Device { String name() { return "unknown"; } }
class Phone extends Device { String name() { return "phone"; } }
class Computer extends Device { String name() {return "computer"; } }

class Main {
public static void main(String[] args) {
Device device = new Phone(); // new Computer()
String result = device.name();
System.out.println(result);
}
}

so if you want a new type of device you don't have to touch anything, just add
class Tablet extends Device { String name() {return "tablet"; } }

and everything works, automatically.

Good job OOPtard, you just split up a simple function into four three files.

>With most languages this will start to get a pain in the ass when you get to the actual "streaming music" part
and why is that? C++ or Python can't handle that?

Not really. In java it works like that (if the class is public, otherwise you can do as you please) and regardless of the language that's a good practice for large projects. Many other languages that support the object-oriented paradigm have no such requirement. I picked java just to make OP feel stupid for thinking that scala is so much superior (it is neat to some degree, but not due to the feature shilled by OP).

>C++ or Python can't handle that?
C++ can, but it'll be an absolute pain in the ass to write instead of comfy coding with scala
Python? Lmao

I've been writing more Rust recently and most of the time I would just use dyn. I also used a lot of virtual in C++.

>lmao
?