The Artima Developer Community
Sponsored Link

Weblogs Forum
Coupling is not neccessarily a bad thing!

35 replies on 3 pages. Most recent reply: May 5, 2005 11:49 PM by Greg Jorgensen

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 35 replies on 3 pages [ « | 1 2 3 ]
Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: Coupling is not neccessarily a bad thing! Posted: May 5, 2005 9:50 AM
Reply to this message Reply
Advertisement
> Yes, in retrospect my example stinks. I half-regret
> opening this particular can of worms.

Given your own dissatisfaction with the given example and the observation elsewhere that different people may have differing ideas about what constitutes coupling; it might be useful if you give a further example of the construct you're trying to defend.

V.

Christopher Diggins

Posts: 1215
Nickname: cdiggins
Registered: Feb, 2004

Re: Coupling is not neccessarily a bad thing! Posted: May 5, 2005 2:08 PM
Reply to this message Reply
> > Hmmm, I dont want to quibble over definitions. But I'd
> > like to ask you one question.
>
> I don't want to quibble either.

I actually think quibbling with regards to definitions is important, so that we can communicate effectively. Otherwise it is all just babble.

> But if we're going to talk
> about coupling we should agree on what it means.

I agree.

> Perhaps
> my definition is outdated, but it is how I've understood
> the term since 1975.

You provided a definition of "data coupling" which I am in full agreement with. This does imply that there other forms of coupling. I believe it is now widespread practice to use coupling to refer to both data coupling, and what you have referred to as dependencies.

> Obviously the books I learned about
> coupling from did not contemplate the additional risks of
> object-oriented programming languages.

And probably metaprogramming and aspect oriented programming as well.

> Inheritance creates a greater dependency between B
> and A, but as I've said I don't believe that dependency is
> the same as coupling. Coupling is a particular kind of
> dependency caused by modules sharing data or data
> structures, or by parameters that encode behavior rather
> than data (control coupling).

This seems like an overly narrow defintion of control coupling, at least in today's environment. Control coupling can be achieved without neccessarily passing parameters.

I think we need to introduce into this mix the concept of type coupling as well.

I think coupling is synonmous with dependency, and that the old defined categories of coupling were an attempt to categorize and understand the various kinds of dependencies within software.

> Whether we call that coupling or not, it isn't necessarily
> bad for B and C to be dependent on A -- every connection
> between modules is a dependency, and dependency means that
> changes to one may affect the other.

This is a fundamental point I was trying to make, I was using coupling where you would use dependency.

> When the
> dependency is through a global variable the modules are
> dependent in a hard-to-see and dangerous way.

I agree that that kind of dependency is in my view a clear cut example of data coupling at its most dangerous. It is very rarely neccessary nor a good idea. However, once in a while it is a good idea. Using global variables can occasionally greatly simplify a design, and if used sparingly can sometimes be worth the risk.

Christopher Diggins

Posts: 1215
Nickname: cdiggins
Registered: Feb, 2004

Re: Coupling is not neccessarily a bad thing! Posted: May 5, 2005 2:21 PM
Reply to this message Reply
> Your example shows increasing generality (and
> decreasing clarity). It doesn't demonstrate coupling.

Many people (myself included) consider the dependency of an algorithm on specific data types to be a form of coupling.

Christopher Diggins

Posts: 1215
Nickname: cdiggins
Registered: Feb, 2004

Re: Coupling is not neccessarily a bad thing! Posted: May 5, 2005 2:26 PM
Reply to this message Reply
> I don't want to quibble either. But if we're going to talk
> about coupling we should agree on what it means. Perhaps
> my definition is outdated, but it is how I've understood
> the term since 1975. Obviously the books I learned about
> coupling from did not contemplate the additional risks of
> object-oriented programming languages.

I just want to add the following rhetorical question:

You provided a good definition of "data coupling" as a form of dependency between sections of code through variables. "Control coupling" was defined as a form of dependency between sections of code through parameters representing behaviour. What could "coupling" by itself possibly be, if it isn't the broad notion of dependency between modular sections of software?

indranil banerjee

Posts: 38
Nickname: indranil
Registered: Nov, 2004

Re: Coupling is not neccessarily a bad thing! Posted: May 5, 2005 8:29 PM
Reply to this message Reply
I've made a search over google and I cant find an ISO standard definition of coupling. It means at lot of diiferent things to different people. I dont think any 30 year old text book can have greater authority on this subject than a 3 day old web page.

This reminds of some tedious arguments I used to get into with Java programmers over whether C++ was more or less Object Oriented than Java because it had multiple inheritance. It was completely pointless because no 'standard' definition of OO exists anywhere. Just like coupling.

The best definition I can find out there is in wikipedia http://en.wikipedia.org/wiki/Coupling . The majority of definitions are much more wooly even from academic sources. "The extent to which subsystems depend on each other." http://cwx.prenhall.com/bookbind/pubbooks/valacich/chapter1/custom1/deluxe-content.html#C

I really dont want to quibble over definitions. But I know a bad thing when I see it.

Greg Jorgensen

Posts: 65
Nickname: gregjor
Registered: Feb, 2004

Re: Coupling is not neccessarily a bad thing! Posted: May 5, 2005 11:49 PM
Reply to this message Reply
> You provided a good definition of "data coupling" as a
> form of dependency between sections of code through
> variables. "Control coupling" was defined as a form of
> dependency between sections of code through parameters
> representing behaviour. What could "coupling" by itself
> possibly be, if it isn't the broad notion of dependency
> between modular sections of software?

The concept of coupling (along with the concepts of modules, module strength, and cohesion) were introduced in the modular/structured programming literature in the mid-1970s. Glenford Myers' books were influential at the time, because he offered good definitions of different types of coupling (common, data, stamp, control, etc.) and module strength. Myers also described ways to remove unnecessary coupling. Yourdon taught much the same thing, and used the term "coupling" to mean the same thing as Myers. Steve McConnell dusted those old books off and introduced the ideas to a new generation of programmers, using a more modern langauge (more modern than Fortran and PL/I, anyway) for examples.

I've always understood coupling to be one type of dependency, specifically dependency caused by data shared by or passed between modules. Object-oriented and other modern programming techniques offer new ways to couple modules, and also introduce new types of dependencies that Myers and Yourdon did not contemplate. Metaprogramming introduces opportunties for type dependencies -- type coupling, if you prefer -- that 1970s-era langauges did not support.

I'm willing to accept that modern programming languages have outgrown Myers' definition of coupling, and perhaps I'm making distinctions between data and types and relationships among chunks of code that are a lot blurrier today than they were in the 1970s.

Still, I find it useful to use the term "coupling" to refer to the kind of dependency Myers described, and to use other terms for other kinds of dependencies: inheritance, composition, fragile base class, common type definitions, etc.

When Myers named and described the kinds of coupling, and ranked them from bad to better, he didn't say that all coupling is bad. He did say that modules should not be coupled any more than necessary (i.e. don't use globals or common variables), and that some kinds of coupling are worse than others. His principles are mostly still applicable today, but obviously he didn't address all of the trouble C++ can get someone into.

When I read the original example, I didn't see a coupling problem; I saw the fragile base class problem. I didn't mean to get into a debate about the meaning of "coupling."

Flat View: This topic has 35 replies on 3 pages [ « | 1  2  3 ]
Topic: Working Around Non-Virtual Destructors Previous Topic   Next Topic Topic: Contract Enforcement for humanity ... ?


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us