reengineering c++ code that uses pthreads on Sun Solaris

M

My Python

greetings All,

Please respond to this posting if you have ever involved in a rewrite
of a complicated software system or driven such a project or have
insight into reengineering aspects:

Context:

Originally written using C++/pthreads on Sun Solaris, we need to
rewrite a component of a large system, so (A) the database,
communications (with other SW and devices), event management
infrastructure needs to be kept (so some reengineering in order), (B)
the rest of the logic code has to be rewritten or refactored whichever
suits the purpose. (C) The primary purpose of the rewrite is the code
has become difficult to maintain. Over 180,000 lines of code and uses
pthreads, code was written about 10 years ago with lot of changes
impacting the code maintainablity to date.

Challenges:

1. Reengineering tool for reusing the classes by feeding this huge
amount of code (A). Rational rose chokes on this and I need a better
tool. Do any of you use a reeng tool for this size of C++ code, if so
throw some light this tool, forums, your experience using this, etc.

2. while the logic is complicated (B), there are several portions of
code which can be treated as modules and adapted to a clear threading
model, instead of what we have now a hodge-podge of thread startegies,
this will celar up the data sync issues (deadlocks) and race condition
related bugs. But I can't find any one book that addresses various
threading models with pthreads in context with examples (I need good
books pictures or diagrams). Any suggestions?

3. Any suggestions on code maintainability -- that is, the design
aspects we need to consider while rewriting. (C) Rather than pointing
to something like design patterns etc, what is really desired is
learning from how do others refactor/write (original code) large
amounts of code that interacts with lot of HW devices and SW
components?

Any URLs, case studies of such projects, responses to A,B,C 1,2,3 are
appreciated!

thanks!
 
J

Joshua Maurice

3. Any suggestions on code maintainability -- that is, the design
aspects we need to consider while rewriting. (C) Rather than pointing
to something like design patterns etc, what is really desired is
learning from how do others refactor/write (original code) large
amounts of code that interacts with lot of HW devices and SW
components?

For my completely unknown and humble opinion, the key to avoiding this
kind of mess, and /perhaps/ what you should aim for, is well separated
components with clearly defined interfaces. Yes, I am saying not "full
agile". For large code bases, you do need some big design up front
insofaras it allows different teams to code to interfaces and not to
implementations. This doesn't mean strict waterfall, nor does it mean
that interfaces cannot change. I am trying to stress that the success
of a large code base depends on turning the large project into a bunch
of small ones. Break it up into logical distinct pieces that can be
tested separately and used together to build up more complex pieces of
software.

(End humble opinion.)
 
I

Ian Collins

greetings All,

Please respond to this posting if you have ever involved in a rewrite
of a complicated software system or driven such a project or have
insight into reengineering aspects:

Context:

Originally written using C++/pthreads on Sun Solaris, we need to
rewrite a component of a large system, so (A) the database,
communications (with other SW and devices), event management
infrastructure needs to be kept (so some reengineering in order), (B)
the rest of the logic code has to be rewritten or refactored whichever
suits the purpose. (C) The primary purpose of the rewrite is the code
has become difficult to maintain. Over 180,000 lines of code and uses
pthreads, code was written about 10 years ago with lot of changes
impacting the code maintainablity to date.

Read "Working Effectively with Legacy Code" by Michael Feathers

http://www.amazon.com/Working-Effectively-Legacy-Michael-Feathers/dp/0131177052
Challenges:

1. Reengineering tool for reusing the classes by feeding this huge
amount of code (A). Rational rose chokes on this and I need a better
tool. Do any of you use a reeng tool for this size of C++ code, if so
throw some light this tool, forums, your experience using this, etc.

No, they tend to be more trouble than they worth.

How does the SunStudio IDE cope with your code? Once you ave the code
assistance configured correctly, it is a great help navigating a new
code base.
2. while the logic is complicated (B), there are several portions of
code which can be treated as modules and adapted to a clear threading
model, instead of what we have now a hodge-podge of thread startegies,
this will celar up the data sync issues (deadlocks) and race condition
related bugs. But I can't find any one book that addresses various
threading models with pthreads in context with examples (I need good
books pictures or diagrams). Any suggestions?

Have you considered an abstraction such as boot thread?
3. Any suggestions on code maintainability -- that is, the design
aspects we need to consider while rewriting. (C) Rather than pointing
to something like design patterns etc, what is really desired is
learning from how do others refactor/write (original code) large
amounts of code that interacts with lot of HW devices and SW
components?

