FEATURED STORY

Using the command pattern with lambda expressions

Reduce boilerplate and make the intent of your code more obvious.

As Java developers we’re all familiar with the concept of Design Patterns. These are codified template solutions to problems that we may encounter when developing. We’re probably also familiar with being told by our functional programming brethren that design patterns are just “missing” language features. So the question now arises, with the introduction of lambda expressions in Java 8 and a more functional style of programming, how do design patterns change? In this article we’ll be looking at the command pattern.

A command object is an object that encapsulates all the information required to call another method later. The command pattern is a way of using this object in order to write generic code that sequences and executes methods based on runtime decisions.

There are four classes that take part in the command pattern:

  • Receiver – Performs the actual work
  • Command – Encapsulates all the information required to call the receiver
  • Invoker – Controls the sequencing and execution of one or more commands
  • Client – Creates concrete command instances

invoker

Let’s look at a concrete example of the command pattern and see how it improves with lambda expressions. Read more…

Comment

Where apps end and the system begins

Exploring the system calls and control flow that underpin high-level languages.

Editor’s note: Sometimes we can forget how important it is to truly understand how a system works, and how the nuts and bolts affect our everyday activities. Marty Kalin asks us to dive a little deeper and strengthen our computational thinking abilities.

It’s clear that applications need system resources to execute: a processor, memory, and usually I/O devices such as the keyboard and screen. It’s less clear how applications gain access to these shared resources, which are under operating system (OS) control. The OS, like any good manager, is efficient and unobtrusive as it handles resource requests from applications. Let’s take a look at how applications interact with the OS, in both routine and dramatic fashion.

Consider what happens when a print statement executes. Here’s a Ruby example:

The Ruby puts statement wraps a call to a high-level I/O function in the standard C library (in this case, printf), which acts as the interface between resource-requesting applications and resource-granting OS routines. In this example, the screen is the requested resource. The standard library interacts seamlessly with the OS, which also is written in C with some assembly language. The library function printf is high-level because, as the f in the name indicates, the function can format the bytes to be written as integers, floating-point values, and character strings such as Hello, world!. In systems-speak, the Ruby application and the C library function execute in user space, which does not bestow the rights and privileges needed to control system resources such as the screen.

Read more…

Comment

Web by default

You're using the web even when you don't think you are.

InternetCities by Chris Harrison (ChrisHarrison.net), via Wikimedia Commons

With the rise of native apps and the Internet of Things (IoT), you might think we’re leaving the web behind.

We’re not. The web continues to be the easiest way for developers to connect people and computers. Whether you think you’re “on the web” or not, web tools power a huge chunk of communications and a vast number of interfaces. While HTML, CSS, and JavaScript are common, even in installable apps, even native apps and back-end systems use JSON, HTTP, and web services to communicate. IoT devices may not always use those protocols directly, but many of them have a web interface lurking somewhere.

Other languages and approaches absolutely have their place, especially in the many environments where constraints matter more than connection, but the web core is everywhere: in your phone, your apps, the kiosks you find in stores and museums. It lurks invisibly on corporate networks helping databases and messaging systems communicate.

That enormous set of web-related possibilities includes more than a set of technologies, though. Tools and techniques are great, but applying them yields a richer set of sometimes happy and sometimes controversial conversations.

I’ll be exploring a core set of nine key themes over the next few months, but I’ve started with brief explanations below. These short tellings set the stage for deeper explorations of the web’s potential for changing both computing and the broader world, as well as what you need to learn to join the fun.

Those pieces digging deeper will appear on this site, but you can also stay in the loop on our latest analysis and coverage through our weekly web platform newsletter.

Read more…

Comment

Unit Testing Java 8 Lambda Expressions and Streams

Two approaches to testing lambdafied code.

valve

Over the past 18 months or so I’ve been talking to a lot of people about lambda expressions in Java 8. This isn’t that unusual when you’ve written a book on Java 8 and also run a training course on the topic! One of the questions I often get asked by people is how do lambda expressions alter how they test code? It’s an increasingly pertinent question in a world where more and more people have some kind of automated unit or regression test suite that runs over their project and when many people do Test Driven Development. Let’s explore some of the problems you may encounter when testing code that uses lambdas and streams and how to solve them.

Usually, when writing a unit test you call a method in your test code that gets called in your application. Given some inputs and possibly test doubles, you call these methods to test a certain behavior happening and then specify the changes you expect to result from this behavior.

Lambda expressions pose a slightly different challenge when unit testing code. Because they don’t have a name, it’s impossible to directly call them in your test code. You could choose to copy the body of the lambda expression into your test and then test that copy, but this approach has the unfortunate side effect of not actually testing the behavior of your implementation. If you change the implementation code, your test will still pass even though the implementation is performing a different task.

Read more…

Comment: 1

Signals from Velocity Europe 2014

From design processes to postmortem complexity, here are key insights from Velocity Europe 2014.

Practitioners and experts from the web operations and performance worlds came together in Barcelona, Spain for Velocity Europe 2014. We’ve gathered highlights and insights from the event below.

Managing performance is like herding cats

Aaron Rudger, senior product marketing manager at Keynote Systems, says bridging the communication gap between IT and the marketing and business sectors is a bit like herding cats. Successful communication requires a narrative that discusses performance in the context of key business metrics, such as user engagement, abandonment, impression count, and revenue.

Read more…

Comment: 1

Measure your open source community’s age to keep it healthy

Your data is telling you what you need to know about turnover and age

instrumentsTo really grasp a free/open source software project, you need to know how the community that develops and supports it is evolving. Attracting lots of new members will be a reason for celebrating success in a young project — but you should also check whether they stick around for a long time. In mature projects, however, you can afford not attracting many new members, as long as you are retaining old ones. The ratio of experienced, long-term members to recent ones also tells you about the quality of the code and need to support members.

Read more…

Comment