3 ms·
Object orientism is just encapsulation. It’s the only thing that is required. You can have objects without inheritance and virtual dispatch.
by vips7L 11mo ago
Object orientism is just encapsulation. It’s the only thing that is required. You can have objects without inheritance and virtual dispatch.
- vbezhenar 11mo agoSo Python is not OOP language? You can't hide fields.
- bluGill 11mo agoIt has conventions to hide data. Good enough.
- vips7L 11mo agoPython was a mistake if you ask me ¯\_(ツ)_/¯
- cpburns2009 11mo agoPython is the worst programming language except for all of the others.
- vips7L 11mo agoI don’t know man. It’s honestly the last thing I would choose. There is literally always something else that is more appetizing.
- nr378 11mo agoYou can hide fields in Python with a little bit of gymnastics: class EncapsulatedCounter: def __init__(self, initial_value): _count = initial_value def increment(): nonlocal _count _count += 1 return _count self.increment = increment counter = EncapsulatedCounter(100) new_value = counter.increment() print(f"New value is: {new_value}")
- d0mine 11mo agoUsually, a simple function is enough: def make_counter(start=0): count = start def incr(): nonlocal count count += 1 return count return incr Example: >>> c = make_counter() >>> c() 1 >>> c() 2 But it hides nothing: >>> c.__closure__[0].cell_contents 2 >>> c.__closure__[0].cell_contents = -1 >>> c() 0 "private" in Python is cultural, not enforced. (you can access `self.__private` from outside too if you want).
- taberiand 11mo agoI would say specifically encapsulation of mutable data
- vips7L 11mo agoLots of modern OO uses immutable data.
- bccdee 11mo agoA lot of the underlying intuition behind OOP is expressed as "cells exchanging messages like an organism" and such, and I think that implies the distribution of state among a variety of small, special-purpose state-managers. More functional variants of OOP where state is managed centrally are a meaningful shift away from traditional ideas of OOP, and I think calling them both equally OO glosses over that shift a little.
- taberiand 11mo agoWhat's a good example? What comes to my mind is modern C# which I would say is a multi-paradigm language that encourages things like immutable records and interfaces and composition over inheritance as alternatives to the now less favoured OOP styles that it also supports
- bccdee 11mo agoLanguages like Go and Rust have module-scoped visibility, though. This is definitely encapsulation, but I wouldn't call it inherently OO.