[lug] Learning to code on Linux.
Bear Giles
bgiles at coyotesong.com
Sat Mar 28 19:00:25 MDT 2009
I'm going to take a contrary voice here.
> A friend called me today to ask about getting the source for libc. I
> installed Linux for him but didn't include the source packages. He
> wants to rewrite a FORTRAN app in C, so that it will be more portable
> and maintainable down the road. He has little experience with Linux.
I think the key words here are PORTABLE and MAINTAINABLE. Like many
other people here I have worked with scientists who picked up a C book
and were convinced they could write C apps just because they got their
stuff to compile. It might have compiled, but it was clearly "Fortran
in C". It was just as bad as "Pascal in Ada" (1980s) and even, shudder,
the "Fortran in Ada" I saw a few times at a defense contractor.
Anyone with experience in one procedural language can write something
that compiles in another procedural language in a few days to a few
weeks. But it's at least six months until you write stuff that doesn't
consistently make you flinch later, and probably at least two years
until you can do something truly portable and maintainable. You can't
do the latter until you understand at a deep level how other people will
approach the code.
To be honest the best answer may be learning how to use the gcc Fortran
tool chain under Linux and cleaning up the code in a language he knows
well. Bring it up to the latest version of Fortran, fix all warnings,
use modern naming conventions instead of one- or two-character variable
names for anything other than loop indexes and the like. It should also
be possible to use Fortran/C bindings, especially if everything is
handled by the gcc tools. GCC has changed the game entirely since they
have multiple front-ends to the compiler -- I seem to recall it offering
C/C++, java, fortran, ada, more.
> So, I can get him the source. He said, "if I have the source it will
> answer all my questions about libc, and probably teach me what I need
> to write my app." He's not scared of doing hard work to gain a skill.
Reading the libc source will tell him how to write a C library. That's
not what he wants to do. He wants to port a Fortran app. To see how to
do that, he should look at the source code of similar apps that are
already written in C, and ideally review them with a friend who's both C
literate and scientifically literate so the friend can point out bad C
practices while understanding what the author was trying to do.
> But I wonder what might be more efficient for him. A study group or
> book might be a big help. Unfortunately he doesn't get around at all
> and has dial-up Internet.
There's the classic "Numerical Methods in C".
> I expect he can figure out gcc, make, etc, but might need some help
> with the easiest way to get source packages, how to use -dev packages,
> etc.
There should be 'hello world' demonstrations for all of the standard
portable tools, at least under Debian/Ubuntu. It's basically an empty
project that does nothing but has all of the configuration files set up
to do autoconf, automake, and then package as a .deb package. You just
have to add your source and set up the build process. "just" hee hee.
Bear
More information about the LUG
mailing list