About String empty and others

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

About String empty and others

Stéphane Ducasse
Hi guys

chris mueller proposed in squeak to have


Exception>>messageText
       "Return an exception's message text."
+       ^ messageText ifNil: [ String empty ]!
-
-       ^messageText!

- Added Array class>>#empty and String class>>#empty to provide applications with
canonicalized instances of these oft-used objects; since they are embedded as literals in the
CompiledMethod.

=============== Diff against Collections-ar.304 ===============

Item was added:
+ ----- Method: Array class>>empty (in category 'instance creation') -----
+ empty
+       "A canonicalized empty Array instance."
+       ^ #()!

Item was added:
+ ----- Method: String class>>empty (in category 'instance creation') -----
+ empty
+       "A canonicalized empty String instance."
+       ^ ''!

Item was removed:
- ----- Method: String>>asDefaultDecodedString (in category 'converting') -----
- asDefaultDecodedString
-
-       ^ self


http://code.google.com/p/pharo/issues/detail?id=1961
_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: About String empty and others

Michael Roberts-2
would the idea to be to rewrite every #() with Array empty?

If that was the case could you get the compiler to do that as an
optimization? I quite like the fact that #() is the empty array. it's
nice and compact; quite aesthetic.

cheers,
Mike

On Sat, Feb 13, 2010 at 11:06 AM, Stéphane Ducasse
<[hidden email]> wrote:

> Hi guys
>
> chris mueller proposed in squeak to have
>
>
> Exception>>messageText
>       "Return an exception's message text."
> +       ^ messageText ifNil: [ String empty ]!
> -
> -       ^messageText!
>
> - Added Array class>>#empty and String class>>#empty to provide applications with
> canonicalized instances of these oft-used objects; since they are embedded as literals in the
> CompiledMethod.
>
> =============== Diff against Collections-ar.304 ===============
>
> Item was added:
> + ----- Method: Array class>>empty (in category 'instance creation') -----
> + empty
> +       "A canonicalized empty Array instance."
> +       ^ #()!
>
> Item was added:
> + ----- Method: String class>>empty (in category 'instance creation') -----
> + empty
> +       "A canonicalized empty String instance."
> +       ^ ''!
>
> Item was removed:
> - ----- Method: String>>asDefaultDecodedString (in category 'converting') -----
> - asDefaultDecodedString
> -
> -       ^ self
>
>
> http://code.google.com/p/pharo/issues/detail?id=1961
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: About String empty and others

Stéphane Ducasse

On Feb 13, 2010, at 7:40 PM, Michael Roberts wrote:

> would the idea to be to rewrite every #() with Array empty?

no and this is a good question.
For now I do not see what we learn. I'm not sure that these empty messages bring anything.
besides one extra message.

> If that was the case could you get the compiler to do that as an
> optimization? I quite like the fact that #() is the empty array. it's
> nice and compact; quite aesthetic.

yes I will roll back some of the changes

>
> cheers,
> Mike
>
> On Sat, Feb 13, 2010 at 11:06 AM, Stéphane Ducasse
> <[hidden email]> wrote:
>> Hi guys
>>
>> chris mueller proposed in squeak to have
>>
>>
>> Exception>>messageText
>>       "Return an exception's message text."
>> +       ^ messageText ifNil: [ String empty ]!
>> -
>> -       ^messageText!
>>
>> - Added Array class>>#empty and String class>>#empty to provide applications with
>> canonicalized instances of these oft-used objects; since they are embedded as literals in the
>> CompiledMethod.
>>
>> =============== Diff against Collections-ar.304 ===============
>>
>> Item was added:
>> + ----- Method: Array class>>empty (in category 'instance creation') -----
>> + empty
>> +       "A canonicalized empty Array instance."
>> +       ^ #()!
>>
>> Item was added:
>> + ----- Method: String class>>empty (in category 'instance creation') -----
>> + empty
>> +       "A canonicalized empty String instance."
>> +       ^ ''!
>>
>> Item was removed:
>> - ----- Method: String>>asDefaultDecodedString (in category 'converting') -----
>> - asDefaultDecodedString
>> -
>> -       ^ self
>>
>>
>> http://code.google.com/p/pharo/issues/detail?id=1961
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: About String empty and others

Stéphane Ducasse
In reply to this post by Michael Roberts-2
the only think is that the #() and '' will not be created all the time but in the compile method literal frame.

Stef


> would the idea to be to rewrite every #() with Array empty?
>
> If that was the case could you get the compiler to do that as an
> optimization? I quite like the fact that #() is the empty array. it's
> nice and compact; quite aesthetic.
>
> cheers,
> Mike
>
> On Sat, Feb 13, 2010 at 11:06 AM, Stéphane Ducasse
> <[hidden email]> wrote:
>> Hi guys
>>
>> chris mueller proposed in squeak to have
>>
>>
>> Exception>>messageText
>>       "Return an exception's message text."
>> +       ^ messageText ifNil: [ String empty ]!
>> -
>> -       ^messageText!
>>
>> - Added Array class>>#empty and String class>>#empty to provide applications with
>> canonicalized instances of these oft-used objects; since they are embedded as literals in the
>> CompiledMethod.
>>
>> =============== Diff against Collections-ar.304 ===============
>>
>> Item was added:
>> + ----- Method: Array class>>empty (in category 'instance creation') -----
>> + empty
>> +       "A canonicalized empty Array instance."
>> +       ^ #()!
>>
>> Item was added:
>> + ----- Method: String class>>empty (in category 'instance creation') -----
>> + empty
>> +       "A canonicalized empty String instance."
>> +       ^ ''!
>>
>> Item was removed:
>> - ----- Method: String>>asDefaultDecodedString (in category 'converting') -----
>> - asDefaultDecodedString
>> -
>> -       ^ self
>>
>>
>> http://code.google.com/p/pharo/issues/detail?id=1961
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: About String empty and others

Marcus Denker-4

On Feb 13, 2010, at 8:03 PM, Stéphane Ducasse wrote:

> the only think is that the #() and '' will not be created all the time but in the compile method literal frame.
>
Yes, right now it's created once per method... the compiler could easily make sure that it's shared globally.

        Marcus


> Stef
>
>
>> would the idea to be to rewrite every #() with Array empty?
>>
>> If that was the case could you get the compiler to do that as an
>> optimization? I quite like the fact that #() is the empty array. it's
>> nice and compact; quite aesthetic.
>>
>> cheers,
>> Mike
>>
>> On Sat, Feb 13, 2010 at 11:06 AM, Stéphane Ducasse
>> <[hidden email]> wrote:
>>> Hi guys
>>>
>>> chris mueller proposed in squeak to have
>>>
>>>
>>> Exception>>messageText
>>>      "Return an exception's message text."
>>> +       ^ messageText ifNil: [ String empty ]!
>>> -
>>> -       ^messageText!
>>>
>>> - Added Array class>>#empty and String class>>#empty to provide applications with
>>> canonicalized instances of these oft-used objects; since they are embedded as literals in the
>>> CompiledMethod.
>>>
>>> =============== Diff against Collections-ar.304 ===============
>>>
>>> Item was added:
>>> + ----- Method: Array class>>empty (in category 'instance creation') -----
>>> + empty
>>> +       "A canonicalized empty Array instance."
>>> +       ^ #()!
>>>
>>> Item was added:
>>> + ----- Method: String class>>empty (in category 'instance creation') -----
>>> + empty
>>> +       "A canonicalized empty String instance."
>>> +       ^ ''!
>>>
>>> Item was removed:
>>> - ----- Method: String>>asDefaultDecodedString (in category 'converting') -----
>>> - asDefaultDecodedString
>>> -
>>> -       ^ self
>>>
>>>
>>> http://code.google.com/p/pharo/issues/detail?id=1961
>>> _______________________________________________
>>> Pharo-project mailing list
>>> [hidden email]
>>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>>
>>
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

--
Marcus Denker  -- http://www.marcusdenker.de
INRIA Lille -- Nord Europe. Team RMoD.


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: About String empty and others

Chris Muller-3
Even if you make the compiler change, I hope you will still consider
leaving the two #empty methods in place for expressiveness.  They,
too, would answer the single canonicalized global stored in the
compiler.  However, the use of #empty makes the canonicalization
explicit rather than implicit, and affords appreciation of a Pharo
system that describes itself, e.g., associating the word "empty" with
the notation that a new Pharo user might find cryptic.


On Sat, Feb 13, 2010 at 1:06 PM, Marcus Denker <[hidden email]> wrote:

>
> On Feb 13, 2010, at 8:03 PM, Stéphane Ducasse wrote:
>
>> the only think is that the #() and '' will not be created all the time but in the compile method literal frame.
>>
> Yes, right now it's created once per method... the compiler could easily make sure that it's shared globally.
>
>        Marcus
>
>
>> Stef
>>
>>
>>> would the idea to be to rewrite every #() with Array empty?
>>>
>>> If that was the case could you get the compiler to do that as an
>>> optimization? I quite like the fact that #() is the empty array. it's
>>> nice and compact; quite aesthetic.
>>>
>>> cheers,
>>> Mike
>>>
>>> On Sat, Feb 13, 2010 at 11:06 AM, Stéphane Ducasse
>>> <[hidden email]> wrote:
>>>> Hi guys
>>>>
>>>> chris mueller proposed in squeak to have
>>>>
>>>>
>>>> Exception>>messageText
>>>>      "Return an exception's message text."
>>>> +       ^ messageText ifNil: [ String empty ]!
>>>> -
>>>> -       ^messageText!
>>>>
>>>> - Added Array class>>#empty and String class>>#empty to provide applications with
>>>> canonicalized instances of these oft-used objects; since they are embedded as literals in the
>>>> CompiledMethod.
>>>>
>>>> =============== Diff against Collections-ar.304 ===============
>>>>
>>>> Item was added:
>>>> + ----- Method: Array class>>empty (in category 'instance creation') -----
>>>> + empty
>>>> +       "A canonicalized empty Array instance."
>>>> +       ^ #()!
>>>>
>>>> Item was added:
>>>> + ----- Method: String class>>empty (in category 'instance creation') -----
>>>> + empty
>>>> +       "A canonicalized empty String instance."
>>>> +       ^ ''!
>>>>
>>>> Item was removed:
>>>> - ----- Method: String>>asDefaultDecodedString (in category 'converting') -----
>>>> - asDefaultDecodedString
>>>> -
>>>> -       ^ self
>>>>
>>>>
>>>> http://code.google.com/p/pharo/issues/detail?id=1961
>>>> _______________________________________________
>>>> Pharo-project mailing list
>>>> [hidden email]
>>>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>>>
>>>
>>> _______________________________________________
>>> Pharo-project mailing list
>>> [hidden email]
>>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>
>>
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>
> --
> Marcus Denker  -- http://www.marcusdenker.de
> INRIA Lille -- Nord Europe. Team RMoD.
>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: About String empty and others

Marcus Denker-4

On Feb 16, 2010, at 8:01 PM, Chris Muller wrote:

> Even if you make the compiler change, I hope you will still consider
> leaving the two #empty methods in place for expressiveness.  They,
> too, would answer the single canonicalized global stored in the
> compiler.  However, the use of #empty makes the canonicalization
> explicit rather than implicit, and affords appreciation of a Pharo
> system that describes itself, e.g., associating the word "empty" with
> the notation that a new Pharo user might find cryptic.
>

You are right!

So we should just add the methods for now. In the end, compiling everywhere the
same #() would than be just an inlining step of a good optimizer, not special logic in the
compiler. So I vote for your methods and wait for the inliner to optimize it away ;-)

        Marcus


>
> On Sat, Feb 13, 2010 at 1:06 PM, Marcus Denker <[hidden email]> wrote:
>>
>> On Feb 13, 2010, at 8:03 PM, Stéphane Ducasse wrote:
>>
>>> the only think is that the #() and '' will not be created all the time but in the compile method literal frame.
>>>
>> Yes, right now it's created once per method... the compiler could easily make sure that it's shared globally.
>>
>>        Marcus
>>
>>
>>> Stef
>>>
>>>
>>>> would the idea to be to rewrite every #() with Array empty?
>>>>
>>>> If that was the case could you get the compiler to do that as an
>>>> optimization? I quite like the fact that #() is the empty array. it's
>>>> nice and compact; quite aesthetic.
>>>>
>>>> cheers,
>>>> Mike
>>>>
>>>> On Sat, Feb 13, 2010 at 11:06 AM, Stéphane Ducasse
>>>> <[hidden email]> wrote:
>>>>> Hi guys
>>>>>
>>>>> chris mueller proposed in squeak to have
>>>>>
>>>>>
>>>>> Exception>>messageText
>>>>>      "Return an exception's message text."
>>>>> +       ^ messageText ifNil: [ String empty ]!
>>>>> -
>>>>> -       ^messageText!
>>>>>
>>>>> - Added Array class>>#empty and String class>>#empty to provide applications with
>>>>> canonicalized instances of these oft-used objects; since they are embedded as literals in the
>>>>> CompiledMethod.
>>>>>
>>>>> =============== Diff against Collections-ar.304 ===============
>>>>>
>>>>> Item was added:
>>>>> + ----- Method: Array class>>empty (in category 'instance creation') -----
>>>>> + empty
>>>>> +       "A canonicalized empty Array instance."
>>>>> +       ^ #()!
>>>>>
>>>>> Item was added:
>>>>> + ----- Method: String class>>empty (in category 'instance creation') -----
>>>>> + empty
>>>>> +       "A canonicalized empty String instance."
>>>>> +       ^ ''!
>>>>>
>>>>> Item was removed:
>>>>> - ----- Method: String>>asDefaultDecodedString (in category 'converting') -----
>>>>> - asDefaultDecodedString
>>>>> -
>>>>> -       ^ self
>>>>>
>>>>>
>>>>> http://code.google.com/p/pharo/issues/detail?id=1961
>>>>> _______________________________________________
>>>>> Pharo-project mailing list
>>>>> [hidden email]
>>>>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>>>>
>>>>
>>>> _______________________________________________
>>>> Pharo-project mailing list
>>>> [hidden email]
>>>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>>
>>>
>>> _______________________________________________
>>> Pharo-project mailing list
>>> [hidden email]
>>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>
>> --
>> Marcus Denker  -- http://www.marcusdenker.de
>> INRIA Lille -- Nord Europe. Team RMoD.
>>
>>
>> _______________________________________________
>> Pharo-project mailing list
>> [hidden email]
>> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>>
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

--
Marcus Denker  -- http://www.marcusdenker.de
INRIA Lille -- Nord Europe. Team RMoD.


_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: About String empty and others

Stéphane Ducasse
In reply to this post by Chris Muller-3

On Feb 16, 2010, at 8:01 PM, Chris Muller wrote:

> Even if you make the compiler change, I hope you will still consider
> leaving the two #empty methods in place for expressiveness.  They,
> too, would answer the single canonicalized global stored in the
> compiler.  However, the use of #empty makes the canonicalization
> explicit rather than implicit, and affords appreciation of a Pharo
> system that describes itself, e.g., associating the word "empty" with
> the notation that a new Pharo user might find cryptic.

this changes was already integrated.

Now your argument could work if the syntax #(a b c) would disappear.
Now since you have to teach/learn #(a b c), it should be clear that #()
is an empty array. The same argument holds for '' versus String empty.
So I do not see the real gain.

Stef

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: About String empty and others

Michael Roberts-2
it is an interesting topic. I find #() more expressive than Array
empty. but perhaps this is because I have learnt to recognize it
deeply. Something i remember Michele Lanza talking about visualisation
and the types of things (size, colour, shape) that we have a primitive
recognition of
  http://www.se-radio.net/podcast/2009-03/episode-130-code-visualization-michele-lanza
and I am sure all the Moose folks are very familiar... I am not sure
if it applies in this case or not of course...

Anyway I feel that I never have to 'parse' #() but when I see Array
empty, i have to read it in my head.  So for me it might be more
expressive but it is more verbose.  I am just interested in the debate
from a syntax point of view, not an optimization point of view. I feel
there is a correlation between #() being physically small, about
5-10mm say on the screen with Array new, or String new which is at
least 5cm with a space that breaks it up. Do you see my point?

I guess I don't understand why without it, Pharo does not describe
itself.  You would only expect a single send of Array empty in the
system (from the optimzation machinery)?  If people started using it
generally, i would find that a shame for the reason described above
that it is not compact.  If all you want is the empty array defined in
a single place, I guess that is fine. but then how do you mark it
private?

cheers,
Mike

On Tue, Feb 16, 2010 at 8:57 PM, Stéphane Ducasse
<[hidden email]> wrote:

>
> On Feb 16, 2010, at 8:01 PM, Chris Muller wrote:
>
>> Even if you make the compiler change, I hope you will still consider
>> leaving the two #empty methods in place for expressiveness.  They,
>> too, would answer the single canonicalized global stored in the
>> compiler.  However, the use of #empty makes the canonicalization
>> explicit rather than implicit, and affords appreciation of a Pharo
>> system that describes itself, e.g., associating the word "empty" with
>> the notation that a new Pharo user might find cryptic.
>
> this changes was already integrated.
>
> Now your argument could work if the syntax #(a b c) would disappear.
> Now since you have to teach/learn #(a b c), it should be clear that #()
> is an empty array. The same argument holds for '' versus String empty.
> So I do not see the real gain.
>
> Stef
>
> _______________________________________________
> Pharo-project mailing list
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project