S
spinoza1111
Goodie , a flame war !
<Sits back in seat with pop-corn in hand>
Glad to oblige. Right you swine...
Goodie , a flame war !
<Sits back in seat with pop-corn in hand>
pemo said:Andrew Poelstra wrote:
I followed the link,
but alas couldn't find any such comment from Richard.
Richard said:[X-posted, and followups set]
I found something interesting on the Web today, purely by chance.
It would be funny if it weren't so sad. Or sad if it weren't so funny. I'm
not sure which.
http://www.developerdotstar.com/community/node/291
This "teacher of C" demonstrates his prowess with a masterful display of
incompetence in a 200-line program that travels as swiftly as possible to
Segfault City.
(Actually, using my normal gcc switches, it doesn't even get past TP3, but
it will at least compile if you just use gcc -o foo foo.c, after hacking it
around a bit to do things like mending the line-spanning single-line
comments and string literals, which - in fairness to the author - are
probably an artifact of the Webification of the code.)
Richard Heathfield said:[X-posted, and followups set]
I found something interesting on the Web today, purely by chance.
It would be funny if it weren't so sad. Or sad if it weren't so funny. I'm
not sure which.
http://www.developerdotstar.com/community/node/291
This "teacher of C" demonstrates his prowess with a masterful display of
Interesting. I just tried it myself. Copy-and-pasting the program
was tedious, but once I did that there were no line-wrapping errors.
Perhaps it's a function of which browser you use.
Obviously the "//" comments won't work if you use strict C90 mode.
Is this a result of -pedantic?With "gcc -g -std=c99 -pedantic -Wall -W -O3 sieve.c -o sieve", I got:
sieve.c: In function `string2Number':
sieve.c:64: warning: comparison between signed and unsigned
sieve.c: In function `main':
sieve.c:202: warning: int format, time_t arg (arg 2)
The first is a comparison between an int and the result of strlen();
assuming no strings longer than 2**31-1 characters (on my 32-bit
system), this bug shouldn't cause any visible symptoms. Likewise, I
left the second bug in place, since both int and time_t happen to be
32-bit signed integers on the system I'm using. (If I were actually
going to use the program, I'd fix both bugs first.)
I got a quick seg fault when I ran it, because of the following really
dumb statement:
printf( strcat(strcat("Sieve of Eratosthenes primes from least prime >= %d ",
"to greatest prime <= %d\n"),
"Sieve contains %d entries\n"),
MAX(intStart, 3),
intFinish,
intSieveLimit );
Using "-fwritable-strings" avoided the seg fault, but messed up the
output (obviously it was still invoking undefined behavior).
I changed the above to use string literal catenation rather than
strcat():
printf( "Sieve of Eratosthenes primes from least prime >= %d "
"to greatest prime <= %d\n"
"Sieve contains %d entries\n",
MAX(intStart, 3),
intFinish,
intSieveLimit );
With that change, the program seems to work (its failure to indicate
that 2 is prime seems to be an intentional design flaw rather than a
coding error).
It's still a good example of ugly C (they're called argc and argv, not
intArgCount and strArgValues), and it could probably be written more
clearly in no more than half the space, but it's not nauseatingly bad.
Andrew said:[X-posted, and followups set]
I found something interesting on the Web today, purely by chance.
Just out of curiousity, did you stumble upon that while Googling your own
name? I'm not accusing you of arrogance, but it's interesting that he
mentions and insults you specifically in his preamble.
It would be funny if it weren't so sad. Or sad if it weren't so funny. I'm
not sure which.
http://www.developerdotstar.com/community/node/291
This "teacher of C" demonstrates his prowess with a masterful display of
incompetence in a 200-line program that travels as swiftly as possible to
Segfault City.
Ooh. Segfault City. Where all bad programs go to die.
(Actually, using my normal gcc switches, it doesn't even get past TP3, but
it will at least compile if you just use gcc -o foo foo.c, after hacking it
around a bit to do things like mending the line-spanning single-line
comments and string literals, which - in fairness to the author - are
probably an artifact of the Webification of the code.)
I wonder how long I'll take to stop laughing.
I stopped reading after the first function. I wasn't sure why he kept
casting chars to ints, as though there wasn't implicit casting going on
by default. Then he tested for > '9', which made no sense to me. Realizing
that I wouldn't be able to trace that logic, I stopped.
What, if anything, can it be guaranteed will be > '9' in standard C?
Seriously, a professional would say in as neutral a way as possible, so
as not to give unnecessary offense, what he found and why he thinks it
is wrong.
But we knew you are a hack and not a professional.
Furthermore, to make a positive assertion [...]
I didn't use the Gnu compiler with what I shudder to think might be
what you believe a normal combination of its switches.
Given that C is
such a primitive language, the actual result of any one compile with
any one setting of the large numbers of switches provided by gcc is of
course going to be precise but not in general predictable for any one
program.
I used the free Navia compiler, instead, with default settings.
It's already obvious to me that you are at best a paraprofessional, who
seriously recommends C for new development. I'd hazard that your C
environment is that of a Mad Scientist:
I am certain that when you pull C code (that you can't write yourself)
from the Web, you have to fiddle with your elaborate installation to
make it work.
Did it run?
Alf said:* Richard Heathfield:[X-posted, and followups set]
I found something interesting on the Web today, purely by chance.
It would be funny if it weren't so sad. Or sad if it weren't so funny. I'm
not sure which.
http://www.developerdotstar.com/community/node/291
This "teacher of C" demonstrates his prowess with a masterful display of
incompetence in a 200-line program that travels as swiftly as possible to
Segfault City.
(Actually, using my normal gcc switches, it doesn't even get past TP3, but
it will at least compile if you just use gcc -o foo foo.c, after hacking it
around a bit to do things like mending the line-spanning single-line
comments and string literals, which - in fairness to the author - are
probably an artifact of the Webification of the code.)
I wonder how long I'll take to stop laughing.
I can understand you responding, Rirchard, since the web page contains a
comment about you, but I think it would have been more helpful to Edward
Nilges if you'd just sent him a private e-mail pointing out some of the
errors, such as the use of strcat in
printf( strcat(strcat("The %s program calculates primes ",
"in a user-specifiable range. "),
"Use the following syntax: %s"),
strArgValues[0],
SYNTAX_REMINDER );
It's evident from the introductory text that Edward isn't a C
practitioner (e.g., he mentions how he had to figure out the declaration
syntax for arrays) and is used to more object-oriented languages, and
the code, such as the above, makes it painfully evident that he doesn't
have anybody doing quality assurance of the code -- which, one is led
to believe, is used in some C.Sc. course.
Perhaps he'd be glad to receive some help about that?
CC: (e-mail address removed), which I'm assuming is Edward G. Nilges.
Yes, I'd used strcat in that way because I was returning to C after
several years.
I'd posted the rather trivial code because I'd
developed it for a class precisely to get word of any bugs.
I taught C at Princeton and assisted Nash with it when I was using it
every day in the early 1990s.
But when OO languages became available, I
abandoned it because it was impossible to manage large data structures
properly in this language (Richard H thinks it's possible, which only
indicates his limitations).
In fact, given that I'm so [elided] smart , my really stupid error in
using strcat into an unknown region that would cause a segment fault in
many cases (but didn't on my system) illustrates that C is inadequate
for new development.
Keith said:I probably would have if I'd read it before compiling it.
Here's the function you're probably talking about:
========================================
// Convert character to its numeric form
//
//
int char2Number( char chrInChar )
{
int intInCharValue = ( int )chrInChar;
int intZeroValue = ( int )'0';
if ( intInCharValue < intZeroValue
||
intInCharValue > ( int )'9' ) return -1;
return intInCharValue - intZeroValue;
}
========================================
If something is < '0' or > '9', it's not a digit, and the function
returns -1 as an error indication.
On first glance, I assumed that something that size would convert a
string to an integer ("123" --> 123). Then I realized it only
converts a single character.
It's really impressive how ugly this manages to be without actually
being incorrect.
Which disqualifies you from a technical discussion.
Why are you posting?
It was a straightforward test for numerics.
Again, are you qualified to be in this discussion?
You stopped trying to understand things twice, so your opinion is
worth...what?
This isn't grammatical therefore I do not fully understand it. If you
are saying there is no character greater than 9, well I wish you all
the best in your future career. You'll need it.
Keith said:Richard Heathfield said:[X-posted, and followups set]
I found something interesting on the Web today, purely by chance.
It would be funny if it weren't so sad. Or sad if it weren't so funny. I'm
not sure which.
http://www.developerdotstar.com/community/node/291
This "teacher of C" demonstrates his prowess with a masterful display of
incompetence in a 200-line program that travels as swiftly as possible to
Segfault City.
(Actually, using my normal gcc switches, it doesn't even get past TP3, but
it will at least compile if you just use gcc -o foo foo.c, after hacking it
around a bit to do things like mending the line-spanning single-line
comments and string literals, which - in fairness to the author - are
probably an artifact of the Webification of the code.)
I wonder how long I'll take to stop laughing.
Interesting. I just tried it myself. Copy-and-pasting the program
was tedious, but once I did that there were no line-wrapping errors.
Perhaps it's a function of which browser you use.
If you try the printer friendly version of the page copy and pasting
is easy with no line-wrapping.
I got a quick seg fault when I ran it, because of the following really
dumb statement:
printf( strcat(strcat("Sieve of Eratosthenes primes from least prime >= %d ",
"to greatest prime <= %d\n"),
"Sieve contains %d entries\n"),
MAX(intStart, 3),
intFinish,
intSieveLimit );
Using "-fwritable-strings" avoided the seg fault, but messed up the
output (obviously it was still invoking undefined behavior).
I changed the above to use string literal catenation rather than
strcat():
printf( "Sieve of Eratosthenes primes from least prime >= %d "
"to greatest prime <= %d\n"
"Sieve contains %d entries\n",
MAX(intStart, 3),
intFinish,
intSieveLimit );
His use of strcat was very puzzling for me. Even if he doesn't know
that the compiler will concatenate strings why not use multiple
printf's ? The use of nested strcat's make it a lot less readable even
if it was working.
I haven't tried compiling it but I tried to read it and understand it.
After
a while I gave up. His general verbosity and use of Hungarian notation
in particular made it unreadable for me. Based on what I could
understand
I doubt that it actually implements Eratosthenes's sieve. Here's a
programme which does:
#include <stdio.h>
#define LIMIT 1000
int main() {
int sieve[LIMIT+1] , i , j ;
for (i=2 ; i<=LIMIT ; i++) sieve=1 ;
for (i=2 ; i <= LIMIT/2 ; i++) {
for (j=2 ; i*j <= LIMIT ; j++) {
sieve[i*j] = 0 ;
}
}
for (i=2 ; i<=LIMIT ; i++) {
if (sieve) printf("%d\n",i) ;
}
}
Spiros Bousbouras
Keith Thompson wrote:
It's still a good example of ugly C (they're called argc and argv,
not intArgCount and strArgValues), and it could probably be written
more
Richard said:Andrew Poelstra said:
[X-posted, and followups set]
I found something interesting on the Web today, purely by chance.
Just out of curiousity, did you stumble upon that while Googling your own
name? I'm not accusing you of arrogance,
...just of self-indulgence. Yes, I was actually looking for a specific Terry
Pratchett quote. I knew it was on a page of quotations that /also/ quoted
something by me, but that's all I could remember, so I googled for my name
+ quote and Google showed me:
Wayne's World of C Code (The Sieve of Eratosthenes) | developer ...
[Richard Heathfield and his team have some good advice in his book, ... I
wish I could quote the whole column (or link to it--it's not available
online), ...
www.developerdotstar.com/community/node/291 - 59k - Cached - Similar pages
which looked promising, but alas, turned out to be junk after all.
I stopped reading after the first function. I wasn't sure why he kept
casting chars to ints, as though there wasn't implicit casting going on
by default. Then he tested for > '9', which made no sense to me. Realizing
that I wouldn't be able to trace that logic, I stopped.
What, if anything, can it be guaranteed will be > '9' in standard C?
UCHAR_MAX + 1.0, I think, although if you have really amazingly colossal
chars you might manage to break it.
Do enlighten us, Richard. I was testing the character 9 which isn't the
highest value character,
in ascii or unicode or even ebcdic.
Has your
favorite standard defined '9' as the perfect character?
[X-posted, and followups set]
I found something interesting on the Web today, purely by chance.
It would be funny if it weren't so sad. Or sad if it weren't so funny. I'm
not sure which.
http://www.developerdotstar.com/community/node/291
Richard said:(e-mail address removed) said:
No, it doesn't, because he can always go back and read it if he wishes. And
he is certainly qualified to discuss the part he has read.
Why are you?
No, it wasn't even remotely straightforward. It was unnecessarily verbose.
This would be a straightforward test for numerics:
int to_digit(int ch)
{
return isdigit((unsigned char)ch) ? ch - '0' : -1;
}
If you think that's too obfuscated, here's another, which I don't like very
much as it trades structural elegance for simplicity, but it /is/ simple:
int to_digit(int ch)
{
if(isdigit((unsigned char)ch))
{
return ch - '0';
}
return -1;
}
As much as you are, and probably more.
Plenty. What he's saying is that your code is unnecessarily obscure and
difficult to read. That's the mark of a bad programmer, unless your intent
is to win the IOCCC.
C offers no guarantee that there is any character with a code point higher
than '9'. In EBCDIC, the code point of '9' is 249, so there are just six
characters (none with well-defined interpretations) with higher code
points. So Andrew's point is perfectly valid. It was also sufficiently
grammatical than I could understand it.
Richard said:(e-mail address removed) said:
The C Standard does not guarantee that. It's a minor point.
Curiously, it /is/ the highest EBCDIC character with a well-defined meaning,
although it is certainly true that there are half a dozen slots above it.
No, but neither has it guaranteed that '9' is not the highest character.
pemo said:Nope, they are called what I called them. The abandonment of Hungarian
notation was a mistake.
I think Keith's comment on argc/argv is right, i.e., using argc/argv follows
the rule of keeping 'the least possible surprise value' to a minimium. It's
what's 'expected' - I feel that there's no good reason for changing the
parameter names, and doing so will only cause confusion somewhere down the
line.
On Hungarian Notation, a few years ago [oh, now that I come to think about
it, that's quite a few years ago] I would have agreed with you - I used HN
all of the time, and liked it once I got used to it [I *had* to adopt their
use where I worked].
However, IMHO, modern development environments makes their use redundant -
now, if you want to know the type-of-something, its storage-class, or where
it's declared/defined - you simply use some shortcut/gesture built into the
development environment and you'll get all the information you need. And
that's great - this kind of feature, when used with meaningful names makes
code more readable [more easily parsable, and kinder on the eye]. In fact,
in dropping them, it might also make one think just a little harder about
the 'usage' part of any name used?
Are you for real? And you are sitting on your fat ass telling me I
don't know how to program?
If you are going to argue that C is unusable for new development, onBecause you're engaged in a campaign of personal destruction as you
were with Schildt.
A function in C only has to be well-behaved for legal inputs. That's aNo, the mark of a bad programmer is inability to think outside the
particular set of chosen inputs and your insistence that C is still
usable for new development.
What it means is that the codeOK, this is complete nonsense. Are you pulling my leg?
You read in the standard that "C offers no guarantee with a code
point..."
But it MEANS that there CAN be. Can you read?