« first day (4027 days earlier)      last day (913 days later) » 
06:00 - 19:0019:00 - 00:00

7:00 PM
It's essentially just a slightly fancier version of inspect.signature. Unless you do too much metaprogramming, like me, the inspect module should be totally sufficient for your needs
 
user12867493
@CoolCloud What if I want the result of car.add() to be stored as car2?
 
@Xnero that is what you're doing now
 
user12867493
@JonClements Thanks but that is what I want.
 
if you want the result of car.add() to be something other than None, you have to return something else
 
In other words, you need to use return inside your add method
 
user12867493
7:02 PM
@Aran-Fey I understand functions and return statements.
 
If this sentence is not clear, please read a decent Python tutorial.
 
user12867493
@AndrasDeak Yes I see, thanks.
 
the next step will probably be that you'll expect car2 to be a new Car instance, so good luck with that part
 
user12867493
@AndrasDeak Just managaed to do it with a return statement. Thanks for the pointer.
 
excellent
 
7:05 PM
Hmmm is returning self a good idea here?
 
user12867493
@CoolCloud That's what I did.
 
he didn't say that's what he did, and in any case it'll be an important lesson
@Xnero car2 is car
 
Yep, important lesson
 
@CoolCloud No. A function should that mutates self should have a return value of None. And besides, what's the point of returning self? The caller already has the self, otherwise they couldn't have called the add() method in the first place
 
user12867493
So when calling different attributes of a Class, self is the content of the object that is being called upon?
 
7:07 PM
it would only make sort of sense for a "fluent API" where you want to chain methods like there's no tomorrow
 
user12867493
@Aran-Fey Returning self worked.
 
@Xnero have you read a good tutorial that talks about OOP in python?
 
@Xnero The question wasn't if it "works", the question was if it's a good idea.
 
user12867493
@AndrasDeak No.
 
one man's bad idea is another man's it runs without error
 
7:09 PM
@Aran-Fey Hmmm yes, makes sense
 
@Xnero you probably should
 
user12867493
What about my question?
 
I can't make sense of your question
 
user12867493
1 min ago, by Xnero
So when calling different attributes of a Class, self is the content of the object that is being called upon?
 
yes, we all saw it
 
user12867493
7:10 PM
So when I do car.add(), it calls add(self). Is self the contents of car?
 
self is the object itself, isnt it?
 
@Xnero no, self is car
 
user12867493
@AndrasDeak Makes sense.
 
that's reassuring
 
user12867493
How would I go about using special methods to adding a constant to one part of the object?
 
user12867493
7:12 PM
I tried implement def __add__(self) but that didn't work.
 
user12867493
Can you even use __add__ to add a part of an object and a constant?
 
__add__ requires another argument
 
But that's a scatter-gun approach to building classes. Please revisit the advice to read an OOP tutorial
 
Sep 21 '20 at 17:49, by Andras Deak
@Xnero we'll need an MCVE
 
car = Car()
car + something  # `car` is `self`, `something` is the second parameter to `__add__`
 
user12867493
7:13 PM
@roganjosh Any ones you would recommend?
 
Off the top of my head, I can't now remember the ones that I found most useful that were brief intros, if I'm honest
A lot of tutorials end up skipping different aspects or (in some bad cases) making incorrect claims. But that's part of research - finding reliable sources
 
user12867493
@roganjosh Why do you call it a scatter-gun approach?
 
"I tried implement def __add__(self) but that didn't work.". Do you know how dunder methods are intended to be used?
 
user12867493
@roganjosh Yeah, I read about it in my book.
 
user12867493
I was intrigued about whether you can use them to add constants.
 
7:17 PM
In which case it's interesting that the book has introduced them before you have a grasp of self and how to use instance methods
 
you keep saying that so I should note that python doesn't really have "constants"
 
user12867493
So if I do car + 2 but 2 is completely irrelevant as I always want to add 3 to car.price.
 
you probably mean "things that aren't instances of the same class" or "literals"
 
user12867493
I guess I could pass it as a parameter and not use it.
 
7:18 PM
@Xnero Ok, now I've totally lost the point of what you're trying to do.
 
user12867493
@roganjosh It probably did, I just skip over half of the boring stuff.
 
Also, it needs to be an MCVE or it's not worth trying to explain to me
Right, so we're getting to the point. You get bored by it, and we'll just handle those gaps for you because it's for us to understand it on your behalf?
 
I think Nero is trying to describe something that resembles an appreciation model - the car's value increments every year (I dunno.. maybe because it's a vintage/antique). The method is counter-intuitively named add, which doesn't make iteasier
 
or it's just an MCVE
 
user12867493
@Xnero That worked.
 
user12867493
7:20 PM
class Car:
    # Class variable
    manufacturer = 'BMW'

    def __init__(self, model, price):
        # instance variable
        self.model = model
        self.price = price
    def __add__(self, constant):
        print(self)
        self.price = self.price + 3
# create Object
car = Car('x1', 2500)
car + 2
print(car.price)
 
excellent
 
I'm impressed you've managed to make that worse... :p
 
user12867493
@JonClements How have I made it worse?
 
I don't have time to explain and I don't think you'd listen anyway... I'll just sit and watch...
 
user12867493
@JonClements I will listen, I want to improve. Just please tell me what's wrong with it in a nutshell? It's not meant to model a real-life situation by the way.
 
7:23 PM
It's just horribly peculiar behaviour from a class and its methods, contradicting anything we'd normally expect.
But if the goal was to prove that you can run arbitrary code in __add__, it works
 
user12867493
@AndrasDeak I got the code off a website and was just playing around with it. I realise that manufacturer is not supposed to be a class-level attribute in theory. Is that it?
 
that's the least of the problems now
 
That's just the tip of the iceberg
 
user12867493
@AndrasDeak What would you "normally expect"?
 
to add to that: __add__ controls the behavior of +, which is a binary operator. You typically expect a+b to be a new thing, rather than to change a
 
user12867493
7:25 PM
What's the problem?
 
I'll let others explain, no need to pile on. Inspector seems engaged enough.
 
user12867493
@inspectorG4dget I realise that.
 
Would you normally expect that foo + 2 will increment foo.attr by 3?
 
no. You would normally expect foo + x to return a new Foo object
 
user12867493
Ideally, you would want something like totalPrice = car1 + car2 with the __add__ function adapted obviously, right?
 
7:27 PM
...adding two cars returns their price? You think anyone would find that intuitive?
If you want the total price of two cars, do car1.price + car2.price
 
so let's back up a sec... forget cars for the moment, let's talk about tables. Let's say you go to a restaurant and there's a lot of people in your party. None of the tables at the restaurant are large enough to fit your party. So they helpfully add two tables together to make a larger table. You with me so far?
 
user12867493
@Aran-Fey It's not meant to model a real-life situation by the way.
 
@Xnero sounds like you have a solution (__add__) and you're looking for a problem for it. This is fine; you don't often have to define __add__ for a custom class.
 
user12867493
It's for me to understand how it works.
 
How what works?
 
user12867493
7:29 PM
@inspectorG4dget Yes.
 
user12867493
@Aran-Fey __add__.
 
@Xnero there's really no need to start using excessive formatting. We're all relaxed people here and I'd like it to stay that way.
 
user12867493
@AndrasDeak Ok.
 
in this case, you do table1 + table2 and get a brand new table of different dimensions. As a sidenote, in this specific case, "add these two tables" might mean "lay them end to end without any gap between them". Makes sense?
 
user12867493
@inspectorG4dget Yes.
 
7:31 PM
@Xnero And implementing an __add__ method that ignores one of its arguments and does something no __add__ method should ever do will help you understand it? Carry on then I suppose, but I'm out
 
user12867493
@Aran-Fey Yes.
 
user12867493
@Aran-Fey Just helps me understand exactly when __add__ is called.
 
ok, so the code for that might look something like this:
class Table:
    def __init__(self, length, width):
        self.length = length
        self.width = width

    def __add__(self, other_table):
        new_table = Table(self.length + other_table.length, self.width)
        return new_table
 
The geometry doesn't quite check out :P
 
(and fixed your naming there... :p)
 
7:34 PM
thanks Aran
 
that only works if the widths match, otherwise the table will be broken
 
Tables can have all sorts of fancy foldy-joiny methods these days
 
and in this case the new table consumes the input tables...
 
or I did... but it keeps getting reset lol
 
that's exactly right. Let's pretend that this restaurant has all equal-width tables, just to make the example simpler
all this make sense, @Xnero?
 
7:35 PM
are they going to be moving these tables around much longer... or will they eventually get around to serving me my scooby snacks... :p
 
a SQL query walks into a bar, walks up to two tables and asks "may I join you?" :P
 
user12867493
@inspectorG4dget I think so, it adds the lengths of 2 Table objects and stores the result as a new_table Table object?
 
correct. So you would call that in this way: long_table_for_my_party = table1 + table2. Still with me?
 
@JonClements I don't think this bar has ever had a puppy as a customer before... they're probably unsure what to do with their tables because you didn't sit down at one of them...
 
it's a pretty low bar
 
7:40 PM
puppy jumps over the bar... his tail catches and the bar follows on the upward trajectory. Puppy has raised the bar for us all
 
user12867493
@inspectorG4dget Yes. (I have to drop out for a while though)
 
so you see, __add__ is called when you use +, which therefore requires a second operator. You therefore need to first clarify what adding two cars would semantically mean before you start implementing Car.__add__
 
hopefully the inspector will be around when the lack of boring-tutorial-reading sprouts further questions
 
@inspectorG4dget I'm not overly optimistic that was your time well spent :(
 
@JonClements I did the most I could on my breaktime. Beyond this, I'm at the mercy of my calendar
 
7:47 PM
You keeping busy then I take it?
 
pretty much. I had to spend most of my morning/afternoon explaining basic linux commandline. Now I'm fiddling around with CSS on wiki.js
how've you been? Definitely missed you at the last hangout
 
Just chaotic with various projects... so if I'm not pulling my hair out over one of those I'm trying to get a couple of hours sleep... hoping to have a week off in a couple of weeks though... so paws crossed
 
I need to take some time off, too. Trying to figure out scheduling, etc
 
I still have 2 weeks that I need to shift at some point before the end of the year, and that's in addition to the time off over xmas. This year the company has decided that they're refusing to carry any days over
It would be easier to get through it if I didn't have everything organised into 2 week sprints that are offset by a week across multiple projects... but hey
 
8:05 PM
ouch! that's a tough problem. Looks like you'll need to miss <=2 sprints on each project
got a sufficiently capable intern that you can tryst to hold down the fort?
 
Trust someone with my code? Are you high?
 
usually...
not necessarily your code, but the codebase in general never mind, I think I'm useless
sidenote: anyone know of any custom wiki.js themes out in the wild?
 
How do y'all write multi-line withs? Is this how it's done?
async with (
    aiohttp.ClientSession() as session,
    session.get(self.url) as response
):
 
@inspectorG4dget To be fair, it's a convoluted mess atm because it's a Jenga tower of assumptions that the customer is forcing me to build
 
yikes! don't do that to your intern
 
8:22 PM
@Aran-Fey I think that's what black would do with it tbh. Given that the arg lengths don't pose any problems with the 80 character limit, I might go with the following. However, I'm really only particular with chained operations like pandas and sqlalchemy which just get obliterated by black, and I'm anything but an authority. Just adding an opinion to the pool
async with (aiohttp.ClientSession() as session,
            session.get(self.url) as response):
 
Oh, I stopped using that kind of indentation. I align everything to 4 spaces now
The times of pressing spacebar to align text with other text are over
 
@Aran-Fey I don't but that's what I'd do I think
 
python-indent in VSCode does alleviate a lot of it, but I've convinced myself it's like tending a Bonsai tree, so I hold on to it :)
 
user12867493
@AndrasDeak OR the inspector explained it so well and used such a great example that there are no more further questions.
 
user12867493
Thanks @inspectorG4dget
 
8:35 PM
:')
 
cheers mate! happy you understand this now
 
user12867493
@inspectorG4dget My initial confusion was that you have to treat car.add as a function e.g. return to assign to a value.
 
a function within a class is called a method, but it's still a function
 
user12867493
@inspectorG4dget Ok.
 
Joe
8:52 PM
anyone learn some basic game dev with PyGame first and then transition to something like Unity afterwards? Good idea or are there better strategies for learning game dev?
 
user12867493
@Joe I started learning with Unity straight away.
 
Speaking with no experience whatsoever, I doubt that a lot of PyGame knowledge will translate into Unity knowledge
 
^
But there is of-course the growth in related knowledge/terminology that might increase once you are familiar with a framework(pygame or whatever).
 
Joe
To be honest the PyGame part is simple really, the difficult part has been the programming/structuring the code - which I think is now a transferrable skill. Exactly what @CoolCloud said. But I do wonder if I'm wasting my time creating PyGame assets which are never going to be easily transferrable....
 
If you are new to it, you might need to start low. But doesn't Unity use an entirely different language?
 
Joe
9:03 PM
Yeh, it's C#! Not ready to move to C# just yet...
 
Mmmm no experience whatsoever, hope you figure out the best way :)
 
 
3 hours later…
11:58 PM
Hello Guys
Linear search in best case would need $n-1$ or $1$ to locate it!
Determine the least number of comparisons, or best-case performance,

1) required to find the maximum of a sequence of n integers.
2) used to locate an element in a list of n terms with a linear search.
My answer to both is $n-1$
What do you think?
 
06:00 - 19:0019:00 - 00:00

« first day (4027 days earlier)      last day (913 days later) »