-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Variables, methods, objects #37
Comments
Are there specific examples of confusing variable names? I am wary of the suggested approach which is dangerously close to Hungarian notation and I think teaches bad habits. If there are places in the example code where we are clobbering scoped modules or other objects, then those should definitely be fixed. I'd be okay with a convention such a using a 'my' prefix (my_writer, my_integer, etc.) as is often used in tutorial and instructive contexts, but again would be wary of teaching an approach that sanctions "variablizing" the name. |
Here's an example from one of the scripts we did on Thursday: writer = csv.writer(output_file,delimiter=',') It's immensely confusing when "writer" is used in two different ways. I don't understand why it would be bad to "variablize" names. "my_writer", You guys have to remember that you need to help beginners by lowering the On Tue, Mar 15, 2016 at 4:18 PM, Scott Bradley [email protected]
MaryJo Webster |
@mjwebster, I don't think it's an issue to carry those |
I think in this example, |
I agree that we should use variable names that are not confusing, however Adriana data journalist +31-652245912 | 0F097E0F | @naberacka On Tue, Mar 15, 2016 at 4:30 PM, Scott Bradley [email protected]
|
I run into this problem quite frequently. Even if In the latter case, the variable name is not descriptive but this is one of those situations where a novice doesn't know better...in that if you use a verbose name for a variable that lives for 2 lines, you've greatly added onto the cognitive load. Novices need to get used to the fact that variables can be super simple, and, when seeing a super-simple variable, train yourself to focus on the next few lines. |
This is actually one of the issues I noticed myself as we were going through the class. I spend a lot of time thinking about short, declarative variable names as I write my code so that it is self-documenting. I noticed that we had at times single or double letter variables, used reserved keywords for variables or used singular variable names for lists and dictionaries. Now some of this may be up to a matter of personal taste, but I do feel we could be a bit clearer in our variables. In specific to the with open('example.csv','w') as outfile:
output = csv.writer(outfile)
output.writerows(rows) When I code I also try to avoid using the same variable name as another function, object or whatever in python, even if it is something that requires namespacing such as I also think we should talk about making variable names consistent across projects. Each one right now contains the personal preferences of the individuals that created the project. This is fine to some extent but I wonder if developing a convention that spans projects will make it easier for new coders to digest. The last point is that we are journalists; we can use our words to write short, declarative and self-documenting code - often I find quite a bit of joy in doing that. I personally would like to pass that on to new coders as they are learning Python. |
A small piece of feedback on PyCAR16 from @mjwebster:
I agree this is very confusing for newcomers to programming and to Python. Is there a way to simplify this, or to explain why we name the variable after the object created by the same-named method?
The text was updated successfully, but these errors were encountered: