Going to do functional programming

2014-05-24 23:01:38 +0200

I've learned about functional programming during my university years, with Haskell as primary language. I considered functional programming as quite elegant, but also impractical. I felt I could get practical results more quickly when using Java or C# than using Haskell. Sometimes I used functional constructs like immutability, separating action from calculation or transforming and trying to limit the side-effects of functions. Usually this ended up in remarks from colleagues, ranging from 'just accept java isn't functional' to 'I don't understand this code'.

Older, and more experienced at, and sometimes wearied of,software development, I'm getting to change my mind about how practical functional programming, as well as the inpractactically of object-oriented programming.

Some insights:

  • Distributed software, SOA, services get much more understandable with functional patterns rather than with  object-oriented patterns. What if you have to call multiple services, where each call depends on the result of another service? You don't want to block your software while doing a service-call? And how do you handle errors? What to do about nullpointerexceptions? Using reactive programming allows you to handle these problems a lot easier, and then you start doing functional programming already .
  • Software-architects like to split up software in 'layers'. When using an object oriented language, this leads to translation of objects living in one layer to objects living in another layer, to avoid objects having behavior that belong in one layer ending up in another layer: like persistable domain objects ending up in the UI-layer or business-logic in a service-layer. I am quite fed up with yet another Dozer implementation. And xslt almost looks like a functional programming language, with a very verbose syntax.
    Instead of discussing what belongs in which layer and wetter or not a domain-object should be anemic or not: lets separate behavior, data and logic altogether. Functional programming languages allow that more naturally and readable.
  • Reusability is often desired. Lots of reusable components are created at many companies. Rarely they're used. Software that is reused most successfully consists mostly just of a set of functions, having little or no state.
    I rather have a function validIban then a class BankAccount with some method setIban or worse that may throw a validation error and a whole lot of other methods I don't want.
  • When enterprise-system, software grows, so grows the complexity. Nowadays people try to handle the complexity by adding testers, architects, functional/business analysts, information analyst, requirement engineering, ESB, SOA, middleware etc. All in vain, bugs still occur and software becomes unmaintainable legacy quickly, adding the need to add yet another software system.
    To truly handle software complexity, software must be of high quality and written in a highly expressive language.
    Failed releases, software caused system-outages and software bug related security-flaws should not be considered a given we have to live by. TDD or automatic tests (not the same), clean-code, continuous deployment and similar practices may help. In the end I think a functional, pure, language may be our only hope.

My goal will be for the coming year to both use and learn functional programming (fp) a lot more, explain it to other people and hope to popularize fp or ride the wave when functional-programming becomes more popular.

More bold, or maybe foolish, I take up my personal challenge to create something practically useful in Haskell.

Read more

Demonstrating using GWT-RequestFactory and Spring togetter

2014-03-24 14:29:52 +0100

I present a sample-project that demonstrates using the GWT RequestFactory together with Spring.

GWT, the Webapplication Toolkit formerly owned/led by Google allows you to write single-page, client-side webapplications fully in Java. Older versions of GWT only allowed communication with the client via RPC, which has quite a few drawbacks. Using RPC may lead to unresponsive design as it tries to hide that you're communicating over an unreliable (internet)connection. Also RPC can quickly result in ugly mixture of back- and frontend-code.

Since recent years in GWT you can also use the RequestFactory (RF) for client/server communication. RF allows for a better separation of the client/server code and enforces better design of client/server communication.
The GWT-SDK ships with a sample project, DynaTableRF which demonstrate how to use the RequestFactory. Integrating the RF back-end technologies such as JEE and Spring is not as straight-forward as the sample-project suggested. So I've extended the sample-project to use Spring. The sample-project gwt-dynatablerf-spring can be found at my Github-page.

I hope you find the sample-project useful. If you have any questions or remarks, feel free to contact me.

Read more

Archive

subscribe via RSS