Scala for Java Developers – A practical guide to building apps and integrating code – #programming #bookreview

Scala for Java Developers

Build reactive, scalable applications and integrate Java code with the power of Scala

Thomas Alexandre

(Packtpaperback, Kindle)

 

The increasingly popular Scala programming language runs on the Java Virtual Machine (JVM). And “Java and Scala stacks can be freely mixed for totally seamless integration,” Scala’s website proudly trumpets.

The Scala site goes on to note: “Scala is a modern multi-paradigm programming language designed to express common programming patterns in a concise, elegant, and type-safe way. It smoothly integrates features of object-oriented and functional languages.”

Indeed, in Scala, “every value is an object” and “every function is a value.”

Scala’s continuing  rise poses something of a dilemma for many Java developers. Their questions include:

  • Should I learn Scala and blend it with Java?
  • Should I take up Scala and use it instead of  Java?
  • Should I just keep my head down, ignore Scala, and focus on getting better at developing with Java?

Thomas Alexandre’s well-written new book, Scala for Java Developers, clearly is aimed at those who would much rather add Scala to their skills and resumes than attempt to hide from the changes Scala can offer to Java development.

He notes in his preface: “When I tell people around me that I now program in Scala rather than Java, I often get the question, ‘So, in simple words, what is the main advantage of using Scala compared to Java?’  I tend to respond with this: ‘With Scala, you reason and program closer to the domain, closer to plain English.’ “

However, Alexandre’s new how-to guide does not try to browbeat developers into abandoning Java and pledging allegiance to Scala alone. Instead, Alexandre shows how the two programming languages can be used together. And he demonstrates how Scala solutions often can be shorter and less complex than their Java equivalents.

He focuses on “exploring progressively some of the new concepts brought by Scala, in particular, how to unify the best of Object-Oriented and functional programming without giving away any of the established and mature technologies built around Java for the past fifteen years.”

Decisions regarding how far to go with Scala remain with the reader. Yet Alexandre and his numerous code examples make a compelling case for becoming at least reasonably familiar with the language and experiencing how easily it can integrate with Java.

And, yes, he does evangelize a bit; this is, after all, a book about Scala. “Scala is the only language that has it all,” Alexandre touts. “It is statically typed, runs on the JVM and is totally Java compatible, is both object-oriented and functional, and is
not verbose, thereby leading to better productivity, less maintenance, and therefore more fun.”

His book is divided into 10 chapters:

  • Chapter 1: Programming Interactively within Your Project – Includes advantages of using Scala, learning Scala via the REPL, and performing operations on collections.
  • Chapter 2: Code Integration – Focuses on creating a REST API from an existing database, adding a test in Scala, setting up Scala within a Java Maven project, and showing how Scala and Java work together despite some differences in code style.
  • Chapter 3: Understanding the Scala Ecosystem – Includes inheriting Java Integrated Development Environments (IDEs), building with Simple Build Tool (SBT), using Scala worksheets, working with HTTP, and using Typesafe Activator.
  • Chapter 4: Testing Tools – Writing tests with ScalaTest and testing with ScalaCheck.
  • Chapter 5: Getting Started with the Play Framework – Getting started with the classic Play distribution, getting started with the Typesafe Activator, the architecture of a Play application, authentication, and practical tips when using Play.
  • Chapter 6: Database Access and the Future of ORM – In this case, ORM is Object Relational Modeling. Chapter topics include integrating an existing ORM – Hibernate and JPA, dealing with persistence in the Play framework, replacing ORM, learning about Slick, and scaffolding a Play application.
  • Chapter 7: Working with Integration and Web Services – Includes binding XML data in Scala, working with XML and JSON, and handling Play requests with XML and JSON.
  • Chapter 8: Essential Properties of Modern Applications – Asynchrony and Concurrency – Covers the pillars of concurrency, the async library – SIP-22-Async, and getting started with Akka.
  • Chapter 9: Building Reactive Web Applications – Includes describing reactive applications, handling streams reactively, experimenting with WebSockets and Iteratees in Play, learning from activator templates, and playing with Actor Room.
  • Chapter 10: Scala Goodies – Covers exploring MongoDb and scratching the surface of Big Data. Also introduces DSLs in Scala and introduces Scala.js, which compiles Scala to JavaScript.

Alexandre makes a strong pitch for using the Play framework in Scala web development. And he again speaks out for Scala at the conclusion of his well-structured book:

“The concise and expressive syntax of the Scala language should make your code not only more readable but also more maintainable for yourself and other developers,” he writes. “You don’t have to give up any of the libraries of the very large and mature Java ecosystem as all the APIs can be reused directly within Scala. Moreover, you benefit from many additional great Scala-specific libraries. Our recommendation is to take a piece of Java code from a domain you understand well, maybe because you wrote it in the first place one or several times before. Then, try to convert it to Scala code and refactor it to get rid of the boilerplate and to make it in a more functional style.”

Si Dunn

 

 

 

 

 

 

 

 

Making Sense of NoSQL – A balanced, well-written overview – #bigdata #bookreview

Making Sense of NoSQL

A Guide for Managers and the Rest of Us
Dan McCreary and Ann Kelly
(Manning, paperback)

This is NOT a how-to guide for learning to use NoSQL software and build NoSQL databases. It is a meaty, well-structured overview aimed primarily at “technical managers, [software] architects, and developers.” However, it also is written to appeal to other, not-so-technical readers who are curious about NoSQL databases and where NoSQL could fit into the Big Data picture for their business, institution, or organization.

Making Sense of NoSQL definitely lives up to its subtitle: “A guide for managers and the rest of us.”

Many executives, managers, consultants and others today are dealing with expensive questions related to Big Data, primarily how it affects their current databases, database management systems, and the employees and contractors who maintain them. A variety of  problems can fall upon those who operate and update big relational (SQL) databases and their huge arrays of servers pieced together over years or decades.

The authors, Dan McCreary and Ann Kelly, are strong proponents, obviously, of the NoSQL approach. It offers, they note, “many ways to allow you to grow your database without ever having to shut down your servers.” However, they also realize that NoSQL may not a good, nor affordable, choice in many situations. Indeed, a blending of SQL and NoSQL systems may be a better choice. Or, making changes from SQL to NoSQL may not be financially feasible at all. So they have structured their book into four parts that attempt to help readers “objectively evaluate SQL and NoSQL database systems to see which business problems they solve.”

Part 1 provides an overview of NoSQL, its history, and its potential business benefits. Part 2 focuses on “database patterns,” including “legacy database patterns (which most solution architects are familiar with), NoSQL patterns, and native XML databases.” Part 3 examines “how NoSQL solutions solve the real-world business problems of big data, search, high availability, and agility.” And Part 4 looks at “two advanced topics associated with NoSQL: functional programming and system security.”

McCreary and Kelly observe that “[t]he transition to functional programming requires a paradigm shift away from software designed to control state and toward software that has a focus on independent data transformation.” (Erlang, Scala, and F# are some of the functional languages that they highlight.) And, they contend: “It’s no longer sufficient to design a system that will scale to 2, 4, or 8 core processors. You need to ask if your architecture will scale to 100, 1,000, or even 10,000 processors.”

Meanwhile, various security challenges can arise as a NoSQL database “becomes popular and is used by multiple projects” across “department trust boundaries.”

Computer science students, software developers, and others who are trying to stay knowledgeable about Big Data technology and issues should also consider reading this well-written book.

Si Dunn

Testing in Scala – How to Test First, Then Develop Effective Code – #programming #bookreview

Testing in Scala
Daniel Hinojosa
(O’Reilly – paperback, Kindle)

In test-driven development (TDD), a software developer first creates some specific tests that are intended to fail and then writes code that is good enough to pass the tests. After that, the code is refactored, improved to make it better and easier to maintain and extend.

A key goal of TDD is to reduce the time and costs required to develop software.

Daniel Hinojosa’s well-written Testing in Scala effectively introduces test-driven development basics to Scala newcomers, as well as to developers already familiar with Scala or other programming languages, including Java, Ruby or Python.

The scala-lang.org website describes Scala as “a general purpose programming language designed to express common programming patterns in a concise, elegant, and type-safe way. It smoothly integrates features of object-oriented and functional languages, enabling Java and other programmers to be more productive. Code sizes are typically reduced by a factor of two to three when compared to an equivalent Java application.”

Both TDD and Scala have been around for a number of years, but each is now gaining new traction with corporations, software companies, and individual developers seeking faster results at lower costs.

One big reason for Scala’s rising popularity, the Scala website proclaims, is Scala’s close ties to Java:

“Existing Java code and programmer skills are fully re-usable. Scala programs run on the Java VM, are byte code compatible with Java so you can make full use of existing Java libraries or existing application code. You can call Scala from Java and you can call Java from Scala; the integration is seamless. Moreover, you will be at home with familiar development tools, Eclipse, NetBeans or IntelliJ for example, all of which support Scala.”

The Spring Tool Suite also can support Scala using the Scala IDE for Eclipse, but there recently were a few “caveats” if you have the Java 7 JDK installed. Meanwhile, the Spring Scala project, announced last October, is underway.

The new book Testing in Scala is structured as six chapters that utilize different testing frameworks while an example application is tested and developed from scratch:

  1. Setup
  2. Structure and Configuration of Simple Build Tool (SBT)
  3. ScalaTest
  4. Spec2
  5. Mocking
  6. ScalaCheck

The book and its code examples, Hinojosa says, are “organized in a TDD fashion: test first, fail; test again, succeed maybe; test again, succeed, and so on.”

If you’ve never tried TDD, Testing in Scala may help you learn how to become a better, more efficient Scala developer.

It also can introduce you to a development style that you may be able to adapt quickly and effectively to other programming languages, as well.

Si Dunn