Write unit tests for the code you are about to change. This will
confirm your understanding of the behaviour of the code and validate
your changes.

If they are not already separate, make sure your application logic is
well isolated from your low level drivers.
 
J

Jorgen Grahn

["Followup-To:" header set to comp.lang.c++.]
greetings All,

Please respond to this posting if you have ever involved in a rewrite
of a complicated software system or driven such a project or have
insight into reengineering aspects:

Context:

Originally written using C++/pthreads on Sun Solaris, we need to
rewrite a component of a large system, so [...](A) the database,
communications (with other SW and devices), event management
infrastructure needs to be kept (so some reengineering in order), (B)
the rest of the logic code has to be rewritten or refactored whichever
suits the purpose. (C) The primary purpose of the rewrite is the code
has become difficult to maintain. Over 180,000 lines of code and uses
pthreads, code was written about 10 years ago with lot of changes
impacting the code maintainablity to date.

I am fairly convinced that the only right way to do such things is to:

- First spend time doing actual /maintenance/ work so you get to
learn the code base in practice. IME, a messed-up code base has
problems in many different areas, but some of them can be isolated
and left as-is; they are not important[1].

- Improving it /incrementally/, and in the areas which matters.
Don't spend months tinkering with the code in isolation.

- Having a good, close relationship with the users, so your
incrementally improved versions actually get /used/.

- I should say something about a system test strategy here, too ...

- Since you use C++ already, use the features of C++ to tighten things
up. Let classes to contain state. Use const. Use RAII. Use the
standard containers. Let the type system find the bugs for you, and
eliminate or isolate all type unsafety (casts, memcpy, malloc ...).

- Have a sane build system. where typing 'make' causes it to rebuild
exactly those parts which need to be rebuilt, neither less nor more.
I've worked with code bases where each build takes 30+ minutes.
That means you can't do experimental/speculative changes, that you
can't use the warnings from the compiler efficiently, ...

- I'm not a huge fan of unit tests, but I think you should make it
easy to add unit tests (to the build system) in case they are
needed. Sometimes you go "oh, this class would be so easy to write
some tests for, and if I did I could stop worrying about it".
Challenges:

1. Reengineering tool for reusing the classes by feeding this huge
amount of code (A). Rational rose chokes on this and I need a better
tool. Do any of you use a reeng tool for this size of C++ code, if so
throw some light this tool, forums, your experience using this, etc.

