Feel the power of Functional Programming in Scala

Feel-the-power-of-Functional-Programming-in-ScalaDevelopers, architects and anyone with an interest in learning functional programming techniques should take a look at how it is supported by the Scala language

Over time, programming languages certainly do evolve significantly. Once upon a time, when your WhaTech correspondent was learning programming way back in the 1970s, a procedural or imperative programming style was always used.

A computer program back then was a long and detailed step-by-step series of individual commands (program statements) that often proved hard to manage. Debugging and maintenance become difficult due to the sheer number of often-repetitive statements and the complex interrelationship between them -- poor programmers tend to create an unfathomable tangle (usually labelled  ‘spaghetti code’).

One of the few ways to reduce code bulk in procedural programming is to build subroutines to handle repetitive tasks such as performing a complex calculation, opening a database, or checking the amount of funds in a bank account. You coded a given subroutine once and then called it from different points of your main program.

Around about the early to middle of the 1980s object-oriented programming moved out of the research labs into the mainstream. This programming style extended the above simple subroutines into the concepts of objects and encapsulation. Objects are self-defining structures that hold both the data definitions and the code needed to correctly manipulate that data.

Object-oriented programming led to a general improvement in application reliability and coding efficiency, but still has its limitations. For example, objects can be complex to build and test, can be a lot wordier than procedural programs, sometimes are simply unsuitable for the job in hand, and the object-oriented approach requires a fairly steep learning curve.

Then more recently along came functional programming, the concepts behind which are a little more obscure, nevertheless support for this style of programming in various computer languages is rising and its popularity is rising. It’s quite possible that your favourite language already supports this programming style. In other words, the message is that you can’t just ignore it

According to the description at Stack Overflow, functional programming languages (compared with procedural and object-oriented languages) use a different paradigm that has side-effect-free functions as a basic building block in the language.

“One of the biggest advantages with functional programming is that the order of execution of side effect free functions is not important. For example in Erlang this is used to enable concurrency in a very transparent way. And because functions in functional languages behave very similar to mathematical functions it's easy to translate those into functional languages. In some cases this can make code more readable.”

With languages such as Scala, a pure function aims to provide certainty that a given input to it will always provide the same output. Functional programmers know they can depend upon referential integrity which enables an expression to be replaced by its value without affecting the program.

Thereby you can reason about the program’s code, and can get proof that your program works correctly. This is powerful stuff, and deserves serious consideration by application architecture and development teams.

Scala offers a blend of object-oriented and functional programming capabilities. It runs on the Java virtual machine (JVM) and is tightly integrated with the Java language, while offering many advanced language features not available in Java.. You can integrate Scala into your existing Java applications, thus gaining additional power beyond the native Java.

Learn more about Scala and functional programming by attending the Introduction to Functional Programming in Scala hands-on workshop being conducted at the YOW! Conference 2013 in early December. The presenters are Mark Hibberd who works at Australian research centre NICTA and contributes to open source software, plus Tony Morris who has been involved with functional programming for over a decade.

This workshop is aimed at an audience with little exposure to the Scala programming language and little or no exposure to functional programming. Participants should expect to finish with a basic understanding of Scala as well as the tools and inspirations to continue investigation of functional programming concepts.

You can register for the Sydney workshop Here

This email address is being protected from spambots. You need JavaScript enabled to view it.