News for hackers. Stuff that matters.
Re:Frankenstein's `__init__` by ptsneves on Saturday April 19, 2025 @01:07PM (#43737717)
It is a tragedy that python almost got some form or RAII but then figured out an object has 2 stages of usage.

I also strongly disagree constructors cannot fail. An object that is not usable should fail fast and stop code flow the earliest possible. Fail early is a good thing.

Re:Frankenstein's `__init__` by jakewins on Saturday April 19, 2025 @02:01PM (#43738139)
There is no contradiction between “constructors cannot fail” and “fail early”, nobody is arguing the constructor should do fallible things and then hide the failure.

What you should do is the fallible operation outside the constructor, before you call __init__, then ask for the opened file, socket, lock, what-have-you as an argument to the constructor.

Fallible initialisation operations belong in factory functions.

Re:Frankenstein's `__init__` by int_19h on Tuesday April 22, 2025 @07:11PM (#43767143)
The real problem is that constructors and factory functions are distinct in the first place. They aren't, in Rust, and it's much easier to reason about and requires far less verbiage to write.
Re:Frankenstein's `__init__` by throw-the-towel on Wednesday April 23, 2025 @04:46AM (#43769919)
Why though?