« first day (3385 days earlier)      last day (1787 days later) » 

wim
wim
01:03
> Default to doing a user install (as if --user was passed) when the main site-packages directory is not writeable and user site-packages are enabled
^ in pip v20 release notes 🎉
sudo pip install problems on SO should plummet !!
 
7 hours later…
user10984358
07:57
If I have a class class A and I declare some other class class B inside it, is there any disadvantages to that? Like every time I create an instance for the class A will class B be defined every time?
08:11
> Like every time I create an instance for the class A will class B be defined every time?
No
user10984358
thank you!
08:34
@PM2Ring thanks for sharing this. I feel it is often the case on SO and a few times here on chat as well. But chat usually gives in a better answer that helps. Unsure how it can be helped though.
dac = 1000 * (LED Current value) / 25.0

is this the right form of formula to be written in Python?

And I want to add the LED current value from 0 to 15 range. How does it supposed to make sense?
It is like,
for LEDcurrent in range(15):
dac = 1000 * (LED Current value) / 25.0
input("enter a number")

something like this?
08:58
I don't understand the question
> is this the right form of formula to be written in Python?
Is it syntactically valid? Yes. Does it do what you want? I have no idea
haha, syntactically right?
thank you.
09:28
brief cbg
09:47
@wim nice
@Aran-Fey note the spaces in "LED current value"...
I assumed it's just a placeholder *shrug*
Closing as unclear :P
 
2 hours later…
11:37
@JonClements it looks like you need to pay for CBS to watch it though :/
cbg guys
I asked a question on upgrading packages in venvs, if anyone wants a bounty in 2 days... :P
@AndrasDeak constant discounts are not illegal, only advertising them as discounts is.
11:58
What's the difference? Actual adverts in media?
@AndrasDeak you can give a discount from your recommended retail price but you may not constantly say it is -33 % anywhere if you're not ever selling at that original price :D
if you don't write "-33%" anywhere it's not a discount, is it?
it is :D
-33 % does not make it a discount :P
selling at a lowered price is a discount
but if you don't show the original price it's not a discount...
anyone is legally allowed to make a bad deal, that's not a discount
How does this begin to answer my question? — Antti Haapala 9 secs ago
12:12
flagged as NAA
it's a comment at best
12:50
Cbg
@AnttiHaapala Every python interpreter should take a moment of silence..
13:41
:(
13:52
for finding shortest paths a lot of the leetcode questions use BFS, however i would have thought you should you Dijsktra's algorithm. Why use either?
@Permian BFS is "easy", and can be considered a special case of Dijkstra
Dijkstra uses a priority queue.
And A* uses heuristics.
@AnttiHaapala "easy"
ah and BFS has edge length of 1, while Dijkstra can have any non-negative weights
@Permian if you make a good Dijkstra algorithms then
@AnttiHaapala thats what i needed to know
BFS is easy
14:07
if you studied CS
(which i didnt)
BFS is easy compared to the alternatives
@Permian often easiest is to generate all solutions brute force and then verify and pick the smallest :P
@Permian neither have I
@AndrasDeak cool
discrete math specifically gives me the creeps
14:15
@AndrasDeak but then your material physics and chemistry and so on and I am like "wtf?" :d
well yeah, and even complex analysis and linear algebra, but none of that helps with BFS :P
the code for socket module starts with import "_socket"but I can't open _socket, where is its code?
>>> import _socket
>>> print(_socket.__file__)
C:\Python37\DLLs\_socket.pyd
@AndrasDeak I can do complex analysis and linear algebra. I just don't understand anything about complex analysis any more, if I ever did :P
something something residue theorem
14:28
Hello everyone, I am parsing through an XML file in python and I have an attribute in one tag that is a dictionary. However, I want to add this attribute to a multidimensional dictionary and I am struggling to do so. Here is my code:
@AndrasDeak yes, I was like "ok the answer is 42... wtf"
elif child.tag == prefix + 'measurement':
if 'index' in child.attrib:
doc = child.attrib
but I get an error " TypeError: 'str' object does not support item assignment"
@AnttiHaapala sorry for interrupting your discussion
the code you posted can't throw that error
sorry afterwards I try to assign it to a dictionary: mydictionary[id]['name']['address'] then it does not go into address
is mydictionary[id]['name'] a string?
14:37
@Vasilis clearly one is not a dictionary :P
for site in root.findall(prefix+'something'):
        id_name = site.attrib['id']
        mydict[id_name]= {}
        for child in site:
            if child.tag == prefix + 'something':
                side = child.text
                mydict[id_name]['direction'] = child.text
            elif child.tag == prefix + 'sth':
                if 'index' in child.attrib:
                    **then I want to pass that attribute as the next dimension in my dictionary
where the ** are I am having difficulty assigning that attribute to my dictionary. Sorry for explaining poorly I am new in python :)
Like mydict[id_name]['something'] = child.attrib?
Let me rephrase that: What do you want to add to the dict and where?
@Aran-Fey So it's a binary file and I can't see the inside? I wanted to check the method "sendall" but it is neither inside dir(socket) nor dir(_socket). why?
I have my key being the id_name and I want to add to each id_name the attribute next to it
@AndrasDeak my understanding of the residue theorem ended about 2 hours after the last exam where I needed it :P
14:47
like I have done with direction but then do it for that attribute as well
@aderchox Yeah, it's pre-compiled C code
@Vasilis The problem is your dictionary, not your assignment to it.
@AnttiHaapala I've even used it a few times for physics!
I didn't know Python advocated for getter and setter methods, I just thought you directly changed the attribute whenever needed. Huh, interesting ...
@Aran-Fey thanks, what about the sendall method? shouldn't it be listed as a name of the socket library?
14:49
@SebastianNielsen where did that come from?
class C:
    def __init__(self):
        self._x = None

    @property
    def x(self):
        """I'm the 'x' property."""
        return self._x

    @x.setter
    def x(self, value):
        self._x = value

    @x.deleter
    def x(self):
        del self._x
