Warning to newbies

S

spinoza1111

The next version of the code followed by its expected output is at the
end of this post. The following changes have been made. Seebs' Swift
Boating looks like it will be fun to demolish when I have
time...perhaps I should just ignore him. It appears to be the same
sort of nonsense he wrote about Schildt, padded with opinions
masquerading as facts.

Seebach is or in 2000 was a fan of George Bush, which makes the
Dijkstra quote apropos.

The following changes have been made:

* New comments have been added to clarify and because comments
constitute an informal proof of correctness.

* The end testing in the scan for replacement strings was not
structured. It has been made so by exploiting C's comma-as-operator
facility and the ability to assign in an expression. I wish I had
these facilities in C sharp.

* The "replace at end" flag in the structure was evilness, since it
was only on in the LAST member of the linked list. It has been removed
and replaced by a test.

* The replace() function now returns a count of replacements.

* An "assertion" has been added to the TESTER macro to verify that
the result string has the predictable length, using the replacement
count.

// ***************************************************************
// * *
// * replace() demo *
// * *
// * Demonstrates how to replace non-NUL-defined strings in C *
// * using a simple function, and bypassing string.h. *
// * *
// * C H A N G E R E C O R D --------------------------------- *
// * DATE PROGRAMMER DESCRIPTION OF CHANGE *
// * -------- ---------- --------------------------------- *
// * 02 07 10 Nilges Version 1.0 *
// * *
// * 02 07 10 Nilges Bug: partial matches not handled *
// * correctly: need to iterate search *
// * for match. *
// * *
// * 02 07 10 Nilges 1. Santosh suggested tests *
// * 2. Heathfield put the boot in re *
// * including malloc *
// * *
// * 02 07 10 Nilges 1. Remove string.h use and code *
// * strlen by hand *
// * 2. Add comment block and comments*
// * inline. *
// * 3. free() storage *
// * 4. Use macro for testing *
// * 5. Bug: calculation of *
// * lngNewLength used incorrect *
// * index (intIndex3 instead of 2)*
// * which caused a memory leak. *
// * *
// * 02 07 10 Nilges 1. Bug: Ike Naar test failed. *
// * At end of scan loop, main *
// * string pointer was not *
// * correctly updated from index3 *
// * *
// * 02 07 10 Nilges Added new Santosh test *
// * *
// * 02 07 10 Nilges Added new Ike Naar test *
// * *
// * 02 08 10 Nilges 1. Added some new comments *
// * 2. Make "check for a complete *
// * match "structured" by means *
// * of a tested assignment *
// * 3. Get rid of "replace at end" *
// * evilness: the only time this *
// * flag is meaningful is in the *
// * LAST segment. *
// * 4. Return replace count *
// * 5. TESTER macro assertion added *
// * *
// * ----------------------------------------------------------- *
// * *
// * "In the near future we shall have to live with the *
// * superstition that programming is 'so easy that even a *
// * Republican can do it!'" *
// * *
// * - E. W. Dijkstra *
// * *
// * *
// ***************************************************************

#include <stdio.h>
#include <stdlib.h>

// ***** Segmentation *****
struct TYPsegmentstruct
{ char * strSegment;
long lngSegmentLength;
struct TYPsegmentstruct * ptrNext; };

// ---------------------------------------------------------------
// Calculate string length
//
//
long strLength(char *strInstring)
{
char *ptrInstring;
for (ptrInstring = strInstring; *ptrInstring; ptrInstring++);
return ptrInstring - strInstring;
}

// ---------------------------------------------------------------
// Replace target by replacement string in master string
//
//
// Caution: the string returned by this function should be freed.
//
//
char * replace(char * strMaster,
char * strTarget,
char * strReplacement,
long * ptrReplacements)
{
char * ptrIndex0;
char * ptrIndex1;
char * ptrIndex2;
char * ptrIndex3;
char * strNew;
char * strNewStart;
long lngNewLength;
long lngCount;
long lngReplacementLength;
struct TYPsegmentstruct * ptrSegmentStructStarts;
struct TYPsegmentstruct * ptrSegmentStruct;
struct TYPsegmentstruct * ptrSegmentStructPrev;
lngReplacementLength = strLength(strReplacement);
if (!*strTarget)
{
printf("Error in calling replace(): target can't be null");
abort();
}
ptrIndex1 = strMaster;
ptrSegmentStructPrev = 0;
lngNewLength = 0;
*ptrReplacements = 0;
while(*ptrIndex1)
{
ptrIndex0 = ptrIndex1;
while (-1)
{
// --- Check for (one character) handle
for(;
*ptrIndex1 && *ptrIndex1 != *strTarget;
ptrIndex1++);
// --- Check for complete match
for(ptrIndex2 = strTarget, ptrIndex3 = ptrIndex1;
*ptrIndex3
&&
*ptrIndex2
&&
*ptrIndex3 == *ptrIndex2;
ptrIndex3++, ptrIndex2++);
// End test: check complete match, update main ptr past
// partial match while checking for end of loop
if ((!*ptrIndex2 ? ((*ptrReplacements)++, -1) : 0)
||
!*(ptrIndex1 = ptrIndex3)) break;
}
// --- Create new segment
if (!(ptrSegmentStruct =
malloc(sizeof(struct TYPsegmentstruct))))
abort();
ptrSegmentStruct->strSegment = ptrIndex0;
ptrSegmentStruct->lngSegmentLength =
ptrIndex1 - ptrIndex0;
ptrSegmentStruct->ptrNext = 0;
if (ptrSegmentStructPrev != 0)
ptrSegmentStructPrev->ptrNext = ptrSegmentStruct;
else
ptrSegmentStructStarts = ptrSegmentStruct;
ptrSegmentStructPrev = ptrSegmentStruct;
// --- Update mallocation length
lngNewLength += ptrSegmentStruct->lngSegmentLength +
(!*ptrIndex2
?
lngReplacementLength
:
0);
// --- Get past end of target string & iterate
ptrIndex1 = ptrIndex3;
}
// --- Allocate just enough storage for the new string
if (!(strNewStart = malloc(lngNewLength + 1))) abort();
// --- Build the new string whilst freeing the list
strNew = strNewStart;
ptrSegmentStruct = ptrSegmentStructStarts;
while (ptrSegmentStruct)
{
for (ptrIndex1 = ptrSegmentStruct->strSegment,
lngCount = 0;
lngCount < ptrSegmentStruct->lngSegmentLength;
ptrIndex1++, lngCount++, strNew++)
*strNew = *ptrIndex1;
if (ptrSegmentStruct->ptrNext || !*ptrIndex2)
for (ptrIndex1 = strReplacement;
*ptrIndex1;
ptrIndex1++, ++strNew)
*strNew = *ptrIndex1;
ptrSegmentStructPrev = ptrSegmentStruct;
ptrSegmentStruct = ptrSegmentStruct->ptrNext;
free(ptrSegmentStructPrev);
}
*strNew = '\0';
return strNewStart;
}

// ---------------------------------------------------------------
// Statement-format test macro
//
//
#define TESTER(resultPtr, master, target, replacement, expected,
expectedReplacements, replacements) \
{ \
printf("Replace \"%s\" by \"%s\" in \"%s\"\n", \
(target), (replacement), (master)); \
printf("Expect \"%s\":\n\"%s\"\n", \
(expected), \
resultPtr = replace((master), \
(target), \
(replacement), \
&(replacements))); \
printf("Replacements expected: %d: replacements: %d\n", \
(expectedReplacements), \
(replacements)); \
if (!(strLength(resultPtr) \
== \
strLength(master) \
+ \
(strLength(replacement)-strLength(target)) \
* \
replacements)) \
printf("Assertion failed\n"); \
printf("\n\n"); \
free(resultPtr); \
}

// ---------------------------------------------------------------
// Main procedure
//
//
int main()
{
char *ptrResult;
long lngReplacements;
printf("\nReplace\n\n\n");
TESTER(ptrResult,
"a stupid error",
"stupid error",
"miracle",
"a miracle",
1,
lngReplacements)
TESTER(ptrResult,
"a stupid error",
"stupid",
"miracle",
"a miracle error",
1,
lngReplacements)
TESTER(ptrResult,
"the stupid error",
"the stupid error",
"a miracle",
"a miracle",
1,
lngReplacements)
TESTER(ptrResult,
"the miracle",
"the",
"a",
"a miracle",
1,
lngReplacements)
TESTER(ptrResult,
"a miraclsnirpKamunkle",
"snirpKamunkle",
"e",
"a miracle",
1,
lngReplacements)
TESTER(ptrResult,
"a miraclesnirpKamunkle",
"a miracle",
"",
"snirpKamunkle",
1,
lngReplacements)
TESTER(ptrResult,
" a miraclesnirpKamunkle",
"a miracle",
"",
" snirpKamunkle",
1,
lngReplacements)
TESTER(ptrResult,
" a miraclesnirpKamunklea miraclea miracle",
"a miracle",
"",
" snirpKamunkle",
3,
lngReplacements)
TESTER(ptrResult,
"a miracle a miraclesnirpKamunkle a Miraclea miraclea
miracle",
"a miracle",
"",
" snirpKamunkle a Miracle",
4,
lngReplacements)
TESTER(ptrResult,
"a stupid errord",
"stupid error",
"miracle",
"a miracled",
1,
lngReplacements)
TESTER(ptrResult,
"a stupid errod",
"stupid error",
"miracle",
"a stupid errod",
0,
lngReplacements)
TESTER(ptrResult,
"a sstupid error",
"stupid error",
"miracle",
"a smiracle",
1,
lngReplacements)
TESTER(ptrResult,
"a stupid errorstupid error",
"stupid error",
"miracle",
"a miraclemiracle",
2,
lngReplacements)
TESTER(ptrResult,
"a stupid error stupiderror",
"stupid error",
"miracle",
"a miracle stupiderror",
1,
lngReplacements)
TESTER(ptrResult,
"bbbbbbbbbb",
"b",
"a",
"aaaaaaaaaa",
10,
lngReplacements)
TESTER(ptrResult,
"In the halls of R'yleh great %s lies dreaming",
"%s",
"Cthulu",
"In the halls of R'yleh great Cthulu lies dreaming",
1,
lngReplacements)
TESTER(ptrResult,
"%s%s%s%s%s%s",
"%s",
"Cthulu",
"CthuluCthuluCthuluCthuluCthuluCthulu",
6,
lngReplacements)
TESTER(ptrResult,
"banana",
"ana",
"oat",
"boatna",
1,
lngReplacements)
TESTER(ptrResult,
" a stupid errorstupid errorHeystupid errors",
"stupid error",
"+",
" a ++Hey+s",
3,
lngReplacements)
TESTER(ptrResult,
"foo barfoo barf",
"foo bar",
"bas",
"basbasf",
2,
lngReplacements)
TESTER(ptrResult,
"abab",
"ba",
"ba",
"abab",
1,
lngReplacements)
TESTER(ptrResult,
"abab",
"bab",
"boop",
"aboop",
1,
lngReplacements)
printf("\n\nTesting complete: check output carefully: \"Assertion
failed\" should not occur!\n\n");
return 0;
}



