Strings.. Objects or not???

J

Jon Skeet [C# MVP]

Cor Ligthert said:
Thirth try,

We know that the immutability of a string can take more time when we concate
them when we do not use the stringbuilder, thinking about this subject we
know that it can take even more time than we maybe think to create a string.

Can this have your agreement?

Sort of. However, immutability also speeds things up as you don't need
to copy strings all over the place just to make sure they don't change.
Immutability itself doesn't cost anything - it's not like the CLR has
to do anything special with an object just because it's immutable. The
impact of immutability on the API (for example, concatenating strings)
can cost time and save time, depending on what you're doing.
 
G

Guest

aye laddie,
2Mhz solder in the resistors NASCOM, write your own (polling) diskcontrollers and it STILL runs today:)
 
C

Cor Ligthert

Hi Jon,
Sort of. However, immutability also speeds things up as you don't need
to copy strings all over the place just to make sure they don't change.
Immutability itself doesn't cost anything - it's not like the CLR has
to do anything special with an object just because it's immutable. The
impact of immutability on the API (for example, concatenating strings)
can cost time and save time, depending on what you're doing.
I have to go back very much time in memory, I though that we wrote than a
string something like this S(length). And it was ofcours mutable. The
approach of the constant (which I did not know before I saw this message) is
for me something the same as the not redundant database, it is nice however
cost time.

For the rest I refer to the message from OHM and Guy which gave me as well
some insight in this problem.

I hope that you do not mind that we make this EOT, my purpose from my first
message was an answer to Lucky which seems to me to come from a special
area, however I did not wanted to answer it to direct.

And than as for ever, I have to answer Jon, (not offended ment just for
fun).

:)

Cor
 
J

Jon Skeet [C# MVP]

I have to go back very much time in memory, I though that we wrote than a
string something like this S(length). And it was ofcours mutable.

What do you mean by "we wrote"?
The approach of the constant (which I did not know before I saw this
message) is for me something the same as the not redundant database,
it is nice however cost time.

String literal interning costs time, yes. (We agree that the amount of
time is almost always insignificant.) That's not the same as
immutability though - you seem to be switching from one to the other
all the time as if they're the same thing.
For the rest I refer to the message from OHM and Guy which gave me as well
some insight in this problem.

They both seem to be talking about interning, too - not immutability.
I hope that you do not mind that we make this EOT, my purpose from my first
message was an answer to Lucky which seems to me to come from a special
area, however I did not wanted to answer it to direct.

The problem was that your answer to Lucky talked about immutability,
when Lucky was talking about interning. That's why I replied to your
post - you seemed to be confusing the two, even if you actually
weren't.
 
O

One Handed Man \( OHM - Terry Burns \)

Immutability has nothing to do with performance of string matching. I was
simply making a point about the matching itself.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 
C

Cor Ligthert


The programmers in those very old days in the old big king mainframe
assembler time (however as I told, I am not even sure anymore of that
statement so do not arguing about that, I will loose at the start).
The problem was that your answer to Lucky talked about immutability,
when Lucky was talking about interning. That's why I replied to your
post - you seemed to be confusing the two, even if you actually
weren't.

That was why I tried to make two times a correction, did I make any
statement of disagrement with you about that or do you think that I am to
afraid to do that to you?

:)

Cor
 
J

Jon Skeet [C# MVP]

Immutability has nothing to do with performance of string matching.
Indeed.

I was simply making a point about the matching itself.

And that's why I was surprised when you agreed with Cor who seemed to
be making a point about immutability...
 
J

Jon Skeet [C# MVP]

Cor Ligthert said:
The programmers in those very old days in the old big king mainframe
assembler time (however as I told, I am not even sure anymore of that
statement so do not arguing about that, I will loose at the start).

Ah. I see what you mean now. Some frameworks certainly have mutable
strings, yes.
That was why I tried to make two times a correction, did I make any
statement of disagrement with you about that or do you think that I
am to afraid to do that to you?

The first time you corrected it was fine - but then in that previous
post you seemed to be confusing them again. Maybe you were, maybe you
weren't - it wasn't very clear.
 
O

One Handed Man \( OHM - Terry Burns \)

When I agreed, it was in respect of matching performance, I must have missed
that.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
 
C

Cor Ligthert

Do you think that I am to afraid to do that to you?
Maybe you were, maybe you weren't - it wasn't very clear.

No I am not, do not make yourself any illusion.

:))))

A little bit constructive quoting before you say it, about the other point
because of this discussion I become more and more to disagree with you, I
cannot see the string creation as a part of different things, however see it
more and more as a method and a storage item, thight together like in every
OOP situation. However Jon, not something what I like to argue about, that
was long ago that I liked it to make things as this more clear for me. When
I needed that it is more clear, I will investigate it, so sorry I only say
in this one "I agree with you".

Cor
 
C

Cor Ligthert

Hi Jon,
And that's why I was surprised when you agreed with Cor who seemed to
be making a point about immutability...

This is not cricket,



Do not tell things about me, that I have to see by accident. You put words
in my mouth I never said.



A string in this situation is nothing more than address (length) where the
address is the address of a pool of different strings without redundancy.



Happy with this?



Cor
 
J

Jon Skeet [C# MVP]

Cor Ligthert said:
This is not cricket,

Do not tell things about me, that I have to see by accident. You put words
in my mouth I never said.

Note the "seemed to". To me, you seemed to be making a point about
immutability.
A string in this situation is nothing more than address (length) where the
address is the address of a pool of different strings without redundancy.

Happy with this?

Only when it's a string literal. Strings aren't interned automatically
in other situations. It doesn't affect normal string creation.
 
G

Guest

This thread seems to have gone off on tangents everythere.

The original question was if strings are objects. They are, in fact everything is. However some objects do behave differently, like people responding to discussions in news groups.

what does x1 = x2 mean? You need to (thourougly) read the language specs.

is it x1.ReferenceEquals(x2)

or is it x1.Compare(x2) = 0

also, if its the jit compiler, it does happen at runtime (at least once).

All strings have an internal pointer to their own string. even if those strings happen to contain the same group and length of characters.
 
J

Jon Skeet [C# MVP]

Cor Ligthert said:

Sure. When you've got two string literals which contain the same
characters, you only end up with one string. If you create two
equivalent strings dynamically, however, you end up with two different
string objects.

For instance, in C#:

string x = "hello";
string y = "hello";

StringBuilder sb = new StringBuilder();
sb.Append(x);
string a = sb.ToString();

sb = new StringBuilder();
sb.Append(x);
string b = sb.ToString();

x and y are references to the same string. a and b are references to
different strings - so there are 3 strings in total in the above.
 
J

Jon Skeet [C# MVP]

<"=?Utf-8?B?TWljaGFlbCBHIFc=?=" <Michael G
This thread seems to have gone off on tangents everythere.

The original question was if strings are objects. They are, in fact
everything is. However some objects do behave differently, like
people responding to discussions in news groups.

what does x1 = x2 mean? You need to (thourougly) read the language
specs.

Not sure about VB, but in C# you don't need to read the language specs
particularly thoroughly - you just need to see that String overloads
the equality operator, just as other classes can.
is it x1.ReferenceEquals(x2)

or is it x1.Compare(x2) = 0

also, if its the jit compiler, it does happen at runtime (at least
once).

If *what's* the JIT compiler?
All strings have an internal pointer to their own string. even if
those strings happen to contain the same group and length of
characters.

Could you explain that, please? Strings contain their data directly -
there's no extra level of indirection.
 
C

Cor Ligthert

Jon,
For instance, in C#:

string x = "hello";
string y = "hello";

StringBuilder sb = new StringBuilder();
sb.Append(x);
string a = sb.ToString();

sb = new StringBuilder();
sb.Append(x);
string b = sb.ToString();
Are you sure of this, I did not check this however what you write in my
translation is that "string a" and "string b" are not strings however
references to a stringbuilder object, which holds strings, which are not
strings. And in that case there is only one string and two objects which has
maybe a concationation of characters and is not a string in the meaning of
this however a method.

I am not saying you are wrong, as you wrote (and what was committed by me)
is that the String is a kind of strange object.

The String looks for me as a legacy C method which is inherited in dotNet.

Cor
 
J

Jon Skeet [C# MVP]

Are you sure of this

Absolutely. It's very easy to test:

using System;
using System.Text;

class Test
{
static void Main()
{
string x = "hello";
string y = "hello";

StringBuilder sb = new StringBuilder();
sb.Append(x);
string a = sb.ToString();

sb = new StringBuilder();
sb.Append(x);
string b = sb.ToString();

Console.WriteLine (object.ReferenceEquals(x, y));
Console.WriteLine (object.ReferenceEquals(x, a));
Console.WriteLine (object.ReferenceEquals(x, b));
Console.WriteLine (object.ReferenceEquals(a, b));
}
}
I did not check this however what you write in my
translation is that "string a" and "string b" are not strings however
references to a stringbuilder object, which holds strings, which are not
strings.

No, they're strings (or rather, string references).
StringBuilder.ToString() returns a string. The StringBuilder object
itself can be garbage collected after its use.
And in that case there is only one string and two objects which has
maybe a concationation of characters and is not a string in the meaning of
this however a method.

No, they're both strings. Otherwise they wouldn't be able to be held by
string variables, would they?

Other than the fact that the object x and y refer to are interned and
the objects a and b refer to aren't, there's basically no difference
between them.
I am not saying you are wrong, as you wrote (and what was committed by me)
is that the String is a kind of strange object.

It's not nearly as strange as some people think, to be honest.
The String looks for me as a legacy C method which is inherited in dotNet.

Nonsense - pretty much every development platform ever created has
strings.
 
C

Cor Ligthert

Jon,
No, they're strings (or rather, string references).
StringBuilder.ToString() returns a string. The StringBuilder object
itself can be garbage collected after its use.

Got it and made the sample more easy,

using System;
using System.Text;
class Test
{static void Main()
{string x = "hello";
string y = "hello";
string z = "hellom";
z = z.Substring(0,5);
Console.WriteLine (object.ReferenceEquals(x, y));
Console.WriteLine (object.ReferenceEquals(x, z));}}

Which means for me that only when the String is made as a constant it is
referencing to that constant object which can only be once in memory, and
therefore it has nothing to do with Strings however with constants.

(Correct me in this when I am wrong)
Nonsense - pretty much every development platform ever created has
strings.

That is nonsense itself, not every development platform had strings it is
only something from I think the last 25 years. Before that it was as I
showed you only an memoryaddress with the words and the length of those or
the end point of those.

Cobol by instance did not have it, although a pic X(10) Value "Jon Skeet"
you can call a string.

(I have seen systems with 24bits words. While now it is mostly that a word
is a synonime for a byte with usable 8 bits)

:)

Cor
 
J

Jon Skeet [C# MVP]

Cor Ligthert said:
Got it and made the sample more easy,

using System;
using System.Text;
class Test
{static void Main()
{string x = "hello";
string y = "hello";
string z = "hellom";
z = z.Substring(0,5);
Console.WriteLine (object.ReferenceEquals(x, y));
Console.WriteLine (object.ReferenceEquals(x, z));}}

Yes, that's a good simplification. (Just using "hellom".Substring(0, 5)
would work too.)
Which means for me that only when the String is made as a constant it is
referencing to that constant object which can only be once in memory, and
therefore it has nothing to do with Strings however with constants.

(Correct me in this when I am wrong)

Well, those string literals *are* still strings - they act just like
other strings apart from this one interning part.

Note also that you can intern other strings, using String.Intern.
That is nonsense itself, not every development platform had strings it is
only something from I think the last 25 years. Before that it was as I
showed you only an memoryaddress with the words and the length of those or
the end point of those.

Cobol by instance did not have it, although a pic X(10) Value "Jon Skeet"
you can call a string.

Exactly - even if they didn't *call* them strings, the concept was
still there. I don't see why you're dismissing it as a legacy concept -
what would you replace it with?
(I have seen systems with 24bits words. While now it is mostly that a word
is a synonime for a byte with usable 8 bits)

Um, I don't think so, actually. "Word" can have varying meanings.
What's more confusing is that "byte" doesn't always mean "8 bits" -
maybe that's what you meant?
 

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

Top