Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
No Safe Word
Feb 26, 2005

Hammerite posted:

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.

If I see an underscore I know without any thought "oh, that's stuff that's not used". If I see anything else, I have to parse it. I also have to wonder "hmm, is it really unused? if this were just an underscore it would stand out elsewhere if somebody tried to use it, but somebody got cute and tried to use a name with semantic meaning for a throwaway variable"

So yeah, something you can immediately and without any conscious thought ignore is simpler

Adbot
ADBOT LOVES YOU

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

QuarkJets posted:

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

That's because it's a programming convention, not a Python convention. It's used in probably dozens of languages.


Hammerite posted:

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.

Because there's more cognitive overhead in reading a word vs recognizing an underscore. But mainly because everyone knows what a _ means, and then you come across some guy wanting to use "unused" and then you don't know wtf is going on. Did this guy really not know that everyone uses "_"? Maybe he did, so now maybe he means something different by "unused"?

lifg
Dec 4, 2000
<this tag left blank>
Muldoon

Thermopyle posted:

That's because it's a programming convention, not a Python convention. It's used in probably dozens of languages.

I do like this convention, but I don't see it much.

(And coming from 10 years in Perl World, the $_ variable is quite important, it's the implied default of many builtins.)

No Safe Word
Feb 26, 2005

lifg posted:

I do like this convention, but I don't see it much.
The most common other use I see in other languages is in pattern matching constructs like:

Haskell
O'Caml
F#

They all have the convention of "anytime we need a placeholder for bindings we will discard, use an underscore"

Fergus Mac Roich
Nov 5, 2008

Soiled Meat

lifg posted:

I do like this convention, but I don't see it much.

(And coming from 10 years in Perl World, the $_ variable is quite important, it's the implied default of many builtins.)

I know for sure it's used in Haskell and Rust, and I'm pretty sure it's used in Lisps as well(Scheme is the one I have in mind). Also you will notice that your linter will complain about your unused unused, but not about your unused _.

lifg
Dec 4, 2000
<this tag left blank>
Muldoon
Perl's way of ignoring return values is (oddly) obvious. You assign to the 'undef' keyword, which is like Python's None.

($a, $b, undef, undef, $c) = foo()

But I can get used to using _.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

No Safe Word posted:

If I see an underscore I know without any thought "oh, that's stuff that's not used". If I see anything else, I have to parse it. I also have to wonder "hmm, is it really unused? if this were just an underscore it would stand out elsewhere if somebody tried to use it, but somebody got cute and tried to use a name with semantic meaning for a throwaway variable"

So yeah, something you can immediately and without any conscious thought ignore is simpler

All of the advantageous aspects you attribute to the name "_" in this post apply equally to the name "unused", and all of the disadvantageous aspects you attribute to the name "unused" apply equally to the name "_". In your final sentence, you describe _ as "something you can ... without any conscious thought ignore", but this description applies equally to the word "unused"; if it is indeed unused then I may ignore it. The names "_" and "unused" make the same promise as to the irrelevance of the variable, assuming the reader is aware of the convention, and whichever is used it is equally easy or difficult to verify that the promise isn't broken.

Thermopyle posted:

Because there's more cognitive overhead in reading a word vs recognizing an underscore.

I disagree. There is no more cognitive overhead. However, I will recognise that whether one thing presents more, less, or same amount of cognitive overhead compared to another is down to individual perception, so what presents overhead to you may not present it to me, and vice versa.

A few times people have noted that the convention of using _ to refer to an unused variable exists in other languages than Python. This is true, and it is a bad convention in those languages too.

This will be my last post on this matter.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Hammerite posted:

I disagree. There is no more cognitive overhead. However, I will recognise that whether one thing presents more, less, or same amount of cognitive overhead compared to another is down to individual perception, so what presents overhead to you may not present it to me, and vice versa.

You seem to be unaware that there is psychological literature on the subject pointing out that there is an objective reality on symbol vs word recognition and it's not just a personal preference thing, but as you're not interested in continuing the discussion (and TBH, it's not really worth me digging up the cites) I won't go into it.

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

It's not even just a symbol though, it's literally squashing irrelevant stuff out of sight. Like redacting your code so you can focus the reader on the stuff that needs to be there.

It's such a neat solution that it's honestly hard to see why anyone would have a problem with it, unless they're just used to doing things a different way. Technical issues with using that symbol aside of course :frogbon:

Eela6
May 25, 2007
Shredded Hen
I'm trying to learn how to better write concurrent code. Does anyone have a slick example of concurrent code using the new python 3.6 syntax? Having a little trouble with the examples in the docs.

Edit: in addition, what are peoples' favorite packages?

Eela6 fucked around with this message at 05:12 on Feb 3, 2017

QuarkJets
Sep 8, 2008

Thermopyle posted:

That's because it's a programming convention, not a Python convention. It's used in probably dozens of languages.


Because there's more cognitive overhead in reading a word vs recognizing an underscore. But mainly because everyone knows what a _ means, and then you come across some guy wanting to use "unused" and then you don't know wtf is going on. Did this guy really not know that everyone uses "_"? Maybe he did, so now maybe he means something different by "unused"?

Okay you're exaggerating though, right? If you saw someone assign something to a variable named "unused" surely you wouldn't clutch your head in confusion, instead you'd probably think "oh this variable must not be used by anything" regardless of your experience level

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Maybe it's a boolean that contains information about whether something is used? Or a collection of unused things from a pool? Like, is the value you're assigning part of an object's state, or something you're going to be ignoring? You can make an assumption, but how sure are you without further investigation?

That's the nice thing about conventions, it gets everyone on the same page so you be pretty drat sure what's happening and what you can forget immediately. Thermo's making the point that when someone ignores a convention, you have to start asking why and you can't really rely on your assumptions anymore

QuarkJets
Sep 8, 2008

baka kaba posted:

Maybe it's a boolean that contains information about whether something is used? Or a collection of unused things from a pool? Like, is the value you're assigning part of an object's state, or something you're going to be ignoring? You can make an assumption, but how sure are you without further investigation?

That's the nice thing about conventions, it gets everyone on the same page so you be pretty drat sure what's happening and what you can forget immediately. Thermo's making the point that when someone ignores a convention, you have to start asking why and you can't really rely on your assumptions anymore

Neither of those arguments are working for me, as they both also apply against "_" and for "unused" respectively

The "_" character is even less descriptive than "unused", and so it could store literally anything. Case in point, _ is already aliased to the gettext function, and in the interpreter it maps to the value returned by the previous command. Even if the convention is to store unneeded data in "_", that doesn't necessarily make it a good idea; using a different convention might be better

I've seen "unused" used to hold unused returns many times, so apparently that is a convention as well, although possibly it's just more commonly used in scientific computing than in other fields. But still, it's conventional, so your point about the positives of convention applies to it as well.

I'd like to re-raise the idea of always labeling returned variables descriptively like you would have done anyway but prefixing those names with "_" when they're unused. Pylint already supports this, it's more explicit, it's more readable, and it still carries the benefits of conventions. It seems like this is the best of all possible worlds, the only downside being that you have to type a few more characters, which seems pretty negligible.

Eela6
May 25, 2007
Shredded Hen
The problem is that prefixing variables with a single underscore already means something by python convention. It's signifies a "protected" variable that's internal to the module and not meant to be used by a public consumer of the function. . If you wanted to postfix an unused variable with an underscore: EG, foo_, be my guest. But the single underscore prefix already has a meaning and you're actively going to confuse most python programmers by using it that way.

Further, that convention is recognized by the language itself in imports:
Ex:
Python code:

"""example.py"""
def _mystery():
    pass
def foo():
    pass
code:
from example import *
This will import foo but not _mystery

I use single underscore prefixes almost every single time I use classes, and it's used all over pretty much every library that I can think of. The use of underscores in python is a solidly established convention that's uniform throughout every book and PyCon talk I've ever seen.

Just glancing at my bookshelf, the following books uniformly use the underscore the way I describe it : fluent python, effective python, the python cookbook (2nd and 3rd ed) , test driven development in python, python machine learning.

Every single core developer I know of uses single underscores to prefix "protected" variables and the lone single underscore for unused variables, including Raymond Hettinger and Guido Van Rossum.

There's nothing wrong with the conventions that you suggest, if we were starting from a blank slate. But they're swimming upstream from python convention. I don't know where you picked up your approach, and it's fine if you want to use it for your own projects. But it is not pythonic, and it's trying to overturn a usage tradition at least a decade old.

This will be my last post on this issue.

Eela6 fucked around with this message at 06:29 on Feb 3, 2017

QuarkJets
Sep 8, 2008

Eela6 posted:

The problem is that prefixing variables with a single underscore already means something by python convention. It's signifies a "protected" variable that's internal to the module and not meant to be used by a public consumer of the function.

That's actually consistent though; just as you shouldn't use a variable marked as unused, you also shouldn't use a variable marked as "protected". So that's not a problem.

You also shouldn't want to import an unused variable, so that's all the more reason to label unused variables with leading underscores! I'm sure that "_" is already captured in this rule, and switching to using "_" as a prefix character wouldn't change the behavior, which is good.

So... no downsides so far except "it's not already the convention"

GobiasIndustries
Dec 14, 2007

Lipstick Apathy
Very little experience with programming person here. About a year ago I did a pre-release review for a new-to-javascript book that really made sense to me: the book was designed to build a game and while each chapter built on the previous one and toward the game, they also had end-of-chapter exercises for other tasks based on the lessons in that chapter. Are there any books on Python that are in this style? I want to start working with python for some IoT devices I have and learn best when I have something very structured but with clear examples on how what I'm learning can be applied elsewhere.

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

QuarkJets posted:

The "_" character is even less descriptive than "unused", and so it could store literally anything.

That's kinda the point though - it's as close to nothing as you can get without being whitespace. You're not bothering to name it, so there's nothing to read into. Visibly it may as well not be there, like a really low noise floor. It just works better at its intended function, being a hole to throw stuff in so the important info sticks out

That's not to say it's necessarily easier to understand the first time you run into it - pretty sure it confused me coming from Java - but that goes for a lot of things, and really it depends on your background too, what you're used to seeing and doing

I'm not saying you can't use a word if you want, and if that's the pattern already in use then even more reason to stick with it. But _ is great and if it's available to you without issues in your language, I definitely wouldn't recommend you avoid it. It's so clean and simple, the sooner it becomes at least a generally recognised convention the better imo

QuarkJets
Sep 8, 2008

But explicit is better than implicit, right? Doesn't _ go against that?

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

Flat is better than nested :v:

Honestly a lot of those rules seem better served by _. Sparseness, readability, one way to do things (in the sense you don't need to think of a context-appropriate name to convey 'unused', that's what _ is actually for).

I guess you can argue it's less explicit than a name, but that goes for a lot of sugar and basic language features. It's a tool to pick up like anything else, once you know it it's about as explicit as you can get

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
I know I said I'd mute myself on this, but there is a semi-related thing that occurred to me last night.

Weren't we supposed to be able to something like this at one point, or am I imagining it:

a, *, b = [1, 2, 3, 4, 5, 6]

(so a would be 1, b would be 6, and the middle elements go unassigned)

This would be the best of all possible worlds (if you don't give a name to something, then clearly it's unused)... but it doesn't work on 3.4.2 which is what I have installed on this machine. And searching for it I get a deluge of articles/questions about function args/kwargs/unpacking, so it's a bit difficult to look up.

I could have sworn they were adding syntax like this. Of course, it doesn't handle the case where you have just one argument you want to ignore, rather than a variable number. It would be good to be able to do something like

a, ~, b, ~, c = [1, 2, 3, 4, 5]

(pulling syntax out of my rear end, but the point is it's new syntax that wouldn't previously have been valid)

shrike82
Jun 11, 2005

a, *_, b = [1, 2, 3, 4, 5, 6] works

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

shrike82 posted:

a, *_, b = [1, 2, 3, 4, 5, 6] works

This is so small but it's definitely on my TOP 3 python3 favorite features. :3:

QuarkJets
Sep 8, 2008

baka kaba posted:

Flat is better than nested :v:

Honestly a lot of those rules seem better served by _. Sparseness, readability, one way to do things (in the sense you don't need to think of a context-appropriate name to convey 'unused', that's what _ is actually for).

I guess you can argue it's less explicit than a name, but that goes for a lot of sugar and basic language features. It's a tool to pick up like anything else, once you know it it's about as explicit as you can get

That's not what explicit means, there is no way that _ could be considered more explicit than a descriptive variable name. And again any argument you make about conventions (which you're now calling "a tool") applies equally well to using _ as a prefix (which is already a convention/tool in pylint).

I'm not sure why you're against using _ as a prefix for marking unused variables, it's already an in-use convention, it's in accordance with the other ways that underscores are usually used, and it's friendlier to people on the outside who may have never seen the convention before (such as C programmers).

QuarkJets fucked around with this message at 13:19 on Feb 3, 2017

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

shrike82 posted:

a, *_, b = [1, 2, 3, 4, 5, 6] works

I'm aware of that, but as I remarked, not having to give the variable a name is the best solution.

Dominoes
Sep 20, 2007

Hey dudes. How do I make pip work with Ubuntu on Python 3.6? Ie pretend I'm an idiot and need basic instructions.

I've been using Anaconda for a while on Windows and Ubuntu. Thought I'd try 3.6 on Windows, so uninstalled Anaconda, and got 3.6 up and running smooth by installing packages with pip from a requirements.txt, and a few from Chris Gohlke's site.

Trying on Ubuntu, now, and it's a mess. There's a beta in the official packages you can run with 'python3.6', and a source dist on python's site that I can get sort of working (make works, but make install crashes, and it sort of works, but the files are in th wrong place?), and there are some unofficial repos. In all cases, I can't get pip to work with the 3.6 install. Any ideas, other than going back to Anaconda? The main issue seems to be having 3 version of Python floating around.

The command 'python3.6 -m pip...' results in an error: 'ModuleNotFoundError: No module named 'pip._vendor'



edit: After experimenting with the default 3.5 setup, the amount of packages that won't install with pip's about the same as on Windows! Rather than CG's site, these can be installed with 'sudo apt install'.

Packages that install with pip in Win and Ubuntu:

code:
# Scipy stack
numpy  # mkl??
pandas
matplotlib
jupyter
sympy


# Science extras
pandas-datareader
numba  # once llvmlite's installed from a binary
scikit-image
pillow
seaborn


# Misc
requests
requests_oauthlib
pytest
toolz
cytoolz
beautifulsoup4
lxml
sqlalchemy
Packages that install with pip on Ubuntu but not Win:
code:
scikit-learn
h5py
Packages that install with pip on Win but not Ubuntu:
code:
PyQt5
psycopg2
Scipy won't install on either.

Dominoes fucked around with this message at 15:42 on Feb 3, 2017

baka kaba
Jul 19, 2003

PLEASE ASK ME, THE SELF-PROFESSED NO #1 PAUL CATTERMOLE FAN IN THE SOMETHING AWFUL S-CLUB 7 MEGATHREAD, TO NAME A SINGLE SONG BY HIS EXCELLENT NU-METAL SIDE PROJECT, SKUA, AND IF I CAN'T PLEASE TELL ME TO
EAT SHIT

QuarkJets posted:

That's not what explicit means, there is no way that _ could be considered more explicit than a descriptive variable name. And again any argument you make about conventions (which you're now calling "a tool") applies equally well to using _ as a prefix (which is already a convention/tool in pylint).

I'm not sure why you're against using _ as a prefix for marking unused variables, it's already an in-use convention, it's in accordance with the other ways that underscores are usually used, and it's friendlier to people on the outside who may have never seen the convention before (such as C programmers).

I mean that once you realise _ is specifically used as a junk variable for values that are ignored, your intent becomes explicit when you use it. I'm talking about the wider convention, which in some languages gives _ special privileges (like reuse or exemption from unused checks) because it has that specific function, which is why I'm calling it a 'tool'. It allows you to do a specific thing in a neat, widely* recognised way, in multiple languages

I don't have any problem with using it in prefixes or whatever!

* for some definition of 'wide' anyway

Eela6
May 25, 2007
Shredded Hen

Dominoes posted:

Hey dudes. How do I make pip work with Ubuntu on Python 3.6? Ie pretend I'm an idiot and need basic instructions.

I've been using Anaconda for a while on Windows and Ubuntu. Thought I'd try 3.6 on Windows, so uninstalled Anaconda, and got 3.6 up and running smooth by installing packages with pip from a requirements.txt, and a few from Chris Gohlke's site.

Trying on Ubuntu, now, and it's a mess. There's a beta in the official packages you can run with 'python3.6', and a source dist on python's site that I can get sort of working (make works, but make install crashes, and it sort of works, but the files are in th wrong place?), and there are some unofficial repos. In all cases, I can't get pip to work with the 3.6 install. Any ideas, other than going back to Anaconda? The main issue seems to be having 3 version of Python floating around.

The command 'python3.6 -m pip...' results in an error: 'ModuleNotFoundError: No module named 'pip._vendor'



edit: After experimenting with the default 3.5 setup, the amount of packages that won't install with pip's about the same as on Windows! Rather than CG's site, these can be installed with 'sudo apt install'.

Packages that install with pip in Win and Ubuntu:

code:
# Scipy stack
numpy  # mkl??
pandas
matplotlib
jupyter
sympy


# Science extras
pandas-datareader
numba  # once llvmlite's installed from a binary
scikit-image
pillow
seaborn


# Misc
requests
requests_oauthlib
pytest
toolz
cytoolz
beautifulsoup4
lxml
sqlalchemy
Packages that install with pip on Ubuntu but not Win:
code:
scikit-learn
h5py
Packages that install with pip on Win but not Ubuntu:
code:
PyQt5
psycopg2
Scipy won't install on either.

Scipy is notoriously finicky. My honest advice is to start with anaconda and expand on it with pip from there. I know that's not what you want to hear, but it's probably the easiest solution. The good news is Anaconda is finally up and running with Python 3.6!

I will ask my linuxhead / devops buddy about it on his lunch break.

Dominoes
Sep 20, 2007

Eela6 posted:

Scipy is notoriously finicky. My honest advice is to start with anaconda and expand on it with pip from there. I know that's not what you want to hear, but it's probably the easiest solution. The good news is Anaconda is finally up and running with Python 3.6!
You're right, that would be the easiest solution. This is more of a curiosity. Since switching to stock Python on Win, I appreciate having one package man instead of 2. I've gotten burned a few times with Anaconda when trying to manually update one package that breaks another, and Qt version headaches. It's a wash either way.

Dominoes fucked around with this message at 12:53 on Feb 4, 2017

vikingstrike
Sep 23, 2007

whats happening, captain
For scipy I remember when building from source it can be really picky about the compiler version and flags that are being used. Not sure if this helps you any. :/

Dominoes
Sep 20, 2007

Thx. It installs fine from CG's site on Win, and sudo apt install on Ubuntu; I was hoping it'd work with pip, now that pip supports binary wheels.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

QuarkJets posted:

Okay you're exaggerating though, right? If you saw someone assign something to a variable named "unused" surely you wouldn't clutch your head in confusion, instead you'd probably think "oh this variable must not be used by anything" regardless of your experience level

No, I'd think "this variable is probably unused, but I can't be sure of that because everyone knows you use '_' for unused variables". Then, I'd either have to trace code to see if it's really unused or if it's a boolean for something in the code that indicates whether the business logic needs to know if something is unused, or I'd just hope it's just some rear end in a top hat bucking convention on principle or some newbie who doesn't know the convention...and even in the latter case I'd still never be sure until I actually traced through the code.


People can make all sorts of arguments about whether '_' is appropriate or not based upon other usages of '_' in Python...but it doesn't matter, '_' won and everyone knows what it means when you see something assigned to it. It's 100% clear unless you're a newbie. 'unused' or whatever is not.

Nippashish
Nov 2, 2005

Let me see you dance!
Its almost like clarity of different conventions depends on which conventions you're used to seeing and using yourself.

Nah, there's definitely a universal objective answer.

Cingulate
Oct 23, 2012

by Fluffdaddy

Nippashish posted:

Its almost like clarity of different conventions depends on which conventions you're used to seeing and using yourself.

Nah, there's definitely a universal objective answer.
Conventions aren't objective or universal, but they're generally accepted by, well, convention.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Nippashish posted:

Its almost like clarity of different conventions depends on which conventions you're used to seeing and using yourself.

Nah, there's definitely a universal objective answer.

I don't thins there's a universal truth, but then again that doesn't have anything to do with my point.

Are there code bases where unused is used instead of_? Sure, probably.

Is that the norm, or you might say...the convention? No. And that means the code base has extra on-boarding costs for additional developers.

QuarkJets
Sep 8, 2008

Nippashish posted:

Its almost like clarity of different conventions depends on which conventions you're used to seeing and using yourself.

Nah, there's definitely a universal objective answer.

This. Even just in this thread we've seen several posters who had either not seen the "_ as unused" convention, had seen a similar but different convention, or who knew of the convention but don't use it because they think that a different convention is better. These all seem like okay states to be in and I don't see anything wrong with someone using an alternative if they think that's better, especially when that alternative is already recognized in pylint

We are talking about something that is usually inconsequential (variable name) that contains something that is definitely inconsequential (unused return value) so maybe it's just more important that a codebase is internally consistent than that it aligns with an unstated convention ported over from other languages?

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

QuarkJets posted:

This. Even just in this thread we've seen several posters who had either not seen the "_ as unused" convention, had seen a similar but different convention, or who knew of the convention but don't use it because they think that a different convention is better. These all seem like okay states to be in and I don't see anything wrong with someone using an alternative if they think that's better, especially when that alternative is already recognized in pylint

We are talking about something that is usually inconsequential (variable name) that contains something that is definitely inconsequential (unused return value) so maybe it's just more important that a codebase is internally consistent than that it aligns with an unstated convention ported over from other languages?

I think this is the first time this argument has been brought up against the "_" in this discussion which seems odd if it's the best argument or right-est argument.

I also don't think it's an accurate characterization of the ubiquity of '_', nor accuracy of pylint. But pinning down both of those things is the only way to go forward with this conversation, and I certainly don't think that's an easy thing to quantify, I don't guess there's anywhere else to go because I certainly am not interested in spending the time quantifying the ubiquity of '_', nor whether pylint's rules say anything about that ubiquity.

Regardless, I don't think anyone would argue against staying consistent with an already existing codebase...using a style different from the existing codebase is even worse than not using '_'.

Thermopyle fucked around with this message at 02:45 on Feb 5, 2017

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

In other news I've been spending some time recently converting a bunch of bash scripts to python because gently caress bash.

I came across the plumbum library that's pretty neat for easing this type of work.

code:
>>> from plumbum import local
>>> ls = local["ls"]
>>> ls
LocalCommand(<LocalPath /bin/ls>)
>>> ls()
u'build.py\ndist\ndocs\nLICENSE\nplumbum\nREADME.rst\nsetup.py\ntests\ntodo.txt\n'
>>> notepad = local["c:\\windows\\notepad.exe"]
>>> notepad()                                   # Notepad window pops up
u''                                             # Notepad window is closed by user, command returns
code:
>>> chain = ls["-a"] | grep["-v", "\\.py"] | wc["-l"]
>>> print chain
/bin/ls -a | /bin/grep -v '\.py' | /usr/bin/wc -l
>>> chain()
u'13\n'
...and a ton of other features.

Space Kablooey
May 6, 2009


Thermopyle posted:

I came across the plumbum library that's pretty neat for easing this type of work.

I mean, gently caress bash and that's a really sexy API, but I feel like this is just hiding the bash under a Python rug and calling it a day.

QuarkJets
Sep 8, 2008

Thermopyle posted:

I think this is the first time this argument has been brought up against the "_" in this discussion which seems odd if it's the best argument or right-est argument.

I also don't think it's an accurate characterization of the ubiquity of '_', nor accuracy of pylint. But pinning down both of those things is the only way to go forward with this conversation, and I certainly don't think that's an easy thing to quantify, I don't guess there's anywhere else to go because I certainly am not interested in spending the time quantifying the ubiquity of '_', nor whether pylint's rules say anything about that ubiquity.

Regardless, I don't think anyone would argue against staying consistent with an already existing codebase...using a style different from the existing codebase is even worse than not using '_'.

:ughh:

Pylint recognizes other conventions as being okay, why won't you?

Adbot
ADBOT LOVES YOU

Tigren
Oct 3, 2003

Thermopyle posted:

In other news I've been spending some time recently converting a bunch of bash scripts to python because gently caress bash.

I came across the plumbum library that's pretty neat for easing this type of work.

code:
>>> from plumbum import local
>>> ls = local["ls"]
>>> ls
LocalCommand(<LocalPath /bin/ls>)
>>> ls()
u'build.py\ndist\ndocs\nLICENSE\nplumbum\nREADME.rst\nsetup.py\ntests\ntodo.txt\n'
>>> notepad = local["c:\\windows\\notepad.exe"]
>>> notepad()                                   # Notepad window pops up
u''                                             # Notepad window is closed by user, command returns
code:
>>> chain = ls["-a"] | grep["-v", "\\.py"] | wc["-l"]
>>> print chain
/bin/ls -a | /bin/grep -v '\.py' | /usr/bin/wc -l
>>> chain()
u'13\n'
...and a ton of other features.

That does seem fun, but why not learn the Standard Library os module and rely on subprocess when needed? They're already included for you.

  • Locked thread