I'm reviewing some code and I'm seeing a lot of this:
class Foo
{
public:
Foo()
{
// 'nuffin
}
void init()
{
// actual construction code
}
} ;
The only advantage I can see is if you create a Foo without using a pointer and you want to hold off its construction code until later, then you can.
Is this a good idea or a bad idea?
"__init__" is a reserved method in python classes. It is known as a constructor in OOP concepts. This method called when an object is created from the class and it allows the class to initialize the attributes of a class.
The ConstructorThe special method __init__ is the Python constructor. With an understanding of object oriented programming and classes, let's now look at how the __init__ method works within a Python program.
__init__() is not a constructor. We saw the self as the first parameter which is nothing but the object itself i.e object already exists. __init__() is called immediately after the object is created and is used to initialize it.
Creating the constructor in python In Python, the method the __init__() simulates the constructor of the class. This method is called when the class is instantiated. It accepts the self-keyword as a first argument which allows accessing the attributes or method of the class.
I dislike it. It seems to me that after construction, an object should be... well... constructed. That code leaves it in an invalid state instead, which is almost1 never a good thing.
1Weasel word inserted to account for unforeseen circumstances.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With