[View]  [Edit]  [Lock]  [References]  [Attachments]  [History]  [Home]  [Changes]  [Search]  [Help] 

String issues

This section will describe specific String compatibility issues, differences and similarities between VSE & S8
As it mentioned above, javascript string is inmutable, although VSE String is modifiable. This means that whenever you send an #at:put: message on String instances you will get an error exception 'Object is read-only'.

Avoid String>>at:put:
If your code is using #at:put: it is recommended to do a manual revision and modify your code avoiding #at:put: doing a concatenation instead.
As an example capitalize a word in VSE could be done as follows:
 
   word := word asLowerCase.
   word at: 1 put: word first asUpperCase.   

and must be changed to:
   word := word asLowerCase.
   word := word first asUppercase ,(word copyFrom: 2 to: word size)].

Avoid String class>>new:
In VSE sometimes a string can be used as a kind of buffer. Instantiate a string defining its lenght in advance can be interpreted as an intent of avoiding overhead in sucesives growing stages of strings. In javascript this is pointless because string implementation is inmutable and concatenation oriented. String concatenation is fast. In S8 intantiate a string using #new: will throw an error exception 'Needs revision'
If your code is using String class>>new: it is recommended to do a manual revision and modify your code avoiding #new:. In most cases replacing:
   | aString |
   aString := String new:5120. 

with this:
   | aString |
   aString := String new. 

is enough.

Empty string and nil
In S8 evaluating the following expression returns true
   '' isNil ----> true

Most cases do not result in side effects although you should pay special attention in lazy initializations, like this:
   value isNil ifTrue:[ value := ''].
   ^value.