Towards Greater Code Reuse

3 views
Skip to first unread message

William la Forge

unread,
Oct 1, 2015, 9:03:46 AM10/1/15
to AgileWikiDevelopers

Code reuse is for me the holy grail of software. It is something we lost in large measure with the adoption of top-down development. And OO has only complicated the matter. For some time now I have advocated the use of factories and interfaces as a means of decoupling, but writing reusable code has continued to be a bit of a lost art. But then, I was a Java developer.

Having been exposed to Clojure, I've come to realize that a function is the smallest unit of reusable code, not a class. Simply moving logic from methods to functions (or to static methods, if you are still using Java) opens up a lot of possibilities. Mind, I still advocate the use of interfaces for method polymorphism, but limit method bodies to be little more than a call to a function or a property accessor.

Doing this allows us to avoid class extensions and mind-numbing class hierarchies. The code becomes much clearer, defining new classes becomes much easier, and the need to refactor the code is greatly diminished. And writing reusable functions is much easier than writing reusable classes.


from https://github.com/laforge49/aatree/wiki/Towards-Greater-Code-Reuse

Raoul Duke

unread,
Oct 1, 2015, 1:57:31 PM10/1/15
to AgileWikiDevelopers
There is no silver bullet. There are plenty of things wrong with
functional approaches. It isn't a gimme. You have to know what you are
doing, and the language(s) have to help. (I say this as somebody who
generally loves FP.)

e.g. I rewrote our build scripts from bash to functional style Go, and
they are horrible evil death spawn crap. And it is because the data
and the functions are so separated, and there's too much attempt to
use abstractions. So when it comes time to really really really
understand WTF the damned thing is doing, to what file, where, and how
to change it or re-use it, it is way too hard confusing complicated
opaque risky badness.

I really do think there is a lot to be said positively in defense of
Kay's idea of little computers communicating. Services. I was just
working on a take home interview programming question, and sorta
started off with the standard "meh" type OO but am now trying to push
more towards smart communicating coordinating objects, and it feels a
little better.

Now there are a ZILLION things wrong with going the OO route, of course.

So there's really no single way to do everything, even when it comes
to reuse. You really have to define the different kinds of reuse! I
mean, just go look at the 'expression problem'.
Reply all
Reply to author
Forward
0 new messages