Replace


Replace "stupid error" by "miracle" in "a stupid error"
Expect "a miracle":
"a miracle"
Replacements expected: 1: replacements: 1


Replace "stupid" by "miracle" in "a stupid error"
Expect "a miracle error":
"a miracle error"
Replacements expected: 1: replacements: 1


Replace "the stupid error" by "a miracle" in "the stupid error"
Expect "a miracle":
"a miracle"
Replacements expected: 1: replacements: 1


Replace "the" by "a" in "the miracle"
Expect "a miracle":
"a miracle"
Replacements expected: 1: replacements: 1


Replace "snirpKamunkle" by "e" in "a miraclsnirpKamunkle"
Expect "a miracle":
"a miracle"
Replacements expected: 1: replacements: 1


Replace "a miracle" by "" in "a miraclesnirpKamunkle"
Expect "snirpKamunkle":
"snirpKamunkle"
Replacements expected: 1: replacements: 1


Replace "a miracle" by "" in " a miraclesnirpKamunkle"
Expect " snirpKamunkle":
" snirpKamunkle"
Replacements expected: 1: replacements: 1


Replace "a miracle" by "" in " a miraclesnirpKamunklea miraclea
miracle"
Expect " snirpKamunkle":
" snirpKamunkle"
Replacements expected: 3: replacements: 3


Replace "a miracle" by "" in "a miracle a miraclesnirpKamunkle a
Miraclea miraclea miracle"
Expect " snirpKamunkle a Miracle":
" snirpKamunkle a Miracle"
Replacements expected: 4: replacements: 4


Replace "stupid error" by "miracle" in "a stupid errord"
Expect "a miracled":
"a miracled"
Replacements expected: 1: replacements: 1


Replace "stupid error" by "miracle" in "a stupid errod"
Expect "a stupid errod":
"a stupid errod"
Replacements expected: 0: replacements: 0


Replace "stupid error" by "miracle" in "a sstupid error"
Expect "a smiracle":
"a smiracle"
Replacements expected: 1: replacements: 1


Replace "stupid error" by "miracle" in "a stupid errorstupid error"
Expect "a miraclemiracle":
"a miraclemiracle"
Replacements expected: 2: replacements: 2


Replace "stupid error" by "miracle" in "a stupid error stupiderror"
Expect "a miracle stupiderror":
"a miracle stupiderror"
Replacements expected: 1: replacements: 1


Replace "b" by "a" in "bbbbbbbbbb"
Expect "aaaaaaaaaa":
"aaaaaaaaaa"
Replacements expected: 10: replacements: 10


Replace "%s" by "Cthulu" in "In the halls of R'yleh great %s lies
dreaming"
Expect "In the halls of R'yleh great Cthulu lies dreaming":
"In the halls of R'yleh great Cthulu lies dreaming"
Replacements expected: 1: replacements: 1


Replace "%s" by "Cthulu" in "%s%s%s%s%s%s"
Expect "CthuluCthuluCthuluCthuluCthuluCthulu":
"CthuluCthuluCthuluCthuluCthuluCthulu"
Replacements expected: 6: replacements: 6


Replace "ana" by "oat" in "banana"
Expect "boatna":
"boatna"
Replacements expected: 1: replacements: 1


Replace "stupid error" by "+" in " a stupid errorstupid errorHeystupid
errors"
Expect " a ++Hey+s":
" a ++Hey+s"
Replacements expected: 3: replacements: 3


