The Artima Developer Community
Sponsored Link

Weblogs Forum
Scala, Patterns and The Perl Effect

18 replies on 2 pages. Most recent reply: Nov 28, 2012 7:19 AM by philippos papadatos

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 18 replies on 2 pages [ « | 1 2 ]
Trond Olsen

Posts: 14
Nickname: tolsen
Registered: Mar, 2007

Re: Scala, Patterns and The Perl Effect Posted: Dec 25, 2011 9:55 AM
Reply to this message Reply
Advertisement
Further extending the example with a catch-all clause:

val f4: PartialFunction[Any,String] = {
case _ => "undefined"
}
// f4: PartialFunction[Any,String] = <function1>

val f5 = f3 orElse f4
// f5: PartialFunction[Any,String] = <function1>

f5("a")
// res3: String = undefined

Channing Walton

Posts: 32
Nickname: channing
Registered: May, 2003

Re: Scala, Patterns and The Perl Effect Posted: Dec 30, 2011 6:41 PM
Reply to this message Reply
Here is a another simple, concrete example.

val root:PartialFunction[Int, Double] = {
case x if x >=0 => math.sqrt(x)
}

val printIt:PartialFunction[Int, String] = { case i => "Root(" + i + ")"}

val roots = root orElse printIt

(-3 to 3) map (roots(_))
= Vector(Root(-3), Root(-2), Root(-1), 0.0, 1.0, 1.4142135623730951, 1.7320508075688772)

philippos papadatos

Posts: 6
Nickname: firesoft
Registered: Mar, 2012

Re: Scala, Patterns and The Perl Effect Posted: Mar 28, 2012 10:02 PM
Reply to this message Reply
I’m in the process of evaluating scala for a new project.
The Perl effect indeed! I had a look at scala's website and i downloaded the free ebook.
I don't know about you but for me it feels like common best practices in Scala introduce very cryptic syntax in order to produce one liners. I don't see the value in that , I rather keep my code base stupidly simple, rather to reduce LOC, which at a glance can make sense rather spend 1-2 minutes figuring out what each line do.
Where is the productivity of scala then is it all hype ?
I don't know about you but i almost never write a component once and move on, i almost always revisit the code and make improvements- modifications. I feel with scala if i revisit a part of my code base say after a few months it will take me a long time to figure out what i was doing then!
I mainly use java & python and i don't see the benefits of Scala. If i need functional - dynamic features i use python and the combination of java + jython is very appealing to me.

Any suggestions on what Scala brings to the table?

philippos papadatos

Posts: 6
Nickname: firesoft
Registered: Mar, 2012

Re: Scala, Patterns and The Perl Effect Posted: Nov 28, 2012 7:19 AM
Reply to this message Reply
well upon further investigation Scala is very interesting and complex ! if choose to make it complex...

Flat View: This topic has 18 replies on 2 pages [ « | 1  2 ]
Topic: In Defense of Pattern Matching Previous Topic   Next Topic Topic: Service Locator Pattern Revisited, Part 2


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2013 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us