Re: What do you think about a C# 6 like nameof() expression for JavaScript.
It depends I guess. Should be a configuration option. On Thu, Sep 10, 2015 at 10:37 AM Waldemar Horwatwrote: > This would have interesting consequences if you run your code via a > minifier. Should the minifier return a string with the old name or the new > name? > > Waldemar > -- Best regards, Behrang Saeedzadeh ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: What do you think about a C# 6 like nameof() expression for JavaScript.
This would have interesting consequences if you run your code via a minifier. Should the minifier return a string with the old name or the new name? Waldemar ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
RE: What do you think about a C# 6 like nameof() expression for JavaScript.
While its true most IDE's can search for references in strings, `nameof` takes some of the guesswork out of determining whether a substring that matches a symbol refers to the symbol or is merely part of the sentence. That said, `nameof` is primarily a convenience for an IDE. Ron Sent from my Windows Phone From: Isiah Meadowsmailto:isiahmead...@gmail.com Sent: 8/8/2015 8:57 PM To: Ron Bucktonmailto:ron.buck...@microsoft.com; Behrang Saeedzadehmailto:behran...@gmail.com; EcmaScript Discuss Mailing Listmailto:es-discuss@mozilla.org Subject: Re: What do you think about a C# 6 like nameof() expression for JavaScript. To be honest, most larger IDEs also search for references in strings, and even if it doesn't, any decent editor can do a regex replace of `identifierName` without problem. I don't see much of a problem here. Also, do you know of any other language that has this at the syntax level (not macro)? On Sat, Aug 8, 2015, 23:12 Ron Buckton ron.buck...@microsoft.commailto:ron.buck...@microsoft.com wrote: One of the main purposes of the `nameof` operator is to provide the string value of a symbol, so that if you perform a Rename refactoring of that symbol that the change is also reflected. This is primarily for cases where you perform precondition assertions tied to an argument: ``` ... static void Method(string x) { if (x == null) throw new ArgumentNullException(nameof(x)); ... } ``` Now, if I later rename `x`, I don't need to also find any string literals of x and manually update them. There are other uses of `nameof`, but they all boil down to roughly the same thing. Ron From: Isiah Meadowsmailto:isiahmead...@gmail.com Sent: 8/8/2015 7:23 PM To: Behrang Saeedzadehmailto:behran...@gmail.com; EcmaScript Discuss Mailing Listmailto:es-discuss@mozilla.org Subject: Re: What do you think about a C# 6 like nameof() expression for JavaScript. Call me crazy, but I don't see anything that couldn't be done more concisely with a string literal. Is it supposed to be able to do this? ```js function foo(x) { return nameof(x); } foo(bar); // bar; ``` In that case, the engine would have to keep track of usages as well, in a similar sense as `arguments.callee`, and if it were a function, it would make optimization quite difficult, as engines don't have the capacity to statically analyze that such a function is used. If it is like `typeof`, we now have a breaking change - a keyword that was a valid Identifier before. ```js // Error? function nameof(value) { return value.namehttps://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fvalue.namedata=01%7c01%7cron.buckton%40microsoft.com%7ca2e2c4d35400435810d008d2a061897d%7c72f988bf86f141af91ab2d7cd011db47%7c1sdata=pwV45avF9RX6COETpoLIY4EF%2bmCVmk6kEEmLc2JXSCY%3d; } var bar = {name: 2}; nameof(bar); // bar or 2? ``` I don't think this is going to work out in practice, not in ECMAScript proper. You might appreciate Sweet.js, though. On Sat, Aug 8, 2015, 21:27 Behrang Saeedzadeh behran...@gmail.commailto:behran...@gmail.com wrote: Forgot to mention that nameof works with local variables too: function foo() { var aNum = 1; console.log(nameof(aNmum), aNum); } On Sat, Aug 8, 2015 at 10:38 AM Behrang Saeedzadeh behran...@gmail.commailto:behran...@gmail.com wrote: So basically we could use it like this: function aFunc(aParam) { throw new Error(nameof(aParam)); } and nameof(aParam) would return the string aParam. This is possible to do even right now using arguments.callee and some hacky code, but having it built-in to spec would be nicer IMHO. -- Best regards, Behrang Saeedzadeh -- Best regards, Behrang Saeedzadeh ___ es-discuss mailing list es-discuss@mozilla.orgmailto:es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discusshttps://na01.safelinks.protection.outlook.com/?url=https%3a%2f%2fmail.mozilla.org%2flistinfo%2fes-discussdata=01%7c01%7cron.buckton%40microsoft.com%7ca2e2c4d35400435810d008d2a061897d%7c72f988bf86f141af91ab2d7cd011db47%7c1sdata=7DHMx5gTd2OexSlKscSrKlMIxABMUkOKRC%2fuCbc6pWk%3d ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: What do you think about a C# 6 like nameof() expression for JavaScript.
Forgot to mention that nameof works with local variables too: function foo() { var aNum = 1; console.log(nameof(aNmum), aNum); } On Sat, Aug 8, 2015 at 10:38 AM Behrang Saeedzadeh behran...@gmail.com wrote: So basically we could use it like this: function aFunc(aParam) { throw new Error(nameof(aParam)); } and nameof(aParam) would return the string aParam. This is possible to do even right now using arguments.callee and some hacky code, but having it built-in to spec would be nicer IMHO. -- Best regards, Behrang Saeedzadeh -- Best regards, Behrang Saeedzadeh ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: What do you think about a C# 6 like nameof() expression for JavaScript.
Call me crazy, but I don't see anything that couldn't be done more concisely with a string literal. Is it supposed to be able to do this? ```js function foo(x) { return nameof(x); } foo(bar); // bar; ``` In that case, the engine would have to keep track of usages as well, in a similar sense as `arguments.callee`, and if it were a function, it would make optimization quite difficult, as engines don't have the capacity to statically analyze that such a function is used. If it is like `typeof`, we now have a breaking change - a keyword that was a valid Identifier before. ```js // Error? function nameof(value) { return value.name; } var bar = {name: 2}; nameof(bar); // bar or 2? ``` I don't think this is going to work out in practice, not in ECMAScript proper. You might appreciate Sweet.js, though. On Sat, Aug 8, 2015, 21:27 Behrang Saeedzadeh behran...@gmail.com wrote: Forgot to mention that nameof works with local variables too: function foo() { var aNum = 1; console.log(nameof(aNmum), aNum); } On Sat, Aug 8, 2015 at 10:38 AM Behrang Saeedzadeh behran...@gmail.com wrote: So basically we could use it like this: function aFunc(aParam) { throw new Error(nameof(aParam)); } and nameof(aParam) would return the string aParam. This is possible to do even right now using arguments.callee and some hacky code, but having it built-in to spec would be nicer IMHO. -- Best regards, Behrang Saeedzadeh -- Best regards, Behrang Saeedzadeh ___ 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: What do you think about a C# 6 like nameof() expression for JavaScript.
One of the main purposes of the `nameof` operator is to provide the string value of a symbol, so that if you perform a Rename refactoring of that symbol that the change is also reflected. This is primarily for cases where you perform precondition assertions tied to an argument: ``` ... static void Method(string x) { if (x == null) throw new ArgumentNullException(nameof(x)); ... } ``` Now, if I later rename `x`, I don't need to also find any string literals of x and manually update them. There are other uses of `nameof`, but they all boil down to roughly the same thing. Ron From: Isiah Meadowsmailto:isiahmead...@gmail.com Sent: 8/8/2015 7:23 PM To: Behrang Saeedzadehmailto:behran...@gmail.com; EcmaScript Discuss Mailing Listmailto:es-discuss@mozilla.org Subject: Re: What do you think about a C# 6 like nameof() expression for JavaScript. Call me crazy, but I don't see anything that couldn't be done more concisely with a string literal. Is it supposed to be able to do this? ```js function foo(x) { return nameof(x); } foo(bar); // bar; ``` In that case, the engine would have to keep track of usages as well, in a similar sense as `arguments.callee`, and if it were a function, it would make optimization quite difficult, as engines don't have the capacity to statically analyze that such a function is used. If it is like `typeof`, we now have a breaking change - a keyword that was a valid Identifier before. ```js // Error? function nameof(value) { return value.namehttps://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fvalue.namedata=01%7c01%7cron.buckton%40microsoft.com%7ca2e2c4d35400435810d008d2a061897d%7c72f988bf86f141af91ab2d7cd011db47%7c1sdata=pwV45avF9RX6COETpoLIY4EF%2bmCVmk6kEEmLc2JXSCY%3d; } var bar = {name: 2}; nameof(bar); // bar or 2? ``` I don't think this is going to work out in practice, not in ECMAScript proper. You might appreciate Sweet.js, though. On Sat, Aug 8, 2015, 21:27 Behrang Saeedzadeh behran...@gmail.commailto:behran...@gmail.com wrote: Forgot to mention that nameof works with local variables too: function foo() { var aNum = 1; console.log(nameof(aNmum), aNum); } On Sat, Aug 8, 2015 at 10:38 AM Behrang Saeedzadeh behran...@gmail.commailto:behran...@gmail.com wrote: So basically we could use it like this: function aFunc(aParam) { throw new Error(nameof(aParam)); } and nameof(aParam) would return the string aParam. This is possible to do even right now using arguments.callee and some hacky code, but having it built-in to spec would be nicer IMHO. -- Best regards, Behrang Saeedzadeh -- Best regards, Behrang Saeedzadeh ___ es-discuss mailing list es-discuss@mozilla.orgmailto:es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discusshttps://na01.safelinks.protection.outlook.com/?url=https%3a%2f%2fmail.mozilla.org%2flistinfo%2fes-discussdata=01%7c01%7cron.buckton%40microsoft.com%7ca2e2c4d35400435810d008d2a061897d%7c72f988bf86f141af91ab2d7cd011db47%7c1sdata=7DHMx5gTd2OexSlKscSrKlMIxABMUkOKRC%2fuCbc6pWk%3d ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: What do you think about a C# 6 like nameof() expression for JavaScript.
To be honest, most larger IDEs also search for references in strings, and even if it doesn't, any decent editor can do a regex replace of `identifierName` without problem. I don't see much of a problem here. Also, do you know of any other language that has this at the syntax level (not macro)? On Sat, Aug 8, 2015, 23:12 Ron Buckton ron.buck...@microsoft.com wrote: One of the main purposes of the `nameof` operator is to provide the string value of a symbol, so that if you perform a Rename refactoring of that symbol that the change is also reflected. This is primarily for cases where you perform precondition assertions tied to an argument: ``` ... static void Method(string x) { if (x == null) throw new ArgumentNullException(nameof(x)); ... } ``` Now, if I later rename `x`, I don't need to also find any string literals of x and manually update them. There are other uses of `nameof`, but they all boil down to roughly the same thing. Ron -- From: Isiah Meadows isiahmead...@gmail.com Sent: 8/8/2015 7:23 PM To: Behrang Saeedzadeh behran...@gmail.com; EcmaScript Discuss Mailing List es-discuss@mozilla.org Subject: Re: What do you think about a C# 6 like nameof() expression for JavaScript. Call me crazy, but I don't see anything that couldn't be done more concisely with a string literal. Is it supposed to be able to do this? ```js function foo(x) { return nameof(x); } foo(bar); // bar; ``` In that case, the engine would have to keep track of usages as well, in a similar sense as `arguments.callee`, and if it were a function, it would make optimization quite difficult, as engines don't have the capacity to statically analyze that such a function is used. If it is like `typeof`, we now have a breaking change - a keyword that was a valid Identifier before. ```js // Error? function nameof(value) { return value.name https://na01.safelinks.protection.outlook.com/?url=http%3a%2f%2fvalue.namedata=01%7c01%7cron.buckton%40microsoft.com%7ca2e2c4d35400435810d008d2a061897d%7c72f988bf86f141af91ab2d7cd011db47%7c1sdata=pwV45avF9RX6COETpoLIY4EF%2bmCVmk6kEEmLc2JXSCY%3d ; } var bar = {name: 2}; nameof(bar); // bar or 2? ``` I don't think this is going to work out in practice, not in ECMAScript proper. You might appreciate Sweet.js, though. On Sat, Aug 8, 2015, 21:27 Behrang Saeedzadeh behran...@gmail.com wrote: Forgot to mention that nameof works with local variables too: function foo() { var aNum = 1; console.log(nameof(aNmum), aNum); } On Sat, Aug 8, 2015 at 10:38 AM Behrang Saeedzadeh behran...@gmail.com wrote: So basically we could use it like this: function aFunc(aParam) { throw new Error(nameof(aParam)); } and nameof(aParam) would return the string aParam. This is possible to do even right now using arguments.callee and some hacky code, but having it built-in to spec would be nicer IMHO. -- Best regards, Behrang Saeedzadeh -- Best regards, Behrang Saeedzadeh ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss https://na01.safelinks.protection.outlook.com/?url=https%3a%2f%2fmail.mozilla.org%2flistinfo%2fes-discussdata=01%7c01%7cron.buckton%40microsoft.com%7ca2e2c4d35400435810d008d2a061897d%7c72f988bf86f141af91ab2d7cd011db47%7c1sdata=7DHMx5gTd2OexSlKscSrKlMIxABMUkOKRC%2fuCbc6pWk%3d ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
What do you think about a C# 6 like nameof() expression for JavaScript.
So basically we could use it like this: function aFunc(aParam) { throw new Error(nameof(aParam)); } and nameof(aParam) would return the string aParam. This is possible to do even right now using arguments.callee and some hacky code, but having it built-in to spec would be nicer IMHO. -- Best regards, Behrang Saeedzadeh ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss