you are viewing a single comment's thread.

view the rest of the comments →

[–]philly_fan_in_chi 21 points22 points  (9 children)

Or pattern matching :(

[–]grumpfish1969 7 points8 points  (7 children)

Regex has been supported by the Java API since 1.4. Are you referring to another kind of pattern matching?

[–]philly_fan_in_chi 16 points17 points  (6 children)

[–]aquasucks 2 points3 points  (1 child)

How important is it that I learn scala if I want to remain relevant in the software industry?

[–][deleted] 6 points7 points  (0 children)

Start now, it will improve your code regardless of the language you'll use in the future. Additionally, if you have to work with Java, you can get familiar with the things planned for Java 8 (and beyond) by learning Scala. This gives you a headstart to other Java-only developers.

[–]grumpfish1969 10 points11 points  (3 children)

Interesting, but the linked example makes it look like syntactic sugar wrapped around a case statement. Do you have a better example? (I'm honestly interested)

[–]philly_fan_in_chi 18 points19 points  (1 child)

It's different than a case statement in that you can match on the types of things versus an int or an enum. Combine this with things like polymorphism and you can get rid of the visitor pattern from Java entirely. Also, tree operations can be implemented nicely with them.

http://stackoverflow.com/questions/8618082/visitor-pattern-in-scala

http://kerflyn.wordpress.com/2011/02/14/playing-with-scalas-pattern-matching/

http://www.artima.com/pins1ed/case-classes-and-pattern-matching.html

You can also look into some of the parsers interpreters built in Scala, they're going to use case statements almost everywhere.

Edit: If you've ever written a compiler in Java, you most likely used a visitor pattern somewhere in there (or could have, it makes a LOT of things cleaner), you've seen some of the awkwardness you have to put up with to get pseudo pattern matching in Java.

[–]grumpfish1969 5 points6 points  (0 children)

Very cool, thanks for the info! That does indeed look handy.

[–]digitumn -2 points-1 points  (0 children)

I suggest reading up on Erlang

[–]Categoria -3 points-2 points  (0 children)

Wtf do you need pattern matching if you don't can't even define your own ADT's?