2
$\begingroup$

This might be better somewhere else, but I'll give it a try here first.

I'm implementing a finite volume scheme for an axisymmetric problem in C, and am looking for a more efficient way to handle all of the necessary parameters each function needs.

Is a pointer to a struct better, more efficient, or easier in implementation than a list of the function parameters? I personally think the struct is easier to handle when writing the code, but my professor, who loves Fortran, probably doesn't agree. Is the use of structs in scientific computing accepted? Tolerated? Something that should be avoided?

Thanks for your thoughts.

$\endgroup$
1
  • $\begingroup$ Gromacs a patricle simulation software for biomolecular simulations is written entirely in C and uses a lot of pointer to structs to pass information around. Keeping stuff together which belongs together is exactly why C has structs. Modern Fortran has a very similar concept of type definitions. So just remind him that the old fortran days are no longer upon us. $\endgroup$
    – Bort
    Commented Oct 27, 2015 at 16:04

1 Answer 1

1
$\begingroup$

All sorts of programming style are accepted, tolerated, and definitely not avoided. You should look at some open source scientific computing packages out there in the world to see the diverse styles that they are written in. They run the gamut from million-line, common-block heavy Fortran to much more object-oriented C++ or very idiomatic Python.

$\endgroup$
2
  • $\begingroup$ Thanks for the response. I've started looking at some gsl code to get a better feel for what else is out there. I've written some very pythonic solvers for this professor, which he's not really commented on. I've used structs before and gotten lots of red marks back on the printout. I wasn't sure if structs were verboten, or if it was more of my professor's personal preference. $\endgroup$ Commented Sep 28, 2015 at 0:49
  • $\begingroup$ I'd look at more than GSL. I'm not saying it's bad, but you want to get a look at as large a variety of programming styles as you can. Structs are not forbidden. They are part of the language, you should use them if they are appropriate--no different than you would a class or a dictionary. I'd say you've run into a preference of your professor's. Fortran 90 has structures, too. $\endgroup$
    – Bill Barth
    Commented Sep 28, 2015 at 0:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.