InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

Is OOP Better for Structuring your Code?

Posted by Sadek Drobi on Nov 30, 2008

Sections
Development,
Architecture & Design
Topics
Architecture ,
Language ,
Programming
Tags
Productivity ,
OOP ,
Functional Programming

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
Re: I thought this was about functional programming. by Sadek Drobi Posted
  1. Back to top

    I thought this was about functional programming.

    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. Back to top

    Re: I thought this was about functional programming.

    by Sadek Drobi

    @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

New-age Transactional Systems - Not Your Grandpa's OLTP

John Hugg discusses high volume transaction processing applications with high and low frequency profiles, and how VoltDB can be used for that purpose.

Cool Code

Kevlin Henney examines code samples to see what can be learned from them starting from the premise that one won’t write great code unless he knows how to read it.

Collaboration: At the Extremities of Extreme

Jason Ayers share the observations he made watching a team of developers collaborating in real time on the same code base, pushing XP, pair programming and continuous integration to their extremes.

Yesod Web Framework

Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).

Transactions without Transactions

Richard Kreuter and Kyle Banker on how to avoid classical RDBMS transactional systems by using compensation mechanisms, transactional messaging or transactional procedures.

Attila Szegedi on JVM and GC Performance Tuning at Twitter

Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.

Interview: Software Systems Architecture: Working With Stakeholders Using Viewpoints and Perspectives

InfoQ spoke to the authors of Software Systems Architecture on a couple of new topics, the System Context viewpoint and Agile, which have been added to the second edition.