On 2/3/20 12:02 AM, Bruce Leban wrote:
People keep mentioning refactoring. It's a red herring.
No refactoring tool needs a nameof operator added to the language in order to do its job. And certainly an operator that requires running the program in order to use it is not going to be helpful. Refactoring tools analyze the program; they don't run it.
And f-strings are another red herring. There is nothing magical about expressions inside f-strings compared to those outside.
Ignoring the red herrings, I see no utility in a nameof operator and no way for it to actually do anything useful.
--- Bruce
IF Python had a proper refactoring tool (see my other message where I question the ability to do that) then the nameof operator would clearly help keep logging/debug strings in line with the program definitions. A statement like print("bar", foo.bar) would be very hard to notice that the "bar" match the foo.bar, while print(nameof(foo.bar), foo.bar) makes the connection explicit. This is where such an operation could help with refactoring, having an actual Python attribute reference that the refactoring operation could see, so it knows that the string is based on that attribute and not something else. As I mentioned elsewhere, the issue is that in Python, if we change the attribute bar in class Foo, then we have the problem that we often can't tell if in foo.bar if foo is of type Foo, so we should apply the change. This isn't a problem is statically typed languages, as there we can determine the type of foo, and see if the change applies (at least in most cases). -- Richard Damon