[Bloc] Do we want <return: #Point> or <return: Point>

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

Re: [Bloc] Do we want <return: #Point> or <return: Point>

Ben Coman
On Tue, Feb 23, 2016 at 8:17 PM, stepharo <[hidden email]> wrote:
> I do not think that Pharo will become a static language :)
> For the moment we can let it as a documentation.
> Now I would prefer to have tests because such annotations may be obsolete.

Maybe not if those pragmas become *active* when the unit tests are
run.  Then they might be treated like asserts without application
runtime penalty.  The benefit over unit tests for package A, would be
these asserts would be active when called from the unit tests of
package B. (??)
cheers -ben

Reply | Threaded
Open this post in threaded view
|

Re: [Bloc] Do we want <return: #Point> or <return: Point>

Eliot Miranda-2
In reply to this post by stepharo


On Tue, Feb 23, 2016 at 12:47 AM, stepharo <[hidden email]> wrote:
Hi

I saw that something <return: #Point> or <return: Point>
I do not know why but I have the impression that <return: #Point> is better.
Because we may have code not present and still want to load the code.

Given the current semantics of pragmas only <return: #Point> is valid.

_,,,^..^,,,_
best, Eliot
Reply | Threaded
Open this post in threaded view
|

Re: [Bloc] Do we want <return: #Point> or <return: Point>

Aliaksei Syrel

