|
Eela6 posted:Thanks! I picked up those tricks from Luciano Ramalho's Fluent Python and Brett Slatkin's Effective Python, respectively. "Functions should have as few arguments as possible" gets introduced on slide 41 but it probably belongs in the list of Function rules on slides 21-26. This is basically just another function rule, is it not? I think "needless identifiers" is a misnomer; _ is just a variable name like anything else. I understand that some people like to use _ to indicate "this variable is not used" but that's still an identifier. I'm not sure what to actually call it
|
# ? Feb 1, 2017 01:26 |
|
|
# ? May 8, 2024 05:15 |
Thank you. Good eye on slide 41 --> 27 Re: 'omit needless identifiers' - it's mostly there as a take on Strunk & White's famous 'omit needless words'. If I can come up with a better way to phrase the concept I will. '_' is just a variable name, but it's also a well-known Python idiom for 'don't worry about it'. It allows the reader to focus on the important identifiers. I also realized that this is way, way too long, so I'm going to split it into three more focused talks and try and give one a month. I tried 'giving' the speech in the car while stuck in traffic and it went over 40 minutes. Considering I have a 15-20 minute time slot, this needs a lot of cutting down. Thank you for your input.
|
|
# ? Feb 1, 2017 06:12 |
|
The use of _ to mean "this is an unused variable" is bad. Don't tell people to do that. If you need a variable that's unused, use the word "unused".
|
# ? Feb 1, 2017 10:56 |
|
Eela6 posted:Thanks! I picked up those tricks from Luciano Ramalho's Fluent Python and Brett Slatkin's Effective Python, respectively. `@timed` probably isn't a (simple) past tense verb, but a past participle here (possible resultative passives? not sure). (i.e., I assume you'd say @eaten vs. @ate?) `get_current_time()` is a verbal phrase, not just a verb. In principle, class names are deverbal nominalizations, specifically agent nouns. But I guess that's the one where people really stop caring. Sorry, I'm a linguist
|
# ? Feb 1, 2017 13:51 |
Thank you everyone for your feedback. Cingulate posted:
Thanks! I am sure you are right. I don't understand some of what you are talking about, so I will read more about parts of speech and correct my errors. You are dead right about @eaten vs @ate. I would use "eaten". Examples of "good" decorator names, from my point of view: code:
Obviously I wouldnt say "eated", I would say "eaten", but I'm having trouble thinking of other words that have that form change without the -ed ending. Hammerite posted:The use of _ to mean "this is an unused variable" is bad. Don't tell people to do that. If you need a variable that's unused, use the word "unused". I'm sorry, I disagree. It's a matter of... style. It is a super common python convention, recognized by most. IDEs. More importantly, I find the alternative visually noisy. Compare Python code:
If you still disagree that's fine, I certainly think it'd better to explicitly say "unused" rather than just have meaningless identifiers. But I like the underscore! Eela6 fucked around with this message at 15:29 on Feb 1, 2017 |
|
# ? Feb 1, 2017 15:17 |
|
Eela6 posted:Thanks! I am sure you are right. I don't understand some of what you are talking about, so I will read more about parts of speech and correct my errors. It's also convention in (at least) Ruby and Elixir as well as Python.
|
# ? Feb 1, 2017 15:39 |
|
Pretty much every language with pattern matching / tuple destructuring uses _ as the "ignore this, just a placeholder" value.
|
# ? Feb 1, 2017 15:41 |
|
Eela6 posted:Obviously I wouldnt say "eated", I would say "eaten", but I'm having trouble thinking of other words that have that form change without the -ed ending. See - saw - seen Speak - spoke - spoken Throw - threw - thrown Etc But most modern and most rare words should be regular. E.g. calculate, email etc.
|
# ? Feb 1, 2017 15:51 |
|
Hammerite posted:The use of _ to mean "this is an unused variable" is bad. Don't tell people to do that. If you need a variable that's unused, use the word "unused". Good lord no, _ as "ignore me" is convention. Naming a variable "unused" is worse than just naming it the intentionally-awkward-and-already-established-as-conventional name.
|
# ? Feb 1, 2017 18:02 |
|
I actually recently had this discussion at my job. I've been using _ in my code here and there (in Python) at work without anyone saying anything. Then, recently in a review, it was brought up that our only sr engineer didn't know why I was using it. I mentioned it was just convention for unused, and he told me it was not and that I should just prepend a variable name with an underscore if it wasn't going to be used. I was about to bring up that this would probably be confusing, since it is convention in Python to prepend things with underscores to denote that they are "private", not that they are unused, but then instead I gave up.
|
# ? Feb 1, 2017 18:11 |
|
The March Hare posted:and he told me it was not welp
|
# ? Feb 1, 2017 18:16 |
|
What are peoples thoughts on unicode variable names (e.g., Φ)? I do a lot of programming of equations that might have variables without physical meaning (no proper name) and are just a greek symbol. I will usually use an ascii representation of that variable because it is simpler to enter, but it is a little removed from the original reference.
|
# ? Feb 1, 2017 18:18 |
|
Yep, already brushing up on my binary trees and scoping new work. Not just for that, obviously, but it is indicative of the work environment. Not really where I want to be as a jr. Also, I assume ^ are joking, but why not just "phi"?
|
# ? Feb 1, 2017 18:18 |
|
accipter posted:What are peoples thoughts on unicode variable names (e.g., Φ)? I do a lot of programming of equations that might have variables without physical meaning (no proper name) and are just a greek symbol. I will usually use an ascii representation of that variable because it is simpler to enter, but it is a little removed from the original reference. If you're working in Python3 you should be fine, since source file encoding is UTF-8. If you're using 2.x, I think you need to declare the encoding like this (not 100%, I had to look it up) Python code:
Proteus Jones fucked around with this message at 18:52 on Feb 1, 2017 |
# ? Feb 1, 2017 18:50 |
|
accipter posted:What are peoples thoughts on unicode variable names (e.g., Φ)? I do a lot of programming of equations that might have variables without physical meaning (no proper name) and are just a greek symbol. I will usually use an ascii representation of that variable because it is simpler to enter, but it is a little removed from the original reference. I dunno...if I had to figure out how to type such a thing when working with your code, I'd hate you forever. However, I rarely do anything requiring me to type anything other than whats on my US keyboard. Maybe if your code is only ever going to be used by math people who routinely use unicode math symbols it'd be ok?
|
# ? Feb 1, 2017 19:01 |
|
flosofl posted:If you're working in Python3 you should be fine, since source file encoding is UTF-8. I know that it is possible. I am just wondering if it makes any sense. Thermopyle posted:I dunno...if I had to figure out how to type such a thing when working with your code, I'd hate you forever. This is my basic thought. Entering something that is not on the keyboard is painful so I have avoided it in the past.
|
# ? Feb 1, 2017 19:04 |
|
I would avoid it if it would cause any friction with someone else who might use your code.
|
# ? Feb 1, 2017 19:18 |
|
a witch posted:I would avoid it if it would cause any friction with someone else who might use your code. Please also note that "someone else" might be you in six months.
|
# ? Feb 1, 2017 19:19 |
|
No Safe Word posted:Good lord no, _ as "ignore me" is convention. Naming a variable "unused" is worse than just naming it the intentionally-awkward-and-already-established-as-conventional name. It's a bad convention. It's unnecessarily cryptic, and fails to be self-explanatory. On the other hand if you name a variable "unused", that's self-explanatory. Not only these objections, but also _ is used in the Python command line interpreter to refer to the object last evaluated, so it's giving something two different meanings for no good reason.
|
# ? Feb 1, 2017 19:23 |
|
_ is less garbage to read than unused.
|
# ? Feb 1, 2017 19:27 |
accipter posted:What are peoples thoughts on unicode variable names (e.g., Φ)? I do a lot of programming of equations that might have variables without physical meaning (no proper name) and are just a greek symbol. I will usually use an ascii representation of that variable because it is simpler to enter, but it is a little removed from the original reference. I think it's almost always a mistake to use non- I can also see doing it if you're writing mathematic or physics library functions. Don't have any of it face the public, but if you can get the internals of your function to line up with the established scientific notation, that can make it easy for someone deep in the field to 'check your work' and make sure you've implemented it correctly. If you want to show someone you've implemented an equation or algorithm, having your language be identical can be nice. But it's one of those things where if you have to ask, the answer is probably no. (I also will use greek identifiers when loving around on project euler on my own time. drat it, it's ϕ(n), not totient(n)!) Eela6 fucked around with this message at 20:17 on Feb 1, 2017 |
|
# ? Feb 1, 2017 20:12 |
|
Hammerite posted:It's a bad convention. It's unnecessarily cryptic, and fails to be self-explanatory. On the other hand if you name a variable "unused", that's self-explanatory. code:
|
# ? Feb 1, 2017 20:26 |
|
No Safe Word posted:
I'd use the second one but I'd put it in a helper function so I wouldn't have to look at it. I'm a bit baffled by the "internationalized" comment; are you saying you translate your program code into other languages?
|
# ? Feb 1, 2017 21:13 |
|
Hammerite posted:It's a bad convention. It's unnecessarily cryptic, and fails to be self-explanatory. On the other hand if you name a variable "unused", that's self-explanatory. I propose we rename 'zip' to 'as_tuples_by_index' because 'zip' is unnecessarily cryptic, and fails to be self-explanatory unless you already know what it's supposed to mean.
|
# ? Feb 1, 2017 21:17 |
|
If someone was typing "unused" instead of "_" I would immediately assume they were inexperienced with Python. Practicality beats purity and all that.
|
# ? Feb 1, 2017 21:23 |
IMO, the best way to do it is like this:Python code:
|
|
# ? Feb 1, 2017 21:24 |
|
Nippashish posted:I propose we rename 'zip' to 'as_tuples_by_index' because 'zip' is unnecessarily cryptic, and fails to be self-explanatory unless you already know what it's supposed to mean. There is some merit to this argument (unironically), but "zip" is at least a word. It doesn't do a great job of explaining what the function does though, you're right. It has always seemed to me that "transpose" or some variation on it would be a better name for zip.
|
# ? Feb 1, 2017 21:36 |
|
I'd passive-aggresively go and change every variable called "unused" to "_" because goddamn it's a super common convention and whether or not you realize it or not conventions matter...a lot!
|
# ? Feb 1, 2017 21:51 |
|
Join usssss
|
# ? Feb 1, 2017 23:01 |
|
Nippashish posted:I propose we rename 'zip' to 'as_tuples_by_index' because 'zip' is unnecessarily cryptic, and fails to be self-explanatory unless you already know what it's supposed to mean. I think 'zip' is actually pretty simple to understand if you've ever seen or used a zipper before
|
# ? Feb 1, 2017 23:31 |
|
QuarkJets posted:I think 'zip' is actually pretty simple to understand if you've ever seen or used a zipper before zip is intuitive if you know what it means, but if you'd never encountered it before you might not know what it did just from the name. My argument is that _ is the same.
|
# ? Feb 1, 2017 23:42 |
Nippashish posted:zip is intuitive if you know what it means, but if you'd never encountered it before you might not know what it did just from the name. My argument is that _ is the same. Absolutely. But both of them are powerful constructs that allow a programmer to convey their ideas more clearly to a fluent audience. Whenever you're writing anything, you have to consider your target audience. If I were teaching an intro to programming class, I would avoid things like closures or "yield from" or magic methods. I might even avoid zip and stick with enumerate and c-style indexing. But if I'm writing for python professionals, I use all of these conventions. Conventions allow us to express high-level ideas quickly and conveniently.
|
|
# ? Feb 2, 2017 00:06 |
|
Like...what do you gain by using the word "unused"? As far as I can tell the only thing you gain is readability by super-new programmers at the expense of making it harder to read for everyone else.
|
# ? Feb 2, 2017 00:20 |
|
Nippashish posted:zip is intuitive if you know what it means, but if you'd never encountered it before you might not know what it did just from the name. My argument is that _ is the same. But only one of those references something in the real world. The other is an arbitrarily-decided convention I'm not saying that _ is a bad convention, but your analogy is really weak
|
# ? Feb 2, 2017 00:37 |
|
It's also worth mentioning that _ is usually used as an alias for the gettext function so you're also committing the sin of shadowing a function with a variable, but _ is a terrible function name. Still, it's easy to get into trouble if you're working on code that uses this badly-named alias Pylint regards any local variable with an underscore in front of it (such as _unused, _foo, _bar) as unused, which seems like it's the most Pythonic solution Python code:
Note that _ isn't mentioned in PEP8 anywhere, I think it's the kind of convention that just kind of spread by word of mouth and is generally safe to ignore for those who want to ignore it
|
# ? Feb 2, 2017 00:55 |
|
No Safe Word posted:
This is the way to handle it: code:
|
# ? Feb 2, 2017 00:56 |
|
Dominoes posted:This is the way to handle it: You whippersnappers with your expanded tuple unpacking. *waves python 1.5.2 stick*
|
# ? Feb 2, 2017 02:06 |
As of yesterday, Anaconda released version 4.3 - which has Python 3.6 as a default! Now is a great time to start using Python 3.6. If you're not sold on Python 3.6, here's another excellent youtube video by Raymond Hettinger https://www.youtube.com/watch?v=p33CVV29OG8 explaining the amazing new dictionary implementation. Plus: Python code:
Eela6 fucked around with this message at 07:23 on Feb 2, 2017 |
|
# ? Feb 2, 2017 04:33 |
|
Eela6 posted:As of yesterday, Anaconda released version 4.3 - which has Python 3.6 as a default! Now is a great time to start using Python 3.6. Yay!
|
# ? Feb 2, 2017 04:59 |
|
|
# ? May 8, 2024 05:15 |
|
Thermopyle posted:Like...what do you gain by using the word "unused"? I've dragged this argument (in which I am clearly in the minority) out for too many posts already, but... I don't see that it does make it harder to read for anybody, irrespective of their level of experience.
|
# ? Feb 2, 2017 10:14 |