Replace "foo bar" by "bas" in "foo barfoo barf"
Expect "basbasf":
"basbasf"
Replacements expected: 2: replacements: 2


Replace "ba" by "ba" in "abab"
Expect "abab":
"abab"
Replacements expected: 1: replacements: 1


Replace "bab" by "boop" in "abab"
Expect "aboop":
"aboop"
Replacements expected: 1: replacements: 1




Testing complete: check output carefully: "Assertion failed" should
not occur!
 
S

spinoza1111

A classic example of massively overthinking a problem.

Overthinking? Wow. When I started out, IBM programmers had signs
saying Think, and they produced real wealth (which was massively
stolen by the microkids). They also had long-term economic security.

After the election of Reagan, they were replaced by ADHD and substance-
abusing creeps because the game (as in the former Soviet Union) became
smashing and grabbing wealth created by the labor and taxes of the
middle class in the USA, and the labor of the proletariat in the
Soviet Union.

The result? A few slobs became rich and for the middle class, the game
changed to the display of subservience to existing "solutions" at all
time, coupled with the deliberate projection of lack of craft
(masquerading as "real" craft) and the abuse of the poor and homeless.

The result? A best-selling computer book: "Don't Make Me Think".
One of the most useful skills in programming is learning when you don't need
to build an entire infrastructure layer to support a straightforward
operation.

But I haven't "built an entire infrastructure layer", dear little man.
The strstr scan is embedded in the code without being separated.
I just hope he never realizes that his implementation of a string length
counter is not particularly overth^H^H^H^H^Hrobustly engineered.  If he does,
we'll get something like this:

    #include <sys\types.h>
    #include "curses.h"
    #include <iso646.H>
    #include <emmintrin.h>

    /* C does not provide a value which is distinct from all possible
     * char values, because the idiots who wrote the standard didn't
     * realize that the "char" type which they stupidly left undefined
     * could hold the value -1.
     */
    #define EndOfFileValue -3

    int isPointerNull(void *p) {
        if ((void *) p == (void *) 0) {
            return ~0;
        } else {
            return 0;
        }
        /* because the standard was written by autistic twerps who have
         * never studied computer science, it is crucially important that
         * there be an explicit return statement at the end of every
         * function.
         */
        return 0;
    }

    int characterAtPointer(const char *pointerToCharacter) {
        if (isPointerNull((void *)pointerToCharacter) == ~0) {
            return EndOfFileValue;
        } else {
            return pointerToCharacter[(int) 0];
        }
        return EndOfFileValue;
    }

    int lengthOfString(const char *stringToMeasure) {
        int nextCharacter;
        int nextCharacterIsEndOfFileValue;
        const char *nextCharacterPointer;
        int charactersSoFar;
        if (isPointerNull((void *)stringToMeasure)) {
            return ~0;
        } else {
            /* important not to modify the caller's string, which is on
             * the STACK STACK STACK STACK STACK STACK STACK STACK you
             * transvestite nazi motherfuckers
             */
            nextCharacterPointer = stringToMeasure;
            charactersSoFar = 0;
            nextCharacterIsEndOfFileValue = 0;
            /* the following monstrosity is necessary because C is
             * intrinsically unsafe, providing no type-safe way to
             * extract a value from a pointer without first verifying
             * that the pointer is valid, as I proved in the 1980s.
             */
            while(characterAtPointer((const char *)nextCharacterPointer) != '\0' && nextCharacterIsEndOfFileValue != ~0) {
                if (characterAtPointer((const char *)nextCharacterPointer) == EndOfFileValue) {
                    nextCharacterIsEndOfFileValue = ~0;
                }
                if (nextCharacterIsEndOfFileValue != ~0) {
                    nextCharacter = characterAtPointer((const char *)nextCharacterPointer);
                    if (nextCharacter == '\0') {
                        /* when I was working with Ogden Nash,
                         * he told me to always phrase my tests in
                         * a positive way
                         */
                    } else {
                        charactersSoFar = charactersSoFar + (int) 1;
                    }
                }
                nextCharacterPointer = (const char *) &nextCharacterPointer[1];
            }
        }
        return (int) charactersSoFar;
    }

-s
p.s.:  Needless to say, I have not tried to compile the above fragment.
However, I consider it fairly representative.


You've written this code and presented it as mine. This is egregious
dishonesty and highly unprofessional. In my experience, incompetent
programmers turn to lies and mockery when their incompetence is
exposed.
 
S

spinoza1111

[...]
I don't know what's more funny- Spinoza's inability to get this simple
problem right, or Seebs' continued childish insistence that he only

As I said, I posted the code for COLLABORATIVE development and
testing, and I received professional assistance from Santosh and Ike
Naar, which helped me to complete the project.

That is what this ng was meant for: not for posting "satiric" code as
mine in an actionably libelous lie.

Santosh and Ike Naar found problems which I fixed in a few hours on
Sunday.

