« first day (3534 days earlier)      last day (1397 days later) » 

12:26 AM
Why does the __init___ method have self as an argument?
 
12:37 AM
@jigglypuff It gets the class instance as an arg, complete with any class attrs and methods? If in the __init__ I have self.var = self.class_var + self.modify_arg(var_passed_to_init), it needs access to class_var, as well as the modify_arg method, which it will find in...*itself* via the reference to self if I understand correctly.
 
okay that makes sense, so it's as if it creates an instance already before __init__ to access those class attrs and methods as you say
thanks
 
I think it's more like it takes a 'blank' template from the class definition (which has all the things I said), then it 'initialises' that template with instance variables etc rather than that there's 'already an instance', but yes, the details from the definition are there before __init__ runs, or can be run, since the __init__ method itself is part of that definition.
 
 
3 hours later…
user13682510
3:18 AM
will there be any consequence for users whose comments are always flagged for no longer needed? like they never clean up after themselves.
 
3:33 AM
@joshua no. "not needed" is fine. only see consequences if its repeated flags of spam or abuse or unfriendly
 
user13682510
4:01 AM
@LinkBerest So there's ABSOLUTELY nothing stackoverflow does to encourage cleaning up after one's self?
 
user13682510
oof
 
4:20 AM
well, I delete my own comments as "no longer needed" all the time (like when I ask the OP to add details, code, etc) to the post and they do - that comment is not needed. Sometimes I get busy (esp. when timezones mean I'm not on at the same time as OP) and others delete it for me - this is also okay. "no longer needed" doesn't mean someone failed to do something - it means something changed and that comment is just...not...needed. So I definitely agree on not adding negative consequences here
 
^^ What they said. No consequences whatsoever for having your comments flagged as "no longer needed". However, moderators do notice users who repeatedly engage in lengthy discussions in the comments section, and we do reach out to those users in hopes of modifying their behavior.
 
That's kinda why SO was so nice when I first started using it (and still today): it was the only code site I saw where the community could edit and improve stuff (this was huge compared to the forums where you had to wait and hope OPs would show back up and edit) and really helped it be the place for finding "good" answers
 
We especially don't want to start assigning any penalties to "no longer needed" flags, as we don't want to discourage anyone from flagging comments that have become, for whatever reason, "no longer needed".
@LinkBerest This, among many other reasons.
Have you ever heard anyone say that SO is really nice because you can give handwashing emojis? Me neither.
 
Yeah, I had a discussion with Shog on Tavern once about using Java Ranch with Java 2 and the nightmare finding information on Collections was at the time (ah, memories)
 
@LinkBerest Lowering close votes to 3 was a sustained effort with support from several staff members at the time, including moderators (ahem), who pushed it forcefully. Shog9 and Megan Risdal were the main employees who got it going.
 
4:30 AM
yeah, I remember it being Shog's answer (or maybe it was just a bunch of comments) that pushed some of the nay-sayers over to the "okay, lets try it side" but then how often has this been the case?... sigh now this without Jon, Shog, or Tim (he's at least not listed as a CM anymore) - oi
The teams literal reaction: "we wanted to use SE to avoid all the Slack level chatting that happens and steals focus from work - why would we want this?" — LinkBerest 25 mins ago
 
Tim still works for the company. He's just been promoted to a director-level position, which is why he's not a CM anymore.
 
ah, well mazel tav - that I can say is very deserved
 
@LinkBerest Already upvoted that one. :-) Although, to be fair, this "reactions" feature has been on Teams for quite some time. I had complained about it in private channels, expressing my worst fears that it would be rolled out to main, and I distinctly remember being reassured that it wasn't (or, at least, wasn't "planned").
 
yeah, the two companies (or to be more accurate government agency teams) decided on Stack over Slack mostly because of that during the whole Covid remote-work change over (literally, regulations make "reactions" sit in a weird "does this met regulation, orders, and requirements" status - which directly state "no social media platforms for communication"). They might be changing off Stack to MS Teams now just because of this so its been a bit of a discussion
 
@LinkBerest Ah, wow. Yeah, those are the kind of data points that SE needs... Make it much more visible than a comment, please.
That also just drove me to your profile in hopes of figuring out which government. Apparently the US. Also, apparently this is a sockpuppet account that is a shadow of your former self. Pardon me if I don't know the history.
 
4:37 AM
in my class methods, should I return some value and assign to a self variable in the __init__ or just assign the variable immediately in the class method when __init__ calls it? Pedantic I know but just wondering what others would do.
 
@CodyGray ehh...more I just had two at one time - this one had my name attached for resume but I also asked on Workplace and Academia and others where I didn't quite want my real name showing up (it had far more rep on SO - this one had far more rep on WB.SE but my real name at one time - so I kept it)
was mostly after the firings - that just peeved me off enough to delete one
 
___init__(self):
self.name = self._get_name()

vs.

___init__(self):
self._set_name() # self.name is assign in the function
 
__init__ should not return a value in most cases
 
Does one of those examples return a value?
 
no, sorry the format got messed up
 
4:46 AM
Yeah, code formatting in chat is sub-optimal.
 
I'm leaning towards the first one as it makes it obvious what attributes the object will have
otherwise you have to dig through the class methods to find all attributes
 
Hmm. Second looks more DRY to me. But I shouldn't really be commenting, because I'm not even a Python programmer.
If only not knowing what you're talking about stopped one from having an opinion...
 
by that I mean - init should not return a value besides None so set_name is better than get_name which would imply a returned value (so use the second one)
It is also more DRY and SOLID if you want (good class principles are still good class principles in Python just may look weird to C++ people :P ;)
@CodyGray technically I'm a Java programmer who just uses a lot of Python for analysis/data flows so :P
 
I had to ask someone the other day in here what the syntax is for a comment in Python, so I think you still beat me.
Java is another language that looks quite funny to C++ people.
 
5:02 AM
Well, C++ looked really weird when I came to it from BASIC and COBOL so there ;p :)
@CodyGray I don't see a place to put it and honestly if I started a new Meta question it feels like it will become a "oh, you just want to say your leaving" (I mean we are but at this point it may just be seen as sour grapes and ignored by SE) - I'll leave it to the team lead to email SE or whatever if she wants
 
@LinkBerest Perhaps as an answer to the announcement of the "reactions"/"thanks" feature that just got posted. A "no thanks, please, thanks" answer.
 
maybe, I'll think about it (and ask the team, someone else might want to do it but I don't think anyone else actually uses SO - at least if you mean "asks or answers questions")
anyway, I'm off for the night - rbrb and always nice to chat Cody :)
 
5:38 AM
@AndrasDeak quick, write a bug report. If you word it right, they might get an intern to fix the code instead of the docs.
@jigglypuff __new__ constructs the instance, i.e. it creates self based on cls. __init__ initialises the existing instance.
@jigglypuff assigning them to self inside __init__ should be the preferred approach. Makes it clear that __init__ is self-contained, even if some of its logic is factored out.
Though consider that if your initialisation is so complicated it has to be split into multiple pieces, perhaps the class itself should be split. There are veritable cases where this is needed, though, mostly classes representing data structures – for example, I had a Graph class where each different input type (adjacency matrix, adjacency list, edges, ...) was normalized by a separate method.
 
 
1 hour later…
7:13 AM
@MisterMiyagi *I can fix the check :P
 
Go for it! What could possiblalaly go wrng?
*proceeds to change UID mapping in the batch farm*
 
7:30 AM
@MisterMiyagi ok thanks, yes it makes more sense to assign to self for me too
that way the function is reuseable as well without having to worry about a self variable being assigned again
 
8:01 AM
I'm thinking of adding covariant and contravariant parameters to my is_instance function. Would this be intuitive or nah?
>>> is_instance(True, int)
True
>>> is_instance(True, int, covariant=False)
False
>>> is_instance(3, bool, contravariant=True)
True
 
I think covariant/contravariant is never intuitive, so.... :P
How about is_instance(True, int, invariant=True)?
That word has much less wiggle room.
 
Would the invariant parameter replace covariant and contravariant? Or is it an addition to those
also, is_instance(X, Y, invariant=True) is just type(X) is Y, isn't it
 
8:17 AM
yeah, it is.
It would replace covariant=False, since isinstance by default checks for subclasses, not baseclasses.
The contravariant check is more complicated to emulate with regular means, that one may have merrit as well.
By the way, I'm wondering whether it is helpful to explain co/contravariance via assignments.
 
Hmm. But then what would invariant=True, contravariant=True be? That's a contradiction, isn't it?
 
target: T_contra = source: S_co
@Aran-Fey yep. Can't have both.
uh, I know. Use an enum! super ergonomic! /sarcasm
 
TypeVars use covariant and contravariant parameters, so I figure I'll stick to the same interface
I'm still wrapping my head around that assignment, but contravariance also doesn't seem terribly difficult to do: is_instance(X, Y, contra=True) == is_subtype(Y, type(X), co=True)
Definitely requires more brain power than invariance though
I don't think assignments need two typevars. Isn't target: T_co = source enough?
 
it's just for making clear which way you can wiggle the types without things going kaput. source: S_Co isn't valid syntax, TBH.
it's just the most common case that probably everybody uses, and just silently accepts contravariance.
As in, you can assign an OrderedDict to d: OrderedDict, to d: dict, and to d: MutableMapping without anyone breaking a sweat.
 
Ah, I think I see what you were going for. T_contra means you can change a target: bool to target: int, and S_co means you can change target = 3 to target = True
got it
 
8:32 AM
yeah, I feel it's the normal type wiggling we all accept to just make sense.
still haven't pondered it completely, yet
but it helps that you don't run away, screaming ^^
main problem: The builtin types have such a flat hierarchy that there aren't many base/subclass relations to demonstrate.
bool <: int is an abomination, so I'd like to avoid that as an example
 
you still have int <: float <: complex
although int being considered a subclass of float may be surprising at first
 
yeah, there are some corner cases that make that ugly as well.
then again, most people probably don't care about these
alright folks. I love black for code formatting. But having a draft PR build fail because of one missing comma is a waste.
 
come to think of it, we actually have a pretty extensive class hierarchy built in - exceptions
 
9:01 AM
@jigglypuff Yes. I see that MisterMiyagi has already mentioned this, but it bears repeating. ;) The __init__ method is not the constructor, it's the initializer. The constructor is __new__, it's the method which returns the new class instance. You rarely need to define a __new__ method yourself, your class can be constructed using the __new__ that it inherits. When __new__ returns, __init__ is automatically called, if it exists.
 
it's weird when someone writes "you rarely need <X>" while I'm fiddling with <X> for an hour.... :P
@Aran-Fey obligatory pessimism: are people actually aware that Exceptions work via inheritance?
 
9:16 AM
Well, they must be aware that there's a hierarchy at least. Even if they don't know it's done via inheritance, it shouldn't be too hard to connect the dots once you bring it up
 
@MisterMiyagi :) Of course, if you're playing with metaclasses, or subclassing immutable built-in types, you do need to mess with __new__. But those things fall into the category of "if you have to ask 'do I need this stuff?' you probably don't need it".
@jigglypuff Indeed. Although you can initialize instance attributes in any method, it makes your class more readable if you initialize them all in __init__. Sometimes, you can't assign the desired value to some attribute when __init__ is executing. In that situation, you may like to assign None (or some other placeholder) to that attribute.
 
9:36 AM
@PM2Ring cool, that explains everything, thanks
 
 
2 hours later…
11:51 AM
Discovered another github issue that's almost 2 months old. Github definitely isn't showing me any notifications for these...
 
well, was it important?
 
fortunately not
 
You should be notified
Did you accidentally mute the repo or something?
Or set your spam settings too strict
 
I blocked emails, but there should be notifications directly on github... right?
Apparently I've only been "watching" 4 out of my 15-ish repos
 
I don't think I've ever seen a github notification :)
Where do they live?
 
12:06 PM
well that explains a lot then :/
 
@AndrasDeak the upper right corner of the UI. There's a bell...
 
@MisterMiyagi if it needs some kind of integration that might explain it
I reject nagging banners for notifications
We complete each other with Aran :P
 
Maybe I should take this opportunity to clean up... take down all the unfinished/undocumented stuff (i.e. everything... except the SO dupe manager, I guess)
 
I see a bell. It's just a bell. And there's a blue circle on my avatar that says "feature preview".
my inbox is completely empty
I guess it either doesn't apply to contributors, or I have them disabled
 
so is mine. New issues don't even show up there, apparently
Ugh, some of my half-finished projects have half-finished documentation. That's not good. That's it, I'm purging everything
 
12:13 PM
@Aran-Fey check settings -> notifications
I've got "web and mobile" ticked out all around
there's also "automatically watch repositories" (which I do and it works)
 
I enabled the "automatically watch" thing recently. I guess it doesn't apply retroactively
 
I wouldn't do that, yeah
 
@AndrasDeak Bingo! Why is email active per default but web isn't -.-'
 
I like that choice ;)
but these days it sounds like the less preferred
 
Whew, that's better. RIP my 2 github stars
Hmm, I guess the guy who I just responded to will get an email that directs him to a 404 page now. Oh well.
 
12:30 PM
did you close the issue?
 
umm... no, I don't think so
 
heh
 
why, what does it matter?
 
well if you'd closed it they would have seen that too in an email notification :)
 
He asked me what the point of the repo was - it was a good question, because I'd been wondering the same thing. When he sees the repo gone, I hope he won't think he bullied me into deleting it...
 
12:36 PM
if you responded something reasonable they probably won't
 
Well, he can't see the response anymore, can he? Or is the text included in the email?
 
latter, by default
 
oh, good
 
I get emails of code reviews and everything
 
1:35 PM
Today I learned that, as of a year ago, the sums of three cubes problem had been solved for every integer between 1 and 100, except for 42.
It seems fitting that they threw an astronomical amount of computing power at the problem of "the answer is 42, now find the question"
I have a great deal of fondness for problems that require a million hours of number crunching, to discover a solution that can be written down on a post-it note and verified with a four function calculator
 
1:54 PM
Exercise: suppose every solved problem in mathematics has a property, "density", which equals the number of years the problem went unsolved, divided by the number of characters in its (verifiable) solution. "42=(-80538738812075974)³ + 80435758145817515³ + 12602123297335631³" has a density of (2019-1955)/66= 0.96 years per character. Which solved problem has the highest density?
Most likely any candidates will be examples or counterexamples of a theory, since those concisely act as a proof/disproof without a lot of intermediary steps
Cheesy candidate: the problem of "how do we record large numbers with log(n) marks?" is answered with "like this: 123", and took 30,000 years to graduate from "tally marks on a mammoth bone" to Mesopotamian base 60, giving the problem a density of 2143.
 
 
1 hour later…
3:31 PM
cbg
how is everyone doing today?
 
user13682510
3:56 PM
@JossieCalderon Banana, melon.
 
4:08 PM
@Kevin From the Wiki article, it looks like someone solved 42 last September. Alas, Douglas Adams...
 
user12867493
4:34 PM
Are there any statistics/speculations of the percentage of users who use Python 3 compared to 2?
 
user12867493
e.g. 99%+ (I hope) Python 3, < 1% Python 2
 
user13682510
Exactly when did the thank you feature get released?
 
here on SO? earlier this week. On teams....I think a month ago
 
user12867493
@joshua 2 days ago
 
user12867493
4:47 PM
@MisterMiyagi Why so many still?
 
@Daniil Why not? Python2 doesn't just magically vanish.
 
user12867493
@MisterMiyagi Python 2 sucks imo
 
That still doesn't make it go away instantly.
Case in point, I'm currently setting up a service that's written in Python2. I'd estimate the maintainers will not have the manpower to move to Python3 before late 2021, and that is being optimistic.
Python2 is still the default on any OS that we deploy. Right now I'm working on deprecating one that ships with Python2.6.
 
user13682510
Why all the doenvotes on the meta post about thank you?
 
5:03 PM
@joshua they didn't like it. Read the answers.
 
@MisterMiyagi I'm surprised this number is so low. Maybe that implies "Another 20% of respondents are just too ashamed to admit they are still using Python2."
 
user13682510
Why is the request fulfilled anyway?
 
@joshua there's no request. Stop asking. Go read meta.
 
@PaulMcG I'm guessing there is some bias from many Py2 devs not using an IntelliJ IDE and subsequently not knowing about the survey. ;)
I mean, come on. What are the chances of there being a shadow army of Python2 developers just waiting for my command to strike?
 
I wonder if it includes IronPython, Py2exe programs, and things like that (I still occasionally run into that kind of stuff)
 
5:12 PM
Definitely lower than the chances of Dinosaurs in room 6. Which is pretty low, because any reports of Dinosaurs in room 6 are fake new.
@LinkBerest You have my sympathy.
I only use IronPython and Jython to prove that even the most obscure Python implementation "does <X>, dear OP asking about strange <X> thingies".
So far, it has not once been fun.
 
@MisterMiyagi that sounds suspiciously like something one would say if they had a shadow army of python 2 developers poised to strike. I feel the odds have increased
 
riding t-rexes
 
cgb
 
yeah, luckily silverlight support being removed from Edge has forced the porting of a lot of the instances of IronPython I had to deal with
 
@roganjosh Now that you mention it, having a shadow army of python 2 developers poised to strike would be awesome! *runs off to the MiyagiMobile*
 
5:37 PM
.....which I say and then get a request for work in IronPython on a system that's still Windows 7 (teach me for saying stuff)
 
sometimes learning to program needs a high pain threshhold but its okay
 
5:56 PM
@LinkBerest What are the use-cases for this? Usually, I know people using Python for its availability and breadth of libraries. IronPython seems to have none of that.
 
@joshua Lemon
 
@MisterMiyagi they were just going to rebuild the program on new machines (which were more windows 10 friendly) but the buying of new machines was put on hold due to covid (and now they need to change some features of this but are still planning to upgrade & re-write soon so don't want to fully re-write yet)
....even though its perfectly possible to re-write it now and then just deploy on new devices (and would probably be easier)
note: I'm guessing at the use-case (I've seen the program but don't only have a parital story on why it exists), I have enough jobs this month that I just declined this one (lucky)
 
6:12 PM
Tripped over a property (written by a junior dev) with a side-effect (created a directory). Ran in the PyCharm debugger, and expanded the "self" variable and >BAM!< property gets evaluated. Took a while to sort out why that only failed while debugging sometimes.
 
lol the bash command line does not open in windows 10 it just opens and closes
guess most of the ppl use Linux or smth like that
 
well, good thing your zsh/csh shell still works then, right?
 
6:32 PM
@MisterMiyagi i ve never written in a cshell this zshell i am googling it has replaced bash on mac OS environment
 
Naz
6:45 PM
cbg friends. what is a good way to check if the two files are similar? they won't be identical, but I need to check if file A is "similar" to file B. Perhaps A is a subset of B. Or A has scrambled parts from B. The first thing that comes to my mind, that definitely is not efficient is to get byte chunks of both and then compute the correlation between shuffled blocks
 
You should define what you consider to be similar.
 
difflib comes to mind
 
Classical approaches are stat features and checksums.
Depending on what you need, you are looking at the field of string distance measurements here.
 
Naz
I am writing an algo that is supposed to check if the output of some algo, which is file A, is "similar" to the input file B on which this algo was ran. This is for purposed of identifying if there was a data leak. So someone can be clever about it and just say take B, chunk it up and shuffle it
don't think checksums will work in this case
since if they shuffle it will impact the hash
 
are those binary files, text files, csvs, JSON, ...?
 
Naz
6:48 PM
csvs, but I suppose they could extend it to JSONs and text files in the future
so operating on the byte level would be preferable
 
if they are csvs, you should rather operate on lines instead of bytes.
if you're just looking at bytes, I'd recommend doing piecewise checksums. E.g. compute the checksums for every chunk of ... bytes and count them. That is very likely not what you want, though.
 
Naz
even if they are csvs, the algo writer can split the rows into parts and just shuffle them around
I don't think it is
 
@Naz shuffling rows means you should check for rowwise similarities, no?
 
@MisterMiyagi meh, your bark is worse than your byte (.. string). I think it's official; I've become old and my only creations are Dad Jokes
 
if you're looking at bytes, you can quickly get out of sync if an early line is longer/shorter
 
Naz
6:51 PM
splitting the rows and then shuffling. say you split first row into three parts and put the first part of first row into somewhere, then second part of first row into somewhere else and so on
 
@roganjosh how appropriate. You fight like a T-Rex!
@Naz that sounds like you should be looking at the occurences of fields.
for example, you can find out if numbers in a document are fake by counting the occurence of digits.
 
Naz
wonder if kullback leibler divergence measure would be appropriate here
 
What are you actually trying to do here? As in, the broader context?
 
Naz
to prevent data leaks. There is Bob who can run algos on my datasets. And I want to prevent Bob from stealing my data
 
What prevents anyone from taking file B, encrypting every value, encoding it as hex or anything else, and turning it into a valid CSV file again? There's no way you can ever detect that
 
Naz
6:55 PM
because I am computing entropy to determine if they have encrypted it :)
the entropy of an encrypted file will be higher
 
Will it really? Is hex data high-entropy?
Or base64
 
Who is Bob? An internal employee? If you put this into a database instead of a CSV then you could set access permissions (but they could still pull the whole table)
 
okay, just to make that clear again: We have literally no practical idea what your data is. We can only randomly guess what will significantly select true positives, and are completely oblivious to what you would consider a false positive.
 
@Naz Erm, how? You have to show it to them somehow, no? What's the point of running queries/algorithms otherwise?
 
6:58 PM
Encryption seems like a pain the posterior if they are required to work on the data, and it still won't stop them stealing anything
 
It seems like you should look at digital signatures instead.
 
Naz
@MisterMiyagi the results of the algo i will show. But it shouldn't reveal the original nature of the data
@roganjosh i don't understand. they are not working on encrypted data
 
So Bob only has access to the results, and he wants to steal the internal data? So he has to reverse-engineer it first?
 
I'm not understanding you, either
9 mins ago, by Naz
to prevent data leaks. There is Bob who can run algos on my datasets. And I want to prevent Bob from stealing my data
I need one run of any script and I'll have all the data on my memory stick (provided it has the capacity to hold it)
 
@Naz I don't follow with this. The point of running an algorithm on data is, practically by definition, to have an output correlated to the input. Extracting input information is the entire point.
 
Does someone know if/where the typing data model is specified? E.g. it seems foo = typing.List[int] means foo.__origin__ == typing.List and foo.__args__ == (int,) but I cannot find something authoritative in the docs.
 
@MisterMiyagi I don't think it's documented because they're subject to change
I think the only public thing is typing.get_origin from 3.7+ or something
 
Hm. That's mildly surprising and mildly inconvenient, and only one of these statements expressions is full of seething sarcasm.
 
@MisterMiyagi Nowhere.
In 3.8 you have a documented get_args and undocumented get_origin. Before that, you only have pain
 
7:22 PM
I wrote a library to do this but it's bloated cause it changed in IIRC 3.5.3, 3.6.1, 3.7.0 and I've not checked 3.8 or 3.9
 
Okay, so re-using them for my own GenericMeta is probably a somewhat daunting undertaking, I presume tentatively.
 
Yeah, definitely find a library (for dealing with typing internals, I mean)
 
user13682510
How to pad a float without a string? like get 3.30 instead of '3.30'
 
Neither of those are padded
 
There's typing_inspect but that only support 3.6.1+ iirc and is fairly basic. Like it swaps from returning list to typing.List between versions.
 
7:26 PM
>>> List[int].__origin__
<class 'list'>
^ 3.8
 
@joshua that requiement makes no sense
 
I'd be willing to motivate the masses to write yet-another-static-type-annotation-system. The last one ended with mad scribblings how to build a fully static runtime compiler, though. I'd prefer not to go there again, at the moment.
 
user13682510
A question wants it...
 
@joshua Please read a python tutorial before asking for help here, just to be on the safe side
 
@joshua Then the question makes no sense.
 
7:28 PM
@joshua then answer it or ignore it
 
