Hacker News new | ask | show | jobs
by the__alchemist 977 days ago
IMO before the before and after patterns are a mess compared to a struct in Rust etc or a dataclass in Python. `this` or `self` is important to be explicit; C++ is an interesting case in that it gives you a choice; `this->` is the better approach than implicit, which is ambiguous.

I can't tell from a glance from either before or after what the fields of the class are, let alone what sort of data goes in them. I suspect my IDE would have a struggle as well, and allow mistakes, at runtime, to either raise exceptions, or perform incorrect behavior.

I think maybe a cleaner approach in this domain may be TS interfaces + standalone functions that act on them.

1 comments

Typescript wil not help, you can create the same mass. What me helped is to write almost all code functional and not oop. Every method had just 1 way data can in and out the method, no side effects. Classes have a lot of flexibility that make things complex and increase bugs. If you are strict in what to accept and what to produce, and start with the test, if you create mess, you can eat refactor to create clean code.