You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ponymail.apache.org by sebb <se...@gmail.com> on 2021/11/17 11:26:17 UTC

Javascript uses var unnecessarily

There are lots of places where the Javascript code uses var when it
should be using let (or const?)

Is there any reason to keep the var type for local variables?

I think it would make it easier to find errors if variables were
scoped as tightly as possible.
Also for const to be used where possible.

Sebb

Re: Javascript uses var unnecessarily

Posted by Daniel Gruno <hu...@apache.org>.
On 18/11/2021 12.12, sebb wrote:
> On Wed, 17 Nov 2021 at 17:47, sebb <se...@gmail.com> wrote:
>>
>> On Wed, 17 Nov 2021 at 17:20, Daniel Gruno <hu...@apache.org> wrote:
>>>
>>> On 17/11/2021 12.26, sebb wrote:
>>>> There are lots of places where the Javascript code uses var when it
>>>> should be using let (or const?)
>>>>
>>>> Is there any reason to keep the var type for local variables?
>>>>
>>>> I think it would make it easier to find errors if variables were
>>>> scoped as tightly as possible.
>>>> Also for const to be used where possible.
>>>
>>> Agreed. Most of the use of var is from a time where let and const were
>>> not as widely supported as they are now.
>>
>> OK
>>
>>> I think we should aim for following the ECMAScript 2018 spec, judging
>>> from the feature set we use, and not necessarily support older systems
>>> that do not have this minimum requirement.
>>
>> It looks like the code uses some ES 2017 features already; not sure if
>> it uses 2018 yet.
>>
>> Probably OK to require 2018, though it may cause issues for some Windows users.
>>
>> I also think we should try to use strict mode; this is likely to catch
>> more errors.
> 
> Strict mode (plus changing to let) has indeed exposed a couple of typos.
> 
> I think it would also be useful to have a naming convention for
> top-level variables (e.g. the ones now in aavariables.js)
> This would make it more obvious when editing the component parts of
> ponymail.js which vars don't need to be declared locally.
> It might also help to detect if some don't need to be top-level.
> 
> Maybe a prefix such as G_?

+1

> 
> I think that would be better than requiring a prefix for local variables.
> 
>>>>
>>>> Sebb
>>>>
>>>


Re: Javascript uses var unnecessarily

Posted by sebb <se...@gmail.com>.
On Wed, 17 Nov 2021 at 17:47, sebb <se...@gmail.com> wrote:
>
> On Wed, 17 Nov 2021 at 17:20, Daniel Gruno <hu...@apache.org> wrote:
> >
> > On 17/11/2021 12.26, sebb wrote:
> > > There are lots of places where the Javascript code uses var when it
> > > should be using let (or const?)
> > >
> > > Is there any reason to keep the var type for local variables?
> > >
> > > I think it would make it easier to find errors if variables were
> > > scoped as tightly as possible.
> > > Also for const to be used where possible.
> >
> > Agreed. Most of the use of var is from a time where let and const were
> > not as widely supported as they are now.
>
> OK
>
> > I think we should aim for following the ECMAScript 2018 spec, judging
> > from the feature set we use, and not necessarily support older systems
> > that do not have this minimum requirement.
>
> It looks like the code uses some ES 2017 features already; not sure if
> it uses 2018 yet.
>
> Probably OK to require 2018, though it may cause issues for some Windows users.
>
> I also think we should try to use strict mode; this is likely to catch
> more errors.

Strict mode (plus changing to let) has indeed exposed a couple of typos.

I think it would also be useful to have a naming convention for
top-level variables (e.g. the ones now in aavariables.js)
This would make it more obvious when editing the component parts of
ponymail.js which vars don't need to be declared locally.
It might also help to detect if some don't need to be top-level.

Maybe a prefix such as G_?

I think that would be better than requiring a prefix for local variables.

> > >
> > > Sebb
> > >
> >

Re: Javascript uses var unnecessarily

Posted by sebb <se...@gmail.com>.
On Wed, 17 Nov 2021 at 17:20, Daniel Gruno <hu...@apache.org> wrote:
>
> On 17/11/2021 12.26, sebb wrote:
> > There are lots of places where the Javascript code uses var when it
> > should be using let (or const?)
> >
> > Is there any reason to keep the var type for local variables?
> >
> > I think it would make it easier to find errors if variables were
> > scoped as tightly as possible.
> > Also for const to be used where possible.
>
> Agreed. Most of the use of var is from a time where let and const were
> not as widely supported as they are now.

OK

> I think we should aim for following the ECMAScript 2018 spec, judging
> from the feature set we use, and not necessarily support older systems
> that do not have this minimum requirement.

It looks like the code uses some ES 2017 features already; not sure if
it uses 2018 yet.

Probably OK to require 2018, though it may cause issues for some Windows users.

I also think we should try to use strict mode; this is likely to catch
more errors.

> >
> > Sebb
> >
>

Re: Javascript uses var unnecessarily

Posted by Daniel Gruno <hu...@apache.org>.
On 17/11/2021 12.26, sebb wrote:
> There are lots of places where the Javascript code uses var when it
> should be using let (or const?)
> 
> Is there any reason to keep the var type for local variables?
> 
> I think it would make it easier to find errors if variables were
> scoped as tightly as possible.
> Also for const to be used where possible.

Agreed. Most of the use of var is from a time where let and const were 
not as widely supported as they are now.

I think we should aim for following the ECMAScript 2018 spec, judging 
from the feature set we use, and not necessarily support older systems 
that do not have this minimum requirement.

> 
> Sebb
>