Questions often ask for nonsensical stuff. Business as usual
 
Leave us alone with it
 
@Aran-Fey 'Tis I found in mine own adventuring. But will it blend stand the test of time?
 
Fun fact: This is (part of) the code I use to go from List[int] to List in 3.8: getattr(typing, cls._name)
 
7:57 PM
Not so sure on what? "Nope", "yep" and "i'm not so sure" clarifies nothing
Yeah, that's enough for me
 
8:14 PM
Listening to Iced Earth - Melancholy ... I see the sadness in their eyes
Melancholy in their cries ..............
 
Hmm, specialform thingies like Tuple and Callable and Union are all covariant, right?
Actually, scratch the latter two
 
8:43 PM
Union is covariant.
Immutable sequences are covariant, mutable ones are invariant.
 
makes sense, thanks
 
9:39 PM
@Naz assuming this is a real requirement - the only way to do that is with permissions. The last time I had a system where people were only allowed certain access I did this with SQLite databases in different directories (so their logins only have permission to access certain ones) but that's just one way out of many (and the security of each varies but also the more secure = more pain to use program so you have to balance)
 
9:58 PM
hey guys, what is the best type of list/object/dictionary to store data in if you have key-value pairs where you also care about grouping/quickly filtering all the keys based on values
 
cbg: polling the room: I just installed Sourcery in PyCharm, and it's suggesting if/else expressions over multiline statements. Is there a rationale for this? I tend to think multiline can be clearer to read, at least some of the time.
 
sounds like bad advice to me. Debatable at best
 
I mean, assigning a var: var = x if y else z` seems fine, but sometimes the if something: # do x elif/else: # do other thing more clearly shows the branching you're doing.
 
@Skyler they're all equally bad for that. Depending on the filtering you want to do, a dict and inverted dict together may be appropriate.
@toonarmycaptain If you're selecting between values, user ternary if. Otherwise, use statements.
 
an inverted dict would be a dict with key:value pairs being in form value:[key_1.....key_n] right
 
10:07 PM
yes
 
yea, that was my first intuition, just wanted to know if i was being bad with my data structures, thanks
if I wanted to design it such that I make sure these two never fall out of sync (updating one updates the other) should I put them in a struct
actually ill hold on that a bit
 
use a class when several objects must act together. Consider to wrap them completely, i.e. provide special methods such as __getitem__
 
I do like turning for key in dict: # do something with dict[key] into for key, value in dict.items(): # do something with key but I saw the refactoring and immediately went...why don't I just change it to for value in dict.values()since I'm not using the keys...
@MisterMiyagi Yeah, that's my intuition also.
 
I've done a defaultdict with callable to basically build a low-end database (the dict + inverted dict is much less painful)
 
It does want to turn my descriptive_var = expression; return descriptive_var into return expressionwhich, sure. Maybe I just need to have clearer docstrings and func names if I see that as an issue.
*rethinking utility*: Either tool is more trouble than help, or my code is well written to begin with and doesn't need much refactoring. Which is plainly not the case due to authorship.
 
10:20 PM
I wonder if Sorcery uses a style guide or is just based on the creators interpretations of the PEPs to build its rules (well some of them)
All the examples on its website focus on code duplication (and pretty direct matches too) so the refactoring seems like pretty simple issues (here simple meaning it seems meant for someone new to Python or if I was refactoring intern/student code)
^ the above may just be my grumpy old man coming out though
 
Idk, I had a quick look for docs, as some tools provide rationale for their recommendations, and couldn't see one.
@LinkBerest lol. What do you think about my assigning to a descriptive var and then returning that eg return very_specific_object vs return complex expression?
 
^ common issue (and minor one): even in Java the rule of thumb is Avoid unnecessarily creating local variables (esp. if just returning or throwing them)
I know most static analyzers have that rule in their sets
I know I've broken that rule on occasion when I have an overly complex expression being evaluated (breaking a large equation into chunks to make it easier to debug) but most of the time its a good rule
 
10:42 PM
Fair enough. Time to unlearn a habit.
 
11:20 PM
 

« first day (3534 days earlier)      last day (1397 days later) »