InfoQ

News

Is OOP Better for Structuring your Code?

Posted by Sadek Drobi on Nov 30, 2008

Community
Architecture
Topics
Programming ,
Language
Tags
Functional Programming ,
OOP ,
Productivity

Programming languages that offer more power and flexibility have been lately gaining momentum. Johnatan Tang highlights, however, the flexibility vs. productivity tradeoff due, amongst other things, to the fact that traditional object orientation makes organizing programs easier and more straightforward.

He argues that in languages with single dispatch, “given a parameter or other value, you know exactly what you can do with it”. Whereas in statically typed languages code is more revealing about values involved, in structurally typed languages it is more general, but still gives an immediate idea what operations are available on a given value. And for both, statically and structurally typed languages, it is pretty clear what to do if you want to perform an operation that is not supported by a given object:

You write a method that performs that operation. This is problematic if you don't control that class, which is why Ruby and C# have moved to open classes. […]

And it's usually obvious where this method should go: on the class that you need to manipulate.

In multi-dispatch languages, it is much less obvious where a method should be written and “which parameter of the new method might take [a given] value”. This provides more flexibility in arranging code but this implies that more decisions should be taken about it and more efforts should be provided to keep these decisions in mind:

And then every time someone uses the method, they need to remember where it was defined and add the appropriate import statement. If they forget, they might get behavior they don't expect, as the appropriate method for the given generic function won't even have been loaded.

Establishing conventions can be considered a solution to this issue. However, Tang believes that “conventions that aren't enforced by the language tend not to be followed”. Moreover, having tried to define some patterns for modules arrangements, he also asserts that “this is inherently problem-domain-specific: there's no one right organizing principle that applies to everyone's programs.”

Hence, according to Johnatan Tang there is no obvious solution to this tradeoff of flexibility vs. productivity in organizing programs. What about your favorite languages? What solutions could you find? And, given your experience, is there any convenient compromise between the two? 

I thought this was about functional programming. by Ricky Clarkson Posted Nov 30, 2008 1:37 PM
Re: I thought this was about functional programming. by Sadek Drobi Posted Nov 30, 2008 6:47 PM
  1. Back to top

    I thought this was about functional programming.

    Nov 30, 2008 1:37 PM by Ricky Clarkson

    The first line mentioned functional programming and the rest of the article talks about multiple dispatch versus single dispatch. Multiple dispatch has absolutely nothing to do with functional programming.

    Was the article generated by a Markov chain?

  2. @Ricky
    You are right. Actually the word "functional" slipped out of my head as I was thinking that functional programming languages might have the same problem.

    I guess the problem is more general than multiple dispatch. Yet I think conventional OOP languages provide a good way of organizing and discovering code.
    Thanks, fixed!

Educational Content

Brian Marick on 4 Challenges and 5 Guiding Values of Agile Software Development

Brian Marick takes us through a quick tour of the most important values and challenges to adopting Agile successfully (they aren't the typical challenges and values we hear in the community).

Are You a Software Architect?

The line between development and architecture is tricky. Does it exist at all? Is an ivory tower actually needed? There's a balance in the middle, but how do you move from developer to architect?

Agile – A Way of Life and Pragmatic Use of Authority

The word 'authority' sometimes produces an allergic response in hard-line agilists. Freedom and authority – both are bad if misused and both are good if used in right spirit for a noble cause.

Getting Started with Grails, Second Edition

"Getting Started with Grails" brings you up to speed on this modern web framework. Companies as varied as LinkedIn, Wired, and Taco Bell are all using Grails. Are you ready to get started as well?

Using ITIL V3 as a Foundation for SOA Governance

Those familiar with only ITIL V2 often scoff at the thought that ITIL could serve as a governance framework for SOA. With ITIL V3, the focus of the framework shifted towards service-orientation.

Adrian Colyer on AspectJ, tc Server and dm Server

SpringSource CTO Adrian Colyer discusses AspectJ, SpringSource's dm Server and tc Server products, OSGi and Scrum.

Adam Wiggins on Heroku

Heroku's Adam Wiggins talks about Rails, Background Jobs, Add-Ons, Ruby, and how Heroku manages to work around Ruby's inefficiencies using Erlang and other languages.

SOA as an Architectural Pattern: Best Practices in Software Architecture

For Grady Booch the foundation of a good architecture is patterns, SOA being just one of many patterns. In this Second Life presentation, Booch attempts to bring more clarity on what architecture is.