Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I don't get this hate toward OOP. OOP is just a tool to organize your code. Like function is a way to organize your code. When the whole program is 5 lines long, putting them in functions would be unnecessary complicate. Does one seeing that would conclude that function is unnecessary complicate in general?


My dislike of OOP is its emphasis on state. If you do foo.bar(), then you have changed the state of foo, even for other references to it. If you do foo=bar(foo), then the state of the original data is unchanged, while code below behaves the same way. In most cases, I find minimizing state minimizes bugs.

I do however like objects, and think that they can have a very good role in code.


There's nothing wrong with state. State is a fact of life in programming. Even pure functional program has states, which are the parameters passed among functions.

I guess you meant mutable state. You don't have to use mutable state with OOP - just create a class that allows state initialization in the constructors but nothing else, with none of the methods changing the states.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: