I wasn't too impressed by Microsoft's intro to OOP in their python teaching material on Coursera.
Shows the power of LLMs.
One way to think about abstraction might be - it provides an interface to the functionality hiding the implementation. You get power through the wall socket. Encapsulation saves you having to worry about whether the power plant is nuclear or hydroelectric.
Microsoft | ChatGPT | |
Encapsulation | This means keeping the details of how an object works hidden inside the object, so you can change those details without breaking the rest of your program. It bundles data and the actions that operate on that data within a class, protecting the internal state of an object. | Encapsulation means wrapping data and the methods that operate on it into a single unit (like a class), while restricting direct access to some of the object’s components. This protects the internal state and allows changes to the internal implementation without affecting external code. |
Abstraction | This simplifies complex systems by focusing on essential features and interactions, hiding unnecessary details. It focuses on what an object does rather than how it does it, so your code is easier to understand and use. | Abstraction focuses on exposing only the relevant features of an object while hiding the complex underlying implementation. It lets you interact with objects through clear interfaces, making the system easier to understand and use. |
There's got to be a few gems too - here's one Kent Beck would love :)
Function length: Finding the right balance
A function should be concise yet complete. A function that's too short can be cryptic and lack context, while a function that's too long becomes a tangled mess, difficult to understand and maintain. The balance lies in functions that fit on a single screen without scrolling, typically around 10-20 lines of code. This makes them easier to digest and comprehend at a glance.
No comments:
Post a Comment