underlining unknown references in maps

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

underlining unknown references in maps

Andrew Eisenberg
Hi all,

I have a design question for everyone.  I am trying to find out what
is the most appropriate way of going here.

When using groovy's special map accessors:

def myMap = [:]
myMap.key = "value"
print myMap.key

This will obviously print "value" to stdout, but the static analyzer
will underline both references to "key".  In this particular case, it
wouldn't be too horrendously difficult to be able to infer that the
"key" references are valid and that they refer to a String.  But, this
is a very, very simple case.  Much more complex forms of this behavior
is used in DSLs, particularly grails in controller classes.  And it is
essentially an undecidable problem and at best it is very resource
intensive.

So, my question is this.  I can see three ways of proceeding:

1. Do nothing and keep behavior as is.  This will cause lots of
underlining when using maps.
2. Assume all map references are valid.  This will mean no
underlining, but also no notification of invalid references.
3. Do the simple analysis as above, and assume all else is invalid.
This may cause some confusion since some valid map references will be
seen as valid, but others will not.

Any thoughts or suggestions?  Any other ways to proceed?

--a

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: underlining unknown references in maps

Jean-Noël Rivasseau
I would suggest starting with 3., and keep trying improving the analysis with further development :)

It will probably be a long time before it really produces good results, but let's not assume from the very start that the task is too complex and we should just "do nothing".
I guess that for Grails DSLs, a hard coded list of valid keys could be used.

Jean-Noel

On Tue, Dec 15, 2009 at 8:34 AM, Andrew Eisenberg <[hidden email]> wrote:
Hi all,

I have a design question for everyone.  I am trying to find out what
is the most appropriate way of going here.

When using groovy's special map accessors:

def myMap = [:]
myMap.key = "value"
print myMap.key

This will obviously print "value" to stdout, but the static analyzer
will underline both references to "key".  In this particular case, it
wouldn't be too horrendously difficult to be able to infer that the
"key" references are valid and that they refer to a String.  But, this
is a very, very simple case.  Much more complex forms of this behavior
is used in DSLs, particularly grails in controller classes.  And it is
essentially an undecidable problem and at best it is very resource
intensive.

So, my question is this.  I can see three ways of proceeding:

1. Do nothing and keep behavior as is.  This will cause lots of
underlining when using maps.
2. Assume all map references are valid.  This will mean no
underlining, but also no notification of invalid references.
3. Do the simple analysis as above, and assume all else is invalid.
This may cause some confusion since some valid map references will be
seen as valid, but others will not.

Any thoughts or suggestions?  Any other ways to proceed?

--a

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email
Reply | Threaded
Open this post in threaded view
|

Re: underlining unknown references in maps

Andrew Eisenberg
On Tue, Dec 15, 2009 at 8:53 AM, Jean-Noël Rivasseau <[hidden email]> wrote:
> I would suggest starting with 3., and keep trying improving the analysis
> with further development :)

That's probably right, but in the short term, (ie- before I can get a
chance to work on this), would you prefer 1 or 2?

>
> It will probably be a long time before it really produces good results, but
> let's not assume from the very start that the task is too complex and we
> should just "do nothing".

Even #3 is not too easy.  It may not make it into 2.0, but it would be
high on the list for 2.1.

> I guess that for Grails DSLs, a hard coded list of valid keys could be used.

Unfortunately, no.  I see this most often when working with
controllers and the flash or params where the maps contain
page-specific keys that are not generalizable.  Similarly, this
happens in GSP taglibs.  Maybe there is a pattern for GSPs or some
common key names, but I am not aware of what they might be (anyone can
enlighten me)?



>
> Jean-Noel
>
> On Tue, Dec 15, 2009 at 8:34 AM, Andrew Eisenberg <[hidden email]>
> wrote:
>>
>> Hi all,
>>
>> I have a design question for everyone.  I am trying to find out what
>> is the most appropriate way of going here.
>>
>> When using groovy's special map accessors:
>>
>> def myMap = [:]
>> myMap.key = "value"
>> print myMap.key
>>
>> This will obviously print "value" to stdout, but the static analyzer
>> will underline both references to "key".  In this particular case, it
>> wouldn't be too horrendously difficult to be able to infer that the
>> "key" references are valid and that they refer to a String.  But, this
>> is a very, very simple case.  Much more complex forms of this behavior
>> is used in DSLs, particularly grails in controller classes.  And it is
>> essentially an undecidable problem and at best it is very resource
>> intensive.
>>
>> So, my question is this.  I can see three ways of proceeding:
>>
>> 1. Do nothing and keep behavior as is.  This will cause lots of
>> underlining when using maps.
>> 2. Assume all map references are valid.  This will mean no
>> underlining, but also no notification of invalid references.
>> 3. Do the simple analysis as above, and assume all else is invalid.
>> This may cause some confusion since some valid map references will be
>> seen as valid, but others will not.
>>
>> Any thoughts or suggestions?  Any other ways to proceed?
>>
>> --a
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: underlining unknown references in maps

Jean-Noël Rivasseau
Hi,

> On Tue, Dec 15, 2009 at 8:53 AM, Jean-Noël Rivasseau <[hidden email]> wrote:
>> I would suggest starting with 3., and keep trying improving the analysis
>> with further development :)
>
> That's probably right, but in the short term, (ie- before I can get a
> chance to work on this), would you prefer 1 or 2?

Like you suggested in 3: everything invalid, except for what you have analyzed and recognized, which is flagged as valid.

>> It will probably be a long time before it really produces good results, but
>> let's not assume from the very start that the task is too complex and we
>> should just "do nothing".
>
> Even #3 is not too easy.  It may not make it into 2.0, but it would be
> high on the list for 2.1.
>
>> I guess that for Grails DSLs, a hard coded list of valid keys could be used.
>
> Unfortunately, no.  I see this most often when working with
> controllers and the flash or params where the maps contain
> page-specific keys that are not generalizable.  Similarly, this
> happens in GSP taglibs.  Maybe there is a pattern for GSPs or some
> common key names, but I am not aware of what they might be (anyone can
> enlighten me)?

For this you need to consider two cases. Cases where the maps contain hardcoded keys (I cannot find of any example right
now, maybe there is none) and cases where basically you cannot predict at all which keys will be there (this happens all
the time with params, session, flash etc). For the second case you really have no way of knowing so any key should be
assumed valid, *for that particular map only*. Eg, some maps as params and session should not be checked by the
inference enfine and always assumed valid for keys.

>
>
>
>> Jean-Noel
>>
>> On Tue, Dec 15, 2009 at 8:34 AM, Andrew Eisenberg <[hidden email]>
>> wrote:
>>> Hi all,
>>>
>>> I have a design question for everyone.  I am trying to find out what
>>> is the most appropriate way of going here.
>>>
>>> When using groovy's special map accessors:
>>>
>>> def myMap = [:]
>>> myMap.key = "value"
>>> print myMap.key
>>>
>>> This will obviously print "value" to stdout, but the static analyzer
>>> will underline both references to "key".  In this particular case, it
>>> wouldn't be too horrendously difficult to be able to infer that the
>>> "key" references are valid and that they refer to a String.  But, this
>>> is a very, very simple case.  Much more complex forms of this behavior
>>> is used in DSLs, particularly grails in controller classes.  And it is
>>> essentially an undecidable problem and at best it is very resource
>>> intensive.
>>>
>>> So, my question is this.  I can see three ways of proceeding:
>>>
>>> 1. Do nothing and keep behavior as is.  This will cause lots of
>>> underlining when using maps.
>>> 2. Assume all map references are valid.  This will mean no
>>> underlining, but also no notification of invalid references.
>>> 3. Do the simple analysis as above, and assume all else is invalid.
>>> This may cause some confusion since some valid map references will be
>>> seen as valid, but others will not.
>>>
>>> Any thoughts or suggestions?  Any other ways to proceed?
>>>
>>> --a

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email