anitsh / til

Today I Learn (til) - Github `Issues` used as daily learning management system for taking notes and storing resource links.
https://anitshrestha.com.np
MIT License
77 stars 11 forks source link

Design Patterns Revisited in Modern Java by Venkat Subramaniam #978

Open anitsh opened 1 year ago

anitsh commented 1 year ago

Arrive to the meaningful patterns via gradual refactoring.

Build mindset as thinking of patterns as a communication tool rather than a design tool.

Think in pattern. Evolve with pattern. Do not try to patch code with patterns.

Patterns should be a part of a well designed programming language. We are already using it in frameworks.

Well designed code should read like a story. It should not be a puzzle. Patterns should help write a good story that should be easy to read.

Code should convey the intention clearly and easily. Code should revel what it's doing simply without making readers think twice. Code should be empathetic to the readers.

Null is smell. Return a value.

Fail at compile time, not at runtime.

Understand mutability. Practice Pure Function. Do NOT mutate data. Return a value. A function must be idempotent.

Idempotent: A property of some operations such that no matter how many times you execute them, you achieve the same result.

Pure functions are the core of Functional Programming. Object-oriented Programming when done correctly, strictly, exercises pure function in a Class method.

Minimize verbosity. Manage the level of verbosity. Too verbose is not good because it take more time read, think about it and understand.

Never trust feature called "Management". 😂

anitsh commented 1 year ago

Building Article

Insightful presentation on Design Patterns by Venkat Subramaniam.

Talk is about refactoring in Java with Functional Programming values using design patterns as a communication tool to add and improve code quality.

Key Points: We must allow ourselves to arrive at meaningful patterns gradually via continuous refactoring.

We must build our mindset to think of patterns as A Communication Tool rather than just a design tool.

Code is an artifact representing the communication from the collaboration between many stakeholders. It’s a document that generates meaningful functionalities.

We must think in patterns and evolve with them. We shouldn’t force patterns into our solutions and we shouldn’t try to patch our code with patterns.

We must try to realize the patterns that exist everywhere and we might already be using them. Object Oriented and Functional Programming are also patterns. Well designed programming languages have in-built patterns. For example, in Java, tools for encapsulation and abstraction such as Inheritance, Polymorphism, Interface, etc. are implementation of design patterns. Also, frameworks like Spring and Hibernate, are built with some pattern to solve certain problems.

A well designed code can tell a good story. Implementing appropriate patterns enables us to write that good story. A good story that is easy on the eye and easy on the mind, we can easily follow what's going on, why it happened and visualize what's going to happen or predict what might happen. Thus, we are enabled to maintain and document the code efficiently and effectively.

Effortless maintainability lowers cognitive load that makes onboarding easier. One of the biggest challenges to many organizations when systems grow large and complex without standard coding practice, the onboarding cost rises significantly. It takes a lot of time and effort to onboard new members to the team. It’s even difficult to revisit the code after some time.

A programmer must be empathetic to the reader. They must code in a way that conveys the intent clearly and easily. A well written code simply reveals its purpose without exerting readers' thoughts. Also when code is readable, it will also become easier to test by default.

Null smells. Always return a value.

Fail at compile time, not at runtime.

We must practice Pure Function. A function or method becomes pure when it does not change the data of any variable that is outside of its scope and it is idempotent.

The key to successful pure function implementation is passing by value and not by reference.

Although pure functions are the core of Functional Programming, Object Oriented Programming, when done correctly, strictly exercises pure function in a Class method. Class encapsulates its attributes(variables) to only allow its methods to access them.

Idempotent: A property of some operations such that no matter how many times you execute them, you achieve the same result.

We must try to minimize verbosity. Manage the level of verbosity because too verbose code takes more time to read and understand.

programming #designpattern #bestpractice #refactoring