Heathfield and Seebie have demonstrated that they are disruptive
creeps.

Don't you DARE compare me to them! There is NO comparision. They are
subprofessional clerks and temps who are misusing this newsgroup to
pretend they are professionals.
 
S

spinoza1111

On Feb 9, 4:32 am, Keith Thompson <[email protected]> wrote:

Keith: there is absolutely no comparision between myself and other
noble and fine spirits here such as Kenny and Navia, and creeps like
Seebach.


There is a certain sort of Creep
Who creeps, along the Way
As the shadows gather
At the end of day.

His Traffic is in lies
Rumor, and surmise
His purpose, to give Pain
The light, he does disdain.

Hellish hurt he tries to give
But he does not Succeed
The Knight who has a mission
To daemon pays no heed.
 
S

Seebs

spinoza1111 wrote:
It's called "parody", and is perfectly legal (except in North Dakota
during the summer months). As parody, it excels, since you think he's
presenting the code as if you'd written it, whereas in fact all he's
really doing is caricaturing your style. There is nothing dishonest or
unprofessional about parody.

Allow me to quote my post to clarify:

(line breaks altered from the original).

Note: "something like this" is clearly intended to demonstrate that I am
talking about the *style* or *manner* of the Nilges code we've seen, such
as a hundred lines of extraordinarily bad code trying to solve a problem
that could easily be solved in about fifteen lines of code... and it
didn't even work after three or four edits to fix bugs introduced by
an overly baroque style.

I do not have any worries about people mistaking my parody code for
actual Nilges code, nor did I present it as such. For one thing, I
didn't use the sort of bastardized and botched systems Hungarian Nilges
uses. I can do a lot for art, but there are limits. For another thing,
I did manage in a few places to go beyond the level of insanity we
normally see in his code. For instance, <malloc.h> is silly, but
<emmintrin.h> is ridiculous. (It's, so far as I can tell, a gcc internal).

I also cleaned it up some by using ~0 rather than -1 as "true" -- I figure
if you're going to ask for all-bits-one, you might as well do it explicitly.

In short, to some extent, it's not a very good caricature; I didn't really
pick up some of the most odious stuff, but I think I did a reasonable job
of capturing the essence of over-engineering informed by mind-numbing
ignorance, coupled with random and misdirected vitriol and name dropping.

-s
 
S

Seebs

If that's true, why did you make it so hard to read? Or, if you think it
*should* be hard to read, why didn't you make it harder to read?

This one's complicated. He's clearly doing some things badly purely out
of spite. However, I suspect he genuinely believes that the elaborate
naming conventions are helpful, even though this one looks like an over
the top parody.
And I found a problem that took you several hours to fix all by itself.
Deleting a single line can be terribly, terribly, difficult, can't it?

More importantly, why on earth would it take "a few hours" to fix something
this simple? One person found a problem with mine, which I fixed in, oh,
call it five or ten minutes -- that's including developing a more elaborate
version, then concluding that it was stupid and giving up on it.
That's up to him, but I can't say I'm overly excited by the idea of
being in the same comparison as you, and I don't suppose Seebs is either.

I think I would mostly just find it surreal. It's like trying to compare
someone to a cat; there's not enough commonality to make the comparison
informative in any meaningful way. ("Well, you're heavier than the cat,
but you do complete more crosswords, so I guess it's a tie.")

-s
 
N

Nick Keighley

I don't agree with you that this is an established fact.  

it's really not worth engaging spinoza on subjects he has a bee in his
bonnet about. You just chew your time up for no purpose (unless, of
course you find him entertaining).

<snip>
 
N

Nick Keighley

 (Usually,
humor has to surprise, but as anyone who has ever watched a Charlie Chaplin
routine can tell you, you can be just as funny with a completely predictable
failure mode.)

I never thought he was funny.
 
S

Seebs

Think about it. It takes him several hours to delete a single line.

That's not quite the same. He didn't understand the criticism, and while
that's sad, it is an explanation for why it would take a while -- he wasn't
actually *working* on it during that time, he just didn't understand the
problem description.

By contrast, with the other parts, he clearly had a pretty good idea of what
the problems were, but it nonetheless took him several hours to debug
something that I'd expect most people who had even a vague comprehension
of pointers could write from *scratch* and debug in that kind of time.

His design is crap, of course, but was it really THAT hard to debug? Was
that time just lost to the idiotic naming conventions, or to the baroque
design, or what?

-s
 
S

spinoza1111

[ snip ]
God, I hate that word, "eccentric". Its use normalizes deviance.

Propose a better one.  (I'm mildly curious about what "normalizes
deviance" means in context, but not optimistic that an attempt to
clarify would help.  <shrug>)

It is a term of art developed by the engineering anthropologist Diane
Vaughan to describe predominantly male technical groups that find ways
of "normalizing" deviations from standards and rules "in order to get
a job done".

She developed it in a groundbreaking study of the 1986 "let's kill a
teacher" Challenger mission, doing a detailed study of the physics of
the O-ring assembly that failed in that launch.

In reviewing the transcript of the meeting at the O-ring subcontractor
before the launch, she discovered that managers were "deviantly"
nagging engineers to approve the launch although the engineers KNEW
that the O-rings had not been tested in full under the unusually low
temperatures they'd endure in the January launch.

Her book "The Challenger Launch Decision: Risky Technology, Culture
and Deviance at NASA" (http://www.amazon.com/Challenger-Launch-
Decision-Technology-Deviance/dp/0226851761/ref=sr_1_1?
ie=UTF8&s=books&qid=1265704835&sr=8-1) identified what anthropologists
call a culture of dismissing engineers' concerns when management, over-
responsive to political pressure to demonstrate American macho
prowess. Unfortunately, although she served on the review panel, her
message wasn't heeded. The same sort of normalized deviance caused the
crash of the Columbia space shuttle in 2003. Here, known problems with
insulation padding were "normalized" in the same way Seebach
"normalized" his deviant failure to foresee that a character scan
would create a problem, with the same sort of pseudo-macho posturing,
and the same sort of bullying of dissidents.

Just as Seebach said "I've neglected the issue, but I'm cute and
normal, unlike Nilges", engineers who pointed out that foam padding
falling off at launch was not in the specifications were laughed at
and shown the door because "we have put this issue in a data base".

A lot of people have died owing to normalized deviance. It is the norm
in programming circles and causes most software problems, in my view.

 
S

spinoza1111

spinoza1111  said:
On Mon, 1 Feb 2010 05:29:52 -0800 (PST),spinoza1111
[ snip ]
I have no respect it is true for Peter Seebach. Why? Because he's
bragged that he's never taken a computer science class in his life
Why do you keep claiming that Seebs "bragged" or boasted about not
having taken CS classes?  as best I can tell, you made a guess about
various people's backgrounds, in message ID
<b591c6a0-33d0-4f9b-954d-275d39a24...@y10g2000prg.googlegroups.com>
Sounds to me that you guys AP'd out of CS 101
and he followed up to someone else's response, in message ID
<[email protected]>
as follows (slightly reformatted for readability):
There is some irony, which is that for reasons not adequately
explained (my brain is pretty weird), it *never occurred to me* to try
to take any CS classes.  Programming was just stuff I did for fun..  So
in fact, I've never taken ANY CS classes, of any level -- I just pick
stuff up as I go, which explains why I have a much more practical
"here's what works" attitude rather than an ivory-tower one... and
also why I have to look up basic algorithms, or be hinted towards
them.  
He later wrote, in message ID
<[email protected]>
In
spinoza1111wrote:
"I have never taken any computer science classes" - Peter Seebach 26
Oct 2003 (with pride)
Lots of programmers have picked up their knowledge as they go along,
and some of them are very bright bunnies indeed.
It's entirely possible that, by sheer coincidence, I said this exact
thing both earlier today (or yesterday, but in a different time zone)
and also exactly six years ago, but it seems more likely to me by far
that Spinny's guessed the year wrong.
But there's a more significant error, which is the attribution "(with
pride)".  So far as I can tell, this is pretty much guaranteed to be
in error, as my brain does not appear to generate the experiences
usually referred to by the word "pride" (or by the word "shame"; at
least I'm an equal-opportunity sort).  I am neither proud of, nor
ashamed of, the coincidence that I never happen to have taken a CS
class.  It has sometimes been a bit of a nuisance in terms of trying
to get my job done, but then, the degree I *did* pick up (psych) turns
out to have been, arguably, more useful to me.  (I also did most of
math and philosophy degrees, and have no regrets about either.)  It
probably would have been useful to pick up CS, and certainly I did
pick a fair bit up by osmosis and exposure.
Where's the bragging or boasting here?
It's in the fact that he's unqualified,

I don't agree with you that this is an established fact.  

So don't agree. However, he's established it:

"The heap is a DOS term".

"Here's my code. It doesn't rilly work, and to fix it you have to mung
two places to add a lookahead, and if I knew my ass from a hole in the
ground, which I don't, I'd know that the lookahead has to lookahead
for 's' in two places, meaning that if the character changes there are
too places to change, but I'm cute."
I don't agree here either.  Humans have a finite number of hours
in which to accomplish whatever they want to accomplish with their
lives, and choosing not to spend any of them on formal academic
coursework in computer science allows spending more of them on other
things, things that might ultimately be more useful or interesting.
"YMMV", maybe.

(As someone who teaches CS to undergraduates, I do think that formal
coursework provides something of value, namely a conceptual framework
on which to hang the technical knowledge one picks up in the course
of a career in IT, but I would not want to claim that there is no
other way to acquire such a framework.)

You're missing the main reason. It's to be able to think about code
without some thug manager breathing down your neck. It is a taste of
human freedom and the civility that results.
His humility is feigned. I detected this when he called me a "moron".
Rahm Emanuel has apologized for this type of language: Seebs has not.
He hurls invective which is not to be humble, and deletes email
offering to discuss differences UNREAD.

Presumably as a result of discussions in this newsgroup.  I'll say
that I would probably have been curious enough to at least read the
e-mail, even if I was fairly certain there would be no point in
replying, but there are certainly many e-mail messages that I delete
unread, based on the combination of sender and subject header.

[ snip ]
 
S

spinoza1111

Lack of consts makes it look amateurish.

....and Job One is looking good, I suppose, and shitting on people.

Pray why do we need constants? They are, almost by definition, one
more point of failure. I lack consts because I don't cover up
incompetence by using "buffers" (the use of which term is always a
sign of incompetence). I didn't need constants because I used a linked
list, for I learned long ago that hard-coded limits are trouble.
 
S

spinoza1111

Joe Wright said:
Ben said:
santosh wrote:
Joe Wright wrote:
spinoza1111wrote:
[ all snipped ]
I suggest you spend overlong on a relatively simple task. Regard..
/*
    Program: stuff.c
    Author:  Joe Wright
    Date:    05/24/1999
    The dBASE stuff() function
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LEN 256
void usage(void) {
    printf("Usage: stuff 'cString' nStart nDelete 'cInsert'\n"
           "Example: stuff 'Now is the time.' 7 0 'NOT '\n"
           "Note: nStart is rel-0 in C\n"), exit(0);
}
char *stuff(char *string, int start, int delete, char *insert) {
    static char str1[LEN];                 /* Return buffer */
    char str2[LEN];                        /* Temporary buffer */
    strncpy(str1, string, start);
    str1[start] = 0;
    strcpy( str2, string+start+delete);
    strcat( str1, insert);
    return strcat(str1, str2);
}
int main(int argc,  char **argv) {
    if (argc < 5) usage();
    printf("%s\n", stuff(argv[1], atoi(argv[2]), atoi(argv[3]), argv[4]));
    return 0;
}
/* End of stuff.c */
Note stuff() is eight lines, not eighty. You are a fraud.
This doesn't exactly do whatspinoza1111set out to do, and what the
subsequent examples from others like Ben and Willem did. That combined
with the fact that you're using static buffers means that a line count
comparison of this program with the others is not very meaningful.
Gimme a break. One malloc() and one free() add two lines.
How does that give you a function like the one being discussed
elsewhere in the thread?
I must be missing something.spinoza1111came up with almost 100 lines
of code to solve what I consider to be a simple problem solvable in 10
lines or so. Maybe I didn't appreciate how hard a real programmer
would work on this sort of thing. Finding a substring and replacing it
with another is almost trivial.

