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

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"

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

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

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

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

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

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```

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)

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

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

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

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

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

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

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)```

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 ==

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

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

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

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

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