Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread guest271314
> I’m not sure I understand what you mean by “false-positive” in this
instance.

Was referring to

const x = nameof y; // "y"
const y = 1;


Where ```y``` is ```undefined``` an error is not expected to be thrown? Is
```y``` declared globally, using ```const``` or ```let```, or not at all?
The use case  described by OP


function func1(param1, param2, param3, userName, param4, param5) {
   if (userName == undefined) {
   throw new ArgumentNullError(nameof userName); // `ArgumentNullError`
is a custom error, derived from `Error`, composes error message like
"Argument cannot be null: userName".
   }

checks if ```userName``` was ```undefined``` before using ```nameof```.  If
error checking is a substantial portion of the proposal, why should an
error (```y``` being ```undefined``` though referenced) be ignored when
referencing an undefined identifier though concentrate on coercing a name
from a different potentially undefined property?


Consider this case:
> ```
> const someObject = { value: 1 };
> function setValue(value /*1*/) {
>   if (typeof value /*2*/ !== "number") throw new TypeError(`Number
> expected: ${nameof value /*3*/}`);
>   someObject["value" /*4*/] = value /*5*/;
> }
> ```

If you rename the parameter `value` of the function `setValue` in an editor
> with a rename refactoring, you want to rename the symbols at 1, 2, 3, and
> 5, but not the string at 4.


Not gathering the purpose or value of ```nameof``` usage in that case. If
the value is not a "number" then why does the value or name matter?

Since the primary use case appears to be an editor environment, why cannot
the editor be programmed to recognize the custom JavaScript ```nameof
function or operator? Then it would not matter if this board concurred with
the ```nameof``` functionality or not. Both CLI and GUI editors (and
JavaScript) are generally extensible. FWIW, some time ago incorporated
features into gedit for HTML templates; should be a similar process to
create custom scripts for the various editor environments where users rely
on such programs for code composition; now simply write the code by hand
and test in different environments, without taking the time to customize or
rely on an editor - take the time to test the code where the code will
actually be run where errors, if any, can be evaluated in the context in
which a specific output is expected. To each their own. What needs to be
implemented outside of what the users which advocate for ```nameof```
cannot implement themselves?

As mentioned earlier do not rely on "an editor with name refactoring" to
compose code. The code has to be tested (outside of the editor
environments) anyway. Test the code itself, here, not the editor.

On Fri, Jun 14, 2019 at 9:49 PM Ron Buckton 
wrote:

> I’m not sure I understand what you mean by “false-positive” in this
> instance.
>
>
>
> Consider this case:
>
>
>
> ```
>
> const someObject = { value: 1 };
>
> function setValue(value /*1*/) {
>
>   if (typeof value /*2*/ !== "number") throw new TypeError(`Number
> expected: ${nameof value /*3*/}`);
>
>   someObject["value" /*4*/] = value /*5*/;
> }
>
> ```
>
>
>
> If you rename the parameter `value` of the function `setValue` in an
> editor with a rename refactoring, you want to rename the symbols at 1, 2,
> 3, and 5, but not the string at 4.
>
>
>
> Ron
>
>
>
> *From:* guest271314 
> *Sent:* Friday, June 14, 2019 2:43 PM
> *To:* Ron Buckton 
> *Cc:* es-discuss@mozilla.org
> *Subject:* Re: Re: What do you think about a C# 6 like nameof()
> expression for
>
>
>
> How is that behaviour related to the use cases presented by OP? Would such
> behaviour not lead to false-positive relevant to the 2 use cases?
>
>
>
> On Fri, Jun 14, 2019 at 9:36 PM Ron Buckton 
> wrote:
>
> > `nameof whatever` → `Object.keys({ whatever })[0]`, but I'm a bit
> confused why it'd be better to type `nameof foo` in code, rather than
> `'foo'` - if you change `foo` to `bar`, you have to change both of them
> anyways.
>
>
>
> If you are using an editor that supports rename refactoring, its generally
> easier to rename the symbol `foo` and have all references (including
> `nameof foo`) be updated. You cannot safely automatically rename `'foo'` to
> `'bar'` since an editor or language service cannot guarantee that by the
> string `'foo'` you meant “the text of the identifier `foo`”.
>
>
>
> *From:* es-discuss  *On Behalf Of *Jordan
> Harband
> *Sent:* Friday, June 14, 2019 2:29 PM
> *To:* guest271314 
> *Cc:* es-discuss 
> *Subject:* Re: Re: What do you think about a C# 6 like nameof()
> expression for
>
>
>
> `nameof whatever` → `Object.keys({ whatever })[0]`, but I'm a bit confused
> why it'd be better to type `nameof foo` in code, rather than `'foo'` - if
> you change `foo` to `bar`, you have to change both of them anyways.
>
>
>
> On Fri, Jun 14, 2019 at 1:31 PM guest271314  wrote:
>
> Am neither for nor against the proposal. Do not entertain "like"s or
> "dislike"s in any field of endeavor. Am certainly not in a 

RE: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Ron Buckton
I’m not sure I understand what you mean by “false-positive” in this instance.

Consider this case:

```
const someObject = { value: 1 };
function setValue(value /*1*/) {
  if (typeof value /*2*/ !== "number") throw new TypeError(`Number expected: 
${nameof value /*3*/}`);
  someObject["value" /*4*/] = value /*5*/;
}
```

If you rename the parameter `value` of the function `setValue` in an editor 
with a rename refactoring, you want to rename the symbols at 1, 2, 3, and 5, 
but not the string at 4.

Ron

From: guest271314 
Sent: Friday, June 14, 2019 2:43 PM
To: Ron Buckton 
Cc: es-discuss@mozilla.org
Subject: Re: Re: What do you think about a C# 6 like nameof() expression for

How is that behaviour related to the use cases presented by OP? Would such 
behaviour not lead to false-positive relevant to the 2 use cases?

On Fri, Jun 14, 2019 at 9:36 PM Ron Buckton 
mailto:ron.buck...@microsoft.com>> wrote:
> `nameof whatever` → `Object.keys({ whatever })[0]`, but I'm a bit confused 
> why it'd be better to type `nameof foo` in code, rather than `'foo'` - if you 
> change `foo` to `bar`, you have to change both of them anyways.

If you are using an editor that supports rename refactoring, its generally 
easier to rename the symbol `foo` and have all references (including `nameof 
foo`) be updated. You cannot safely automatically rename `'foo'` to `'bar'` 
since an editor or language service cannot guarantee that by the string `'foo'` 
you meant “the text of the identifier `foo`”.

From: es-discuss 
mailto:es-discuss-boun...@mozilla.org>> On 
Behalf Of Jordan Harband
Sent: Friday, June 14, 2019 2:29 PM
To: guest271314 mailto:guest271...@gmail.com>>
Cc: es-discuss mailto:es-discuss@mozilla.org>>
Subject: Re: Re: What do you think about a C# 6 like nameof() expression for

`nameof whatever` → `Object.keys({ whatever })[0]`, but I'm a bit confused why 
it'd be better to type `nameof foo` in code, rather than `'foo'` - if you 
change `foo` to `bar`, you have to change both of them anyways.

On Fri, Jun 14, 2019 at 1:31 PM guest271314 
mailto:guest271...@gmail.com>> wrote:
Am neither for nor against the proposal. Do not entertain "like"s or "dislike"s 
in any field of endeavor. Am certainly not in a position to prohibit anything 
relevant JavaScript. Do what thou wilt shall be the whole of the Law.

Have yet to view a case where code will be "broken" by ```nameof``` not being a 
JavaScript feature. "robustness", as already mentioned, is a subjective 
adjective that is not capable of being objectively evaluated as to code itself. 
That description is based on preference or choice.

In lieu of the proposal being specificed, use the posted code example of 
```Object.keys()``` that "works".

```
function func1({userName = void 0} = {}) {
  console.assert(userName !== undefined, [{userName}, 'property needs to be 
defined'])
}
```

provides a direct indication that the property value is required to be defined. 
Note that the example code posted thus far does not first check if 
```options``` is passed at all, for which ```nameof``` will not provide any 
asssitance.

Usually try to meet requirement by means already available in FOSS browsers. 
Have no interest in TypeScript or using an IDE.

FWIW, have no objection to the proposal.

On Fri, Jun 14, 2019 at 7:53 PM Stas Berkov 
mailto:stas.ber...@gmail.com>> wrote:
guest271314, what is you point against `nameof` feature?

If you don't like it - don't use it. Why prohibit this feature for
those who find it beneficial?

I see `nameof` beneficial in following cases

Case 1. Function guard.
```
function func1(options) {
...
   if (options.userName == undefined) {
   throw new ParamNullError(nameof options.userName); //
`ParamNullError` is a custom error, derived from `Error`, composes
error message like "Parameter cannot be null: userName".
 // `Object.keys({options.userName})[0]` will not work here
   }
}
```

Case 2. Accessing property extended info
Those ES functions that accept field name as string.
e.g.
```
const descriptor1 = Object.getOwnPropertyDescriptor(object1, 'property1');
```
vs
```
const descriptor1 = Object.getOwnPropertyDescriptor(object1, nameof
object1.property1);
 // `Object.keys({options1.property1})[0]` will not work here
```
2nd variant (proposed) has more chances not to be broken during
refactoring (robustness).

It would make devs who use IDE more productive and make their life
easier. Why not give them such possiblity and make them happy?
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Augusto Moura
Fri, 14 jun 2019 - 18:29, Jordan Harband  wrote:
>
> `nameof whatever` → `Object.keys({ whatever })[0]`, but I'm a bit confused 
> why it'd be better to type `nameof foo` in code, rather than `'foo'` - if you 
> change `foo` to `bar`, you have to change both of them anyways.
>

Exactly, if you already have the name of the property beforehand in
design time why not write it as a string literal

Again, the only justifiable use case is refactoring tools, but even
today that can be arranged with static code analysis

You can safe guard a string literal to be a property of a type in
Typescript with a bit of handwork
``` ts
interface Options {
  userName?: string;
}

// If you change the property in the interface without changing here, Typescript
// will raise a error informing that 'userName' is not a valid key of Options
const userNameKey: keyof Options = 'userName';

if (options.userName === undefined) {
  throw new ParamNullError(userNameKey);
}
```

-- 
Atenciosamente,

Augusto Borges de Moura
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread guest271314
How is that behaviour related to the use cases presented by OP? Would such
behaviour not lead to false-positive relevant to the 2 use cases?

On Fri, Jun 14, 2019 at 9:36 PM Ron Buckton 
wrote:

> > `nameof whatever` → `Object.keys({ whatever })[0]`, but I'm a bit
> confused why it'd be better to type `nameof foo` in code, rather than
> `'foo'` - if you change `foo` to `bar`, you have to change both of them
> anyways.
>
>
>
> If you are using an editor that supports rename refactoring, its generally
> easier to rename the symbol `foo` and have all references (including
> `nameof foo`) be updated. You cannot safely automatically rename `'foo'` to
> `'bar'` since an editor or language service cannot guarantee that by the
> string `'foo'` you meant “the text of the identifier `foo`”.
>
>
>
> *From:* es-discuss  * On Behalf Of *Jordan
> Harband
> *Sent:* Friday, June 14, 2019 2:29 PM
> *To:* guest271314 
> *Cc:* es-discuss 
> *Subject:* Re: Re: What do you think about a C# 6 like nameof()
> expression for
>
>
>
> `nameof whatever` → `Object.keys({ whatever })[0]`, but I'm a bit confused
> why it'd be better to type `nameof foo` in code, rather than `'foo'` - if
> you change `foo` to `bar`, you have to change both of them anyways.
>
>
>
> On Fri, Jun 14, 2019 at 1:31 PM guest271314  wrote:
>
> Am neither for nor against the proposal. Do not entertain "like"s or
> "dislike"s in any field of endeavor. Am certainly not in a position to
> prohibit anything relevant JavaScript. Do what thou wilt shall be the whole
> of the Law.
>
> Have yet to view a case where code will be "broken" by ```nameof``` not
> being a JavaScript feature. "robustness", as already mentioned, is a
> subjective adjective that is not capable of being objectively evaluated as
> to code itself. That description is based on preference or choice.
>
>
>
> In lieu of the proposal being specificed, use the posted code example of
> ```Object.keys()``` that "works".
>
>
>
> ```
>
> function func1({userName = void 0} = {}) {
>   console.assert(userName !== undefined, [{userName}, 'property needs to
> be defined'])
> }
>
> ```
>
>
>
> provides a direct indication that the property value is required to be
> defined. Note that the example code posted thus far does not first check if
> ```options``` is passed at all, for which ```nameof``` will not provide any
> asssitance.
>
>
>
> Usually try to meet requirement by means already available in FOSS
> browsers. Have no interest in TypeScript or using an IDE.
>
>
>
> FWIW, have no objection to the proposal.
>
>
>
> On Fri, Jun 14, 2019 at 7:53 PM Stas Berkov  wrote:
>
> guest271314, what is you point against `nameof` feature?
>
> If you don't like it - don't use it. Why prohibit this feature for
> those who find it beneficial?
>
> I see `nameof` beneficial in following cases
>
> Case 1. Function guard.
> ```
> function func1(options) {
> ...
>if (options.userName == undefined) {
>throw new ParamNullError(nameof options.userName); //
> `ParamNullError` is a custom error, derived from `Error`, composes
> error message like "Parameter cannot be null: userName".
>  // `Object.keys({options.userName})[0]` will not work here
>}
> }
> ```
>
> Case 2. Accessing property extended info
> Those ES functions that accept field name as string.
> e.g.
> ```
> const descriptor1 = Object.getOwnPropertyDescriptor(object1, 'property1');
> ```
> vs
> ```
> const descriptor1 = Object.getOwnPropertyDescriptor(object1, nameof
> object1.property1);
>  // `Object.keys({options1.property1})[0]` will not work here
> ```
> 2nd variant (proposed) has more chances not to be broken during
> refactoring (robustness).
>
> It would make devs who use IDE more productive and make their life
> easier. Why not give them such possiblity and make them happy?
>
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
> 
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


RE: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Ron Buckton
> `nameof whatever` → `Object.keys({ whatever })[0]`, but I'm a bit confused 
> why it'd be better to type `nameof foo` in code, rather than `'foo'` - if you 
> change `foo` to `bar`, you have to change both of them anyways.

If you are using an editor that supports rename refactoring, its generally 
easier to rename the symbol `foo` and have all references (including `nameof 
foo`) be updated. You cannot safely automatically rename `'foo'` to `'bar'` 
since an editor or language service cannot guarantee that by the string `'foo'` 
you meant “the text of the identifier `foo`”.

From: es-discuss  On Behalf Of Jordan Harband
Sent: Friday, June 14, 2019 2:29 PM
To: guest271314 
Cc: es-discuss 
Subject: Re: Re: What do you think about a C# 6 like nameof() expression for

`nameof whatever` → `Object.keys({ whatever })[0]`, but I'm a bit confused why 
it'd be better to type `nameof foo` in code, rather than `'foo'` - if you 
change `foo` to `bar`, you have to change both of them anyways.

On Fri, Jun 14, 2019 at 1:31 PM guest271314 
mailto:guest271...@gmail.com>> wrote:
Am neither for nor against the proposal. Do not entertain "like"s or "dislike"s 
in any field of endeavor. Am certainly not in a position to prohibit anything 
relevant JavaScript. Do what thou wilt shall be the whole of the Law.

Have yet to view a case where code will be "broken" by ```nameof``` not being a 
JavaScript feature. "robustness", as already mentioned, is a subjective 
adjective that is not capable of being objectively evaluated as to code itself. 
That description is based on preference or choice.

In lieu of the proposal being specificed, use the posted code example of 
```Object.keys()``` that "works".

```
function func1({userName = void 0} = {}) {
  console.assert(userName !== undefined, [{userName}, 'property needs to be 
defined'])
}
```

provides a direct indication that the property value is required to be defined. 
Note that the example code posted thus far does not first check if 
```options``` is passed at all, for which ```nameof``` will not provide any 
asssitance.

Usually try to meet requirement by means already available in FOSS browsers. 
Have no interest in TypeScript or using an IDE.

FWIW, have no objection to the proposal.

On Fri, Jun 14, 2019 at 7:53 PM Stas Berkov 
mailto:stas.ber...@gmail.com>> wrote:
guest271314, what is you point against `nameof` feature?

If you don't like it - don't use it. Why prohibit this feature for
those who find it beneficial?

I see `nameof` beneficial in following cases

Case 1. Function guard.
```
function func1(options) {
...
   if (options.userName == undefined) {
   throw new ParamNullError(nameof options.userName); //
`ParamNullError` is a custom error, derived from `Error`, composes
error message like "Parameter cannot be null: userName".
 // `Object.keys({options.userName})[0]` will not work here
   }
}
```

Case 2. Accessing property extended info
Those ES functions that accept field name as string.
e.g.
```
const descriptor1 = Object.getOwnPropertyDescriptor(object1, 'property1');
```
vs
```
const descriptor1 = Object.getOwnPropertyDescriptor(object1, nameof
object1.property1);
 // `Object.keys({options1.property1})[0]` will not work here
```
2nd variant (proposed) has more chances not to be broken during
refactoring (robustness).

It would make devs who use IDE more productive and make their life
easier. Why not give them such possiblity and make them happy?
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Jordan Harband
`nameof whatever` → `Object.keys({ whatever })[0]`, but I'm a bit confused
why it'd be better to type `nameof foo` in code, rather than `'foo'` - if
you change `foo` to `bar`, you have to change both of them anyways.

On Fri, Jun 14, 2019 at 1:31 PM guest271314  wrote:

> Am neither for nor against the proposal. Do not entertain "like"s or
> "dislike"s in any field of endeavor. Am certainly not in a position to
> prohibit anything relevant JavaScript. Do what thou wilt shall be the whole
> of the Law.
>
> Have yet to view a case where code will be "broken" by ```nameof``` not
> being a JavaScript feature. "robustness", as already mentioned, is a
> subjective adjective that is not capable of being objectively evaluated as
> to code itself. That description is based on preference or choice.
>
> In lieu of the proposal being specificed, use the posted code example of
> ```Object.keys()``` that "works".
>
> ```
> function func1({userName = void 0} = {}) {
>   console.assert(userName !== undefined, [{userName}, 'property needs to
> be defined'])
> }
> ```
>
> provides a direct indication that the property value is required to be
> defined. Note that the example code posted thus far does not first check if
> ```options``` is passed at all, for which ```nameof``` will not provide any
> asssitance.
>
> Usually try to meet requirement by means already available in FOSS
> browsers. Have no interest in TypeScript or using an IDE.
>
> FWIW, have no objection to the proposal.
>
> On Fri, Jun 14, 2019 at 7:53 PM Stas Berkov  wrote:
>
>> guest271314, what is you point against `nameof` feature?
>>
>> If you don't like it - don't use it. Why prohibit this feature for
>> those who find it beneficial?
>>
>> I see `nameof` beneficial in following cases
>>
>> Case 1. Function guard.
>> ```
>> function func1(options) {
>> ...
>>if (options.userName == undefined) {
>>throw new ParamNullError(nameof options.userName); //
>> `ParamNullError` is a custom error, derived from `Error`, composes
>> error message like "Parameter cannot be null: userName".
>>  // `Object.keys({options.userName})[0]` will not work here
>>}
>> }
>> ```
>>
>> Case 2. Accessing property extended info
>> Those ES functions that accept field name as string.
>> e.g.
>> ```
>> const descriptor1 = Object.getOwnPropertyDescriptor(object1, 'property1');
>> ```
>> vs
>> ```
>> const descriptor1 = Object.getOwnPropertyDescriptor(object1, nameof
>> object1.property1);
>>  // `Object.keys({options1.property1})[0]` will not work here
>> ```
>> 2nd variant (proposed) has more chances not to be broken during
>> refactoring (robustness).
>>
>> It would make devs who use IDE more productive and make their life
>> easier. Why not give them such possiblity and make them happy?
>>
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


RE: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Ron Buckton


> Interesting. ```y``` would be able to be evaluated before ```y``` is defined?
I very explicitly stated that `nameof y` would *not* evaluate its operand. 
Evaluation of `nameof` would merely result in a string containing the name of 
the binding referenced by the operand.

From: es-discuss  On Behalf Of guest271314
Sent: Friday, June 14, 2019 12:09 PM
To: Stas Berkov 
Cc: es-discuss@mozilla.org
Subject: Re: Re: What do you think about a C# 6 like nameof() expression for

> A module namespace isn’t an instance of Module, it’s a module namespace spec 
> object. If it has a name member, that is because the module you imported has 
> an exported binding called name. But what kind of thing it is isn’t what 
> matters.

If ```Object.getOwnPropertyDescriptors(ns)``` is used within 

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread guest271314
Am neither for nor against the proposal. Do not entertain "like"s or
"dislike"s in any field of endeavor. Am certainly not in a position to
prohibit anything relevant JavaScript. Do what thou wilt shall be the whole
of the Law.

Have yet to view a case where code will be "broken" by ```nameof``` not
being a JavaScript feature. "robustness", as already mentioned, is a
subjective adjective that is not capable of being objectively evaluated as
to code itself. That description is based on preference or choice.

In lieu of the proposal being specificed, use the posted code example of
```Object.keys()``` that "works".

```
function func1({userName = void 0} = {}) {
  console.assert(userName !== undefined, [{userName}, 'property needs to be
defined'])
}
```

provides a direct indication that the property value is required to be
defined. Note that the example code posted thus far does not first check if
```options``` is passed at all, for which ```nameof``` will not provide any
asssitance.

Usually try to meet requirement by means already available in FOSS
browsers. Have no interest in TypeScript or using an IDE.

FWIW, have no objection to the proposal.

On Fri, Jun 14, 2019 at 7:53 PM Stas Berkov  wrote:

> guest271314, what is you point against `nameof` feature?
>
> If you don't like it - don't use it. Why prohibit this feature for
> those who find it beneficial?
>
> I see `nameof` beneficial in following cases
>
> Case 1. Function guard.
> ```
> function func1(options) {
> ...
>if (options.userName == undefined) {
>throw new ParamNullError(nameof options.userName); //
> `ParamNullError` is a custom error, derived from `Error`, composes
> error message like "Parameter cannot be null: userName".
>  // `Object.keys({options.userName})[0]` will not work here
>}
> }
> ```
>
> Case 2. Accessing property extended info
> Those ES functions that accept field name as string.
> e.g.
> ```
> const descriptor1 = Object.getOwnPropertyDescriptor(object1, 'property1');
> ```
> vs
> ```
> const descriptor1 = Object.getOwnPropertyDescriptor(object1, nameof
> object1.property1);
>  // `Object.keys({options1.property1})[0]` will not work here
> ```
> 2nd variant (proposed) has more chances not to be broken during
> refactoring (robustness).
>
> It would make devs who use IDE more productive and make their life
> easier. Why not give them such possiblity and make them happy?
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Stas Berkov
guest271314, what is you point against `nameof` feature?

If you don't like it - don't use it. Why prohibit this feature for
those who find it beneficial?

I see `nameof` beneficial in following cases

Case 1. Function guard.
```
function func1(options) {
...
   if (options.userName == undefined) {
   throw new ParamNullError(nameof options.userName); //
`ParamNullError` is a custom error, derived from `Error`, composes
error message like "Parameter cannot be null: userName".
 // `Object.keys({options.userName})[0]` will not work here
   }
}
```

Case 2. Accessing property extended info
Those ES functions that accept field name as string.
e.g.
```
const descriptor1 = Object.getOwnPropertyDescriptor(object1, 'property1');
```
vs
```
const descriptor1 = Object.getOwnPropertyDescriptor(object1, nameof
object1.property1);
 // `Object.keys({options1.property1})[0]` will not work here
```
2nd variant (proposed) has more chances not to be broken during
refactoring (robustness).

It would make devs who use IDE more productive and make their life
easier. Why not give them such possiblity and make them happy?
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread guest271314
> A module namespace isn’t an instance of Module, it’s a module namespace
spec object. If it has a name member, that is because the module you
imported has an exported binding called name. But what kind of thing it is
isn’t what matters.

If ```Object.getOwnPropertyDescriptors(ns)``` is used within 

RE: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Ron Buckton
Since `nameof` does not actually evaluate anything, the following would be 
legal:

```
const x = nameof y; // "y"
const y = 1;
```

However, the shorthand property name workaround is not legal due to TDZ:

```
const x = Object.keys({y})[0]; // error due to TDZ
const y = 1;
```

With the shortand property name workaround you also run into the added runtime 
overhead of:

  *   Constructing an object (`{y}`)
  *   Looking up a property (`Object.keys`)
  *   Calling a function (`Object.keys`)
  *   Allocating an array
  *   Indexing into the array

Whereas `nameof` has *no* runtime overhead, because it would be handled during 
static semantics.


From: es-discuss  On Behalf Of guest271314
Sent: Friday, June 14, 2019 11:17 AM
To: Stas Berkov 
Cc: es-discuss@mozilla.org
Subject: Re: Re: What do you think about a C# 6 like nameof() expression for

Terms such as "more robust", "Less fragile." , "Less mess." are subjective. 
"Fragile" how? What is meant by "mess"?

If the proposal is that ```nameof``` is briefer than using shorthand property 
names or computed property names to get an identifier as a string, then 
```nameof``` would be less code.

> You can rename field/property without fear you break something (using IDE 
> refactoring tools).

The use case appears to be within the context of an IDE?

For users that roll their own code by hand at a text editor and do not use an 
IDE for composing code (or relying on an IDE for logging errors), am not able 
to discern how ```nameof``` is different than using 
```Object.getOwnPropertyDescriptors(other).name.value``` or 
```Object.keys({userName})[0]```. The actual code will need to be tested in 
different browsers anyway before deployment to get the actual results.

If a user has decided they _have_ to use some form of a dynamic "IDE" to 
compose code and log errors - while they are writing the code, they can open 
DevTools at Chromium or Chrome then select ```Sources``` => ```Snippets``` => 
```New snippet```, where

```
const n = 123;
const n = 456;
```

will highlight the line where the error occurs - during writing the code - the 
as a red circle with a transparent "x" in the middle

```Uncaught SyntaxError: Identifier 'n' has already been declared

To run the code press ```ctrl+enter```.




On Fri, Jun 14, 2019 at 5:48 PM Stas Berkov 
mailto:stas.ber...@gmail.com>> wrote:
Less fragile. Less mess. You can rename field/property without fear you break 
something (using IDE refactoring tools).
With high probablity you will break something when you refactor and have fields 
hardcoded as strings.
Someone can object that you can rename strings as well.
Issue here that you can ocassionally change non-related strings that should not 
be changed even they match or have matching substring.

On Fri, Jun 14, 2019 at 9:38 PM guest271314 
mailto:guest271...@gmail.com>> wrote:
Is Case 1 equivalent to a briefer version of

```
   if (userName == undefined) {
   throw new Error(`Argument cannot be null: 
${Object.keys({userName})[0]}`);
   }
```

?

If not, how is ```nameof``` different?

What is the difference between the use of 
```message.hasOwnProperty(property)``` and ```nameof msg.expiration_utc_time```?

> You get more robust code.

How is "robust" objectively determined?




On Fri, Jun 14, 2019 at 5:21 PM Stas Berkov 
mailto:stas.ber...@gmail.com>> wrote:
ES can befit from `nameof` feature the same way as TS. There is no TS specific 
in it.
It was ask to introduce in TS as a workaround since TS is considered as 
extention of ES.

Case 1. Function guard.
```
function func1(param1, param2, param3, userName, param4, param5) {
   if (userName == undefined) {
   throw new ArgumentNullError(nameof userName); // `ArgumentNullError` is 
a custom error, derived from `Error`, composes error message like "Argument 
cannot be null: userName".
   }
}
```

Case 2. Access extended information an object property.
Assume a function
```
function protoPropertyIsSet(message, property) {
return message != null && message.hasOwnProperty(property);
}
```
Then in code you use it as `if (protoPropertyIsSet(msg, "expiration_utc_time")) 
{... }`.
Having `nameof` would allow you to do that `if (protoPropertyIsSet(msg, nameof 
msg.expiration_utc_time)) {... }`.
You get more robust code.

On Fri, Jun 14, 2019 at 5:46 PM Augusto Moura 
mailto:augusto.borg...@gmail.com>> wrote:
Can you list the benefits of having this operators? Maybe with example use cases

If I understand it correctly, the operator fits better in compiled
(and typed) languages, most of the use cases don't apply to dynamic
Javascript
The only legit use case I can think of is helping refactor tools to
rename properties (but even mismatch errors between strings and
properties names can be caught in compile time using modern
Typescript)

Em sex, 14 de jun de 2019 às 10:05, Stas Berkov
mailto:stas.ber...@gmail.com>> escreveu:
>
> Can we revisit this issue?
>
>
> In C# there is `nameof`, in Swift you can do the same by 

RE: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Ron Buckton
A module namespace isn’t an instance of `Module`, it’s a module namespace spec 
object. If it has a `name` member, that is because the module you imported has 
an exported binding called `name`. But what kind of thing it is isn’t what 
matters.

`nameof` just returns a string representation of the static symbolic name of 
its operand. `nameof` would be used at runtime (i.e. during code execution), 
but provides the ability for advanced editors to include it in a “rename” 
refactoring.

The operand merely needs to be an identifier that exists within the current 
lexical scope. `nameof` would not observe TDZ and would not evaluate any 
expression. The ECMAScript static semantics would merely: 1) check that the 
identifier provided to `nameof` is the name of something in the current lexical 
scope, and 2) replace the expression with a string literal representing the 
name.

If `nameof foo.bar` were allowed `nameof` would not actually evaluate 
`foo.bar`, but merely result in `”bar”`. `nameof` does not evaluate anything, 
it is merely a syntactic transformation by the runtime that becomes a string.

Ron

From: guest271314 
Sent: Friday, June 14, 2019 10:07 AM
To: Ron Buckton 
Cc: es-discuss@mozilla.org
Subject: Re: Re: What do you think about a C# 6 like nameof() expression for

Not following the module example. Would not ```ns``` be an instance of 
```Module``` where ```* as ns``` is used?

For the ```class``` example would ```nameof``` be equivalent to 
```Object.getOwnPropertyDescriptors(other).name.value```?

It's not that a language like TypeScript would need this, but rather that users 
of an editor like VS Code or WebStorm that have a JavaScript language service 
would benefit from it.

Is the primary use case a non-simple text editor; e.g., _not_ gedit (GUI) or 
pico or nano (CLI), where the user is depending on the program

for diagnostics (logging and errors)

within a text editor _before_ actually running the code in a given environment 
- not to log errors during code execution?

On Fri, Jun 14, 2019 at 4:29 PM Ron Buckton 
mailto:ron.buck...@microsoft.com>> wrote:
The 'nameof' operator provides the string name of a static symbol (in 
compiler/linker terms, not an ECMAScript 'Symbol'). This is often useful for 
diagnostics (logging and errors), and gives developers a way to reduce 
repetition. It is also extremely helpful in editors that support symbolic 
"rename" refactoring.
While ES functions have a 'name' property, one of the main use cases is to get 
a string representation of the name of a thing that isn't itself reified as an 
object, such as a variable, parameter, or module namespace:
```
import * as ns from "foo";
nameof ns; // "ns"
let fn = function g() {};
fn.name;
 // "g"
nameof fn; // "fn"
```
Here is an example of two common use cases:
```
class C {
  compare(other) {
if (!(other instanceof C)) {
  throw new TypeError(`Invalid argument: ${nameof other} `);
}
  set prop(value) {
this._prop = value;
this.emit("propertychanged", nameof prop);
  }
}
```
It's not that a language like TypeScript would need this, but rather that users 
of an editor like VS Code or WebStorm that have a JavaScript language service 
would benefit from it.
Ron

From: es-discuss 
mailto:es-discuss-boun...@mozilla.org>> on 
behalf of guest271314 mailto:guest271...@gmail.com>>
Sent: Friday, June 14, 2019 9:05:55 AM
To: Stas Berkov
Cc: es-discuss@mozilla.org
Subject: Re: Re: What do you think about a C# 6 like nameof() expression for

Have not tried TypeScript. What are the use cases for JavaScript where 
TypeScript is not used? Does ```nameof()``` check if an object has a specific 
property name defined (```"MutationObserver" in window```; 
```window.MutationObserver```; ```"document" in globalThis```)?

On Fri, Jun 14, 2019 at 1:05 PM Stas Berkov 
mailto:stas.ber...@gmail.com>> wrote:
Can we revisit this issue?

In C# there is `nameof`, in Swift you can do the same by calling
```
let keyPath = \Person.mother.firstName
NSPredicate(format: "%K == %@", keyPath, "Andrew")
```
Let's introduce `nameof` in ES, please.

Devs from TypeScript don't want to introduce this feature in TypeScript unless 
it is available in ES ( https://github.com/microsoft/TypeScript/issues/1579 )
This feature is eagarly being asked by TypeScript community.

I understand there are couple issues related to `nameof` feature in ES. They 
are: minification and what to do if user already has `nameof` function.

Minification.
1. If your code to be minimized be prepared that variable names will also 
change.
2. (just a possibility) Minimizer can have option to replace `nameof(someVar)` 
with result of `nameof` 

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread guest271314
Terms such as "more robust", "Less fragile." , "Less mess." are subjective.
"Fragile" how? What is meant by "mess"?

If the proposal is that ```nameof``` is briefer than using shorthand
property names or computed property names to get an identifier as a string,
then ```nameof``` would be less code.

> You can rename field/property without fear you break something (using IDE
refactoring tools).

The use case appears to be within the context of an IDE?

For users that roll their own code by hand at a text editor and do not use
an IDE for composing code (or relying on an IDE for logging errors), am not
able to discern how ```nameof``` is different than using
```Object.getOwnPropertyDescriptors(other).name.value``` or
```Object.keys({userName})[0]```. The actual code will need to be tested in
different browsers anyway before deployment to get the actual results.

If a user has decided they _have_ to use some form of a dynamic "IDE" to
compose code and log errors - while they are writing the code, they can
open DevTools at Chromium or Chrome then select ```Sources``` =>
```Snippets``` => ```New snippet```, where

```
const n = 123;
const n = 456;
```

will highlight the line where the error occurs - during writing the code -
the as a red circle with a transparent "x" in the middle

```Uncaught SyntaxError: Identifier 'n' has already been declared

To run the code press ```ctrl+enter```.




On Fri, Jun 14, 2019 at 5:48 PM Stas Berkov  wrote:

> Less fragile. Less mess. You can rename field/property without fear you
> break something (using IDE refactoring tools).
> With high probablity you will break something when you refactor and have
> fields hardcoded as strings.
> Someone can object that you can rename strings as well.
> Issue here that you can ocassionally change non-related strings that
> should not be changed even they match or have matching substring.
>
> On Fri, Jun 14, 2019 at 9:38 PM guest271314  wrote:
>
>> Is Case 1 equivalent to a briefer version of
>>
>> ```
>>if (userName == undefined) {
>>throw new Error(`Argument cannot be null:
>> ${Object.keys({userName})[0]}`);
>>}
>> ```
>>
>> ?
>>
>> If not, how is ```nameof``` different?
>>
>> What is the difference between the use of 
>> ```message.hasOwnProperty(property)```
>> and ```nameof msg.expiration_utc_time```?
>>
>> > You get more robust code.
>>
>> How is "robust" objectively determined?
>>
>>
>>
>>
>> On Fri, Jun 14, 2019 at 5:21 PM Stas Berkov 
>> wrote:
>>
>>> ES can befit from `nameof` feature the same way as TS. There is no TS
>>> specific in it.
>>> It was ask to introduce in TS as a workaround since TS is considered as
>>> extention of ES.
>>>
>>> Case 1. Function guard.
>>> ```
>>> function func1(param1, param2, param3, userName, param4, param5) {
>>>if (userName == undefined) {
>>>throw new ArgumentNullError(nameof userName); //
>>> `ArgumentNullError` is a custom error, derived from `Error`, composes error
>>> message like "Argument cannot be null: userName".
>>>}
>>> }
>>> ```
>>>
>>> Case 2. Access extended information an object property.
>>> Assume a function
>>> ```
>>> function protoPropertyIsSet(message, property) {
>>> return message != null && message.hasOwnProperty(property);
>>> }
>>> ```
>>> Then in code you use it as `if (protoPropertyIsSet(msg,
>>> "expiration_utc_time")) {... }`.
>>> Having `nameof` would allow you to do that `if (protoPropertyIsSet(msg,
>>> nameof msg.expiration_utc_time)) {... }`.
>>> You get more robust code.
>>>
>>> On Fri, Jun 14, 2019 at 5:46 PM Augusto Moura 
>>> wrote:
>>>
 Can you list the benefits of having this operators? Maybe with example
 use cases

 If I understand it correctly, the operator fits better in compiled
 (and typed) languages, most of the use cases don't apply to dynamic
 Javascript
 The only legit use case I can think of is helping refactor tools to
 rename properties (but even mismatch errors between strings and
 properties names can be caught in compile time using modern
 Typescript)

 Em sex, 14 de jun de 2019 às 10:05, Stas Berkov
  escreveu:
 >
 > Can we revisit this issue?
 >
 >
 > In C# there is `nameof`, in Swift you can do the same by calling
 >
 > ```
 >
 > let keyPath = \Person.mother.firstName
 >
 > NSPredicate(format: "%K == %@", keyPath, "Andrew")
 >
 > ```
 >
 > Let's introduce `nameof` in ES, please.
 >
 >
 > Devs from TypeScript don't want to introduce this feature in
 TypeScript unless it is available in ES (
 https://github.com/microsoft/TypeScript/issues/1579 )
 >
 > This feature is eagarly being asked by TypeScript community.
 >
 >
 > I understand there are couple issues related to `nameof` feature in
 ES. They are: minification and what to do if user already has `nameof`
 function.
 >
 >
 > Minification.
 >
 > 1. If your code to be 

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Stas Berkov
> Is Case 1 equivalent to a briefer version of
> ```
   if (userName == undefined) {
   throw new Error(`Argument cannot be null:
${Object.keys({userName})[0]}`);
   }
```
Less readable but in this simple case might work.
What if we do the following:
Case 1. Function guard.
```
function func1(options) {
...
   if (options.userName == undefined) {
   throw new ParamNullError(nameof options.userName); //
`ParamNullError` is a custom error, derived from `Error`, composes error
message like "Argument cannot be null: userName".
   }
}
```

Case 2. Accessing property extended info
e.g.
```
const descriptor1 = Object.getOwnPropertyDescriptor(object1, 'property1');
```
vs
```
const descriptor1 = Object.getOwnPropertyDescriptor(object1, nameof
object1.property1);
```
2nd variant (proposed) has more chances not to be broken during refactoring
(robustness).

On Fri, Jun 14, 2019 at 9:48 PM Stas Berkov  wrote:

> Less fragile. Less mess. You can rename field/property without fear you
> break something (using IDE refactoring tools).
> With high probablity you will break something when you refactor and have
> fields hardcoded as strings.
> Someone can object that you can rename strings as well.
> Issue here that you can ocassionally change non-related strings that
> should not be changed even they match or have matching substring.
>
> On Fri, Jun 14, 2019 at 9:38 PM guest271314  wrote:
>
>> Is Case 1 equivalent to a briefer version of
>>
>> ```
>>if (userName == undefined) {
>>throw new Error(`Argument cannot be null:
>> ${Object.keys({userName})[0]}`);
>>}
>> ```
>>
>> ?
>>
>> If not, how is ```nameof``` different?
>>
>> What is the difference between the use of 
>> ```message.hasOwnProperty(property)```
>> and ```nameof msg.expiration_utc_time```?
>>
>> > You get more robust code.
>>
>> How is "robust" objectively determined?
>>
>>
>>
>>
>> On Fri, Jun 14, 2019 at 5:21 PM Stas Berkov 
>> wrote:
>>
>>> ES can befit from `nameof` feature the same way as TS. There is no TS
>>> specific in it.
>>> It was ask to introduce in TS as a workaround since TS is considered as
>>> extention of ES.
>>>
>>> Case 1. Function guard.
>>> ```
>>> function func1(param1, param2, param3, userName, param4, param5) {
>>>if (userName == undefined) {
>>>throw new ArgumentNullError(nameof userName); //
>>> `ArgumentNullError` is a custom error, derived from `Error`, composes error
>>> message like "Argument cannot be null: userName".
>>>}
>>> }
>>> ```
>>>
>>> Case 2. Access extended information an object property.
>>> Assume a function
>>> ```
>>> function protoPropertyIsSet(message, property) {
>>> return message != null && message.hasOwnProperty(property);
>>> }
>>> ```
>>> Then in code you use it as `if (protoPropertyIsSet(msg,
>>> "expiration_utc_time")) {... }`.
>>> Having `nameof` would allow you to do that `if (protoPropertyIsSet(msg,
>>> nameof msg.expiration_utc_time)) {... }`.
>>> You get more robust code.
>>>
>>> On Fri, Jun 14, 2019 at 5:46 PM Augusto Moura 
>>> wrote:
>>>
 Can you list the benefits of having this operators? Maybe with example
 use cases

 If I understand it correctly, the operator fits better in compiled
 (and typed) languages, most of the use cases don't apply to dynamic
 Javascript
 The only legit use case I can think of is helping refactor tools to
 rename properties (but even mismatch errors between strings and
 properties names can be caught in compile time using modern
 Typescript)

 Em sex, 14 de jun de 2019 às 10:05, Stas Berkov
  escreveu:
 >
 > Can we revisit this issue?
 >
 >
 > In C# there is `nameof`, in Swift you can do the same by calling
 >
 > ```
 >
 > let keyPath = \Person.mother.firstName
 >
 > NSPredicate(format: "%K == %@", keyPath, "Andrew")
 >
 > ```
 >
 > Let's introduce `nameof` in ES, please.
 >
 >
 > Devs from TypeScript don't want to introduce this feature in
 TypeScript unless it is available in ES (
 https://github.com/microsoft/TypeScript/issues/1579 )
 >
 > This feature is eagarly being asked by TypeScript community.
 >
 >
 > I understand there are couple issues related to `nameof` feature in
 ES. They are: minification and what to do if user already has `nameof`
 function.
 >
 >
 > Minification.
 >
 > 1. If your code to be minimized be prepared that variable names will
 also change.
 >
 > 2. (just a possibility) Minimizer can have option to replace
 `nameof(someVar)` with result of `nameof` function.
 >
 >
 >
 > What if user already has `nameof` function.
 >
 > 1. To maintain status quo we can user `nameof` function having
 priority over newly introduced language feature.
 >
 > 2. OR we can use `typeof` syntax, e.g. `nameof msg.userName` (//
 returns "userName" string)
 >
 > 

Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Stas Berkov
Less fragile. Less mess. You can rename field/property without fear you
break something (using IDE refactoring tools).
With high probablity you will break something when you refactor and have
fields hardcoded as strings.
Someone can object that you can rename strings as well.
Issue here that you can ocassionally change non-related strings that should
not be changed even they match or have matching substring.

On Fri, Jun 14, 2019 at 9:38 PM guest271314  wrote:

> Is Case 1 equivalent to a briefer version of
>
> ```
>if (userName == undefined) {
>throw new Error(`Argument cannot be null:
> ${Object.keys({userName})[0]}`);
>}
> ```
>
> ?
>
> If not, how is ```nameof``` different?
>
> What is the difference between the use of 
> ```message.hasOwnProperty(property)```
> and ```nameof msg.expiration_utc_time```?
>
> > You get more robust code.
>
> How is "robust" objectively determined?
>
>
>
>
> On Fri, Jun 14, 2019 at 5:21 PM Stas Berkov  wrote:
>
>> ES can befit from `nameof` feature the same way as TS. There is no TS
>> specific in it.
>> It was ask to introduce in TS as a workaround since TS is considered as
>> extention of ES.
>>
>> Case 1. Function guard.
>> ```
>> function func1(param1, param2, param3, userName, param4, param5) {
>>if (userName == undefined) {
>>throw new ArgumentNullError(nameof userName); //
>> `ArgumentNullError` is a custom error, derived from `Error`, composes error
>> message like "Argument cannot be null: userName".
>>}
>> }
>> ```
>>
>> Case 2. Access extended information an object property.
>> Assume a function
>> ```
>> function protoPropertyIsSet(message, property) {
>> return message != null && message.hasOwnProperty(property);
>> }
>> ```
>> Then in code you use it as `if (protoPropertyIsSet(msg,
>> "expiration_utc_time")) {... }`.
>> Having `nameof` would allow you to do that `if (protoPropertyIsSet(msg,
>> nameof msg.expiration_utc_time)) {... }`.
>> You get more robust code.
>>
>> On Fri, Jun 14, 2019 at 5:46 PM Augusto Moura 
>> wrote:
>>
>>> Can you list the benefits of having this operators? Maybe with example
>>> use cases
>>>
>>> If I understand it correctly, the operator fits better in compiled
>>> (and typed) languages, most of the use cases don't apply to dynamic
>>> Javascript
>>> The only legit use case I can think of is helping refactor tools to
>>> rename properties (but even mismatch errors between strings and
>>> properties names can be caught in compile time using modern
>>> Typescript)
>>>
>>> Em sex, 14 de jun de 2019 às 10:05, Stas Berkov
>>>  escreveu:
>>> >
>>> > Can we revisit this issue?
>>> >
>>> >
>>> > In C# there is `nameof`, in Swift you can do the same by calling
>>> >
>>> > ```
>>> >
>>> > let keyPath = \Person.mother.firstName
>>> >
>>> > NSPredicate(format: "%K == %@", keyPath, "Andrew")
>>> >
>>> > ```
>>> >
>>> > Let's introduce `nameof` in ES, please.
>>> >
>>> >
>>> > Devs from TypeScript don't want to introduce this feature in
>>> TypeScript unless it is available in ES (
>>> https://github.com/microsoft/TypeScript/issues/1579 )
>>> >
>>> > This feature is eagarly being asked by TypeScript community.
>>> >
>>> >
>>> > I understand there are couple issues related to `nameof` feature in
>>> ES. They are: minification and what to do if user already has `nameof`
>>> function.
>>> >
>>> >
>>> > Minification.
>>> >
>>> > 1. If your code to be minimized be prepared that variable names will
>>> also change.
>>> >
>>> > 2. (just a possibility) Minimizer can have option to replace
>>> `nameof(someVar)` with result of `nameof` function.
>>> >
>>> >
>>> >
>>> > What if user already has `nameof` function.
>>> >
>>> > 1. To maintain status quo we can user `nameof` function having
>>> priority over newly introduced language feature.
>>> >
>>> > 2. OR we can use `typeof` syntax, e.g. `nameof msg.userName` (//
>>> returns "userName" string)
>>> >
>>> > ___
>>> > es-discuss mailing list
>>> > es-discuss@mozilla.org
>>> > https://mail.mozilla.org/listinfo/es-discuss
>>>
>>>
>>>
>>> --
>>> Atenciosamente,
>>>
>>> Augusto Borges de Moura
>>>
>> ___
>> es-discuss mailing list
>> es-discuss@mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread guest271314
Is Case 1 equivalent to a briefer version of

```
   if (userName == undefined) {
   throw new Error(`Argument cannot be null:
${Object.keys({userName})[0]}`);
   }
```

?

If not, how is ```nameof``` different?

What is the difference between the use of
```message.hasOwnProperty(property)```
and ```nameof msg.expiration_utc_time```?

> You get more robust code.

How is "robust" objectively determined?




On Fri, Jun 14, 2019 at 5:21 PM Stas Berkov  wrote:

> ES can befit from `nameof` feature the same way as TS. There is no TS
> specific in it.
> It was ask to introduce in TS as a workaround since TS is considered as
> extention of ES.
>
> Case 1. Function guard.
> ```
> function func1(param1, param2, param3, userName, param4, param5) {
>if (userName == undefined) {
>throw new ArgumentNullError(nameof userName); //
> `ArgumentNullError` is a custom error, derived from `Error`, composes error
> message like "Argument cannot be null: userName".
>}
> }
> ```
>
> Case 2. Access extended information an object property.
> Assume a function
> ```
> function protoPropertyIsSet(message, property) {
> return message != null && message.hasOwnProperty(property);
> }
> ```
> Then in code you use it as `if (protoPropertyIsSet(msg,
> "expiration_utc_time")) {... }`.
> Having `nameof` would allow you to do that `if (protoPropertyIsSet(msg,
> nameof msg.expiration_utc_time)) {... }`.
> You get more robust code.
>
> On Fri, Jun 14, 2019 at 5:46 PM Augusto Moura 
> wrote:
>
>> Can you list the benefits of having this operators? Maybe with example
>> use cases
>>
>> If I understand it correctly, the operator fits better in compiled
>> (and typed) languages, most of the use cases don't apply to dynamic
>> Javascript
>> The only legit use case I can think of is helping refactor tools to
>> rename properties (but even mismatch errors between strings and
>> properties names can be caught in compile time using modern
>> Typescript)
>>
>> Em sex, 14 de jun de 2019 às 10:05, Stas Berkov
>>  escreveu:
>> >
>> > Can we revisit this issue?
>> >
>> >
>> > In C# there is `nameof`, in Swift you can do the same by calling
>> >
>> > ```
>> >
>> > let keyPath = \Person.mother.firstName
>> >
>> > NSPredicate(format: "%K == %@", keyPath, "Andrew")
>> >
>> > ```
>> >
>> > Let's introduce `nameof` in ES, please.
>> >
>> >
>> > Devs from TypeScript don't want to introduce this feature in TypeScript
>> unless it is available in ES (
>> https://github.com/microsoft/TypeScript/issues/1579 )
>> >
>> > This feature is eagarly being asked by TypeScript community.
>> >
>> >
>> > I understand there are couple issues related to `nameof` feature in ES.
>> They are: minification and what to do if user already has `nameof` function.
>> >
>> >
>> > Minification.
>> >
>> > 1. If your code to be minimized be prepared that variable names will
>> also change.
>> >
>> > 2. (just a possibility) Minimizer can have option to replace
>> `nameof(someVar)` with result of `nameof` function.
>> >
>> >
>> >
>> > What if user already has `nameof` function.
>> >
>> > 1. To maintain status quo we can user `nameof` function having priority
>> over newly introduced language feature.
>> >
>> > 2. OR we can use `typeof` syntax, e.g. `nameof msg.userName` (//
>> returns "userName" string)
>> >
>> > ___
>> > es-discuss mailing list
>> > es-discuss@mozilla.org
>> > https://mail.mozilla.org/listinfo/es-discuss
>>
>>
>>
>> --
>> Atenciosamente,
>>
>> Augusto Borges de Moura
>>
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Stas Berkov
ES can befit from `nameof` feature the same way as TS. There is no TS
specific in it.
It was ask to introduce in TS as a workaround since TS is considered as
extention of ES.

Case 1. Function guard.
```
function func1(param1, param2, param3, userName, param4, param5) {
   if (userName == undefined) {
   throw new ArgumentNullError(nameof userName); // `ArgumentNullError`
is a custom error, derived from `Error`, composes error message like
"Argument cannot be null: userName".
   }
}
```

Case 2. Access extended information an object property.
Assume a function
```
function protoPropertyIsSet(message, property) {
return message != null && message.hasOwnProperty(property);
}
```
Then in code you use it as `if (protoPropertyIsSet(msg,
"expiration_utc_time")) {... }`.
Having `nameof` would allow you to do that `if (protoPropertyIsSet(msg,
nameof msg.expiration_utc_time)) {... }`.
You get more robust code.

On Fri, Jun 14, 2019 at 5:46 PM Augusto Moura 
wrote:

> Can you list the benefits of having this operators? Maybe with example use
> cases
>
> If I understand it correctly, the operator fits better in compiled
> (and typed) languages, most of the use cases don't apply to dynamic
> Javascript
> The only legit use case I can think of is helping refactor tools to
> rename properties (but even mismatch errors between strings and
> properties names can be caught in compile time using modern
> Typescript)
>
> Em sex, 14 de jun de 2019 às 10:05, Stas Berkov
>  escreveu:
> >
> > Can we revisit this issue?
> >
> >
> > In C# there is `nameof`, in Swift you can do the same by calling
> >
> > ```
> >
> > let keyPath = \Person.mother.firstName
> >
> > NSPredicate(format: "%K == %@", keyPath, "Andrew")
> >
> > ```
> >
> > Let's introduce `nameof` in ES, please.
> >
> >
> > Devs from TypeScript don't want to introduce this feature in TypeScript
> unless it is available in ES (
> https://github.com/microsoft/TypeScript/issues/1579 )
> >
> > This feature is eagarly being asked by TypeScript community.
> >
> >
> > I understand there are couple issues related to `nameof` feature in ES.
> They are: minification and what to do if user already has `nameof` function.
> >
> >
> > Minification.
> >
> > 1. If your code to be minimized be prepared that variable names will
> also change.
> >
> > 2. (just a possibility) Minimizer can have option to replace
> `nameof(someVar)` with result of `nameof` function.
> >
> >
> >
> > What if user already has `nameof` function.
> >
> > 1. To maintain status quo we can user `nameof` function having priority
> over newly introduced language feature.
> >
> > 2. OR we can use `typeof` syntax, e.g. `nameof msg.userName` (// returns
> "userName" string)
> >
> > ___
> > es-discuss mailing list
> > es-discuss@mozilla.org
> > https://mail.mozilla.org/listinfo/es-discuss
>
>
>
> --
> Atenciosamente,
>
> Augusto Borges de Moura
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread guest271314
Not following the module example. Would not ```ns``` be an instance of
```Module``` where ```* as ns``` is used?

For the ```class``` example would ```nameof``` be equivalent to
```Object.getOwnPropertyDescriptors(other).name.value```?

It's not that a language like TypeScript would need this, but rather that
> users of an editor like VS Code or WebStorm that have a JavaScript language
> service would benefit from it.


Is the primary use case a non-simple text editor; e.g., _not_ gedit (GUI)
or pico or nano (CLI), where the user is depending on the program

for diagnostics (logging and errors)


within a text editor _before_ actually running the code in a given
environment - not to log errors during code execution?

On Fri, Jun 14, 2019 at 4:29 PM Ron Buckton 
wrote:

> The 'nameof' operator provides the string name of a static symbol (in
> compiler/linker terms, not an ECMAScript 'Symbol'). This is often useful
> for diagnostics (logging and errors), and gives developers a way to reduce
> repetition. It is also extremely helpful in editors that support symbolic
> "rename" refactoring.
>
> While ES functions have a 'name' property, one of the main use cases is to
> get a string representation of the name of a thing that isn't itself
> reified as an object, such as a variable, parameter, or module namespace:
>
> ```
> import * as ns from "foo";
>
> nameof ns; // "ns"
>
> let fn = function g() {};
> fn.name; // "g"
> nameof fn; // "fn"
> ```
>
> Here is an example of two common use cases:
>
> ```
> class C {
>   compare(other) {
> if (!(other instanceof C)) {
>   throw new TypeError(`Invalid argument: ${nameof other} `);
> }
>
>   set prop(value) {
> this._prop = value;
> this.emit("propertychanged", nameof prop);
>   }
> }
> ```
>
> It's not that a language like TypeScript would need this, but rather that
> users of an editor like VS Code or WebStorm that have a JavaScript language
> service would benefit from it.
>
> Ron
> --
> *From:* es-discuss  on behalf of
> guest271314 
> *Sent:* Friday, June 14, 2019 9:05:55 AM
> *To:* Stas Berkov
> *Cc:* es-discuss@mozilla.org
> *Subject:* Re: Re: What do you think about a C# 6 like nameof()
> expression for
>
> Have not tried TypeScript. What are the use cases for JavaScript where
> TypeScript is not used? Does ```nameof()``` check if an object has a
> specific property name defined (```"MutationObserver" in window```;
> ```window.MutationObserver```; ```"document" in globalThis```)?
>
> On Fri, Jun 14, 2019 at 1:05 PM Stas Berkov  wrote:
>
>> Can we revisit this issue?
>>
>>
>> In C# there is `nameof`, in Swift you can do the same by calling
>>
>> ```
>>
>> let keyPath = \Person.mother.firstName
>>
>> NSPredicate(format: "%K == %@", keyPath, "Andrew")
>>
>> ```
>>
>> Let's introduce `nameof` in ES, please.
>>
>>
>> Devs from TypeScript don't want to introduce this feature in TypeScript
>> unless it is available in ES (
>> https://github.com/microsoft/TypeScript/issues/1579
>> 
>>  )
>>
>> This feature is eagarly being asked by TypeScript community.
>>
>>
>> I understand there are couple issues related to `nameof` feature in ES.
>> They are: minification and what to do if user already has `nameof` function.
>>
>>
>> Minification.
>>
>> 1. If your code to be minimized be prepared that variable names will also
>> change.
>>
>> 2. (just a possibility) Minimizer can have option to replace
>> `nameof(someVar)` with result of `nameof` function.
>>
>>
>>
>> What if user already has `nameof` function.
>>
>> 1. To maintain status quo we can user `nameof` function having priority
>> over newly introduced language feature.
>>
>> 2. OR we can use `typeof` syntax, e.g. `nameof msg.userName` (// returns
>> "userName" string)
>> ___
>> es-discuss mailing list
>> es-discuss@mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>> 
>>
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Ron Buckton
The 'nameof' operator provides the string name of a static symbol (in 
compiler/linker terms, not an ECMAScript 'Symbol'). This is often useful for 
diagnostics (logging and errors), and gives developers a way to reduce 
repetition. It is also extremely helpful in editors that support symbolic 
"rename" refactoring.

While ES functions have a 'name' property, one of the main use cases is to get 
a string representation of the name of a thing that isn't itself reified as an 
object, such as a variable, parameter, or module namespace:

```
import * as ns from "foo";

nameof ns; // "ns"

let fn = function g() {};
fn.name; // "g"
nameof fn; // "fn"
```

Here is an example of two common use cases:

```
class C {
  compare(other) {
if (!(other instanceof C)) {
  throw new TypeError(`Invalid argument: ${nameof other} `);
}

  set prop(value) {
this._prop = value;
this.emit("propertychanged", nameof prop);
  }
}
```

It's not that a language like TypeScript would need this, but rather that users 
of an editor like VS Code or WebStorm that have a JavaScript language service 
would benefit from it.

Ron

From: es-discuss  on behalf of guest271314 

Sent: Friday, June 14, 2019 9:05:55 AM
To: Stas Berkov
Cc: es-discuss@mozilla.org
Subject: Re: Re: What do you think about a C# 6 like nameof() expression for

Have not tried TypeScript. What are the use cases for JavaScript where 
TypeScript is not used? Does ```nameof()``` check if an object has a specific 
property name defined (```"MutationObserver" in window```; 
```window.MutationObserver```; ```"document" in globalThis```)?

On Fri, Jun 14, 2019 at 1:05 PM Stas Berkov 
mailto:stas.ber...@gmail.com>> wrote:
Can we revisit this issue?

In C# there is `nameof`, in Swift you can do the same by calling
```
let keyPath = \Person.mother.firstName
NSPredicate(format: "%K == %@", keyPath, "Andrew")
```
Let's introduce `nameof` in ES, please.

Devs from TypeScript don't want to introduce this feature in TypeScript unless 
it is available in ES ( 
https://github.com/microsoft/TypeScript/issues/1579
 )
This feature is eagarly being asked by TypeScript community.

I understand there are couple issues related to `nameof` feature in ES. They 
are: minification and what to do if user already has `nameof` function.

Minification.
1. If your code to be minimized be prepared that variable names will also 
change.
2. (just a possibility) Minimizer can have option to replace `nameof(someVar)` 
with result of `nameof` function.

What if user already has `nameof` function.
1. To maintain status quo we can user `nameof` function having priority over 
newly introduced language feature.
2. OR we can use `typeof` syntax, e.g. `nameof msg.userName` (// returns 
"userName" string)
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread guest271314
Have not tried TypeScript. What are the use cases for JavaScript where
TypeScript is not used? Does ```nameof()``` check if an object has a
specific property name defined (```"MutationObserver" in window```;
```window.MutationObserver```; ```"document" in globalThis```)?

On Fri, Jun 14, 2019 at 1:05 PM Stas Berkov  wrote:

> Can we revisit this issue?
>
>
> In C# there is `nameof`, in Swift you can do the same by calling
>
> ```
>
> let keyPath = \Person.mother.firstName
>
> NSPredicate(format: "%K == %@", keyPath, "Andrew")
>
> ```
>
> Let's introduce `nameof` in ES, please.
>
>
> Devs from TypeScript don't want to introduce this feature in TypeScript
> unless it is available in ES (
> https://github.com/microsoft/TypeScript/issues/1579 )
>
> This feature is eagarly being asked by TypeScript community.
>
>
> I understand there are couple issues related to `nameof` feature in ES.
> They are: minification and what to do if user already has `nameof` function.
>
>
> Minification.
>
> 1. If your code to be minimized be prepared that variable names will also
> change.
>
> 2. (just a possibility) Minimizer can have option to replace
> `nameof(someVar)` with result of `nameof` function.
>
>
>
> What if user already has `nameof` function.
>
> 1. To maintain status quo we can user `nameof` function having priority
> over newly introduced language feature.
>
> 2. OR we can use `typeof` syntax, e.g. `nameof msg.userName` (// returns
> "userName" string)
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Augusto Moura
Can you list the benefits of having this operators? Maybe with example use cases

If I understand it correctly, the operator fits better in compiled
(and typed) languages, most of the use cases don't apply to dynamic
Javascript
The only legit use case I can think of is helping refactor tools to
rename properties (but even mismatch errors between strings and
properties names can be caught in compile time using modern
Typescript)

Em sex, 14 de jun de 2019 às 10:05, Stas Berkov
 escreveu:
>
> Can we revisit this issue?
>
>
> In C# there is `nameof`, in Swift you can do the same by calling
>
> ```
>
> let keyPath = \Person.mother.firstName
>
> NSPredicate(format: "%K == %@", keyPath, "Andrew")
>
> ```
>
> Let's introduce `nameof` in ES, please.
>
>
> Devs from TypeScript don't want to introduce this feature in TypeScript 
> unless it is available in ES ( 
> https://github.com/microsoft/TypeScript/issues/1579 )
>
> This feature is eagarly being asked by TypeScript community.
>
>
> I understand there are couple issues related to `nameof` feature in ES. They 
> are: minification and what to do if user already has `nameof` function.
>
>
> Minification.
>
> 1. If your code to be minimized be prepared that variable names will also 
> change.
>
> 2. (just a possibility) Minimizer can have option to replace 
> `nameof(someVar)` with result of `nameof` function.
>
>
>
> What if user already has `nameof` function.
>
> 1. To maintain status quo we can user `nameof` function having priority over 
> newly introduced language feature.
>
> 2. OR we can use `typeof` syntax, e.g. `nameof msg.userName` (// returns 
> "userName" string)
>
> ___
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



-- 
Atenciosamente,

Augusto Borges de Moura
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Re: What do you think about a C# 6 like nameof() expression for

2019-06-14 Thread Stas Berkov
Can we revisit this issue?


In C# there is `nameof`, in Swift you can do the same by calling

```

let keyPath = \Person.mother.firstName

NSPredicate(format: "%K == %@", keyPath, "Andrew")

```

Let's introduce `nameof` in ES, please.


Devs from TypeScript don't want to introduce this feature in TypeScript
unless it is available in ES (
https://github.com/microsoft/TypeScript/issues/1579 )

This feature is eagarly being asked by TypeScript community.


I understand there are couple issues related to `nameof` feature in ES.
They are: minification and what to do if user already has `nameof` function.


Minification.

1. If your code to be minimized be prepared that variable names will also
change.

2. (just a possibility) Minimizer can have option to replace
`nameof(someVar)` with result of `nameof` function.



What if user already has `nameof` function.

1. To maintain status quo we can user `nameof` function having priority
over newly introduced language feature.

2. OR we can use `typeof` syntax, e.g. `nameof msg.userName` (// returns
"userName" string)
___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss