On Feb 23, 10:38 pm, (e-mail address removed) <
[email protected]>
wrote:
[ snip ]
And note that "using strstr" has its own dangers. IT FINDS OVERLAPPING
STRINGS. If you use it to construct a table of replace points you're
gonna have an interesting bug-o-rama:
replace("banana", "ana", "ono")
IF you restart one position after the find point, and not at its end.
Why would you do that, though? only if you *wanted* to detect
Search me. But that's what the code I was discussing actually did.
What code is that? I've traced back through predecessor posts, and
the only one that comes close to including code is the one in which
Chris Thomasson references his code in
http://clc.pastebin.com/f62504e4c
which on a quick skim doesn't seem to me to be looking for
overlapping strings.
My code handled string overlap after the bug was pointed out to me,
BEFORE any other code.
So when you said "the code I was discussing", you meant *your*
code? Oh! I understood you to be saying that using strstr() is
dangerous because it finds (or doesn't find?) overlapping strings,
and interpreted "the code I was discussing" to be someone else's
code, someone who was using strstr(). Faulty communication.
I'm too sick of the shit that goes on here to
make a collection of all solutions and find what probably are many
failures, but one of my contributions was to pass on the test case.
There's a lot of claims and counterclaims here and at least two
discussants are complete shitheads. However, we KNOW that other
posters used the test suite I created AFTER my code worked with that
test data.
Is this some kind of race to find out who can post a solution first?
If so, um, haven't you expressed disapproval of boasting about speed
of coding? Or do you suspect others of cribbing from your solution?
I can tell you that I didn't -- reading code is not one of my best
things anyway, and I thought it would be more fun to write my own
code before looking at others'.
I believe I express mostly disapproval about speed of coding as a way
of dodging issues, not speed of coding per se. For example, I didn't
like it at all when Brian Kernighan, in the recent O'Reilly collection
Beautiful Code, praised Rob Pike for only taking an hour to write a
"regular expression processor" because:
* Pike's code wasn't a full or true regular expression processor
* The fact that it took an hour doesn't change the above
Seebie bragged about taking "ten minutes before breakfast" in response
to questions about whether he was solving a problem correctly or in
depth, because in fact, in corporations, programmers, in contrast to
real engineers, seem to believe that in all cases speedy coding makes
up for almost any failing.
overlapping strings, and -- if you did detect them, what would
you do with them? I can't think of any sensible definition of
"replace" that does anything with overlapping strings [*], so
replace(banana, ana, ono) could equal
bonona going left to right without overlap
banono going right to left without overlap
bonono going both ways with overlap
There's a semi-sane answer here in the last case, but isn't
HOW.DARE.YOU. How DARE you start talking about sanity? It isn't
collegial, and it is libel and completely insensitive. It's talking
like those thugs and shitheads here, Seebach and Heathfield.
The word "sane" was meant to apply to the answer, not to a person.
I don't have enough information to form an opinion I'd want to share
publicly about your sanity.
That manages to be rather snide, in my view.
I could offer to substitute "sensible" for "sane" in what I wrote,
but that might not be any better received.
It would have been an improvement. But there are plenty of words such
as "correct" which have zero personal connotation.
Whether the apparent lack of communication here is due to poor
writing on my part or something else -- I don't know. At least
one other person appears to have interpreted my words in the
intended way (and replied to that effect).
[ snip ]
The fact that there is a group of answers does not make the question a
question of a crazy man! In fact, it makes it a good scientific
question, albeit over the heads of the creeps here.
My point was that I don't think that there's an obvious most-sensible
choice here. How about if you just answer my question -- should
replace(banana, ana, xno) be bxnono or bxnxno? If you aren't sure,
how do you decide what your code should do?
Whoa. I'm not sure. "Science" is about possibility as well as fact.
However, I do think that for the same reason your notion of "concat"
is cool since it is independent of direction, I think that a "flat" or
one-time application of "replace" is one of those phony notions that
only seem useful. The basic notion is not replace once, it is replace
until no change, as in macro replacement. I think we can prove that
there's no instance of a replace that always changes the string when
applied.
Let us call an implementation of replace(master, target, replacement)
"kewl" when and only when it is "independent of left to right or right
to left order". I claim that the only form of replace that is "kewl"
is nondeterministic. To simulate it you'd have to apply the
replacement rule randomly. It would sometimes return bonona, and other
times it would return banono.
(Chorus of you say tomayto I say tomahto).
This is an interesting NEGATIVE point. It means that there are
probably bugs out there.
It's a CORRECT result without being, of course, a reasonable
SPECIFICATION for real code. But that don't mean it's not useful.
Turing's Halting Problem is True, and created software, but it's not a
spec.
The truth is something which can be applied immanently as a critical
tool to some spec, but in corporate life, the central idea is that the
employee is idemnified if she works to rule or spec. Requirements
definition is depressing because it excludes critical thought in favor
of applied Postivism.
I mean, ask a kid.
"Why a four year old could do this! Get me a four year old!"
One thing I find terribly amusing and at the same time rather sad in
this intellectual slum is the contrast between the hackneyed,
conventional, authoritarian and "mature" thinking of grownups here,
and my elementary students in my real job (I teach a range of students
from primary to uni).
I think a child would have a great deal of difficulty learning how to
manually do a replace, and would ask if clever about "banana". I think
a real mathematician thinks like a child and would not be satisfied
with a replace() applied once, deterministically and left to right. I
don't know, however, if there is any "real" work on this.
And despite the arcane flavor of this material, the failure to even
consider cases thought "imprecise" because they are non-deterministic
creates real bugs, as when the user says, "oh no, in THAT case you
need to change banana to banono." "Oh, really? Why?" "Because our
customer in Antigua wants it that way."
Children, in making "mistakes", make discoveries, that it's just the
sort of thing programmers miss. For example, Peter didn't ask himself
what would be the case if %s was in the substitution string and would
probably consider the question so quirky as to make it safe to gravely
infer that the asker of the question is a nutbar, and to Call
Security.
[ snip ]
I gave it to you: a hypothetical but possible natural language in
which adjacent lexemes must be split and modified.
You've posited a scenario in which attempting to replace
overlapping strings would be useful or meaningful. What I'm
not getting is an exact specification of how you think it should
work. What should replace(banana, ana, xno) be? Or are there
restrictions on input that would exclude it from consideration?
No, I am not trying to come up with an exact specification, only a
general approach.
It means I couldn't think of a graceful way to express my intended
meaning and decided to just bail out of the sentence. Trying here:
Without a clear specification of what should be done about
overlapping matches, I don't think it makes sense try to come up
code or even an algorithm.
Why is it that in the corporation
The so-called clear specification
Is so often very dear
Costing loads of megabucks,
And never, almost never, ever clear?
The Germans had a Schlieffen Plan
A sort of military requirements definition:
But Tuchman the histori-an
Said that the plan was typically Teuton:
Everything was she said perfectly laid on
Only to fail at the critical point:
The plan violated the neutrality of Belgium.
To "focus", to be obedient, administered and precise
Is to be inhuman, and not very nice:
Yet we fear, even in something so rigid
As computer programming, so precise and so frigid,
Our queer humanity.
And why oh why is actual clarity
So seldom treated with charity
Euclid was as clear as day,
But seems to some a fussbudget and gay
Because he was precise in what he had to say.
But as it happens...as it turns out,
In what Adorno called the administered world,
Merely extending common sense,
Is unrewarded, unsung, and without recompense.
It transgresses in the name of truth
And so it's treated without ruth.
Requirements are ersatz and miss the point
Requirements, I say, please just go away:
We don't need no steenking requirements
Let's do a daily build and use extended common sense
That is, in fact, nothing more or less than science.
[ snip ]
Well, my greater experience with object oriented development in C
Sharp and VB has taught me that given either an adequate OO language,
or sufficient intelligence and patience, concat can work either way
without much drama. In C, the direction has to be a crummy parameter
that is easy to get wrong.
My usage of "concat" here was meant to indicate a mathematical/formal
operation on strings, not a call to a function in some programming
language, real or imagined. How can *that* imply a direction? As
I said, it seems to me that considered as a mathematical operation
string concatenation is associative. Maybe there's something I'm
not getting, though.
I agree. Concat is independent of direction in the abstract. But as
Dijkstra saw, there's a problem when the theory becomes reality. The
fact is that to real developers of the corporate-slave class, the
connotation of concatenation is left to right, they being uneducated
in linguistics.
That was not my intent. (And really, I don't think you're in the
strongest position to talk about not patronizing other posters.)
It's not patronizing when there is a genuine difference, in abilities
that is belied by the patronizing behavior. So don't speak to me of
what is sensible until you have established enough credibility. I
appreciate your collegiality but as yet I don't see any vast
difference in ability that would make "patronizing" inapplicable.
Real "patronizing" is only crudely inferable from a tone of voice. It
is relative to whether the patronizer is without merit adopting an *ex
cathedra* style. I think in my case it is sometimes appropriate to do
so. I would it were not so, for I would prefer to meet better
programmers here.