On Nov 18, 2019, at 06:05, tonycst...@gmail.com wrote: > > Inability to visually identify a variable without looking at where its > placed and/or how its used is sometimes brain damaging task when it comes to > understanding code someone else wrote.
What’s the difference between a variable and anything else? In Python, functions, classes, modules, etc. are all just values, bound to names in the same way as any other value. Everything that looks like an identifier is a variable except for language keywords. IDEs have no problem coloring the fixed set of keywords differently from other identifiers, or coloring identifiers differently from numbers or list brackets or comments or other parts of the syntax. So you must be looking for a distinction between different kinds of variables, maybe based on how they’re defined? But if so, why? Look at this example: def f(a, b): return a**(b+1) g = partial(f, b==2) h = lambda x: f(x, 2) Python can’t tell the difference between f, g, and h; they’re all variables. An IDE could keep track of the fact that f was bound by a def statement, and g and h by assignment. But I’m not sure why you’d want it to. After all, they’re all variables with callable values. Why should f(2,3) be colored differently from g(4)? Also, why would you want to be forced to place a $ before every appearance of a, b, g, h, and x, but not f, in that code? It would make everything longer and uglier, to what benefit? > Many people search google wanting to use $ sign for variables and it is > mentioned to be "not best practice". > Who says "not best practice" ? I don’t know. Who are these many people doing the search? What sites are they finding? If you don’t tell us that, how could any of us guess who’s writing those sites, or why? Since it’s illegal in most languages, and mandatory in most of the rest, I’m not sure who would bother telling you it’s “not best practice” in the first place. Maybe you’re finding Perl blogs, where the sigil $ is how you explicitly distinguish scalar variables from array or hash variables (if I’m remembering that right), there are cases where the $ is unnecessary but allowed, and maybe in some such cases people say best practice is to not use it? (Or maybe something similar with Basic, where a $ sigil means a string variable as opposed to a numeric one?) But even if my wild guess is right, I don’t see how that would be relevant to Python, or any other language but Perl. > If it works and works well, i see no reason to not take advantage of every > great benefit it provides. It doesn’t work in Python, or most other languages. Identifiers have to be made of Unicode identifier characters, and $ isn’t one of them. I suppose it could be made to work in Python, because $ is still reserved for someone to come along with an astoundingly good use for an operator or other syntax, but I don’t think this is an astoundingly good use. It seems like your argument is that even though it makes code harder to read as plain text, and to write, it helps IDEs so much that the readability is a net win? Maybe some examples would help, but it seems implausible. _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/2QUP72BJHO2CJNMLVEUFRTBAIACIXMO5/ Code of Conduct: http://python.org/psf/codeofconduct/