The other parts of programming
April 27, 2005 2:59 PM
Subscribe
Programmers: where did you learn all the aspects of programming
besides actually writing code?
Finding information on writing code is easy enough, but I've lost track of how many times I've taken somebody else's tutorial code, for instance, and found myself unable to compile it successfully. How do I grok the various compiler and linker options? How do multiple source files interact? What's a makefile? More generally, how do I set up my workspace and directory structures to streamline my workflow?
I'm not so much asking for answers to these specific questions, though I'll accept any wisdom you've got lying around. I'm just baffled at how most info I've found seems to assume the reader already knows all this stuff. Incidentally, I'm running win2k and have both VC++ 6 and Bloodshed Dev-C++.
posted by squidlarkin to computers & internet (14 comments total)
1 user marked this as a favorite
It's easy to learn how to compile a C program; it's harder to know how you use automake, autoconf, make, GCC, the linker, etc. together to produce a finished package complete with documentation/man pages, changelog, and so on. How do you arrange and structure the source code, for example? Learning C is dead easy; C++ less so, but in the end it's just a language; but learning to develop efficiently in that language, picking up well-established techniques and patterns, takes time.
This problem is not limited to Unix programming, which is oriented around C/C++ and tons of conventions which often exist because the languages are so low-level; compared to systems like Java or Ruby where you never need to deal with linking, and cross-platform support often comes gratis. (One reason you may have problems compiling tutorials is precisely because you don't have the right dependencies: the right include files installed, or perhaps not the platform the code was designed for.)
Many of those conventions are documented; there's a GNU ChangeLog format, the man format is documented, there's the Unix Programming Frequently Asked Questions, there's the O'Reilly books, and so on. And some you just pick up by reading other people's code or studying their projects. You can read the GNU Makefile manual from cover to cover; but you might need to read a few real-world makefiles to "get" it.
You mention compiler and link options specifically -- and I think that's a bitch for everyone, except perhaps the original compiler developers. VC++ is laughably simple compared to the GCC toolchain, which has lots of options, lots of front ends, lots of back-end support for different platforms and formats, and invokes many subtools (
cpp,ld,libtool). Sometimes these fail, and the pipeline doesn't track the context in a way that lets the tools know what went wrong -- more often than not you will get an error which just doesn't describe the actual problem.In the end, even learning these tools is covered somewhere. The bad part is when there isn't any documentation, or where the documentation is so scattered that the ramp-up time destroys every last smidgen of creativity you have. For example, writing a GCC front end -- which involves generating parse trees and using a barrage of undocumented macros and APIs, where the only way to learn is to study the existing code.
Incidentally, autoconf and automake are designed to automate the compiler stuff. They will generate scripts that construct the makefile for you, based on a number of heuristics, such as what compiler is installed, what the OS is, what libraries and include files are available, etc. You've seen configure scripts, right? That was made with autoconf.
A caveat, though: Even with these tools you will need to know how the pieces fit together; so while they will be useful later on, for now I recommend sticking with manual compilation (with makefiles, natch), until you feel confident enough to delegate the process to the automatic tools. Of course, on small, personal projects, a manual makefile will do fine.
If I haven't answered any of your questions, it's because I can't possibly tell you everything you need to know in a single reply. The answers are out there, if you look. For example, the Wikipedia entry on makefiles.
When I first read your main question, I assumed you were talking about the development process itself. Test-driven development, for example, or how to coordinate a project between multiple developers, all the Mythical Man-Month stuff of managing large projects. For me, writing code is cheap and easy; what's hard is doing it in the minimum amount of time and making the technical decisions that are right for the product, as opposed to being made because they involve cool technology.
posted by gentle at 3:32 PM on April 27, 2005