There is also <return: BlElement or: nil> to indicate explicitly that user must check for nil. There are only a few methods in element (#owner and some collection related methods like "find element such that") that may return nil.

Ideally syntax checker should take into account that method can return nil and indicate it somehow to user.

Annotating return values is very common nowadays in popular dynamically typed languages to help static analysis of IDE.

Annotating return values allows to instantly browse its class.

Small script can remove those annotations and asserts from code during build for production on CI server.

I don't understand why only symbols are allowed. In any console string parameter without spaces can be used directly without quotes. So for pragmas should work (and it works in latest pharo)
<return: Point>
<return: nil>
<return: #Point>
<return: 'Point'>
<return: #'Point of view'>
<return: 'Point of view'>

I had the following pragma:
<return: MyMagicClass> After renaming of MyMagicClass in nautilus it was also renamed in pragma.



On Tue, Feb 23, 2016 at 12:47 AM, stepharo <[hidden email]> wrote:
Hi

I saw that something <return: #Point> or <return: Point>
I do not know why but I have the impression that <return: #Point> is better.
Because we may have code not present and still want to load the code.

Given the current semantics of pragmas only <return: #Point> is valid.

_,,,^..^,,,_
best, Eliot
Reply | Threaded
Open this post in threaded view
|

Re: [Bloc] Do we want <return: #Point> or <return: Point>

Clément Béra
In reply to this post by Ben Coman


2016-02-23 12:00 GMT+01:00 Ben Coman <[hidden email]>:
On Tue, Feb 23, 2016 at 5:33 PM, Tudor Girba <[hidden email]> wrote:
> Hi,
>
> At the moment, it is used for documentation purposes in Bloc. It is part of the effort of Alex to document Bloc thoroughly. I think it is an interesting idea, in that we would have a significant case study for that can be used later as optional types information to improve static tool support. And it does not hurt at the moment.
>
> What do you think?

I have often wonder what a system would be like if you *only* typed
the return values of selectors, defined globally so each selector has
just *one* return type (but it wouldn't a particular object, more a
method-set-fingerprint, you might be able to statically check that the
each message in a chain would be understood - but I never think deep
enough on it to understand the benefit/cost of it.

It feels it does not really work well as for example #at: is used in many places, and on Array the return type is Object whereas on ByteArray it is SmallInteger. Other frequent messages have the same problems (#add:, #+ etc) and they are the most used.

Usually for partial typing, one types only:
- return type of methods/closures
- parameters of methods/closures
- instance variables

Hack (optionally typed PHP by Facebook) is done like that, one can type only these 3 aspects and all the types are fully optional. Reportedly it is very good.

If one follows the microsoft guidelines to develop in C#, one also types these 3 aspects only. Although in the case of C# those 3 aspects have to be typed, they can't remain untyped as in Hack, and even if it's optional, typing is available for the rest of the code.

That implies that according to development guidelines, no temporary variables or literal variables are typed in both languages.

Typed people are not confused, as the IDE infers for them the type of any variable they mouse over. Untyped people have little constraints compared to typing everything.

The Hack direction is probably the direction to go to introduce types in Pharo like the Hack guys did for PHP. Untyped people can keep typing nothing, while typed people still have all the information they need. With a setting to display or not the type annotations in the source code in the core libraries, everyone is happy.


cheers -ben

>
> Cheers,
> Doru
>
>
>> On Feb 23, 2016, at 10:25 AM, Alain Plantec via Pharo-dev <[hidden email]> wrote:
>>
>>
>> From: Alain Plantec <[hidden email]>
>> Subject: Re: [Pharo-dev] [Bloc] Do we want <return: #Point> or <return: Point>
>> Date: February 23, 2016 at 10:23:33 AM GMT+1
>> To: Pharo Development List <[hidden email]>
>>
>>
>> I don’t like it too.
>> Alain
>>
>>> Le 23 févr. 2016 à 09:50, Nicolai Hess <[hidden email]> a écrit :
>>>
>>>
>>>
>>> 2016-02-23 9:47 GMT+01:00 stepharo <[hidden email]>:
>>> Hi
>>>
>>> I saw that something <return: #Point> or <return: Point>
>>> I do not know why but I have the impression that <return: #Point> is better.
>>> Because we may have code not present and still want to load the code.
>>>
>>> I would like to know for what this is used.
>>> I don't like it.
>>>
>>>
>>> Stef
>>>
>>>
>>
>>
>>
>
> --
> www.tudorgirba.com
> www.feenk.com
>
> "We are all great at making mistakes."
>
>
>
>
>
>
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: [Bloc] Do we want <return: #Point> or <return: Point>

Clément Béra
In reply to this post by Eliot Miranda-2


2016-02-23 18:03 GMT+01:00 Eliot Miranda <[hidden email]>:


On Tue, Feb 23, 2016 at 12:47 AM, stepharo <[hidden email]> wrote:
Hi

I saw that something <return: #Point> or <return: Point>
I do not know why but I have the impression that <return: #Point> is better.
Because we may have code not present and still want to load the code.

Given the current semantics of pragmas only <return: #Point> is valid.

Well, yes...

In fact, Opal compiles <return: Point> as <return: #Point>. It does not change the semantics.

I think the real question is: "Do we allow, in the specific case of pragma, symbols to by written without the # ?"

We already allow "[ nil ]" to be written as "[ ]", and the "^self" at the end of each method to be omitted. We could have more specific cases so it won't be too trivial for unaware people to understand the semantics.

We can already see that the syntax colorer is not aware of this specific case, so it colors Point in <return: Point> as a Literal Variable instead of a symbol, which leaded many people here to confusion.

About renaming...

When renaming a class, it checks all the symbol references too, so, assuming you have a class Banana and the following code:

Coconut >> getSomething
    <return: Banana>
    <return: #Banana>
    Banana new.
    ^ #Banana

When we rename the class Banana to Cauliflower, the method is automatically changed to:

Coconut >> getSomething
    <return: #Cauliflower>
    <return: #Cauliflower>
    Cauliflower new.
    ^ #Cauliflower

Again, in this case, as for syntax coloring, the system is not aware that it should rename <return: Banana> to <return: Cauliflower> and not <return: #Cauliflower>, so as it uses standard symbol terminology




_,,,^..^,,,_
best, Eliot

Reply | Threaded
Open this post in threaded view
|

Re: [Bloc] Do we want <return: #Point> or <return: Point>

Nicolai Hess-3-2


2016-02-25 15:25 GMT+01:00 Clément Bera <[hidden email]>:


2016-02-23 18:03 GMT+01:00 Eliot Miranda <[hidden email]>:


On Tue, Feb 23, 2016 at 12:47 AM, stepharo <[hidden email]> wrote:
Hi

I saw that something <return: #Point> or <return: Point>
I do not know why but I have the impression that <return: #Point> is better.
Because we may have code not present and still want to load the code.

Given the current semantics of pragmas only <return: #Point> is valid.

Well, yes...

In fact, Opal compiles <return: Point> as <return: #Point>. It does not change the semantics.

I think the real question is: "Do we allow, in the specific case of pragma, symbols to by written without the # ?"

I am about to change this (with the exception for <primitive:...error:>)
17696 RBParser should not allow variable names for pragma arguments

 

We already allow "[ nil ]" to be written as "[ ]", and the "^self" at the end of each method to be omitted. We could have more specific cases so it won't be too trivial for unaware people to understand the semantics.

We can already see that the syntax colorer is not aware of this specific case, so it colors Point in <return: Point> as a Literal Variable instead of a symbol, which leaded many people here to confusion.

About renaming...

When renaming a class, it checks all the symbol references too, so, assuming you have a class Banana and the following code:

Coconut >> getSomething
    <return: Banana>
    <return: #Banana>
    Banana new.
    ^ #Banana

When we rename the class Banana to Cauliflower, the method is automatically changed to:

Coconut >> getSomething
    <return: #Cauliflower>
    <return: #Cauliflower>
    Cauliflower new.
    ^ #Cauliflower

Again, in this case, as for syntax coloring, the system is not aware that it should rename <return: Banana> to <return: Cauliflower> and not <return: #Cauliflower>, so as it uses standard symbol terminology




_,,,^..^,,,_
best, Eliot


12