background preloader

Scala 4

Facebook Twitter

Actors

Reflection. 2.8 text. Scala ends the Groovy fad. Looks like Groovy is going to loose its steam. Two reasons: tooling and governance. Tooling is a critical element as the code base and number of involved engineers increase. Refactoring in a single code base which involves a dynamic language and dozens or hundreds of engineers may lead to hairy situations. When you change a public library API in Java your tool will let you know where is the effected code, update the references for you and will let you know if a contract is getting broken. Tests should locate problems created by refactoring, but: Groovy engineers (and not only them) are sometimes too cool to do a 100% code test coverage.

Even a 100% test coverage can not guarantee that there are no bugs, it can only confirm that the test code didn't find bugs.Typical refactoring problem with Groovy might be changing Java code like: to: So if you have a method in your Groovy shopping chart that gets a productId and compares it to a local product id it will not break the code. Keeping Up Versus Settling Down. The last few days I have run across several pointers to Scala and Clojure, two dynamic languages that support functional programming style on the JVM. Whenever I run into a new programming language, I start thinking about how much time I should put into learning and using it.

If it is a functional language, I think a bit harder, and naturally wonder whether I should consider migrating my Programming Languages course from the venerable but now 30-plus-years-old Scheme to the new language. My time is finite and in scarce supply, so I have to choose wisely. If I try to chase every language thread that pops up everywhere, I'll end up completely lost and making no progress on anything important.

Choosing which threads to follow requires good professional judgment and, frankly, a lot of luck. Scala and Clojure have been on my radar for a while and, like books that receive multiple recommendations, are nearing critical mass for a deeper look. Lam is wise to think consciously of this now. Scala-tools. Two-Minutes Scala Rules Engine. Scala is really seductive. To drive my learning of this JVM programming language, I thought I should go beyond the obvious experiments and try to tackle a subject dear to my heart: building a general purpose rules engine. Of course, the implementation I am going to talk about here is naive and inefficient but the rules engine is just a pretext here: this is about Scala and how it shines.

And it is also a subset of what Scala is good at: I mainly scratch the surface by focusing on pattern matching and collections handling. The fact representation I use is the same than the one used by RuleML: a fact is a named relationship between predicates. For example, in "blue is the color of the sky", color is the relationship between blue and sky. The rules engine matches these facts on predefined patterns and infers new facts out of these matches. For rules, I opted to have them created as objects constrained by a particular trait: So how is the list of facts fed to the rule run method created? My Reasoned Response about Scala at Twitter. I'm glad that Twitter is working to resolve its scaling issues. It's a service that I love and use on a daily basis and from which I have benefitted immensely. As far as I'm concerned, Twitter is a case-study in how Ruby on Rails does scale, even in their hands.

Also, I know Alex Payne in person. Not very well, but enough that if I was in San Francisco and sat down to share a beer and discuss the Ruby/Scala debate, I imagine that it would be a fairly civil conversation. My interest in the question of Ruby vs. Who can disagree with the need for more reasoned technical discussion? First of all, my exchange with Alex last night, which I triggered by re-tweeting Jeremy McAnally: RT @jm: If you have to use kind_of? To which Alex responded: @obie Indeed, using kind_of? Hmm... @al3x Doesn't make sense.

To which Alex quickly replied: @obie Yes, I mean non-deterministic bugs in the giant, legacy, spaghetti parts of our system. Ah, suspicions confirmed. Most damning: What agenda? Dynamic method calls in Scala. Is Scala or Clojure poised for stardom? Is Scala, which was designed only a short while ago (comparatively speaking, that is) poised for stardom? Or will Clojure achieve greatness instead? There are a number of complementary aspects that seem to indicate for the time being that Scala might; however, what remains to be seen is if Scala can stand above recent newcomer Clojure. Both languages often show up together, especially when the topic of conversation is concurrency; nevertheless, each language is distinctly different. What’s interesting is how each language is starting to show up in various hip places. First, a recent CIO.com article entitled “6 Scripting Languages Your Developers Wish You’d Let Them Use” listed both Scala and Clojure. Scala might have a slight edge on Clojure when it comes to articles, however.

