hi @monorail would you like to see a really fucking stupid joke

Follow

@The_T @monorail its a programming joke so i wasnt sure you would get it

the mechanism available to Python programmers to modify initialization logic for certain kinds of data called "objects" (don't ask) requires creating a function called __init__

@wallhackio (I know, the joke was that I didn't get it so I immediately go to @monorail to explain it)

@onfy @The_T @monorail in case you are familiar with object-oriented programming, what you put in a "constructor" in most other languages (usually) goes in a class method called __init__ in Python

@wallhackio @The_T @monorail ah you see despite knowing how to program to a limited extent, I do not, in spite of this, know what anything is called

@onfy @The_T @monorail I'm not at all familiar with AGS or AGI but a quick scan on wikipedia tells me they are like C, which is not object-oriented, so it makes sense you wouldn't be familiar with the concept

@wallhackio @The_T @monorail I almost forgot about C# actually. it was the first one I learned haha (in high school) though in part because of linux I haven't really used it since

but AGS heavily resembles C# which helped a lot when I made a (terrible) game

@wallhackio @The_T @monorail AGI otoh is really old and more resembles a very limited mix of C and basic

@The_T @monorail most other languages called this function a "constructor"

⚠️ i've been writing python for most of my time on earth ⚠️ 

@wallhackio @The_T extremely loud incorrect buzzer

most languages don't have anything exactly equivalent to __init__, but they have something equivalent to python's __new__. in python we just prefer to create bare objects and initialize them rather than do it in the constructor for some reason

re: programmer wonking 

@monorail @The_T i mean yes you are correct, but you proved me wrong so get reported dummy

re: ⚠️ i've been writing python for most of my time on earth ⚠️ 

@monorail @wallhackio @The_T I'm an absolute noob at Python and mostly use it for non-object-oriented scripting, can you tell me about the difference between __new__ and __init__?

re: ⚠️ i've been writing python for most of my time on earth ⚠️ 

@vaporeon_ @monorail @The_T normally in OOP, object instantiation logic is contained within a constructor, but Python decided to split the process into two steps:

1) __new__ is a function which returns the instantiated object,
2) __init__ is a function that receives the instantiated object and and initializes its state

It is very rare that a Python programmer ever use __new__. In 99% of cases, what you would put in a constructor in some other language is put in the __init__ method when you use Python.

You can override __new__, however, so that it returns anything you want. You typically do this when you subclass immutable types. Because, if you try to manipulate a subclassed immutable object in the __init__ function, well you can't. Because its immutable. So you have to override the creation of the object itself, typically by calling the superclass's constructor, in the __new__ method.

Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.