How to write better code than ChatGPT? Part2

John Francis
5 min readMay 22, 2024

--

This is the continuation of the previous blog

Software Development Principles SOLID-DRY-KISS

In the field of software development, applying solid principles plays a crucial role in ensuring the quality, maintainability, and longevity of projects. These principles provide guidelines and best practices for designing and writing robust and efficient code. Among these principles, SOLID, DRY, and KISS hold a prominent position, but there are also other equally relevant principles

More details regarding software development principles can be found here

Clean Code

Clean code is written in a way that makes it simple, concise, and expressive. It follows a set of conventions, standards, and practices that make it easy to read and follow.

Clean code is free from complexity, redundancy, and other code smells and anti-patterns that can make it difficult to maintain, debug, and modify.

Good documentation, consistent formatting, and a well-organized codebase are all indicators of clean code

There is a good book on how to write a clean code

Code reviews

Code reviews are a part of every healthy engineering team. They are a great way for authors to get peer feedback and for reviewers to gain more knowledge of the system and the new changes.

Here are the 10 tips for better code reviews and check Google’s code review process

Code Performance

Not only writing good/clean code is important, but you also have to measure how your code is performing in the live environment and in specific conditions

Here are some key performance testing metrics you should consider

Documentations

Your comments and variable names are the documents of the code you write. Then what is the need for the document?

The document is a must not only for the code you write but for the product/feature your are building.

As you agree and plan on building a new feature or a new product, there will be multiple discussions and decisions taken by the team. As the days pass the discussion can steer in different directions and there should be a single source of truth for all the stakeholders (Product Managers, Designers, Business, and Engineering teams).

This document will serve as the platform for

  • What is the problem you are solving?
  • What is the solution to the problem?
  • Flow diagrams
  • Architecture design
  • All the decisions which were agreed upon
  • Test Cases to be tested
  • Release timelines
  • Delays and Blockers if any
  • Launch Plan and Release Timelines & Dogfooding
  • Go-To-Market strategies
  • Post-release monitoring
  • Futures enhancements & plans

Here is a sample product coda document for reference

Professionalism

Professionalism is a loaded term. Certainly, it is a badge of honor and pride, but it is also a marker of responsibility and accountability. The two go hand in hand, of course.

You can’t take pride and honor in something that you can’t be held accountable for. It’s a lot easier to be a nonprofessional.

Nonprofessionals don’t have to take responsibility for the job they do — they leave that to their employers. If a nonprofessional makes an error, the employer cleans up the mess. But when a professional makes a mistake, he cleans up the mess.

What would happen if you allowed a bug to slip through a module, and it cost your company $10,000? The nonprofessional would shrug his shoulders, say “stuff happens,” and start writing the next module. The professional would write the company a check for $10,000!

Traits of Professionalism

  • Taking responsibility
  • Do No Harm
  • QA should not find anything
  • You must know it works
  • Work Ethics
  • Know your field
  • Continuous learning
  • Collaboration
  • Mentoring
  • Know your domain
  • Humility

For more details on the above traits read the first chapter of “The clean coder” book

Continuous learning

Would you visit a doctor who did not keep current with medical journals?

Would you hire a tax lawyer who did not keep current with the tax laws and precedents?

Why should employers hire developers who don’t keep current? Read books, articles, blogs, tweets. Go to conferences. Go to user groups. Participate in reading and study groups. Learn things that are outside your comfort zone. If you are a .NET programmer, learn Java. If you are a Java programmer, learn Ruby. If you are a C programmer, learn Lisp. If you want to really bend your brain, learn Prolog and Forth!

Prioritize things

Do things which is important!

The Eisenhower Matrix is a task management tool that prioritizes tasks by urgency and importance. The tool divides tasks into 4 boxes based on what to first, what to schedule, what to delegate, and what to delete

Read more..

Security

You might have written a very good code whose performance is better and works fast and scalable, and is well documented and maintained for a long time. But if it's not secure, and is prone to attacks and leaking customer data, it is of no use.

Software security refers to the degree to which software protects information and system resources, providing access only to authorized users as intended. It encompasses practices like threat modeling, secure coding, security testing, and vulnerability management applied throughout the software development life cycle.

The goal is to prevent, detect, and recover from attacks and unintended weaknesses that could compromise the confidentiality, integrity, and availability of software systems and data. Software security seeks to build in protections proactively rather than reacting to threats.

It involves vigilance across requirements, design, coding, testing, deployment, and maintenance. A comprehensive software security program requires involvement across teams and management levels.

Conclusion: writing better code involves a combination of thorough problem understanding, clear design, adherence to best practices, and continuous learning. By focusing on readability, modularity, error handling, testing, and regular refactoring, you can enhance the quality and maintainability of your code. Staying updated with industry developments and learning from experienced developers will further improve your coding skills over time.

References:

https://talent500.co/blog/good-coding-practices-for-backend-developers/

https://www.toptal.com/software/six-commandments-of-good-code

https://www.quora.com/I-have-written-lots-of-code-and-programs-How-do-I-write-better-code

https://www.freecodecamp.org/news/how-to-write-clean-code/

https://sarrahpitaliya.medium.com/understanding-software-architecture-a-complete-guide-cb8f05900603

https://www.freecodecamp.org/news/an-introduction-to-software-architecture-patterns/

https://github.com/mrbajaj/books/blob/master/clean-coder-conduct-professional-programmers.pdf

--

--

John Francis

FullStack Engineer at @_groww. Love to travel , crack problems and instant jokes. Follow me on twiitter @john1jan