For instance, everyone’s friend Ted Neward has a series of articles on Scala on IBM’s developerWorks. What’s interesting is that both languages lack a killer application– yet, they are already on the map. . The Feel Of Scala. Scala vs Clojure. S-99: Ninety-Nine Scala Problems. These are an adaptation of the Ninety-Nine Prolog Problems written by Werner Hett at the Berne University of Applied Sciences in Berne, Switzerland. I (Phil Gold) have altered them to be more amenable to programming in Scala. Feedback is appreciated, particularly on anything marked TODO. The problems have different levels of difficulty.

Those marked with a single asterisk (*) are easy. If you have successfully solved the preceeding problems you should be able to solve them within a few (say 15) minutes. Problems marked with two asterisks (**) are of intermediate difficulty. Your goal should be to find the most elegant solution of the given problems. Solutions are available by clicking on the link at the beginning of the problem description. [I don't have example solutions to all of the problems yet. Working with lists In Scala, lists are objects of type List[A], where A can be any type. In many cases, there's more than one reasonable approach. P01 (*) Find the last element of a list. About "ScalaBison" By John Boyland and Daniel Spiewak Abstract ScalaBison is a parser generator accepting bison syntax and generating a parser in Scala.

The generated parser uses the idea of ``recursive ascent-descent parsing,'' that is, directly encoded generalized left-corner parsing. Of interest is that fact that the parser is generated from the LALR(1) tables created by bison, thus enabling extensions such as precedence to be handled implicitly. BibTeX Style Reference How to Get a Copy The article is available from ScienceDirect (Elsevier). Last Modified: January 7, 2012. Author Interview.

There are several good looking Scala books on their way to market. I'd like to help you get an early look at the books and their authors, so I'm working on a series of Scala author interviews for the FP side of On Ruby. Here's the second of several interviews. Programming Scala authors Dean Wampler (@deanwampler) and Alex Payne (@al3x) have been good enough to answer several questions for me in this interview. Functional Programming languages seem to be an increasingly popular topic. Why? What do FP languages teach or do for us? Alex FP forces you to think differently about solving problems in code, and in a highly structured way. Dean It seems that every "paradigm" that goes mainstream lurks in the background until some "killer app" comes along for which the paradigm seems tailor made. FP is a promising approach for concurrent programming because in pure FP, variables are immutable and functions have no side effects.

What makes Scala the right FP language for people to pick up? We don’t need anonymous inner classes? Bollocks to that. Robert Fischer over at enfranchisedmind.com has a post about anonymous inner classes which I am forced to disagree with quite strongly. He starts off with the example of a comparator, and shows that defining a lambda and then casting it to a Comparator is terser. I largely agree. I don’t agree with everything about that example, but it would be churlish to quibble over details. I concede the point: For one method anonymous inner classes, lambdas are better. He then attempts to generalise this to anonymous inner classes with multiple methods. Except he doesn’t really. This is an interesting point. We can define the following function (in some sort of pseudo syntax because I don’t know Groovy): defineClass("Kitten", { "meow" => () -> println("meow"), "play" => it -> ...

Hopefully it will be taken as uncontroversial that I don’t consider this to be the best idea I’ve ever heard. Class Kitten{ def meow = println("meow"); def play(it) = ... } So. Consider example the following implementation: Author Interview with David Pollak. There are several good looking Scala books on their way to market. I'd like to help you get an early look at the books and their authors, so I'm working on a series of Scala author interviews for the FP side of On Ruby.

Here's the first of several interviews. I've spent some time talking with David Pollak (@dpp) about his upcoming book from Apress, Beginning Scala (also available, electronicly, as an Alpha book from Apress). Read on to see what he has to say. Functional Programming languages seem to be an increasingly popular topic. David I came to Scala via Ruby. In Scala, passing a function, a block of code, as a parameter is as easy and syntactically pleasing as it is in Ruby (or nearly so... In addition to the simple ability to pass code blocks as parameters, other touch-stones of FP style coding are: Immutable data structuresPattern MatchingOptionally, a math-driven type systemOptionally, lazy evaluation Scala's default collections classes are immutable.

David: David A BDD Test: David. An introduction to the Scala programming language by Bill Venner. Search Subscribe to our feed: About The JAOO Community Blog is a blog for everyone interested in software development and for all participants in the JAOO-conferences. The blog will be dominated by the topics and questions raised at the JAOO conference in Aarhus, Brisbane and Sydney, the QCON conference in London and San Francisco and the Ruby conference in Copenhagen and Oslo.

All comments are greatly appreciated The JAOO show on blip.tv « Handling architecture in the agile world | Main | Sir Tony Hoare at QCon London 2009 » An introduction to the Scala programming language by Bill Venners By Therese Hansen | March 9, 2009 “Scala is, I think, the most mind-blowing language that I have seen in the last couple of years. Bill Venners, co-author of the Scala book, gave a nice introduction to the Scala programming Language at JAOO last year. Could Scala be your language of choice in the future? Iterating over Java Collections in Scala. Project Wallet (was: Why Bother? Just Use Scala!) How do you talk about Scala? I gave a talk about Scala at Last.fm last night (It’s not online: not on Last.fm. At. I physically walked over to their offices and gave the talk to some of their devs). Depending on how you look at it, it either went moderately well or was a complete disaster. People seemed interested, and went away knowing more about Scala than they came in with, so that part went well.

The big issue is that I never actually talked about the subject I went in prepared to talk about. Oops. I think part of the problem is that I aimed the talk at slightly too high a level. What happened instead was that we very quickly got diverted onto basic questions of syntax and semantics, and ended up touring Scala through the interpreter and performing a sort of general Q&A about it. But I feel the talk still sortof missed the mark. The traditional way to present Scala seems to be to present it as a better Java.

The biggest one is that the JVM is not short of languages which are better than Java. Explore Scala concurrency. In 2003, Herb Sutter exposed the industry's biggest "dirty little secret" with his "The Free Lunch Is Over" article, demonstrating clearly that the era of ever-faster processors was at an end, to be replaced by a new era of parallelism via "cores" (virtual CPUs) on a single chip. The revelation sent shockwaves through the programming community because getting thread-safe code correct has always remained, in theory if not in practice, the province of high-powered software developers way too expensive for your company to hire. A privileged few, it seemed, understood enough about Java's threading model and concurrency APIs and "synchronized" keyword to write code that both provided safety and throughput ... and most of those had learned it the hard way.

It is presumed that the rest of the industry was left to fend for itself, clearly not a desirable conclusion, at least not to the IT departments paying for that software being developed. Back-to-concurrency basics Listing 1. Listing 2. Interop Between Java and Scala. 9 Feb 2009 Sometimes, the simplest things are the most difficult to explain. Scala’s interoperability with Java is completely unparalleled, even including languages like Groovy which tout their tight integration with the JVM’s venerable standard-bearer. However, despite this fact, there is almost no documentation (aside from chapter 29 in Programming in Scala) which shows how this Scala/Java integration works and where it can be used. So while it may not be the most exciting or theoretically interesting topic, I have taken it upon myself to fill the gap. Classes are Classes The first piece of knowledge you need about Scala is that Scala classes are real JVM classes. …and the second in Scala: Despite the very different syntax, both of these snippets will produce almost identical bytecode when compiled.

…and from Java: In the case of either language, we can easily swap implementations of the Person class without making any changes to the call-site. Traits are Interfaces Operators are Methods. Criticizing programming languages. Here are snippets from two conversations I had recently: 20:03 < psnively> DRMacIver: I do think of you as taking a “Scala is one of the few languages worth criticizing” stance. llimllib @DRMacIver So by my count, you’ve been in public arguments over the quality of Scala, Java, Ruby, Lua, Haskell, and OCaml? Missing any? Psnively’s comment is of course patently untrue. I criticize all sorts of languages. Llimllib’s comment is much more close to home. All languages have problems with themThere are very few languages which don’t have something good about them as well So the first point gets me into arguments with the people who love the language, the second gets me into arguments with people who hate it.

So, just to piss everyone off, I figured I’d write a post about the different programming languages I have opinions on. Scala Good: Very interesting modularity featuresImplicit arguments are great. Bad: Haskell Ruby Java Ocaml Lua Python Javascript. Deeper Look at the Apply Method in Scala. Scala methods and closure. Interpreting Scala from Scala. Computational Linguistics and Me. The Scala Influence. Refactoring Scala Actors. Repeated Parameters and Initializing Collections. You should learn Scala. Interview: Martin Odersky. Higher Order abstractions in Scala with Type Constructor Polymor.

Partial Applications with binds in Scala and Haskell. The busy Java developer&#039;s guide to Scala: Scala and servlet. Using Scala First Class Functions By Name. The Scala programming language and XML.