@MisterMiyagi could you elaborate a bit more on that please?
@aderchox No, because sendall is a method of the socket class
@SebastianNielsen Properties are something entirely different than getter/setter methods.
The python stdlib is a mess that's not afraid to give a module and a class the same yammin' name
14:51
And they're only advised if you actually need to manage attribute access.
@MisterMiyagi In what way though?
They seem the same to me.
@Vasilis Your error shows that you think mydictionary[id]['name'] is a dictionary. It's a string, though.
@SebastianNielsen properties are descriptors, not functions
hmm I will try to find some documentation online @MisterMiyagi, thank you though!
14:53
# getter/setter methods
x = foo.getX()
foo.setX(42)
# getter/setter property
x = foo.x
foo.x = 42
@SebastianNielsen
properties are syntactically equivalent and thus interchangeable with attributes.
getter/setter methods are not.
morning cabbages, all
15:11
I just tried to read(docs.python.org/3/howto/descriptor.html), though I didn't get it. I feel like I am lacking some essential, more basic knowledge of Python in order to get it.
@SebastianNielsen Descriptors usually aren't intuitive if you're used to other, non-meta languages. I recommend to try building the examples yourself instead of just reading the page.
There isn't really much need to build custom descriptors in daily programming either, though.
15:28
a student called it that in class, once. I couldnt' understand what they were talking about. I felt old that day
@SebastianNielsen That's just a minimal example to illustrate the syntax needed to create a getter, setter, & deleter using @property etc. In real code, you only use that stuff when your getter &/or setter methods need to do more than simply access the attribute. If you don't need to do more then you should just use simple attribute access.
Okay, thanks
The nice thing about Python is that if in a future version of your class you do need a fancy getter or setter instead of plain attribute access, then you can add the @property stuff to your class (or create your own custom descriptors) without needing to change any of the old code that uses instances of the class. You can't do that in Java, which is why Java people create explicit getters & setters for their classes.
@PM2Ring, if the attribute in question is private (has an underscore suffixed the variable name), would it still be wise to access it directly?
(note that the reason why it's private is so to notify other classes not to alter the attribute, they are allowed to get (access) the attribute)
15:44
@SebastianNielsen _protected attributes are not about direct/indirect access. They are about who should access it.
@SebastianNielsen Well, marking an attribute as private indicates that it should only be accessed by the methods of the class. Users of the class shouldn't touch it. They can read it safely, but they should only write to it if they know exactly what they're doing. And how the class uses its private attributes may change without notice in later versions of the class.
"Well, marking an attribute as private indicates that it should only be accessed by the methods of the class." -- so this is why I though a getter method was what I was looking for. Create a public method that then returns the private variable.
Why not just make the variable public though?
Because, other classes should not alter it. I want to signify that other classes shouldn't alter the variable by making it private
Isn't that a good enough of a reason?
Ah, ok. Then yes, it makes sense to create a private variable with a public getter
15:49
Okay, so I should make a public getter method anyway now? I thought you said: "getters in python?! No way dude, we don't do that here".
This Python question intrigued me, but it made me wonder why the author asked it at Ask Ubuntu instead of Stack Overflow. The author is a Stack Overflow user too. I asked him to post and he didn't, so I posted it myself and it was immediately closed as unclear. I thought that asking a question like that would be of general interest, but clearly I don't know how to do it, so if anyone wants to copy/paste the linked question at SO he has my upvote.
@SebastianNielsen you should make a public getter property, not a public getter method
We don't do getX() functions, but we do do getters hidden behind @property
Okay, I'll look into that then
@karel That's because it is unclear. "A variable" can mean anything from "x", "the value stored in x", to "a life reference to x". "bash environment" and "python environment" can mean a myriad of entirely different things.
15:57
Also note that if your variable is some mutable internal structure like a dict or list, and all your property does is return self._myinternalvar you haven't really accomplished much, since the caller gets a handle to the underlying mutable object. If you really, really, really want to expose that inner var and you really, really, really don't want callers mucking with it, then your property getter should build and return a copy.
@MisterMiyagi I figured there was some sort of glitch that prevents a question of general interest like this one from being published at Stack Overflow where it would do the most good. I thought I could walk it in on foot, but this question needs to drive itself in like an autonomous vehicle.
@SebastianNielsen On a related note... Say you have some kind of container class which keeps track of how many items it contains, eg in an attribute named _length. Users of the class want to read the length, but they have no business modifying it directly.
You could make an @property getter for it. But it would be better to give the class a __len__ dunder method that returns _length. Then you can get the length using the standard len function, just like you do with the built-in list, dict, etc.
Asking a general question is hard to do. I don't think I'm good enough to do it, but I'm bad enough to see the necessity for someone else to do it.
@karel What Mr Miyagi said. In particular, that question is tagged with environment-variables, but the accepted answer has nothing to do with actual shell environment variables. Maybe the OP tagged the question incorrectly... or they'll soon discover that that solution doesn't actually do what they want.
16:09
I submitted this code (github.com/duo-labs/parliament/commit/…) to a project on GitHub, for detecting if two glob strings could overlap (have some string that would match both) - did I reinvent an existing wheel? Or overlook an edge case?
That isn't a Python issue. Parent processes don't inherit from their children. You can't even do it with a shell script, unless you source the script. — PM 2Ring Oct 12 '17 at 15:28
@PM2Ring When I asked the question I basically copy/pasted it to SO and tagged it with python, bash and variables, but not environment-variables.
@karel The original is tagged environment-variables and the text makes it unclear whether that is intentional or not.
@MisterMiyagi I don't care about the question anymore. I care about a place being created where its accepted answer could be posted. Stack Overflow userts get the accepted answer and the question is whatever it needs to be so it won't be closed.
Reverse engineering.
Good luck with that.
16:20
That's why I deleted it.
But the only part of this question that is Python is the part where you call subprocess. You could have the same issue from Ruby, Java, C, or whatever. Isn't this question really "how do I access command-line arguments from within my bash script?", which very likely already exists and has an answer.
By the way, the answer is wrong...
There is no way such a subprocess.call will succeed. It's passing in variables as sets.
@MisterMiyagi Good point. I read that {param1} stuff as pseudocode, but I agree that it could easily be misleading.
I'd be willing to settle for "unclear" instead of "wrong". ;)
16:36
cbg?
cabbage
I can't compile a .pyx file here is my paste : pastebin.com/Y1AFD7JP
cabbage.. is it me you're looking for?
@behruzmontazeri Try value instead of values?
@Aran-Fey let me try
@Aran-Fey Great that solve the problem thanks
wim
wim
16:59
Does anyone understand why Guido thwarted the dict merge comprehensions {**d for d in ds} and list concat comprehensions [*x for x in xs] in bpo2292? I don't understand the reasoning ...
Apparently they were part of the original implementation (PEP 448) but then got removed...
17:45
at least the PEP allows it
> This PEP does not include unpacking operators inside list, set and dictionary comprehensions although this has not been ruled out for future proposals.
@wim that would be very handy for flattening data structures.
I guess you have to track down the mailing list discussion hinted at with
> This was met with a mix of strong concerns about readability and mild support. In order not to disadvantage the less controversial aspects of the PEP, this was not accepted with the rest of the proposal.
17:58
Nice work, @AaronHall:
@AaronHall - thanks for your thoughtful answer. I would like to take you up on your offer to meet face-to-face at our NYC office. My team will reach out to you by email to arrange a meeting. I look forward to engaging in a deeper discussion with you. — Pchandrasekar ♦ 2 hours ago
Are we getting a new CM?
No idea. I assume they'll be hiring some new CMs more "aligned" with the company...
wim
wim
some serious EOL 🍿 here. Is zopyx the same Andreas Jung that is suspended until 2025 here on SO?
The CM team was already overworked before it lost 3 people, so it's hard to imagine the remaining team members coping without some assistance. OTOH, Yaakov did say yesterday that there's a lot of stuff that CMs do manually that's overdue to be automated, but even with better tools I think they'll need more people.
wim
wim
how many more of these tauthon fans will come out of the woodwork in 2020 and start raving about "Big Python (TM) "
18:15
> The EOL of Python 2.7 is [yamming] things up.
bad, bad PSF
@wim actually, network-wide
> Python 2 is EOL’ed to make people pay for migration.
wow
no idea why people keep feeding a crackpot
18:36
The internet outside of this chat room is weird
wim
wim
they were remarkably patient
there's no point in repeatedly arguing with "prove to me that python 3 is better"
wim
wim
should this dupe be reversed? stackoverflow.com/q/307305/674039
hmm, maybe not, accepted answer is not good.
18:57
Design question: If I want to implement health potions and mana potions for a little RPG, should they be classes (class HealthPotion(Potion)) or instances (health_potion = Potion('health', heal=25))? Using classes seems weird because HealthPotion/ManaPotion instances have no state and are all exactly equivalent. And making them instances seems weird because... I'm actually not sure why
Perhaps classes can be more extensible?
That's what I thought at first, but I actually can't come up with anything that wouldn't be possible if they were instances
option 3: They should be classes and Potion should be a metaclass
Ummm... my immediate thought is that Potion is a reasonable abstract base class and children need to define name, description and a use method
@Aran-Fey Isn't Potion('health', heal=25) two pieces of state: name, and heal value? Else, where do you store those values?
def __init__(self, nums: List[int]):
what is the nums: List[int] notation called?
19:03
@smci Yes, in that case the instances would have state. But if I did it like this, the instances would all be equivalent:
class HealthPotion(Potion):
    attribute = 'health'
    potency = 25
Oh, you meant to say they're class variables not instance variables.
If it's just name and a basic value then yeah... but what if it's "Double your health (but not above your initial total)" or "Gain 2 life but lose 1 luck" etc...
In your use-case it doesn't currently seem to matter much, but if this is a more geberal question you could conceivably have future enhances where (say) the name, heal value, type etc. might change on a per-instance basis. So I'd make them instance variables, assuming you care about future-proofness.
@JonClements I was actually trying to avoid going as far as adding a use method. It's a bit hard to explain, but basically I want to display a "you restored X health/mana" message when the player uses a potion, which is obviously easiest if potions can only increment the player's attributes by a specific number. If I do add a use method, how would I go about displaying this kind of message while also keeping user interface code cleanly separated from game logic?
@smci Hmm. I suppose that's reasonable. I'd just have to implement a __hash__ and __eq__ so that all the similar potions neatly stack in the player's inventory
What about child classes having a compute effect method which returns any delta or absolute changes and that's called by the base Potion to then sort those things out
19:12
@Aran-Fey re your first option: to reduce everything to one Potion class, with (say) a typeinstance variable, and no need for subclasses or abcs - but only if we're absolutely sure that Mana and Health potions will always be near-interchangeable, and never get separate methods or data members. But that might well prove limiting, I wouldnt do it.
@JonClements Interesting idea
Maybe I should omit potions altogether. The code is a bit longer than I'd like anyway
@Aran-Fey But if you don't have a use() method or equivalent, where in your code do you implement the game logic? Seems to me there are three separate subcomponents to using a potion: a) compute what its properties were/ what the delta on stats should be b) implement that delta change on player stats c) remove that potion instance from that player's inventory. So how do you currently break that down? and which parts are game logic and which are user interface?
(If anyone's wondering, what I'm doing is creating a simple beginner program that contains all the typical beginner mistakes, so that I can use it to explain what's bad about the code and why. A little RPG seemed like a good fit, but it's already more than 100 lines long)
the first game is role playing that you're writing an RPG program
@AnttiHaapala :( What if we use famous Terry Jones quotes/ Monty Python lines for a while in code examples, in observation?
19:19
why are you asking @Antti? He's just a naughty boy! :p
@smci currently I'm still pondering the design (:
user12755667
Clash of clans is trash
But the only part that I'd consider part of the user interface is the "you regained X health" message
user12755667
Clash of clans is the worse game
user12755667
I hate it
user12755667
19:20
it is trash
user12755667
it is poop 💩💩💩💩💩
It's going back a bit, but last May when my boss commented that the acquisition of Nginx by F5 was unexpected, I immediately replied, "NO ONE expects the nginx acquisition!"
user12755667
I cannot even stand the fact that something so shit exists
It's probably a bad idea to include this in a beginner project if there's no clear answer as to how it should be designed. Guess I'll leave it out
@Aran-Fey Fine. But what component is managing inventory? And wouldn't it be good to have a more general base Item object with generic methods that can be triggered when you add/remove(/equip/unequip/destroy/burn/sell/give) an inventory item? For example with weapons and armor, they would also (temporarily) modify player stats, but only when you equip them (and reverse when you unequip them)? Or if you sell them, you could get money.
19:23
Possibly, but for this project it seems like overkill. I have no plans to implement equipment or the like
@Aran-Fey Ok, so there are no other types of Item than Potion? (or else, that game logic is hardcoded in elsewhere)
there aren't, no
The code that removes the item from the player's inventory would most likely go in the Player class
@Aran-Fey Not much of an adventure, mon... no weapons, ropes, rations... the ghost of Steve Jackson will haunt you...
it's not s'posed to be fun, it's s'posed to be full of bugs and bad design :D
@Permian It's called a type hint, or a type signature. See docs.python.org/3/library/typing.html
19:25
actually no, no bugs. Just bad design
@Aran-Fey Please do put it on CodeReview if poss when you can... would like to see people's review comments. Decomposition is often instructive
hahahaha I might do that
Speaking of which, let's brainstorm common newbie mistakes. So far I've got:
1) nondescript variable/class/function names
2) lots of duplicated code
3) error handling by returning None/False/an error string
4) no separation between game logic and user interface
wim
wim
oh 4) is a good one
no separation of concerns. just "stream of consciousness" style programming.
@Aran-Fey Also, as to which object generates a message when a player's stats change, and can it just be the Player object, or does it need to know what changed the stat, and why? e.g. "You restored H health... with a potion" vs "...by sleeping"*
Hmm. It probably wouldn't hurt to know the cause
I need to find a good balance between "well designed" and "short", so it's a bit hard to say though
19:35
@Aran-Fey function definitions and imports in all the wrong places?
misuse of or and and in booleans while trying to compare one variable to multiple values
Hmm. Imports should usually go at the top, sure, but what's a wrong place for a function definition?
@Aran-Fey I would rewrite that a little. The main thing is "bad (OO) decomposition", and 2) lots of duplicated code and 4) not separating game logic(/business logic) from user interface are two main symptoms of bad decomposition. As to 1) nondescript(/confused) names, they can indicate confusion in the aforegoing. And mention the noun vs verb caveats ...
... Is that potionX.drink() or player1.drink(potionX) or player1.inventory['potionX'].use() or what? Thinking through the implications of these is nontriviail exercise in OO deecomposition.
also, issues with mutability. trying to add or remove things from some kind of player inventory
@Aran-Fey I always try putting functions in one clump at the top. I find it weird when there's a "locally" defined function inserted between statements that doesn't actually need a closure
19:37
@ParitoshSingh Ah, I'm thinking of design mistakes. The goal isn't to teach them python, it's to teach them how to write good code
ah i see
That reminds me of 5) Useless comments
hardcoding to solve issues
there are also minor things like [val for val in iterable] and lambda x: lst.append(x)
@Aran-Fey Well, if it 'feels like the function's in the wrong place', e.g. should be a method, or classmethod/helper function, or in a base class, etc.
19:39
@ParitoshSingh good one
@wim thanks, good enough! and exactly the kind of answer I was looking for.
@AndrasDeak Those are bit too minor and too specific to python. I'm planning to make this language agnostic, as much as possible
@Aran-Fey Again, true but that's kind of a symptom. 5a) Classes and methods should have docstrings (rather than comments). 5b) The naming of objects and their interfaces should make things self-evident. Not player1.state.inventory.get('potionX').use()...
@Aran-Fey ah, OK
This reminds me of Raymond Hettinger's oft-repeated advice to eliminate/reduce unnecessary classes to dicts/lists/arrays etc. I don't necessarily agree with it but it's like a mantra to keep in mind "What is the code complexity increase of adding each class/subclass? Will this cause bloat?".
19:45
Agree that good docstrings and variable names make comments redundant. But To be fair, I've seen new people put comments for obvious things too, even when the names are clear. I think it's a fair shout to say "useless comments" are a thing
To be very specific, i often see comments that describe verbatim what a line of code is doing, rather than helping convey what's the thought process behind the code was. x = 5 #set x to 5. oookay?
@smci Many of these might be symptoms of the same root cause, but keep in mind that this is intended for beginners. If I start talking about "OO decomposition", they'll have no clue what I'm on about. The plan is to show them some specific things they do wrong and how to do them better. I think that's the best way to make them follow along
oh, that reminds me of magic numbers too
but i suppose that's already kinda covered perhaps.
@ParitoshSingh I'm not saying useless comments aren't a thing. I'm saying "don't write useless comments" isn't clear actionable advice (to new users, on coding antipatterns), whereas "All objects and methods should have docstrings, and wherever reasonably possible try to avoid unnecessary code comments by improving the docstring"
i'd be overwhelmed by that sentence as a beginner* to programming
@ParitoshSingh That's exactly the kind of comments I was thinking of, yeah
u = ord(c) # get unicode value of char
19:49
@ParitoshSingh I didn't say that advice should be presented to new users as a single long sentence. I'm saying it to Aran-Fey and you. (For new-users, it should be presented tersely, with bad-example-vs-good-example(-vs-better-example) code examples)
fair enough
@Aran-Fey subtype of "nondescript variable name" is when one rebinds the same name to a bunch of different objects which even vary by type. But that's still specific to dynamic languages
Oh, that's actually a pretty good one. I'll see if I can fit that in
also global variables perhaps? not sure if they fit the bill or not. But often see functions that should have had parameters but don't.
now that's a big one
This code will be a masterfully crafted pile of junk
19:52
@Aran-Fey needs a fair bit of work, but kind of along the lines I was thinking was something like: gist.github.com/joncle/f1a5f1c45f2085589da030eca3380823
(bear in mind I only spent 5 minutes mashing that out... so probably not ideal...)
@Aran-Fey good people working together to build something terrible. Sounds like SO Docs to me
haha, that one wasn't bad on purpose though
@JonClements You really nailed the nondescript file name there ;D
@Aran-Fey Sure. In the introduction: "In this chapter we show how to design your code so that classes (Player, Potion) implement specific things." Then optionally in the chapter summary "Converting your specification into individual classes, objects, methods and how they'll work together is called Object-Oriented decomposition". This is not as straightforward as it might sound: there are multiple ways to do something, and each design choice you make can affect your final code. Or sumthing...
@Aran-Fey hey... I normally go for blah.py - count yourself lucky? :p
@ParitoshSingh A first-order piece of advice for new users is "Don't use global variables, for now". They're usually a code smell of a missing class or method. (And they often prevent encapsulation, obfuscate passing state around in non-obvious ways, cause bugs, make testing harder etc.)
20:01
Seems like a pretty good implementation from what I can tell. The player having a use_item method in addition to the Item's apply_to is nice, and health_potion being an instance while SimpleHealthPotion is a class also "feels" natural and intuitive there
Probably should have type checks for apply_to so that potions can only affect Players but you might have an item that increases the attack strength of an existing item inventory - eg a sword or something
@ParitoshSingh Great catch for Aran-Fey: "functions that should have had parameters but don't." Design functions so that they can be called in various different ways (where needed), and so that the parameters not passed get default values. This allows you to call a function various different ways, without writing different signatures or methods. (This is the Python equivalent of multiple signatures in Java/C++. You often see pgroammers coming from Java really at sea with this principle...)
@smci Hmmmmm. I was planning to do pretty much the opposite: start with the bad code, and go over the flaws one by one, presenting potential solutions. But you're saying "OOP is the answer" right off the bat. Not quite sure if I want to do it that way
Again that's all a mouthful, so have to teach by example. e.g. "declaring two totally separate ManaPotion/HealthPotion(/LuckPotion/etc.) classes, for a set of things that generally behave alike, would be bad design. Here's how to do it better ...."
This is gonna take ages to write. I need to muster some motivation for this
20:07
Perhaps keep it simple. two or three of your initial issues* in one code sample
(or keys can only be used on doors... so you could have skeleton key that works on all doors, but specific keys only work against specific instances of doors etc...)
see how that goes
@Aran-Fey No, what you're proposing is best, start with bad example. I'm simply summarizing the points you want to get across (in the mist logical order, not necessarily the order you want to teach them in. That chapter summary is where the action is at)
get some guinea pigs :P
@smci I see, ok
20:08
@smci aye, it's actually really easy to spot java influence for coders who migrate over.
It's weirdly fascinating to see.
@Aran-Fey Just reduce it to the simplest terms and code example. Only after taht's sketched out satisfactorily, might you choose ti get fancier...
@Aran-Fey make a bet with yourself. If you're not <x percent> complete by <date> you'll have to spend half an hour looking at the front page.
@ParitoshSingh Yeah if AF has a big Java(/C++) audience, I'd explicitly summarize a subsectiun on "Things in Python code that Java coders tend to get wrong at first...". Near/at the end of the chapter
@Aran-Fey just trying to think if that's a much less complicated example you could come up with that's also as interesting for someone to see there's some fun in doing programming and it's not just pointless laborious stuff...
@AndrasDeak No thanks, I'll pass :P
20:11
<insert your favorite motivation tactic.> Or just get on with the code now :) You can post a draft for us to review...
I second-guess myself too much while writing, an early draft would probably look nothing like the final product
Is there any documentation for the use of >> in Python (not as bitwise operator)? Example: siuba.readthedocs.io/en/latest/…. Is it specific to certain packages? I don't see it documented there. Looks similar to this usage stackoverflow.com/questions/52389105/… maybe?
@arjan yes, that's abuse of the operator by people who like C++ more than python
wim
wim
@AnttiHaapala do I still get the bounty :)
I've seen the same thing in a scientific package and I hate it
so yeah, this kind of use is very much package-specific
20:16
I think the only use of things similar to that I've seen with the Python stdlib is the use of / for pathlib.Path stuff
this use of >> also means that from siuba import * is absolutely necessary for this "flow", otherwise those names don't exist
Ah I see, thanks. You can infer what it's doing there, but documentation would be nice
wim
wim
@Aran-Fey avoiding classes and storing state in the module, or the opposite extreme, using classes but they have no meaningful state
@Aran-Fey Related to nondescript names: throw out PEP 8 naming conventions, and just use various styles like snake case, camel case, all upper case, etc, randomly.
wim
wim
but this is just again the separation of concerns (data vs logic) ...
20:22
Using styles randomly is a bit too much, but I'm certainly planning on being a bit inconsistent with naming
@arjan You may rarely see Python 2 code using >> in print statements, where it's used to print stuff to a file instead of to the terminal.
wim
wim
@AndrasDeak haha, don't forget python print used to.... Kevin'd
I did in fact forget that entirely
Ahh... I'd completely forgotten that syntax as well...
wim
wim
std::cout << "hello from C++" << std::endl;
20:24
@wim The former is pretty much covered by global variables. As for the latter, I'll try to find a way to fit in a useless class. Having trouble thinking of a "use case" for one, though
@Aran-Fey Fair enough. I just mentioned it because it's a thing that slows me down when I'm trying to read newbie code.
I'm not quite sure yet if I want to make "how to write readable code" a separate thing or mash it all together
@JonClements I used to use it sometimes to print to stderr. I don't think I ever used it to print to an actual file on disk, but I might have...
wim
wim
20:43
other weird piece of history, not equals was "diamond" operator 1 <> 2
I don't know where that came from. I suppose it is a contraction of "left < right and right > left".
Used in quite a few languages... SQL makes use of it
@wim i think you said the same thing twice there effectively? It might help to read "<>" as less than or greater than. Similar to "<=" being less than or equal to.
by that logic, >> should be greater than or greater than. Hmmmm...
wim
wim
@ParitoshSingh yeah sorry I meant to say a contraction of "left < right and left > right"
I have always used != in SQL
I wonder if that logic applies to JS. Then, === would mean == or ==. Coz you know, JS isn't yam'd up enough already
wim
wim
20:53
oh, === could mean == or = or == or = depending on your parser
is there any base where 8 equals D?
21:06
Interesting puzzle: list all the representations of n from base 2 to base n. (none of which give 'D' when n is 8, unfortunately)
100, 22, 20, 13, 12, 11, 10 - nope, no 'D's
...you can't get the D until base 15
5
@wim you need to wait 2 days :P
Anyway... I can't be the only one that plays MTG Arena here? :)
Master The Gameboy?
@inspectorG4dget that or magic.wizards.com/en/mtgarena :)
21:15
ahh. That makes a lot more sense. Thank you
Famous kaiju movie, Mega-Tyranno-Godzilla
... There's something a little depressing that 7 years of Chemical Engineering education at Uni wasn't enough to get me a door in to a major engineering consultancy just round the corner, but self-taught programming has just secured a meeting with one of the directors :/
21:32
@roganjosh did you by any chance go to uOttawa? I've heard pretty much this story of someone else there
wim
wim
@AnttiHaapala maybe you will go to 100k twice
@wim and receive swag 0 times.
so on average both will happen once.
wim
wim
haha, yep. welcome!
valued contributor #918959
@inspectorG4dget Nope. I got rejected by them ~4 years ago when applying for a job for Chem Eng and got rejected without interview. Maybe the education wasn't a complete waste because I can talk on technical terms, but it is... frustrating
Ack! that's unfortunate
21:42
is there a way to use something like 'as' in python, for an if statement?
like...
Oh well; an opportunity is an opportunity :) It's no guarantee that I'll get work from it anyway. Just seems that tech is trumping what I actually started out to do
if requests.get('argument') as arg:
    print(arg)
SyntaxError?
@AmagicalFishy 3.8 introduces assignment expressions for that :(
no waaaaay
if arg:=requests.get('argument'):
    print(arg)
21:45
it's... it's beautiful ;_;
@AmagicalFishy just don't overuse it. This is one of the very few legit use cases.
this is probably the only time i've wanted to ouse it (for simple statements like that)
tyvm
it's perfect
thank Guido
@AndrasDeak Update on this; it's literally just linked him to the docs on string methods and had him test them all.
So Udemy courses are an exercise in drudgery
(Well, at least this one particular course)
22:01
that for money?
£12, the massive 94% (or 96%?) discount
So, yeah, I don't have nice things to say about Udemy, like Idjaw
22:23
I for one have found the best online python course to be found at wiki.python.org/moin/BeginnersGuide
22:56
Ugh. Just been hit by fake news. The VelociPastor is a real film but it's not on NetFlix. "After losing his parents, a priest travels to China, where he inherits a mysterious ability that allows him to turn into a dinosaur. At first horrified by this new power, a hooker convinces him to use it to fight crime. And ninjas."
23:09
That sounds... risky, but potentially fun
I do believe I'll have to watch it. I haven't actually seen any of the Sharknado films, so I'm falling behind on the important films. But I'm upset that FB supports adverts that lie about what is on netflix
Anyway, rbrb :)
23:55
hi all

« first day (3385 days earlier)      last day (1787 days later) »