i would agree, this should be moved somewhere else since there wasn't a question asked or answered.
Printable View
i would agree, this should be moved somewhere else since there wasn't a question asked or answered.
Actually words said and words implied are different, however you did say this:Quote:
STOP putting words in my mouth. ...." I didn't imply anything. I said
Which does put your own words back into your mouth.Quote:
if your post had been Strings and StringBuilder Different, well DUH!
Your whole argument implies that a normally intelligent person would not and should not be making this mistake.
There is no quirk for you, in your mind, so you think it couldn't possibly be an issue for others.
Please put me on your ignore list Oblio.
You certainly will be on mine.
Quote:
i would agree, this should be moved somewhere else since there wasn't a question asked or answered
There is no official requirement for threads.
This is a place of discussion, and this thread is just fine here.
I would be highly offended if it were moved, and I don't think Shuja is a vengful person like that.
How small.
why don't you just stop? or are you the only one allowed to have an opinion? if i wanted it moved because i didn't like you, i would have said so, or not said anything at all.
this is the wrong place to be if you want your opinion to be the only one allowed.
you put words in my mouth, now calling me names. that is offensive.
Common now, are you really going to act like the suggestion to move the thread, is purely objective.
First of all your post mentioned quirk, which is not a correct word, if you read why immutability is desired at first place. Second is that no body gives orders here. Your "Do Not" does not imply that we cannot move the thread into some other section. If you think logically, posting this in a FAQ would be helpful (of course with a changed title) to lot of people rather than posting in a forum. FAQ has an index where people can easily look for what they are searching where as in Forums they have to search for the keyword "quirk" to get to your thread. unlike you i was giving a suggestion not an order to post it in a separate section with a proper heading. I repeat my words, string being immutable is not a quirk (-noun "a sudden twist or turn").Quote:
Originally Posted by TT(n)
Here is my explanation of why it is not a quirk and why it is a good thing that it got introduced in .NET:Quote:
Originally Posted by TT(n)
Protection:
Immutable objects once instantiated cannot be changed so immutable object can flow to different layers of the applicationa nd we will be sire that it is not being altered by any layer. You must be knowing that string in .NET is a reference type and you must also be knowing that when a reference types are passed vetween methods, it is the actual reference that gets passed and not the value, which implies that the called method can chnge the value of that reference type. But because string type is immutable you avoid such kind of un-necessary error checking within your code.
Performance:
With your knowledge you will know that copying objects is much faster than copying the data. So there you go, the performance boost. However, this also means that when a string is used a lot, it will degrade the performance because if you do something like this in a loop, the GC has to collect extra pile of objects which were un-wanted in the first place.The code above will create 10000 objects out of which 9999 are useless because they are not being used anywhere. So the GC has to do some extra cleaning up. For this case, you will use Stringbuilder. This is what I meant when I said that strings are meant for a different operation and StringBuilder is meant for different kind of operation. I guess even though people are experienced and know the facts we still need to explain small bits at times.Code:Dim temp as string, i as Integer
For i = 1 to 10000
temp = temp + "New value"
Next
Scalability:
In a multi-threaded environment an immutable object (in this case string) would never change simply because it is immutable. If it were supposed to be mutable, you would not be sure which thread would change the value of the object. So there you go again, thread safety. Immutability by design would make sure that you don't fall into race conidtions.
This is the reason why I chose to write that strings are meant for different operations that stringbuilder. I don't think that it is safer for newbies and not so safer for experienced programmer because experienced programmers know it all. This is wrong notion and sometimes experienced programmers write code which is far less maintainable and understandable than the code written by newbee.Quote:
Originally Posted by TT(n)
No one is missing any points here. I am still saying that it is not a quirk and newbie should know that the immutability of the string data type is because of design and because of some purpose and it is NOT a quirk.Quote:
Originally Posted by TT(n)
I think a big misunderstanding is the definition of quirk.
Quirk had a closer third definition, which was Vagary.
I had mentioned that, but it seems to be easily overlooked.
Check Vagary, and the word unpredictable fits pretty well, for newbies.
Twist is synonymous with unpredictable. We're not talking about the dance style either. :)
Bugs and errors, are usually on the VB side, including documentation.
Quirks and mistakes are usually on the developer side.
Sometimes a mistake is induced by vague, cryptic, hidden, or ambiguous wording on the VB side.
It's not always immediately clear by definition, but afterwards it makes complete sense.
For example, Gremmy's article on IDE bugs/quirks, originally included a bug, that actually was really an unpredictable quirk for the talented developer.
I pointed out why it was not a bug:
The quirk(not bug), was that the Find/Replace window would not search for text if it was in closed Regions.
The unpredicted twist, was that you have to simply open up the "Find options", and choose "search hidden text".
In this case it's a hidden option(+), that is also vague because the option is titled "Search hidden text", and not "Search Regions", or something more appropriate.
CORRECT.Quote:
A newbie should know that the immutability of the string data type is by design
I never said that the design itself is a quirk.
This is another misunderstanding.
It's just quirky to use, if you don't read up first, and fully understand the meaning of the definition. Newbs are expected to be doing that.
I'm glad you decided to explain what you really meant by performance.Quote:
I guess even though people are experienced and know the facts we still need to explain small bits at times.
You've got a pretty good understanding of the theory.
However, in practice Builder is still faster with a single, or just a few manipulations.
This contradicts what is written in most places, or at least the spirit of the words, but in my testing Builder is faster everytime for manipulations.
The proportion varies throughout the range, but is never slower.
Perhaps some machines, may not contradict this implication.
A real experienced developer does not code outside of his/her means, and always tests things first.
That notion is correct.
You are right though, that far to many developers think they are experts, and so that notion of over-confidence can cause problems.
You made this personal:
"Common now, are you really going to act like the suggestion to move the thread, is purely objective."
And I see where you called me a liar has been removed.
I have seen and answered many posts in many forums that went something like:
SUBJ: Problem With String
The string doesn't change when I did this
I have seen it answered many ways, by many different people(including me), with discussions of immutability and stringbuilder. But this is the very first time I have ever heard it called a "quirk".Code:Dim s As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
s.Remove(0, 6)
'the normal answer for this is
s = s.Remove(0, 6)
As far as speed differences, we all agree. Here is one test from my code timer.
ResultsCode:Dim s As String = "abc"
Dim sb As New System.Text.StringBuilder
Dim retval As String
Private Function TestCase1() As Boolean 'One
'Test One Code Here
retval = ""
For x As Integer = 1 To 10
retval &= s
Next
'end test code
Return True
End Function
Private Function TestCase2() As Boolean 'Two
'Test Two Code Here
sb.Length = 0
For x As Integer = 1 To 10
sb.Append(s)
Next
retval = sb.ToString
'end test code
Return True
End Function
You should take your original post and post it at VBForums.Code:03/26/09 10:19:34.657 CPU - 1.794GHz
x86 Family 6 Model 13 Stepping 6 Address width - 32
One - Concatenation
Two - StringBuilder
Outer Loops(OL)=7 Inner Loops=262,144 (ea. 1,835,008)
( times in ticks. 1 ms. = 10,000 ticks )
>> Two faster, 10.6788 ticks/loop
Ticks / Loop
0.0346 14.3088 3.6300 10.6788
OL Base One Two One - Two
1 8,987 3,078,209 949,328 2,128,881
2 8,998 3,111,321 947,723 2,163,598
3 8,960 5,077,462 953,127 4,124,335
4 8,988 3,129,498 950,599 2,178,899
5 9,665 3,113,121 956,045 2,157,076
6 8,982 5,629,046 950,436 4,678,610
7 9,001 3,118,117 953,758 2,164,359
Average
9,083 3,750,967 951,573 2,799,394
Variance
56,606.3 1,048,870,058,189.0 7,041,699.3
Standard Deviation
237.9 1,024,143.6 2,653.6
03/26/09 10:19:43.941