GithubHelp home page GithubHelp logo

Variables, methods, objects about pycar HOT 7 OPEN

ireapps avatar ireapps commented on July 28, 2024
Variables, methods, objects

from pycar.

Comments (7)

zufanka avatar zufanka commented on July 28, 2024 1

I agree that we should use variable names that are not confusing, however
if I'm not mistaken, using "writer" for csv.writer is sort of a convention.
So I think we also just might explain that while variable names are
arbitrary, some are conventional: as one is going to come across the
conventions further in the documentation and StackOverflow as well

Adriana

data journalist

+31-652245912 | 0F097E0F | @naberacka

On Tue, Mar 15, 2016 at 4:30 PM, Scott Bradley [email protected]
wrote:

I think in this example, my_writer = csv.writer ... would be fine. The
use of "my" variables is something of a tutorial mainstay that I am ok
with. The primary point of these in instruction or tutorial is to make it
clear that the name is arbitrary (although we might have to explain that
point up front.) What I maybe was not clear about is that I am wary of a
"v" or "var" prefix notation or similar that introduces a vague concept of
typification of variables. It's not really quite the same thing as
Hungarian style prefixes, but is close enough in concept that I have a bit
of a knee jerk reaction against it. It seems both non-pythonic and regarded
as poor practice in the industry. This may be a case where it's worth the
trade-off, but I think maybe just using "my_" variables would clarify
enough without introducing bad habits.


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#37 (comment)

from pycar.

scott2b avatar scott2b commented on July 28, 2024

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.

from pycar.

mjwebster avatar mjwebster commented on July 28, 2024

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",
"my_integer" etc would be useful. Why would this be a "bad habit"? Does it
wreck the code somehow? Is it just that it requires extra typing?

You guys have to remember that you need to help beginners by lowering the
bar a little bit. Yes, maybe it's easy for you to figure out what's a
variable and what's not because you've been doing this for awhile. But it's
not so easy for a beginner and based on the questions in last Thursday's
class, I don't think I was the only one struggling with this. I've tried
-- on my own -- to convert other people's sample scripts for my own use,
and figuring out what's a variable and what's not was nearly impossible
being a beginner at this. And, as with most things, cribbing from existing
scripts is one of the best ways to get started learning just about
anything. You had several people in last Thursday's class who said they
were "repeaters" because they didn't grasp it the first time around. Maybe
lowering the bar a little would help reduce that.

On Tue, Mar 15, 2016 at 4:18 PM, Scott Bradley [email protected]
wrote:

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.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#37 (comment)

MaryJo Webster
[email protected] [email protected]
651-491-6576
@MaryJoWebster

from pycar.

richardsalex avatar richardsalex commented on July 28, 2024

@mjwebster, I don't think it's an issue to carry those my_<whatever> conventions forward from the basics section into the first project. I appreciate the suggestion. I think @scott2b was just making the point that it has the capability to make the code less readable as things get more complicated, but this might not really matter for beginners who are just starting to grasp some of the concepts.

from pycar.

scott2b avatar scott2b commented on July 28, 2024

I think in this example, my_writer = csv.writer ... would be fine. The use of "my" variables is something of a tutorial mainstay that I am ok with. The primary point of these in instruction or tutorial is to make it clear that the name is arbitrary (although we might have to explain that point up front.) What I maybe was not clear about is that I am wary of a "v" or "var" prefix notation or similar that introduces a vague concept of typification of variables. It's not really quite the same thing as Hungarian style prefixes, but is close enough in concept that I have a bit of a knee jerk reaction against it. It seems both non-pythonic and regarded as poor practice in the industry. This may be a case where it's worth the trade-off, but I think maybe just using "my_" variables would clarify enough without introducing bad habits.

from pycar.

dannguyen avatar dannguyen commented on July 28, 2024

I run into this problem quite frequently.

Even if writer is the convention when referring to some "writer" class, it is way too easy for a novice (and intermediate-level) to either conflate or mistake csv.writer with writer, when writer is a label that is completely arbitrary. I like using csv_writer if I feel like being explicit. Or, cw.

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.

from pycar.

esagara avatar esagara commented on July 28, 2024

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 writer issue, here is how I normally approach that:

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 csv.writer. For experienced coders its probably difficult for us to overwrite that function by accident (though I have done it), but it is confusing and can make the code harder to read.

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.

from pycar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.