If your point was simply that "this is trivial" then we are in total
agreement; but it looked like you were saying "*this* is how trivial
it is" by giving an function to solve the problem.  My point was that
you really have to match the specification not use a related but
slightly simpler one.

A word from the wise, indeed. The "spec" is "don't use string.h". I
can well imagine this "spec" obtaining in the real world, whether when
using a compiler without a complete library, or simply to save storage
in an embedded world. Or, working for some unreasonable manager from
hell who hates string.h. Like me, for example.

Real professionals enjoy Five Easy Pieces, that is revisiting the
basics. Phonies phear exposure.
 
S

spinoza1111

You may be slightly surprised then.  From the current glibc strstr
sources:

/* We use the Two-Way string matching algorithm, which guarantees
   linear complexity with constant space.  Additionally, for long
   needles, we also use a bad character shift table similar to the
   Boyer-Moore algorithm to achieve improved (potentially sub-linear)
   performance.

   Seehttp://www-igm.univ-mlv.fr/~lecroq/string/node26.html#SECTION00260
   andhttp://en.wikipedia.org/wiki/Boyer-Moore_string_search_algorithm
*/

It's not exactly Boyer-Moore but I suspect that this is more because
this hybrid is superior rather than a reluctance to use BM.  I don't
know enough about this have an opinion (at east not one than anyone
should listen to) about this choice.

Anyway, here is a very important point for C programmers here: anyone
who decides not to use the C library is cutting themselves off from a
considerable pool of expertise.

This is true. However, people sail sailboats and walk to work, cutting
themselves off from the expertise of steamship and automobile
designers simply to stay human in the sense of recapitulating the
efforts needed before, and to create, advanced technology.

I've never implemented Boyer-Moore, although I saw it in
Communications of the ACM when it came out in 1977. All the more
reason to give it a whack in a later version of replace().
 
N

Nick Keighley

I don't agree. Use of const slightly improves the code, but I probably
wouldn't reject code at a walkthru for lack of const (I might comment
though).

Pray why do we need constants?

