Where is Scala’s “break” Keyword?

Does Scala have the break keyword?

The short answer is “No”. Scala doesn’t support break and continue at the language level. However it provides you with the right API calls to achieve the same results.
Read the rest of this entry »

, ,

Leave a comment

Putting manners on JavaScript

Everyone writing web applications at some point has a run in with JavaScript. Frankly, it’s ugly, it’s dynamically typed and not really object orientated.
I’m one of the old school who likes statically type variables (at least by default anyway).
Recently I’ve adopted using TypeScript, an open source language from Microsoft for putting manners on larger scale JavaScript projects.  TypeScript is a superset of JavaScript (For the more nerdy, ECMAScript 6 is their target).  As a result, it runs with just about anything that runs JavaScript, even node.js.  When combined with good IDE integration it’s a really good experience.
A while back I had to construct a technology demonstrator relying heavily on JavaScript, that amounted to a single page application.  I got it finished to my satisfaction, but I was never really happy with the JavaScript.  My “objects” were rudimentary, my functions ugly and it had too many code smells.  I wish I’d known about TypeScript.  My most recent project is heavily dependent on JavaScript and with the use of TypeScript a much cleaner prospect.  I’m using interfaces, small classes and most importantly inferred static typing (awesome!).  When I save it’s automatically compiled to plain old JavaScript.


Leave a comment

gitignore Files… Are You Still Creating Them Manually?

Do you use Git? Do you create your .gitignore files manually?

If yes, here is an on-line tool that can make your life easier. Read the rest of this entry »

, , , , , , ,

Leave a comment

Better Type Inference in Java 8 Generics

Java 7 gave us the diamond operator:

  Map<String, String> dict = new HashMap<>();

The code above doesn’t duplicate the type parameters unnecessarily as it made perfect sense to extend type inference to instantiation. Now Java 8 pushes type inference a little further. Read the rest of this entry »

, , ,

Leave a comment

Java 8 Lambda Expressions Capture Values, Not Variables

Before Java 8, when we needed to use a local variable inside an anonymous inner class, the local variable had to be declared final:

public class ValueCaptureAnon {
  public static void main(String[] args) {
    String name = "Yagiz"; //Compile error in Java 7...

    Runnable runnable = new Runnable() {
      public void run() {
        System.out.println("Name is " + name);

Read the rest of this entry »

, , , ,


Building a RESTful Service Layer with JAX-RS, RESTEasy and Spring Framework

Just like many of you, we’ve been developing RESTful services for a while. We’ve used various frameworks in .NET and in Java, in large systems as well as on the server-side of our mobile apps. Unless there’s a good reason not to do so, REST is our preferred approach in building a service layer. Recently we’ve had a series of discussions about different approaches in building a RESTful service layer and I decided to outline one of the ways to do it using RESTEasy, Jackson, JSON and Spring Framework on the Java platform.

Read the rest of this entry »

, , , , , , , ,

Leave a comment

Alternatives for Limiting Message Size within an Event Driven Architecture

I’ve discussed using event messages to carry payload data, to help with resynchronizing a failed independent component with its loosely coupled neighbours. However, this could very easily lead to extremely large and inefficient messages, for what should ideally be very simple events. This will invariably lead to performance and scalability issues, not to mention affecting the cost of provisioning. Also, since message publishers are unconcerned with how many subscribers there might be, publishing large messages is an irresponsible development practice with potentially unforeseeable consequences. I’ve outlined some alternatives we’ve assessed in attempting to resolve this issue.

The first strategy is, as we’ve discussed, including a data payload within the event itself. For example, consider an order processor component raising an event to indicate successfully closing an order. The event might also include some customer data, which is not strictly necessary, just to indicate the order has been made. As I’ve indicated, this strategy is really only viable for small message sizes. If we were to attempt to include an entire order with the event, the overall payload size would dwarf the event notification and result in the issues we’ve already mentioned.

A second, leaner approach is to include a REST URL to reference the payload data. Thus subscribers can choose to consume the related payload data as required using the REST URL. In our example, a downstream payment processor component might need customer data from the order. By requesting the order customer details via the supplied REST URL, the payment processor potentially has access to the entire order. I like this pattern as it virtually eliminates the size associated with any payload and also leverages the caching benefits of REST, ensuring a flexible, efficient mechanism for very large payloads.

Note: Consider it a tip to include a version determining parameter in the URL, to ensure the reference within the event remains immutable in the face of any later changes to the data.

The third strategy is a little more difficult to explain and involves the use of a mediator object. A mediator is an abstraction used to lower direct coupling between interdependent components. The mediator is responsible for abstracting any communications between components and can be implemented in many different ways depending on its use and the data involved. Communications can be heavily cached, synchronous, asynchronous it really doesn’t matter. It is sufficient for the consuming component to know, the mediator is responsible for executing a required task which is ultimately under the purview of another component. A mediator may make a variety of communications but only ever to a single component, thus ownership of the mediator is clear.

This strategy is only to be considered where some behaviour is required, not just data, which is the responsibility of another component. Within our order example, it might be to obtain the customer’s billing address for the payment processor say. This could be considered behaviour because the customer’s billing address is unlikely to be a property of the newly closed order, and hence it would require a lookup based on the customer (a responsibility of the customer management component). The mediating object might orchestrate the process, acquiring data from the customer management component to do this.

Leave a comment


Get every new post delivered to your Inbox.