Topic: String Class Metrics (was Help! how to implement "+" on string class)
Author: jim.fleming@bytes.com (Jim Fleming)
Date: 17 Mar 1995 20:58:01 GMT Raw View
In article <3jo85h$hdo@News1.mcs.com>, jim.fleming@bytes.com says...
>
>In article <radix-0903950727210001@net16.efn.org>, radix@efn.org says...
>>
>>In article <3ja8eq$34u@wsu-cs.cs.wayne.edu>, zlz@phoebe.cs.wayne.edu (Xin
>>Zou) wrote:
>>
>>> hi, I have a problem about the operator overloading "+" in string class;
>>>
>>> class string {
>>> int nLen; // the length of current string.
>>> int nCap; // the capacity of
>>current buffer.
>>> char *pChar; // string pointer.
>>> ...
>>> }
>>> ...
>>>
>>> string s1("hello ");
>>> string s2("world ");
>>> string s3;
>>>
>>> s3=s1+s2;
>>>
>>> the problem is how to store the temporary result of (s1+s2). I used a
>>> temporary instance of string, but the instance got deconstructed at the
>>> end of function "+"; if I used new to allocate a buffer, I don't know
>>> where to delete it.
>>>
>>> thanks in advance.
>>>
>>> a beginner in c++
>>> zlz@cs.wayne.edu
>>
>>This is one of the examples in Stroustrup's Gray book. Looks like you need
>>it. "The C++ Programming Language, Second Edition" by Bjarne Stroustrup.
>>Also the book "C++ FAQS" by Cline and Lomow has a sample string class.
>>
>>--
>>Gregory Jorgensen
>>radix consulting inc
>>radixinc@aol.com, radix@efn.org
>>
>>"I would consent to have a limb amputated to recover my spirits." --
Samuel
>John
>>son
>
>-------------------------------------------------------------------
IF YOU INTEND TO DELETE ANYTHING BETWEEN THESE LINES...DELETE IT ALL
>-------------------------------------------------------------------
>Can anyone provide me with statistics/answers on the following?
>
>1. Approximately how many times has the String class been written
> from scratch in C++?
>2. Approximately how many popular versions of the String class are
> currently in use?
>3. How can the String class documented in P.J. Plauger's book,
> "The Draft Standard C++ Library", be proposed as an
> ANSI/ISO C++ Standard when the book clearly states the
> software is protected by copyright, is NOT protected by
> the GNU "copyleft" agreement, and can be purchased and/or
> licensed from Plum Hall Inc. in Kamuela, Hawaii? How will
> this work?
>4. In reference to #3. Does this mean that even more implementations
> of the String class will be developed?
>5. Is there any central place which archives "knowledge" on the
> String class?
>6. Does anyone have a patent on Strings?
>7. What is the composite interface of methods for all popular
> String classes in use and how many methods are redundant?
>8. Has OOA and OOD been done on the String class or is it too simple?
>-------------------------------------------------------------------
IF YOU INTEND TO DELETE ANYTHING BETWEEN THESE LINES...DELETE IT ALL
>-------------------------------------------------------------------
>
>--
>Jim Fleming Unir Corporation Unir Technology, Inc.
>%Techno Cat I One Naperville Plaza 184 Shuman Blvd. #100
>Penn's Landing Naperville, IL 60563 Naperville, IL 60563
>East End, Tortola 1-708-505-5801 1-800-222-UNIR(8647)
>British Virgin Islands 1-708-305-3277 (FAX) 1-708-305-0600
>
--
Jim Fleming /|\ Unir Corporation Unir Technology, Inc.
%Techno Cat I / | \ One Naperville Plaza 184 Shuman Blvd. #100
Penn's Landing / | \ Naperville, IL 60563 Naperville, IL 60563
East End, Tortola |____|___\ 1-708-505-5801 1-800-222-UNIR(8647)
British Virgin Islands__|______ 1-708-305-3277 (FAX) 1-708-305-0600
\__/-------\__/ e-mail: jim.fleming@bytes.com
Smooth Sailing on Cruising C+@amarans
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\______to the end of the OuterNet
Author: "Ronald F. Guilmette" <rfg@rahul.net>
Date: 18 Mar 1995 11:00:58 GMT Raw View
In article <3kbio1$k1v@hustle.rahul.net>,
Ronald F. Guilmette <rfg@rahul.net> wrote:
>In article <1995Mar11.222218.22855@mole-end.matawan.nj.us>,
> <mat@mole-end.matawan.nj.us> wrote:
>>Whenever someone offers material protected by copyright--which, in the
>>USA, is ANYTIME original material is offered, since all original writings
>>are protected by copyright--for use in the Standards effort, they
>>surrender their rights to limit the use of the material. I'm not sure
>>of the exact legal description of how this occurs, but it is the essence
>>of the matter.
>
>I think you are dreaming.
>
>I've sent in _lots_ of ``issue'' statements relating to various drafts...
>some of them with proposed wording changes.
>
>So have lots of other people.
>
>To the best of my knowledge, neither I nor they have ever ``surrendered''
>our rights to such materials, either voluntarily or otherwise.
>
>How big does something have to be before it can be protected by copyright?
>Beats the hell out of me.
>
>From a legal/copyright standpoint, I think an awful lot of what goes on
>during the drafting of a standard like this is murky at best.
Sorry to follow-up on my own posting, but...
I've just read the `Law' column in this month's IEEE Software. I think
it is trying to say something quite similar to what I said. It's a good
read.
--
-- Ron Guilmette, Sunnyvale, CA ---------- RG Consulting -------------------
---- E-mail: rfg@segfault.us.com ----------- Purveyors of Compiler Test ----
-------------------------------------------- Suites and Bullet-Proof Shoes -
Author: "Ronald F. Guilmette" <rfg@rahul.net>
Date: 17 Mar 1995 08:54:25 GMT Raw View
In article <1995Mar11.222218.22855@mole-end.matawan.nj.us>,
<mat@mole-end.matawan.nj.us> wrote:
>> 3. How can the String class documented in P.J. Plauger's book,
>> "The Draft Standard C++ Library", be proposed as an
>> ANSI/ISO C++ Standard when the book clearly states the
>> software is protected by copyright, is NOT protected by
>> the GNU "copyleft" agreement, and can be purchased and/or
>> licensed from Plum Hall Inc. in Kamuela, Hawaii? How will
>> this work?
>
>Whenever someone offers material protected by copyright--which, in the
>USA, is ANYTIME original material is offered, since all original writings
>are protected by copyright--for use in the Standards effort, they
>surrender their rights to limit the use of the material. I'm not sure
>of the exact legal description of how this occurs, but it is the essence
>of the matter.
I think you are dreaming.
I've sent in _lots_ of ``issue'' statements relating to various drafts...
some of them with proposed wording changes.
So have lots of other people.
To the best of my knowledge, neither I nor they have ever ``surrendered''
our rights to such materials, either voluntarily or otherwise.
How big does something have to be before it can be protected by copyright?
Beats the hell out of me.
Author: mat@mole-end.matawan.nj.us
Date: Sat, 11 Mar 1995 22:22:18 GMT Raw View
References: <3ja8eq$34u@wsu-cs.cs.wayne.edu> <3jo85h$hdo@News1.mcs.com>
(There is just one item in here on the Standards process and that issue
is the only justification for keeping this on comp.std.c++; please take
followups off unless they amplify that issue.)
In article <3jo85h$hdo@News1.mcs.com>, jim.fleming@bytes.com (Jim Fleming) writes:
> In article <radix-0903950727210001@net16.efn.org>, radix@efn.org says...
> >In article <3ja8eq$34u@wsu-cs.cs.wayne.edu>, zlz@phoebe.cs.wayne.edu (Xin
> >Zou) wrote:
> >> hi, I have a problem about the operator overloading "+" in string class;
:
:
> Can anyone provide me with statistics/answers on the following?
>
> 1. Approximately how many times has the String class been written
> from scratch in C++?
About once for each time someone learns C++.
How many times has the `Hello World' program been written?
...
> 3. How can the String class documented in P.J. Plauger's book,
> "The Draft Standard C++ Library", be proposed as an
> ANSI/ISO C++ Standard when the book clearly states the
> software is protected by copyright, is NOT protected by
> the GNU "copyleft" agreement, and can be purchased and/or
> licensed from Plum Hall Inc. in Kamuela, Hawaii? How will
> this work?
Whenever someone offers material protected by copyright--which, in the
USA, is ANYTIME original material is offered, since all original writings
are protected by copyright--for use in the Standards effort, they
surrender their rights to limit the use of the material. I'm not sure
of the exact legal description of how this occurs, but it is the essence
of the matter.
You may be sure that Plum Hall, Inc, agreed to that surrender, just as
HP agreed to surrender the rights to STL.
> 6. Does anyone have a patent on Strings?
I hope not. On this one, prior art could be shown in the '60s, since
string types have been around since the days of Algol 60.
> 8. Has OOA and OOD been done on the String class or is it too simple?
That I have written the following many times, in many guiesses, does not
make it true. But if it _is_ true, and not acknowledged, either I am a
prophet or `everybody else' (all those people hiding behind that lamppost
over there) is looking in the wrong direction. So if you are following
this thread, I ask you to indulge me and read the following very carefully,
suspending your outrage until you have coolly reached the end and tried
the analysis suggested.
String is a value-oriented type, and its use is a value-oriented use.
> 8. Has OOA and OOD been done on the String class or is it too simple?
It is irrelevant.
While E/R analysis may be meaningful for the _use_ of String and either
E/R or OO might be useful (briefly) for the _implementation_ of String,
OO analysis (as currently defined by Booch or Rumbaugh, or most other
authors) is as meaningful as OO analysis on an int . Since int is
never an object, always an attribute (meaning it is always a value
representation, never an identity or object representation) it falls to
the wayside in these OO methods.
It's true that String may be--indeed, IS--_implemented_ using identity
representations of other types, but that does not change how String itself
is used. An instance of String represents a particular string (in the
OO world) only by virtue of the relationships (including ownership or
containment) that make it part of or an attribute of an object or a
temporality-not-represented-by-object. This is different from (for
example) class Employee, which by its nature, definition, and existance
represents, for each of its instances, a unique instance of that
outer-world entity called Employee.
In the value representation, the relationship with an outerworld (real-
world or solution-world) entity comes about by relationship with other
program objects; in identity representation, the relationship with an
outer-world entity is inherent in the Object (in the instance of the class).
These are fundamentally _different_ representation uses. This becomes
obvious when you do E/R analyses on the correspondence between Outer-World
and Program-World entities for Identity-representation and Value-
representation types.
--
(This man's opinions are his own.)
From mole-end Mark Terribile
mat@mole-end.matawan.nj.us, Somewhere in Matawan, NJ
(Training and consulting in C, C++, UNIX, etc.)
Author: jim.fleming@bytes.com (Jim Fleming)
Date: 10 Mar 1995 00:57:21 GMT Raw View
In article <radix-0903950727210001@net16.efn.org>, radix@efn.org says...
>
>In article <3ja8eq$34u@wsu-cs.cs.wayne.edu>, zlz@phoebe.cs.wayne.edu (Xin
>Zou) wrote:
>
>> hi, I have a problem about the operator overloading "+" in string class;
>>
>> class string {
>> int nLen; // the length of current string.
>> int nCap; // the capacity of
>current buffer.
>> char *pChar; // string pointer.
>> ...
>> }
>> ...
>>
>> string s1("hello ");
>> string s2("world ");
>> string s3;
>>
>> s3=s1+s2;
>>
>> the problem is how to store the temporary result of (s1+s2). I used a
>> temporary instance of string, but the instance got deconstructed at the
>> end of function "+"; if I used new to allocate a buffer, I don't know
>> where to delete it.
>>
>> thanks in advance.
>>
>> a beginner in c++
>> zlz@cs.wayne.edu
>
>This is one of the examples in Stroustrup's Gray book. Looks like you need
>it. "The C++ Programming Language, Second Edition" by Bjarne Stroustrup.
>Also the book "C++ FAQS" by Cline and Lomow has a sample string class.
>
>--
>Gregory Jorgensen
>radix consulting inc
>radixinc@aol.com, radix@efn.org
>
>"I would consent to have a limb amputated to recover my spirits." -- Samuel
John
>son
-----------------------------------------------------------------
Can anyone provide me with statistics/answers on the following?
1. Approximately how many times has the String class been written
from scratch in C++?
2. Approximately how many popular versions of the String class are
currently in use?
3. How can the String class documented in P.J. Plauger's book,
"The Draft Standard C++ Library", be proposed as an
ANSI/ISO C++ Standard when the book clearly states the
software is protected by copyright, is NOT protected by
the GNU "copyleft" agreement, and can be purchased and/or
licensed from Plum Hall Inc. in Kamuela, Hawaii? How will
this work?
4. In reference to #3. Does this mean that even more implementations
of the String class will be developed?
5. Is there any central place which archives "knowledge" on the
String class?
6. Does anyone have a patent on Strings?
7. What is the composite interface of methods for all popular
String classes in use and how many methods are redundant?
8. Has OOA and OOD been done on the String class or is it too simple?
-----------------------------------------------------------------
--
Jim Fleming Unir Corporation Unir Technology, Inc.
%Techno Cat I One Naperville Plaza 184 Shuman Blvd. #100
Penn's Landing Naperville, IL 60563 Naperville, IL 60563
East End, Tortola 1-708-505-5801 1-800-222-UNIR(8647)
British Virgin Islands 1-708-305-3277 (FAX) 1-708-305-0600
Author: jason@cygnus.com (Jason Merrill)
Date: 10 Mar 1995 06:45:36 GMT Raw View
>>>>> Jim Fleming <jim.fleming@bytes.com> writes:
> 3. How can the String class documented in P.J. Plauger's book,
> "The Draft Standard C++ Library", be proposed as an
> ANSI/ISO C++ Standard when the book clearly states the
> software is protected by copyright, is NOT protected by
> the GNU "copyleft" agreement, and can be purchased and/or
> licensed from Plum Hall Inc. in Kamuela, Hawaii? How will
> this work?
The interface is in the public domain. Only the particular implementation
mentioned (and listed?) in the book is copyrighted.
I don't believe that Plauger's implementation has even been designated as a
reference implementation.
> 4. In reference to #3. Does this mean that even more implementations
> of the String class will be developed?
Certainly. There's my implementation of the draft standard string class,
for instance. It can be found in libg++-2.6.2, on all fine GNU mirrors.
I expect that other String classes will live on after the standard is
finalized, though they will most likely be modified to conform to the
published interface; the draft standard string class is significantly less
functional than most of the available alternatives, more's the pity.
> 5. Is there any central place which archives "knowledge" on the
> String class?
Well, there's the ANSI/ISO draft working paper, which contains the current
specification of the draft standard string class.
Jason
Author: jim.fleming@bytes.com (Jim Fleming)
Date: 11 Mar 1995 04:55:46 GMT Raw View
In article <JASON.95Mar9224536@phydeaux.cygnus.com>, jason@cygnus.com
says...
>
>>>>>> Jim Fleming <jim.fleming@bytes.com> writes:
>
>> 3. How can the String class documented in P.J. Plauger's book,
>> "The Draft Standard C++ Library", be proposed as an
>> ANSI/ISO C++ Standard when the book clearly states the
>> software is protected by copyright, is NOT protected by
>> the GNU "copyleft" agreement, and can be purchased and/or
>> licensed from Plum Hall Inc. in Kamuela, Hawaii? How will
>> this work?
>
>The interface is in the public domain. Only the particular
implementation
>mentioned (and listed?) in the book is copyrighted.
>
This is sort of good news, but raises more questions.
-------Summary of questions--------
1. What exactly do you mean by the "interface"?
2. Does the "interface" specification include the comments?
3. Does the standard specify "exact" method names or <meta> method names
which will require a round of "bindings" documents.
4. Does the standard specify exact member function argument names or will
positional standardization be enough?
5. Are the instance variable names copyrighted by Plum Hall, Inc. or
are they part of the public domain standard?
6. What about other comments that may not be part of the "interface"
but which could be part of the Standard?
-------Full text of questions with notes-------
1. What exactly do you mean by the "interface"?
Notes(s) and Additional Questions for #1.
-----------------------------------------
(i.e. Where does "interface" end and implementation begin?
I know what an interface is, I am loking for precision, not a
flame.
2. Does the "interface" specification include the comments?
Notes(s) and Additional Questions for #2.
-----------------------------------------
Let's look at an example:
For the class String there are three find methods. Two have
2 arguments and 1 has 3 arguments:
Are *just* the following lines the interface?
size_t find(const string& str, size_t pos = 0) const;
size_t find(const char* s,size_t pos = 0,size_t n=NPOS) const;
size_t find(char c, size_t pos = 0) const;
Or, do you *also* include the descriptive english as shown here?
find size_t find(const string& str, size_t pos = 0) const;
Determines the lowest position xpos, if possible,
such that both of the following conditions obtain:
pos <= xpos and xpos + str.len <= len;
ptr[xpos+I] == str.ptr[I} for all elements I of
the
string controlled by str.
If the function can determine such a value for xpos, it
returns xpos. Otherwise, it returns NPOS.
17.5.1.1.37 string::find(const char*, size_t, size_t)
size_t find(const char* s,size_t pos = 0,size_t n=NPOS) const;
Returns find(string(s,n),pos).
17.5.1.1.38 string::find(char, size_t)
size_t find(char c, size_t pos = 0) const;
Returns find(string(c),pos).
17.5.1.1.39 string::rfind(const string&, size_t)
3. Does the standard specify "exact" method names or symbolic method
names
which will require a "bindings" documents.
Notes(s) and Additional Questions for #2.
-----------------------------------------
For example, is the word "find" above part of the standard or
part of the copyrighted implementation?
If it is part of the standard, then what is the implementation?
This same question applies to everything shown above except the
comments.
For example, is size_t part of the standard or the
copyrighted implementation?
If I implement a different version do I have to say "size_type",
or "t_size"?
Would there be a cleaner separation between the Standard and
copyrighted implementation(s) if the Standard used
something like <find_string> which is clearly not
an "implementation" name but a symbolic place holder
which an implementor should replace with their chosen
name?
If a symbolic name is used, how would programmers know what
method name to use?
4. Does the standard specify exact member function argument names or will
positional standardization be enough?
Notes(s) and Additional Questions for #4.
-----------------------------------------
For example:
size_t find(const string& str, size_t pos = 0) const;
Are "str" and "pos" above part of the Standard or implementation?
Could the Standard say....?
<Size> find (<String>,[<Size> defaults to: 0])
...and be independent of implementation?
Is there a "meta" language for the Standard?
5. Are the instance variable names copyrighted by Plum Hall, Inc. or
are they part of the public domain Standard?
Notes(s) and Additional Questions for #5.
-----------------------------------------
For example, in the string class, buried down at the end of the
huge list of methods, we have two lonely instance variables,
"ptr" and "len". I think these probably stand for pointer and
length. Actually, there are three instance variables, I did not
notice the one named "res" upon first glance. I *think* "res"
probably stands for reserve although the documentation indicates
that once a string is allocated then res holds the current
allocated
length.
The excerpt looks like:
private:
// char* ptr; exposition only
// size_t len, res; exposition only
I assume that the "exposition" only means that this is "showing"
some of the implementation for the readers' benefit but
not to standardize on an implementation.
Is that correct?
If so, could I then have...?
private:
// char* pointer;
// size_t currentLength;
// size_t initialAndAdditionalAllocation;
// size_t currentAllocation;
If so, could my strings grow, while the Standard ones do not?
Is "auto-grow" and possibly shrink a behavioural characteristic?
If my strings can grow, then what about all of the Standard
methods that are specified that deal with reserving
and growing?
Can I omit the low-level methods like "resize" and "reserve"
if my strings are smart and have a life of their own?
(like real objects?)
Do you folks have a clue how strings really work?
If "exposition only" implies some sort of hiding, then how
can the standard have methods like "reserve" which
says, "Returns "res"."?
Can we have it both ways?
Can the implementation be hidden while the "public domain"
interface is specified in terms of "hidden" details.
Does the Standard, standardize on well-thought-out designs
reviewed by many or on a bunch of "stuff" that
happened to be on someone's disk drive.
What does the A stand for in ANSI?
Have you ever completed an entire ANSI standards process?
How many people on the C++ ANSI committee have completed an ANSI
standard.
Who are they?
Are they all Americans?
Does America include both North and South America?
6. What about other /*comments*/ that may not be part of the "interface"
but which could be part of the Standard?
Notes(s) and Additional Questions for #6.
-----------------------------------------
For example:
Is the following text part of the Standard and in the public
domain?
"The class "string" describes objects that can store a sequence
consisting of a varying number of arbitrary (single-byte)
characters. The first element of the sequence is at position
zero. Such a sequence is also called a /character string/...."
Has there been effort to allign the above definition of a C++
string with other definitions from Smalltalk, C+@, etc.?
>I don't believe that Plauger's implementation has even been designated
as a
>reference implementation.
>
>> 4. In reference to #3. Does this mean that even more implementations
>> of the String class will be developed?
>
>Certainly. There's my implementation of the draft standard string
class,
>for instance. It can be found in libg++-2.6.2, on all fine GNU mirrors.
>
OH Lord!!!...to Certainly...
Thank God you gave me another one to look at for comparison.
>I expect that other String classes will live on after the standard is
>finalized, though they will most likely be modified to conform to the
>published interface; the draft standard string class is significantly
less
>functional than most of the available alternatives, more's the pity.
>
Yes, I think that String classes will live on.
The question at hand is...will the C++ language live on?
Where is C++ going?
I have read postings that say, "Let's get the language defined
before the class library."
I have also read the flip side which says, "Let's get the class
library defined and *then* figure out what is *needed* in the language".
>> 5. Is there any central place which archives "knowledge" on the
>> String class?
>
>Well, there's the ANSI/ISO draft working paper, which contains the
current
>specification of the draft standard string class.
>
>Jason
Thanks for your help. I enjoyed reading your reply. I am both
encouraged and discouraged.
Having been through an ANSI standards process from front to back,
I can tell you that based on what I have seen you folks are in for
a steep climb. If you find that the climb is not that steep and that
you get a "free ride" from the general public, then that will be
a clear indication that they do not care enough to challenge some
of the issues because they see no long-term impact on society from
your work. In other words, "busses full of retired priests and nuns
will not start instantly catching fire and rolling over on highways
if your work is shoddy". As long as you avoid that kind of impact,
the majority of the general public will probably live their lives
and never know a standard exists.
--
Jim Fleming Unir Corporation Unir Technology, Inc.
%Techno Cat I One Naperville Plaza 184 Shuman Blvd. #100
Penn's Landing Naperville, IL 60563 Naperville, IL 60563
East End, Tortola 1-708-505-5801 1-800-222-UNIR(8647)
British Virgin Islands 1-708-305-3277 (FAX) 1-708-305-0600