"const" not "constants". "const" is a C keyword that indicates to the
compiler that the function isn't going to change the value. It labels
the parameters as strictly input only (it also the function using the
parameters as temporary variables- which should please you!). It has
semantics (in this case) of something like Ada's "in" parameters.
"const" is a bit like "assert" its much more powerful than you at
first appreciate.

They are, almost by definition, one
more point of failure.

how so? How are const parameters more prone to failure?

I lack consts because I don't cover up
incompetence by using "buffers" (the use of which term is always a
sign of incompetence).

I've no idea what you are talking about

I didn't need constants because I used a linked
list, for I learned long ago that hard-coded limits are trouble.

what?
 
S

spinoza1111

While I chose to use consts in mine, I am quite sympathetic to avoiding
const, because I did it for years.  That said, I do agree that it would
be improved by the use of const qualifiers.

My mistake, you meant read-only const qualifiers. My apologies for
this misunderstanding. I will add the const qualifiers to the next
version. Do you want to be credited?

No, I am not talking to you, Peter, although you will be credited if
you contribute anything useful.
 
S

spinoza1111

Not at all. The bilgemaster encounters what he considers to be
academic-sounding terms, and then repeats them hoping that he'll
be treated as someone even vaguely erudite. Unfortunately, he
uses the terms in completely hatstand contexts, and thus fails
dramatically. Tragic, and best ignored.

You're mistaking the verbal flexibility of someone who's actually
studied NP complete issues (graduate level class in algorithms, grade
== A) with misuse of "terminology", where unqualified little clerks
have to watch their mouths and use of "terminology" lest their brutal
slave-masters kill them for using the wrong "ears of corn", of
shibboleths.

**** you very much, buddy. And stop making games of people's names.
Fourteen year olds do that.

[The use of four letter words is normally less malicious than
deliberately trashing reputations. There's a world of difference
between "**** you", which means in many contexts "get laid, it might
help you be less of a jerk" and trashing a patronym. "**** you" in
isolation can later change to friendship, as in the Army, whereas use
of Rahm Emanuel's "retard" with or without "fucking" means "this
person doesn't belong in the conversation"; and, Jean Francois Lyotard
defines the essence of real terrorism as exclusion from conversation.
Of course, hardly any of you served in the military, and this is
possibly why you act like jerks. The military teaches many lessons,
some good, some bad.]
 
S

spinoza1111

"spinoza1111" <[email protected]> ha scritto nel messaggio



No, I fixed that. Here is a version just for you, with this test
added.

-----------------

do you read me? someone read me?
this below is better
// ---------------------------------------------------------------
// Statement-format test macro
//
//
#define TESTER(resultPtr, master, target, replacement, expected) \
{ \
    printf("Expect \"%s\":\n\"%s\"\n\n", \
           (expected), \
           resultPtr = replace((master), \
                                 (target), \
                                 (replacement))); \
    free(resultPtr); \

}

because align the string expected to the result
and is easier to ceck

test1
Expect "a miracle":
       "a miracle"

Expect "a miracle error":
       "a miracle error"

Expect "a miracle":
       "a miracle"

Expect "a miracle":
       "a miracle"

Expect "a miracle":
       "a miracle"

Expect "snirpKamunkle":
       "snirpKamunkle"

Expect " snirpKamunkle":
       " snirpKamunkle"

Expect " snirpKamunkle":
       " snirpKamunkle"

Expect " snirpKamunkle a Miracle":
       " snirpKamunkle a Miracle"

Expect "a miracled":
       "a miracled"

Expect "a stupid errod":
       "a stupid errod"

Expect "a smiracle":
       "a smiracle"

Expect "a miraclemiracle":
       "a miraclemiracle"

Expect "a miracle stupiderror":
       "a miracle stupiderror"

Expect "aaaaaaaaaa":
       "aaaaaaaaaa"

Expect "In the halls of R'yleh great Cthulu lies dreaming":
       "In the halls of R'yleh great Cthulu lies dreaming"

Expect "CthuluCthuluCthuluCthuluCthuluCthulu":
       "CthuluCthuluCthuluCthuluCthuluCthulu"

Expect "boatna":
       "boatna"

Expect " a ++Hey+s":
       " a ++Hey+s"

Expect "basbasf":
       "basbasf"

Expect "abab":
       "abab"

Good idea! Thanks. Shall I credit you in the Change Record?
 
I

Ike Naar

I found some bugs
replace("string ", "", "append")
has to return "string append"
and not forever loop

It is not obvious that replace("string ", "", "append") should
return "string append". According to the specification, it
should replace all occurrences of the empty pattern "" in "string "
with the substitute "append".

You seem to claim that the empty pattern only occurs once,
at the end of "string ", but it would be equally valid to say that
an empty pattern occurs, for instance, between the 'r' and the 'i'
of "string ", so the result "strappending " would be okay, too.

One might even argue that "string " contains the empty pattern infinitely
often, and in that case it's only natural that replacing them all will
take forever ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,056
Members
48,769
Latest member
Clifft

Latest Threads

Top