5 Dead-Simple Programming Rules For Junior Developers To Write Senior Level Code Even If They Think They Can’t

I’ve been programming for the last 12 years and consumed dozens of books on software development.

Throughout that time, I observed general rules that make quality code that developers love and make a codebase easy to maintain long-term.

The worst codebases I worked in did not follow these rules. Let’s see what they are:

#1. Use pure functions

Pure function properties :

  1. the function returns the same result for the same arguments
  2. Calling it has no side effects (no mutation of local/global state or of other components).

Pure functions are easy to test, predictable, and easy to work with. We cannot build modern applications only with pure functions but use them as much as possible!

#2. Make it work, then make it pretty

It is easier to rewrite bad code that gets the job done than write good code from the start.

First, solve the problem, then make the code readable.

#3. Be clear, not clever

Junior programmers like “cool” syntax and code that makes them look “smart.”

  • Don’t use regex unless you comment on what it does.
  • Use the easiest syntax to understand
  • Comment algorithm sections that are hard to understand

#4. Keep application levels separate

Spaghetti code — Code that is unorganized and involves different layers on the same level.

Example: You have the DB query logic in the same function that does logic for handling a request

Rule of thumb: Your function/method/code should do one thing, not two or three.

Think of it like this: If you write the database interaction layer for your app, you should write it so that if tomorrow you decide to switch from MongoDB to PostgreSQL, there should be no modifications in other layers of your application.

#5. Keep mutations on the outskirts of your application

Mutations are operations that modify the outside world/global state:

  • POST/PUT requests
  • DB insertions
  • Writing to files
  • Modifying application state

Mutations are not bad, but they can be unpredictable and hard to test.

You should make these operations at the last step of your flow.

Now go out there and write code others will love to read and maintain.

This post was created with Typeshare

--

--

--

Hi, I’m Ovi Stoica! I help people build quality software and I write about technology, startups and marketing for developers.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Bouyant CEO on why cloud-native, why now, and why doing it at Twitter was very hard

Cloud Computing

For Android Developer Collection or Goodbye G+, part 4

How to deploy Scylla DB alternator in EKS?

How to Use AWS API Gateway with Let’s Encrypt

Happy trip to Kubernetes in our company.

Explain Like I’m Five: The S.O.L.I.D Principals of OO Programming

Demystifying Quality Assurance

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ovidiu Stoica

Ovidiu Stoica

Hi, I’m Ovi Stoica! I help people build quality software and I write about technology, startups and marketing for developers.

More from Medium

My Experience on the GTF Engineering Bootcamp

I Was Wrong About Hackathons

4 Great Future-Proof Technologies To Require From Your First Frontend Developer When Starting a New…

Job interviews: how to excel