<div dir="ltr"><div><div>Thanks for the positive tone of your message.<br><br></div>I do think there's some benefit in having a naming convention that's consistent within your own code base -- especially if you're working with a team and you can agree on a convention before you have written much code.<br><br></div>Joel Spolsky agrees: <a href="http://www.joelonsoftware.com/articles/Wrong.html">http://www.joelonsoftware.com/articles/Wrong.html</a><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 15, 2016 at 9:57 AM, Richard Prosser <span dir="ltr"><<a href="mailto:richard.prosser@mail.com" target="_blank">richard.prosser@mail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div><div style="overflow:auto"><div style="max-height:10000px"><div dir="ltr"><p style="color:rgb(52,52,52);font-family:Gotham,'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:23.8px">Is
there any mileage in having a naming convention to indicate the type of
a variable? I have never really liked the fact that the Python 'duck
typing' policy is so lax, yet the new "Type Hints" package for Python 3
is rather clumsy, IMO.</p><p style="color:rgb(52,52,52);font-family:Gotham,'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:23.8px"><br></p><p style="color:rgb(52,52,52);font-family:Gotham,'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:23.8px">For example:</p><p style="color:rgb(52,52,52);font-family:Gotham,'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:23.8px">github_response = requests.get('<a href="https://api.github.com/user" rel="nofollow" style="color:rgb(21,142,194);font-family:'Helvetica Neue',Arial,Helvetica,sans-serif;background-color:transparent" target="_blank">https://api.github.com/user</a>', auth=('user', 'pass')) # Derived from <a href="http://docs.python-requests.org/en/master" rel="nofollow" style="color:rgb(21,142,194);font-family:'Helvetica Neue',Arial,Helvetica,sans-serif;background-color:transparent" target="_blank">http://docs.python-requests.org/en/master</a>.</p><p style="color:rgb(52,52,52);font-family:Gotham,'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:23.8px"><br></p><p style="color:rgb(52,52,52);font-family:Gotham,'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:23.8px">The above request returns a <a title="requests.Response" href="http://docs.python-requests.org/en/master/api/#requests.Response" rel="nofollow" style="color:rgb(21,142,194);font-family:'Helvetica Neue',Arial,Helvetica,sans-serif;background-color:transparent" target="_blank"><code style="font-family:monospace,monospace;font-size:1em">Response</code></a> object and so the variable has 'response' in its name.</p><p style="color:rgb(52,52,52);font-family:Gotham,'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:23.8px"><br></p><p style="color:rgb(52,52,52);font-family:Gotham,'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:23.8px">Likewise:</p><p style="color:rgb(52,52,52);font-family:Gotham,'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:23.8px">word_count = total_words_in_file('text_file')</p><p style="color:rgb(52,52,52);font-family:Gotham,'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:23.8px">where
'count' has been defined (in the IDE, by the user perhaps) as an
Integer and the function is known to return an Integer, perhaps via a
local 'count' or 'total' variable.</p><p style="color:rgb(52,52,52);font-family:Gotham,'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:23.8px"> </p><p style="color:rgb(52,52,52);font-family:Gotham,'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:23.8px">I
know that this has been attempted before but I think that an IDE like
PyCharm could actually check variable usage and issue a warning if a
conflict is detected. Also earlier usages of this 'Hungarian Notation'
have largely been applied to compiled languages - rather strangely, in
the case of known types - rather than an interpreted one like Python. </p><p style="color:rgb(52,52,52);font-family:Gotham,'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:23.8px"><br></p><p style="color:rgb(52,52,52);font-family:Gotham,'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:23.8px">Please note that I have shown suffixes above but prefixes could also be valid. I am not sure about relying on 'type strings' <em>within</em> a variable name however.</p><p style="color:rgb(52,52,52);font-family:Gotham,'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:23.8px">Is this idea feasible, do you think?<br><br><br>Thanks ...<span class="HOEnZb"><font color="#888888"><br><br>Richard</font></span></p><p style="color:rgb(52,52,52);font-family:Gotham,'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:23.8px">PS Originally posted in <a href="https://intellij-support.jetbrains.com/hc/en-us/community/posts/207286145--Hungarian-Notation-and-type-checking" rel="nofollow" target="_blank">https://intellij-support.jetbrains.com/hc/en-us/community/posts/207286145--Hungarian-Notation-and-type-checking</a></p><p style="color:rgb(52,52,52);font-family:Gotham,'Helvetica Neue',Helvetica,Arial,sans-serif;font-size:14px;line-height:23.8px"><br></p></div></div></div></div></div></div>
<br>_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div>