DEV Community

Avinash Tiwari
Avinash Tiwari

Posted on

A cleaner way of writing code

I always have those Ahaa! moments, whenever I start making sense of something, I learn theoretically.

I am lucky to be in such an environment to experiment with my day-to-day work, so I can add that extra delta to my learning each day.

One such moment was to start using a class-based approach!

I mean we have been taught about Object-oriented programming since we started gaining consciousness in IT!

We mug things up for the interview...
"Encapsulation is object's attributes and methods under a single roof...blah blah blah"

But, to use it thoroughly, in our day-to-day life is missed by many of us engineers.

I asses a lot of engineers when I get a chance to take interviews, and I feel that not many are using the class-based approach, which in my opinion might make the thinking around the project much richer and code quality much "sexier".

And of course, a lot less work!

A few things I feel have improved in my code quality after writing in classes are:

  1. I can think beforehand about the business logic thoroughly before writing code
  2. Helps in structuring and refactoring the codebase
  3. I can save myself from writing lots and lots of code, as I can just extend classes
  4. Can follow DRY(don't repeat yourself) and hence, saves a lot of time

For Java people, it is quite mandatory to go with that approach. But, I urge all the other, Python, and Node developers to start writing in a class-based manner.

I promise you! You'll come and thank me!

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay