Home » JVM Languages » Scala

Scala

Gang of Four Patterns With Type-Classes and Implicits in Scala (Part 2)

Type-classes are a powerful tool for library creators and maintainers. They reduce boilerplate, open libraries to extension, and act as a compile time switch. Similarly, the GoF patterns are also a collection of software organizational patterns aimed at improving the quality of code. The last blog post explored using one such pattern with type-classes and implicits, the bridge pattern. In ...

Read More »

Dependency injection with Scala macros: auto-wiring

You can look at dependency injection as a fancy name for passing parameters to a function (or constructor arguments to a constructor). However usually, DI containers do much more than that. Among other things, one very nice feature is auto-wiring: instantiating the right objects with the right arguments. Most popular frameworks (Spring, Guice, CDI/Weld) accomplish this task at runtime using ...

Read More »

Gang of Four Patterns With Type-Classes and Implicits in Scala

Type-classes, as they’re known within the Scala language, have a wonderful place in library development. They make code open to extension, less verbose and simplify APIs. I’ve yet to find many other patterns in languages which do the same. A close second, depending on your point of view, being one of either the concept of a generator or decorator in ...

Read More »

Futures in Akka with Scala

Akka is actor based, event-driven framework for building highly concurrent, reliable applications. Shouldn’t come a surprise that concept of a future is ubiquitous in a system like that. You typically never block waiting for a response, instead you send a message and expect response to arrive some time in the future. Sounds like great fit for… futures. Moreover futures in ...

Read More »

Using Twitter4j with Scala to perform user actions

Introduction My previous post showed how to use Twitter4j in Scala to access Twitter streams. This post shows how to control a Twitter user’s actions using Twitter4j. The primary purpose of this functionality is perhaps to create interfaces for Twitter like TweetDeck, but it can also be used to create bots that take automated actions on Twitter (one bot I’m ...

Read More »

Complex Numbers in Scala

Overview I recently delivered an introductory talk about Scala at an internal geek’s event at SAP. In this talk, I used an example complex numbers class to illustrate important language concepts and features. In many respects, this is a classical example that can be found in many other introductory materials about Scala, for example in this Scala Tutorial for Java ...

Read More »

Using twitter4j with Scala to access streaming tweets

Introduction My previous post provided a walk-through for using the Twitter streaming API from the command line, but tweets can be more flexibly obtained and processed using an API for accessing Twitter using your programming language of choice. In this tutorial, I walk-through basic setup and some simple uses of the twitter4j library with Scala. Much of what I show ...

Read More »

Scala pattern matching: A Case for new thinking?

The 16th President of the United States. Abraham Lincoln once said: ‘As our case is new we must think and act anew’. In software engineering things probably aren’t as dramatic as civil wars and abolishing slavery but we have interesting logical concepts concerning ‘case’. In Java the case statement provides for some limited conditional branching. In Scala, it is possible ...

Read More »

Dry parameter names

How often do you see code like this, especially when using dependency injection, single-responsibility principle, and other “good practices”?                   class FriendsTimelineReader(userFinder: UserFinder, userStatusReader: UserStatusReader, statusSecurityFilter: StatusSecurityFilter) { ... } Note that the parameter names are exact copies of the class name. That’s certainly not DRY! In Java writing such code is ...

Read More »