retiring gets(3)

Dave Brower daveb at gonzo.UUCP
Tue Nov 22 16:04:04 AEST 1988


>Jas writes:
>In <8915 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:
>
>[In effect:  sometimes gets() really is safe, or sufficient:  e.g., in
>programs whose input is known a priori, or in small, one-shot test
>programs, or ....]
>
>>Why work harder when gets() does exactly what one needs?
>
>But how much harder do you end up working without gets()?  Using fgets()
>isn't exactly 5 years of hard labor.  gets() just doesn't seem to
>provide much added value, and is almost never safe.  (I've certainly
>written some small, one-shot test programs that ended up being so useful
>that lots of people had the opportunity to gag at my "one-shot" code.)

Jasbo obviously doesn't want to tell the story here, so I will, with
minor embellishments.

Once upon a time, the 'Zbo tried to figure out how the large character
writing on a VT100 family terminal worked.  In order to do so, he wrote
a little test program that took the command line arguments like echo,
and spat them out with the right escape sequences and multi-line
duplication to correctly drive the terminal.

It is lost to history who started it, but there followed a brief period
of "writebig" wars, with surreal messages in large letters appearing at
random times on compatriot's screens, to humourous effect.

"Wonderful!" said the workmates, who quickly snatched the program for
use in a messaging service that would send out the clarion call to go to
lunch in nice big letters.

"But! But! But!  It's a hack!", said 'Zbo, "I don't want to support it!"

And the users said, "Oh pleeaze, 'Zbo, it's so handy, please don't take
it away."  And then they whispered, "it would be awfully nice if it
would center lines on the screen"

"No! No! No!", said 'Zbo, "It's a hack!  I don't want to be responsible!
Next thing I know, people will start asking for documentation!"

But the user's cajoled and begged, and twisted the 'Zbo's arm, and
writebig was changed to center lines.

Then one day at tea, the Ceferino Lamb innocently inquired about the
neat announcement program that wrote letters double high and double
wide.  "Writebig, huh.  Where's the man page?"  And the 'Zbo let out a
quiet scream.

Moral:  There is _never_ a one shot test program.

(Corrollaries are left as an excercise to the reader.)

-dB

[ This is one of the few times I've ever disagreed with Doug Gwyn.
  Don't use gets().  It is the work of the devil. ]




-- 
If life was like the movies, the music would match the picture.

{sun,mtxinu,hoptoad}!rtech!gonzo!daveb		daveb at gonzo.uucp



More information about the Comp.lang.c mailing list