3 ms·
# Map from user ID to User object. userIdMap = {} Or as I would write this: userIdsToUserObjects = {} Ctrl + n in vim completes this easily, so I don
by devishard 11y ago
# Map from user ID to User object.
userIdMap = {}
Or as I would write this:
userIdsToUserObjects = {}
Ctrl + n in vim completes this easily, so I don't care how long the name is.
I agree about the general point of the article, being strong in one language, but poor naming will bite you in any language. Comments are apologies for bad code: only write comments when you can't write better code.
- catnaroek 11y agoAlgorithmically tricky code is going to need as much explanation as you can provide, no matter how good your variable names are.
- stickfigure 11y agoI split my time between Java and less-typed languages, and what always annoys me is: messagesByUser = {} Is the key a user id, username, a user object, some sort of stripped down user hash, what? What about the messages? If you try to cram all this information into the variable name then you've invented a perverse form of hungarian notation. And of course you lose all that precious type information every time you pass it off to a function. Python is my go-to crutch for quickie projects that will never grow beyond a few hundred lines of code. Anything more complicated needs a typechecker. I only wish Java's was more robust.
- aryamaan 11y agoWhat do you mean by more robust?
- anon4 11y agoA suggestion, you should use the form valueTypeFromKeyType. The key is always on the right side and the value on the left side. This also applies to conversion functions - myFoo = fooFromBar(myBar); I find that makes the code easier to read than myFoo = barToFoo(myBar);