some little static analysis with great impact

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

some little static analysis with great impact

stepharo
Hi

I often end up forgetting a period.

printOn: aStream
     super printOn: aStream.
     aStream nextPutAll: ' "'
     aStream nextPutAll: contents.
     aStream nextPutAll: '" '.


And statically the system could see it with a simple heuristics:

     if the message as the same name as self, super, a tmp or an argument

May be there is a missing period.

Could the compiler get this analysis?

Stef


Reply | Threaded
Open this post in threaded view
|

Re: some little static analysis with great impact

EstebanLM
wouldn’t this be better to solve this with QA?

> On 3 Nov 2016, at 15:17, stepharo <[hidden email]> wrote:
>
> Hi
>
> I often end up forgetting a period.
>
> printOn: aStream
>    super printOn: aStream.
>    aStream nextPutAll: ' "'
>    aStream nextPutAll: contents.
>    aStream nextPutAll: '" '.
>
>
> And statically the system could see it with a simple heuristics:
>
>    if the message as the same name as self, super, a tmp or an argument
>
> May be there is a missing period.
>
> Could the compiler get this analysis?
>
> Stef
>
>


Reply | Threaded
Open this post in threaded view
|

Re: some little static analysis with great impact

Nicolai Hess-3-2
In reply to this post by stepharo


2016-11-03 15:17 GMT+01:00 stepharo <[hidden email]>:
Hi

I often end up forgetting a period.

printOn: aStream
    super printOn: aStream.
    aStream nextPutAll: ' "'
    aStream nextPutAll: contents.
    aStream nextPutAll: '" '.


And statically the system could see it with a simple heuristics:

    if the message as the same name as self, super, a tmp or an argument

May be there is a missing period.

Could the compiler get this analysis?

Stef



The highlighter gives some hints ( as in this example, message nextPutAll:nextPutAll: isn't known).
And we have the RBUncommonMessageSendRule, but this rule only checks for messagenames like "self" or "true". It does not check the variables or argument names.

 

Reply | Threaded
Open this post in threaded view
|

Re: some little static analysis with great impact

stepharo
In reply to this post by EstebanLM


Le 3/11/16 à 15:52, Esteban Lorenzano a écrit :
> wouldn’t this be better to solve this with QA?
but QA needs the analysis first.

>
>> On 3 Nov 2016, at 15:17, stepharo <[hidden email]> wrote:
>>
>> Hi
>>
>> I often end up forgetting a period.
>>
>> printOn: aStream
>>     super printOn: aStream.
>>     aStream nextPutAll: ' "'
>>     aStream nextPutAll: contents.
>>     aStream nextPutAll: '" '.
>>
>>
>> And statically the system could see it with a simple heuristics:
>>
>>     if the message as the same name as self, super, a tmp or an argument
>>
>> May be there is a missing period.
>>
>> Could the compiler get this analysis?
>>
>> Stef
>>
>>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: some little static analysis with great impact

Uko2
In reply to this post by stepharo
There is already RBUncommonMessageSendRule which checks for #(#self #super #thisContext #true #false #nil). I could also extend it to temps and args.

Uko

> On 3 Nov 2016, at 15:17, stepharo <[hidden email]> wrote:
>
> Hi
>
> I often end up forgetting a period.
>
> printOn: aStream
>    super printOn: aStream.
>    aStream nextPutAll: ' "'
>    aStream nextPutAll: contents.
>    aStream nextPutAll: '" '.
>
>
> And statically the system could see it with a simple heuristics:
>
>    if the message as the same name as self, super, a tmp or an argument
>
> May be there is a missing period.
>
> Could the compiler get this analysis?
>
> Stef
>
>


Reply | Threaded
Open this post in threaded view
|

Re: some little static analysis with great impact

Nicolas Cellier


2016-11-03 21:53 GMT+01:00 Yuriy Tymchuk <[hidden email]>:
There is already RBUncommonMessageSendRule which checks for #(#self #super #thisContext #true #false #nil). I could also extend it to temps and args.

Uko

Hi Uko,
I often write things like
    | abs |
    abs := self abs.
so I would not like the temp/args rule...

What make it obvious to our eyes is indentation in this case.
From compiler POV it's just a yet unimplemented message.
Can we have rules about indentation?
 

> On 3 Nov 2016, at 15:17, stepharo <[hidden email]> wrote:
>
> Hi
>
> I often end up forgetting a period.
>
> printOn: aStream
>    super printOn: aStream.
>    aStream nextPutAll: ' "'
>    aStream nextPutAll: contents.
>    aStream nextPutAll: '" '.
>
>
> And statically the system could see it with a simple heuristics:
>
>    if the message as the same name as self, super, a tmp or an argument
>
> May be there is a missing period.
>
> Could the compiler get this analysis?
>
> Stef
>
>



Reply | Threaded
Open this post in threaded view
|

Re: some little static analysis with great impact

Uko2
On 3 Nov 2016, at 22:05, Nicolas Cellier <[hidden email]> wrote:

Can we have rules about indentation?

Yes, we can. I think that even easier heuristic would be to check if a unary is separated from the receiver by a line break.
Reply | Threaded
Open this post in threaded view
|

Re: some little static analysis with great impact

Nicolas Cellier


2016-11-03 23:39 GMT+01:00 Yuriy Tymchuk <[hidden email]>:
On 3 Nov 2016, at 22:05, Nicolas Cellier <[hidden email]> wrote:

Can we have rules about indentation?

Yes, we can. I think that even easier heuristic would be to check if a unary is separated from the receiver by a line break.

+1, I guess such formatting is pretty unusual indeed...

Reply | Threaded
Open this post in threaded view
|

Re: some little static analysis with great impact

Denis Kudriashov
In reply to this post by Nicolas Cellier

2016-11-03 22:05 GMT+01:00 Nicolas Cellier <[hidden email]>:
Hi Uko,
I often write things like
    | abs |
    abs := self abs.
so I would not like the temp/args rule...

But for args it could be not bad
Reply | Threaded
Open this post in threaded view
|

Re: some little static analysis with great impact

Peter Uhnak
In reply to this post by stepharo
I'm always applying the autoformatting before I save the method, which helps me a lot in detecting those problems, because I immediately see that the code is formatted strangely.

But of course analysis would be nice for people that don't use autoformatting, or for better (and automated) detection.

Peter


On Thu, Nov 03, 2016 at 05:47:51PM +0100, stepharo wrote:

>
>
> Le 3/11/16 à 15:52, Esteban Lorenzano a écrit :
> >wouldn’t this be better to solve this with QA?
> but QA needs the analysis first.
> >
> >>On 3 Nov 2016, at 15:17, stepharo <[hidden email]> wrote:
> >>
> >>Hi
> >>
> >>I often end up forgetting a period.
> >>
> >>printOn: aStream
> >>    super printOn: aStream.
> >>    aStream nextPutAll: ' "'
> >>    aStream nextPutAll: contents.
> >>    aStream nextPutAll: '" '.
> >>
> >>
> >>And statically the system could see it with a simple heuristics:
> >>
> >>    if the message as the same name as self, super, a tmp or an argument
> >>
> >>May be there is a missing period.
> >>
> >>Could the compiler get this analysis?
> >>
> >>Stef
> >>
> >>
> >
> >
>
>