This article shows how to install and use Scala programming language on Raspberry Pi.
Traditionally, the programming language of choice for Raspberry Pi was Python, while JVM-based languages were set aside. That was reasonable, because JVM platform is rather resource-intensive, especially in interpreted mode, and the first version of Raspberry Pi was hardly apt for such a task.
However, things have changed: on the one hand, Raspberry Pi 2 now offers a 900MHz quad-core CPU and 1GB of RAM, on the other hand, Oracle released JDK 8 for ARM (with HardFP, JIT and server VM), which provides >10X performance boost (comparing to Zero VM from OpenJDK), so Scala runs nicely even on Raspberry Pi 1 (and, RPi 2 can run IntelliJ IDEA, if you wish).
This article presents a list of simplifications and optimizations of typical Scala Collections API usages.
Some of the tips rest upon subtle implementation details, though most of the recipes are just common sense transformations that, in practice, are often overlooked.
The list is inspired by my efforts to devise practical Scala Collections inspections for the IntelliJ Scala plugin. We’re now in process of implementing those inspections, so if you use the plugin in IDEA, you’ll automatically benefit from static code analysis.
Nevertheless, the recipes are valuable by themselves and can help you to deepen your understanding of Scala Collections and to make your code faster and cleaner.
The content of the article is also (independently) translated into Russian and Chinese.
Design pattern is a general reusable solution to a commonly occurring problem in software design. A design pattern is not a finished code, but rather a template for how to solve a problem that can be used in many different situations.
Patterns are formalized best practices of effective design, which helps to prevent subtle issues, improve code readability and speed up the development process.
The classical design patterns (mostly, the GoF patterns) are object-oriented. They show relationships and interactions between classes and objects. These patterns are less applicable in pure functional programming (see Haskell’s Typeclassopedia and Scalaz for “functional” design patterns, kind of), however, since Scala is an object-functional hybrid language, these patterns are still very relevant, even in “functional” Scala code.
Sometimes, design patterns may be a sign of some missing feature in a programming language. In such cases, the patterns might be simplified or eliminated when a programming language provides the required features. In Scala, it’s possible to implement most classical design patterns directly, relying on the expressive language syntax.
While Scala may employ additional, language-specific design patterns, this article focuses on the well-known, classical patterns, because these patterns also serve as the means of communication between developers.
Sure we can use the Force all the power of Scala to completely transcend all these patterns, but in this article I intentionally tried to avoid more advanced techniques in favor of more simple and pictorial ones, in order to provide a clean mapping between languages.
ToyIDE is an imitation of a full-featured IDE plus toy languages (imperative, functional) with complete IDE support, interpreters and compilers. All the parts were built from scratch in Scala, without relying on any existing code or libraries.
The project is purely educational. It is a product of a long vacation in the country and a desire to learn how all this stuff really works.
Although I applied evolutionary design in the development (to uncover the reasons behind architecture), it turns out that many techniques in the code come close to commonly used patterns. I learned a lot from the project and hope it might be useful to the people who want to know more about lexers, parsers, AST, Java bytecode and other similar fun, but tricky things.
Project Euler is a collection of interesting computational problems intended to be solved with computer programs. Most of the problems challenge your skills in algorithm design rather than your knowledge of mathematics.
Thanks to short concrete problems and number-only solutions you don’t have to thinker with IDEs, GUI designers, programming libraries and frameworks, so Project Euler is an excellent tool for learning a new programming language or improving your core programming skills. Continue reading →