Subject: RE: [hackers-il] How to define "modular" code?

From: Omer Musaev <[email-masked]>
Date: Sun, 21 Apr 2002 09:46:25 +0200

> -----Original Message-----
> From: Shlomi Fish [mailto:[email-masked]]
> Sent: Friday, April 19, 2002 3:39 PM
> To: Hackers-IL
> Subject: [hackers-il] How to define "modular" code?
> 
> 
> 
> Most experienced hackers can enumerate the principles of OOP or FP or
> Patterns P. However, I found modularity to be much harder to define.
> According to OmerZ, it is the most important paradigm, but some
> beginning hackers cannot understand what it is. (and Googlizing for it
> turns out zilch)
> 
> What are the concepts behind modular design? Things of top of my head:
> 
> 1. Make sure that there is no duplicate code (or only such in 
> appropriate
> places)

Consequence: Templatize.

> 2. Make sure everything appropriate is instantizable.

I did not understand that statement. What did you intend to say?

> 3. Make sure each object (not necessarily inherited) or function has a
> well-defined interface with few if any side effects on the
> external environment.

Consequence: Preffer functors on functions.

> 4. Avoiding Kludges that add extra features or solve a 
> particular problem.
> Sub-cases should be generalized to keep the code modular.

This is dangerous statement. We had been stuck lately into a project
that was heavily generalized and as a consequence of that failed 
to perform as required.  

> 5. Trying to keep functions non-monolithic and to split them 
> into several
> logical routines.

This is dangerous statement too. One can find himself in "too many
layers of abstraction" hell quite easy.

> 
> What else can you think of?

Policy based design[1],[4]. Contract based design[2]. Generic
programming[1],[3]
Strong typing. Platform independent code.
 
> Regards,
> 	Shlomi Fish

[1] http://cseng.aw.com/book/0,3828,0201704315,00.html
[2] http://www.eiffel.com/doc/manuals/technology/contract/
[3] http://www.research.avayalabs.com/user/wadler/topics/gj.html
[4] http://www.codeproject.com/wtl/anotheruiupdate.asp

---

From: guy keren <[email-masked]>
Date: Sun, 21 Apr 2002 13:08:24 +0300 (EET DST)

> > beginning hackers cannot understand what it is. (and Googlizing for it

"hackers" don't write modular code. they hack. you probably meant
"designers" or "programmers"? ;)

> > 1. Make sure that there is no duplicate code (or only such in

that's _one_ way to avoid duplicate code. there are others. thus, its not
a 'consequence:'. its 'one method:'. don't let "C++ generic programming"
hide out all other methods ;)

> I did not understand that statement. What did you intend to say?

i think he meant "don't use globals. each object should be stored fully in
some data structure that can be instantiated during runtime, so you can
create as many different objects of that kind, as you need".
i also see it as a "no for singletons - cause there never are real
singletons, as the program's requirements begin to change".

> Consequence: Preffer functors on functions.

why?

> that was heavily generalized and as a consequence of that failed

its not 'a dangerous statement'. what you are saying is that modular code
comes at the expense of performance. the question was about modular code.
you have other considerations when designing/writing code. when you
actually go design some system - then you consider the tradeoffs and
decide.

> layers of abstraction" hell quite easy.

i can second that. and for some reason, this seems to be a common sickness
amongst people who are "too deep into OO" ;)  turning every little thing
into an object, and having a class on top of a class on top of a...

> Strong typing. Platform independent code.

those were the buzzwords. can we have their interpretation now, and how
they are related to modularity (no, i won't go looking into those
resources unles i have some intensive to do so, in the saying of at least
one sentence explaining what 'policy based design' is.

as for contract-based design, if i remember it correctly, its about having
a very strict interface between caller and callee, regarding what values
may or may not be in different parameters, and the status of data
structures used. what does this got to do with modularity, any more then
"write good code" has to do with modularity?

-- 
guy

"For world domination - press 1,
 or dial 0, and please hold, for the creator." -- nob o. dy