old-www/LDP/LG/issue89/bint.html

293 lines
7.8 KiB
HTML

<!--startcut ==============================================-->
<!-- *** BEGIN HTML header *** -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML><HEAD>
<title>Laurel and Hardy Try to Write a C Program LG #89</title>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#0000AF"
ALINK="#FF0000">
<!-- *** END HTML header *** -->
<!-- *** BEGIN navbar *** -->
<!-- *** END navbar *** -->
<!--endcut ============================================================-->
<TABLE BORDER><TR><TD WIDTH="200">
<A HREF="http://www.linuxgazette.com/">
<IMG ALT="LINUX GAZETTE" SRC="../gx/2002/lglogo_200x41.png"
WIDTH="200" HEIGHT="41" border="0"></A>
<BR CLEAR="all">
<SMALL>...<I>making Linux just a little more fun!</I></SMALL>
</TD><TD WIDTH="380">
<CENTER>
<BIG><BIG><STRONG><FONT COLOR="maroon">Laurel and Hardy Try to Write a C Program</FONT></STRONG></BIG></BIG>
<BR>
<STRONG>By <A HREF="../authors/bint.html">Stephen Bint</A></STRONG>
</CENTER>
</TD></TR>
</TABLE>
<P>
<!-- END header -->
<BLOCKQUOTE>
<STRONG>... featuring those Lovable Dolts, Stan Laurel and Oliver Hardy.</STRONG><BR>
<A HREF="http://www.laurel-and-hardy.com/">(Official L&H site)</A> &nbsp;&nbsp;
<A HREF="http://www.laurelnhardy.co.uk/">(UK tribute page)</A>
<P> This article is a follow-up to the author's
<A HREF="../issue87/bint.html">The Ultimate Editor</A> in January and the
<A HREF="../issue88/lg_mail.html#mailbag.1">Mailbag letters</A> (three of them)
it received in February.
<HR>
</BLOCKQUOTE>
<P>
<EM>Ollie is sitting in front of a terminal. Stan enters,
carrying a book.</EM>
<P>
<STRONG>Ollie:</STRONG> Where have you been?
<P>
<STRONG>Stan:</STRONG> I went to the bookstore to get a book like you
said.
<P>
<STRONG>Ollie:</STRONG> Well, you took your sweet time. We have to get
this CGI script finished by tomorrow morning. Let's
see what you've got.
<P>
<EM>Stan hands Ollie the book.</EM>
<P>
<STRONG>Ollie:</STRONG> "A Guide to Programming in C". What is this?
<P>
<STRONG>Stan:</STRONG> It's a guide to programming in C, Ollie.
<P>
<EM>Ollie looks at camera - not amused.</EM>
<P>
<STRONG>Ollie:</STRONG> I can see that, you idiot. I thought I told
you we were going to write it in Perl.
<P>
<STRONG>Stan:</STRONG> But Mr. Bint said...
<P>
<STRONG>Ollie:</STRONG> Mr. Bint?
<P>
<STRONG>Stan:</STRONG> The man at the bookstore. Mr. Bint.
<P>
<STRONG>Ollie:</STRONG> <EM>[Impatiently]</EM> What did "Mr. Bint" say?
<P>
<STRONG>Stan:</STRONG> He said he was all sold out of books about
Perl, but he had a whole shelf full of books about
C. He said I was lucky.
<P>
<STRONG>Ollie:</STRONG> How did he make that out?
<P>
<STRONG>Stan:</STRONG> He said C is a better choice for CGI programs.
He said C is a professional programming language,
but Perl is a toy language. He said Perl is a jumped
up scripting language that's gotten ahead of itself.
<P>
<STRONG>Ollie:</STRONG> Oh, he did, did he?
<P>
<STRONG>Stan:</STRONG> <EM>[Nods]</EM> Mr. Bint says that though the learning
curve with C is initially steeper, ultimately there
is less to learn, because C has fewer rules. He said
Perl does most things for you and you need to learn
exactly what it does in every case, to understand what
your program is doing. He said that's why books about
C are so thin and books about Perl are so fat. He says the reason he is sold
out is that Perl books are so fat he can only fit four on a shelf. Not only
that, but the trucks that deliver them often fail to arrive because their tyres
keep exploding.
<P>
<STRONG>Ollie:</STRONG> Is that a fact?
<P>
<STRONG>Stan:</STRONG> <EM>[Nods]</EM> That's what Mr. Bint says. He says that
Perl has confusing syntax and fails to define function
interfaces correctly, which invites sloppiness.
<P>
<STRONG>Ollie:</STRONG> And what else does he say?
<P>
<STRONG>Stan:</STRONG> He says that C is often made out to be full of
danger and potential for disaster compared to Perl,
but in fact, Perl is only proof against a couple of
common bugs and its lack of readability makes other
bugs more likely. He says the gcc compiler gives
good warnings about badly written C, there are tools
which can check for memory leaks and Lint to check
for other common errors.
<P>
<STRONG>Ollie:</STRONG> Mmmph. Mr. Bint recommends Lint, does he?
<P>
<STRONG>Stan:</STRONG> Yes.
<P>
<EM>Ollie looks impatiently at the camera, then at Stan. </EM>
<P>
<STRONG>Ollie:</STRONG> Well, I suppose we will just have to write it
in "C".... "Mr. Bint". Mmmpph!
<P>
<EM>Ollie faces keyboard and prepares to type.</EM>
<P>
<STRONG>Ollie:</STRONG> OK, you read the book out to me and I'll type
in the program.
<PRE>
while( ollie_waits ) {
Stan_looks_at_book();
Stan_looks_at_Ollie();
Stan_looks_panic_stricken();
if( ollie_looks_around() )
ollie_waits = false;
}
</PRE>
<P>
<STRONG>Ollie:</STRONG> Well, what is it now Stanley?
<P>
<STRONG>Stan:</STRONG> <EM>[Blubbering]</EM> I'm sorry Ollie... blubber...
I don't think we can just start straight away...
snivel...I think we have to read the book and
learn the language first...
<P>
<STRONG>Ollie:</STRONG> Will you stop sniveling? How hard can it
be? We'll simply learn the language, then we'll
write the program.
<P>
<EM>Ollie turns to give Stan his full attention.</EM>
<P>
<STRONG>Ollie:</STRONG> OK, tell me what we need to learn about C
before we can start.
<P>
<STRONG>Stan:</STRONG> According to this table of contents...
variable types, user-defined types, typedefs,
static variables, initialisation vs. assignment,
constants, statements, binary operators, unary
operators, arithmetic operators, logical
operators, bitwise operators, operator precedence,
if, for, switch, while, continue, break, arrays...
<P>
<EM>Ollie looks at camera - not amused.</EM>
<P>
<STRONG>Stan:</STRONG> multi-dimensional arrays, pointers, pointer
arithmetic, function pointers, function declaration
and definition, preprocessor directives and macros,
printf formats, automatic and allocated memory,
command-line arguments, recursion...
<P>
<EM>Ollie removes Stan's hat, slaps him round the chops
with the mouse mat (both sides), carefully replaces
hat. Stan stops reading.</EM>
<P>
<STRONG>Ollie:</STRONG> Well, congratulations Stanley. This is another
fine mess you've gotten me into.
<PRE>
while( camera_is_running() )
Stan_blubbers();
</PRE>
<P>
<EM>Fin.</EM>
<!--
<H3>Further Reading (anti-Perl)</H3>
<a
href="http://groups.google.com/groups?as_umsgid=2969@jato.Jpl.Nasa.Gov">
Readability suffers slightly...</a> (by Larry Wall)
<P>
<A HREF="http://www.garshol.priv.no/download/text/perl.html">What's Wrong with Perl</A>
<H3>Further Reading (obfuscated C)</H3>
<A HREF="http://www0.us.ioccc.org/2001/cheong.c">A rectangular program</A>
<P>
<A HREF="http://www0.us.ioccc.org/2001/anonymous.c">A program with one-letter #define's</A>
-->
<!-- *** BEGIN author bio *** -->
<P>&nbsp;
<P>
<!-- *** BEGIN bio *** -->
<P>
<img ALIGN="LEFT" ALT="[BIO]" SRC="../gx/2002/note.png">
<em>
Stephen is a homeless Englishman who lives in a tent in the woods. He eats out
of bins and smokes cigarette butts he finds on the road. Though he once worked
for a short time as a C programmer, he prefers to describe himself as a "keen
amateur".
</em>
<br CLEAR="all">
<!-- *** END bio *** -->
<!-- *** END author bio *** -->
<!-- *** BEGIN copyright *** -->
<hr>
<CENTER><SMALL><STRONG>
Copyright &copy; 2003, Stephen Bint.
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 89 of <i>Linux Gazette</i>, April 2003
</STRONG></SMALL></CENTER>
<!-- *** END copyright *** -->
<HR>
<!--startcut ==========================================================-->
<CENTER>
<!-- *** BEGIN navbar *** -->
<!-- *** END navbar *** -->
</CENTER>
</BODY></HTML>
<!--endcut ============================================================-->