[NTLUG:Discuss] Wanting to speak the language

Kevin Brannen kbrannen at pwhome.com
Thu Feb 24 21:57:28 CST 2005


Ed Leach wrote:

>I'd appreciate it if an enthusiast of a particular language (my
>interests: C, C++, Perl, Python) could point to 2-3 relatively simple
>open source projects that could be examined after finishing some intro
>book. There are so many it's difficult to know where to look for good
>samples.
>  
>

The answer to this is probably similiar to Andrew's original question.  
Find a project that interests you and jump in.  You could also find a 
small project or idea and just go for it -- sort of "scratch an itch" to 
something that has been bothering you.

For example, when you do a listing of a directory with "ls -l" (aliased 
to "ll" on my system), you get something like:

[104 ~ /usr/bin] ll xp*
-rwxr-xr-x  1 root root 1029441 2005-01-04 06:34 xpdf
-rwxr-xr-x  1 root root     635 2004-10-01 20:47 xphalanx
-rwxr-xr-x  1 root root   14268 2004-10-01 20:08 xpmtoppm

These numbers are a bit small, but if they were larger, you'd be 
wondering if that first file is 1M or 10M.  Gee, if we just had commas 
in there.  Write a program to take the output to "ls -l" and put commas 
in the size field.  For example:

[105 ~ /usr/bin] llc xp*
-rwxr-xr-x  1 root     root           1,029,441 2005-01-04 06:34  xpdf
-rwxr-xr-x  1 root     root                 635 2004-10-01 20:47 xphalanx
-rwxr-xr-x  1 root     root              14,268 2004-10-01 20:08 xpmtoppm
Total Bytes: 1,044,344

"llc" is a 50 line perl program I wrote (that does a few extra things so 
it could be a bit shorter), but write that program in C.  You'll learn 
string manipulation.  Next, rewrite the program to do what "ls -l" does, 
and put commas in.  [Hint:  do "man readdir" which will be the heart of 
your function that gets the dir entries, also look at the man pages for 
the other functions in the "SEE ALSO" section.]  Now that you've done it 
both ways, which is shorter?  Which is easier to understand?  Which do 
you prefer (to maintain if you had to)?  etc.

Anyway, almost any project will do, just find something you like.  (Ever 
wondered why there are a bazillion utilities on Freshmeat/Sourceforge 
that do the same thing?  Many of them were learning projects for people 
too. :-)

HTH,
Kevin




More information about the Discuss mailing list