Index

Subject : Re: LUG: Coding Horrors -- post your evils

From : "Daniel Underwood" <daniel.underwood@ncsu.[redacted]>

Date : Thu, 06 Aug 2009 06:49:45 -0400

Parent


> I'm up for any suggestions on how to clean this up,

Some scientific computation routines are almost unavoidably
complex/messy. What do you hope to achieve by cleaning up the code? Is
it primarily for your own benefit in avoiding errors? Is it primarily
in order for others to be able to modify your code? What?

If you modularize and isolate the "messiness", and if the code works and
is efficient, there should be no problem. The code that calls these
functions, however, should be cleaned up, especially if there are calls
in multiple locations.

You might clean up the Aniso_Pa_Field_Update() parameters by packaging
the arguments into a struct and then changing this:

void Aniso_Pa_Field_Update(int z_min, int z_max, int x_min, int x_max,
COMPLEX** pxa, COMPLEX** pya, COMPLEX** pza,
COMPLEX** past_pxa, COMPLEX** past_pya, COMPLEX** past_pza,
COMPLEX** past_qx, COMPLEX** past_qy, COMPLEX** past_qz,
COMPLEX** rxx, COMPLEX** rxy, COMPLEX** rxz,
COMPLEX** ryx, COMPLEX** ryy, COMPLEX** ryz,
COMPLEX** rzx, COMPLEX** rzy, COMPLEX** rzz,
COMPLEX** cepx1, COMPLEX** cepx2, COMPLEX** cepx3,
COMPLEX** cepy1, COMPLEX** cepy2, COMPLEX** cepy3,
COMPLEX** cepz1, COMPLEX** cepz2, COMPLEX** cepz3,
double** deltaxx, double** deltaxy, double** deltaxz,
double** deltayx, double** deltayy, double** deltayz,
double** deltazx, double** deltazy, double** deltazz,
COMPLEX** cxi11, COMPLEX** cxi12, COMPLEX** cxi13,
COMPLEX** cxi21, COMPLEX** cxi22, COMPLEX** cxi23,
COMPLEX** cxi31, COMPLEX** cxi32, COMPLEX** cxi33,
double th, double S)

to this:

void Aniso_Pa_Field_Update(structT PTRS, int z_min, int z_max, int
x_min, int x_max, double th, double S)

Granted, this would make the body of Aniso_Pa_Field_Update() a little
more "messy", but the increased messiness there would be justified by
the decreased messiness in the calling code.

I'm far from an expert, and it's 6:45am and I haven't had my morning
coffee, but these are my initial thoughts.
--
Daniel Underwood
North Carolina State University
Graduate Student - Operations Research
email: daniel.underwood@ncsu.[redacted]
phone: XXX.302.3291
web: http://www4.ncsu.edu/~djunderw/



Replies :