[lug] Learning to code on Linux.
David Morris
lists at morris-clan.net
Sat Mar 28 17:49:31 MDT 2009
On Sat, Mar 28, 2009 at 11:50, David L. Anselmi <anselmi at anselmi.us> wrote:
> What's a good way to learn how to write C apps for Linux?
I've learned *many* new programming languages over the years, and here is
the process I've refined (assuming you already know the
basics of programming).
1) Find a language syntax quick-reference card, print it out, and post it
on the wall next to your monitor.
2) Find a reference on the web for functions/libraries/classes/etc.
available standard with the language. Some languages this is part of
the documentation for the compiler (e.g. Python). Others, you must look
elsewhere (e.g. C).
3) (optional) Find a tutorial which at least touches on everything from the
most basic to the most advanced, with a clearly labeled index. Ideally,
the tutorial should include when *not* to use certain features, as well
as how to use them (all languages contain something which is ugly and
should normally be avoided). If the new language is sufficiently
similar to those you already know, this step can be skipped.
4) Pick a simple application, ideally either related to the upcoming task,
or a personal project you have been wanting to get around to. Write
this application in the new language (or at least start doing so, it
doesn't matter if you don't finish).
5) Dive in. Try to keep the application compiling & running at all times
(though not necessarily bug-free) so that you can verify you haven't
made any major mistakes.
6) After getting as far as possible using the above, search the web for
advanced techniques and suggestions on how to use the language to best
effect. Compare to how you wrote the code and see what you could do
better.
7) Repeat steps #5 and #6 (and possibly #4) iteratively until comfortable
with the language.
8) (optional) It can sometimes be useful to subscribe to an email list for
users of the language. Being able to ask questions which are perplexing
you can be invaluable, especially in a language which isn't widely used
(not an issue for C).
This process typically takes me anywhere from 2 hours to 40+ hours depending
on the complexity of the language and how different it is from those I
already know. Typically no more than 2 days of dedicated work though.
As for some C specific references, I can only be of limited help as I
learned C long before the internet made the above process easy. Two
references which are useful though:
Standard C/C++ library reference by Dinkumware:
http://www.dinkumware.com/manuals/
FAQs for C (look at "comp.lang.c" FAQS in particular) for basic and advanced
language tips:
http://www.faqs.org/faqs/C-faq/
C++ FAQ Lite (Some of which is C related) for advanced language tips:
http://www.parashift.com/c++-faq-lite/
> 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.
>
> 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.
I recommend NOT looking at the libc source code. Standard libraries are
written using advanced and highly optimized code. They will create
confusion in anyone just starting out learning the language, and give
mistaken impressions about when certain features of the language should be
used. It will also make the language seem more complex than it is. (Yes,
I made the mistake of doing this once).
> 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.
I can't help with study groups (I find them counter-productive), but as for
dial-up, it shouldn't be a problem. It might be useful to obtain CD's of a
Linux distribution including source-code packages so as to avoid long
download times, but everything else needed to learn a language on your own
is contained in text-only web pages which dial-up is fine for.
I frequently go through the above process on a laptop without internet
access. I find the reference material ahead of time, download a copy so I
can use it offline, then find a comfortable place to dive in to the
learning process.
> 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.
Getting source code for packages depends on the Linux distro being used,
but is typically as easy as (for Debian & similar): "apt-get source <package>"
As for using -dev packages, man pages are your friend. Most libraries are
documented in man pages including instructions on how to compile in the
required functionality.
Hope this helps!
--David
More information about the LUG
mailing list