Rational Rose is a "reengineering tool"? I find it buggy and tedious
to use even as a mere drawing tool. I also wouldn't be surprised if
IBM discontinues it soon in favor of some of its modern competitors
(which are, from what I've heard, also buggy and tedious).

I'd rather use Doxygen (with all graphs enabled) to try to squeeze
some kind of overview out of the code. And use pen and paper to make
temporary sketches of class diagrams and so on. No generated diagram
can beat one which has been filtered by your brain.
2. while the logic is complicated (B), there are several portions of
code which can be treated as modules and adapted to a clear threading
model, instead of what we have now a hodge-podge of thread startegies,
this will celar up the data sync issues (deadlocks) and race condition
related bugs. But I can't find any one book that addresses various
threading models with pthreads in context with examples (I need good
books pictures or diagrams). Any suggestions?

Sorry, no. I find it very difficult to clean up badly written threaded
code. Part of the problem is that it's hard to do it incrementally.

If the code doesn't use RAII-style locking, /that/ is at least something
that's easy to fix.
3. Any suggestions on code maintainability -- that is, the design
aspects we need to consider while rewriting. (C) Rather than pointing
to something like design patterns etc, what is really desired is
learning from how do others refactor/write (original code) large
amounts of code that interacts with lot of HW devices and SW
components?

I don't get the reference to "HW devices". If you use an OS, you
should see it as I/O, which you perform by interacting with software
components.
Any URLs, case studies of such projects, responses to A,B,C 1,2,3 are
appreciated!

/Jorgen

[1] I once spent ~4 years maintaining a messy code base. After that,
some big areas were still fodder for thedailywtf.com -- but not
the areas which mattered for maintainability, stability or
performance!
 
J

Jorgen Grahn

["Followup-To:" header set to comp.lang.c++.]
greetings All,

Please respond to this posting if you have ever involved in a rewrite
of a complicated software system or driven such a project or have
insight into reengineering aspects:

Context:

Originally written using C++/pthreads on Sun Solaris, we need to
rewrite a component of a large system, so [...](A) the database,
communications (with other SW and devices), event management
infrastructure needs to be kept (so some reengineering in order), (B)
the rest of the logic code has to be rewritten or refactored whichever
suits the purpose. (C) The primary purpose of the rewrite is the code
has become difficult to maintain. Over 180,000 lines of code and uses
pthreads, code was written about 10 years ago with lot of changes
impacting the code maintainablity to date.

I am fairly convinced that the only right way to do such things is to:

- First spend time doing actual /maintenance/ work so you get to
learn the code base in practice. IME, a messed-up code base has
problems in many different areas, but some of them can be isolated
and left as-is; they are not important[1].

Reading your other postings, I understand that you are new to Unix
programming and looking for an editor. That's worrying -- it seems to
mean you have no experience with the system you're supposed to clean
up, or with the APIs it relies on. Let's hope there are plenty of
helpful veterans involved, too!

/Jorgen
 
E

Eric Sosman

greetings All,

Please respond to this posting if you have ever involved in a rewrite
of a complicated software system or driven such a project or have
insight into reengineering aspects:

Context:

Originally written using C++/pthreads on Sun Solaris, we need to
rewrite a component of a large system, so (A) the database,
communications (with other SW and devices), event management
infrastructure needs to be kept (so some reengineering in order), (B)
the rest of the logic code has to be rewritten or refactored whichever
suits the purpose. (C) The primary purpose of the rewrite is the code
has become difficult to maintain. Over 180,000 lines of code and uses
pthreads, code was written about 10 years ago with lot of changes
impacting the code maintainablity to date.

Challenges:

1. Reengineering tool for reusing the classes by feeding this huge
amount of code (A). Rational rose chokes on this and I need a better
tool. Do any of you use a reeng tool for this size of C++ code, if so
throw some light this tool, forums, your experience using this, etc.

2. while the logic is complicated (B), there are several portions of
code which can be treated as modules and adapted to a clear threading
model, instead of what we have now a hodge-podge of thread startegies,
this will celar up the data sync issues (deadlocks) and race condition
related bugs. But I can't find any one book that addresses various
threading models with pthreads in context with examples (I need good
books pictures or diagrams). Any suggestions?

3. Any suggestions on code maintainability -- that is, the design
aspects we need to consider while rewriting. (C) Rather than pointing
to something like design patterns etc, what is really desired is
learning from how do others refactor/write (original code) large
amounts of code that interacts with lot of HW devices and SW
components?

Any URLs, case studies of such projects, responses to A,B,C 1,2,3 are
appreciated!
[...]
It *might* be worth while to to re-engineer what you have but I would
give serious consideration to designing and implementing a solution from
the bottom up!

Seconded. The code in question is only 0.18Mlines of fairly
recent vintage, and you should be able to figure out its purpose
even if its implementation is unfashionable. (Put it this way: If
you can't figure out the purpose, how will you know whether your
rewrite is successful?)

So: Analyze, deduce a fresh set of specs, implement the specs,
test for adherence thereto.

-OR-

Think again about your reasons for jettisoning the existing
code. From what you say, it really can't be All That Bad. It uses
a recognized, standardized, and still-current programming language,
not some off-the-wall idiosyncratic extended Lisp-Basic blend. It
uses a multi-threading framework that's also standardized, still
current, and supportable, not some ad-hoc collection of home-brewed
spin-locks. It's possible you might be better off spending N man-
years on a cleanup than spending 2N wrestling with tools that get
you nowhere and another 8N on a re-implementation.

Or not. But base your decision on sound engineering estimates
and a rigorous cost-benefit analysis, not on a feel for what's
trendy today. I can almost guarantee that if you reimplement just
to be trendy, by the time you're done the trend will have passed.
 
M

Miles Bader

I'm a bit confused about what it has to do with pthreads anyway --
don't most other thread packages use roughly the same model anyway?

If the code base is hard to maintain, maybe somethings has to be done,
but it would seem at first glance that the choice of thread package
isn't a main issue...

-miles

--
Mad, adj. Affected with a high degree of intellectual independence; not
conforming to standards of thought, speech, and action derived by the
conformants [sic] from study of themselves; at odds with the majority; in
short, unusual. It is noteworthy that persons are pronounced mad by officials
destitute of evidence that they themselves are sane.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top