3 Simple Steps To Write Beautiful & Better Code

Step 1: Meaningful Names

  • Use Intention Revealing names: The name of a variable, function or class should answer these questions — why it exists, what it does and how it is used. For example →
🟥 DON'T DO THIS int d; // elapsed time in days
int t; // file age in days
function fileList() {} // get flagged files
--------------------------------------------------------------------
🟩 DO THIS
int elapsedTimeInDays;
int fileAgeInDays;
function getFlaggedFiles() {}

Step 2: Minimal Functions

function guessingGame() {
// generate a random number
----
----
// take user input
----
----
// check the input matches or not
----
----
// print the result
-----
-----
}
function isEqual(num1, num2) {
// returns boolean
----
}
function takeUserInput() {
// process & returns the input
----
}
function generateRandomNumber(startingNum, endingNum) {
// generates a random number in range
----
}
function guessingGame() {
// uses the functions for the game logic
----
}

Step 3: Comments

--

--

--

Increasing my knowledge by sharing it.

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

Recommended from Medium

10 Software Design Patterns You Should Know To Become a Principal Software Engineer

Deploying a Flask app to Kubernetes

HTML5 FEATURES

Serverless application with AWS Lambda and Kotlin. Part 4

Viewport Sizing & Resolutions — How it works for the iPhone lineup

5 must-have command line Kubernetes tools

HTB — Bashed Walk Through

Virtual Infrastructure Upgrade

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
Akhter

Akhter

Increasing my knowledge by sharing it.

More from Medium

Day 100/100 Reverse Function

Programming Is Learned Faster With These 7 Tips

7+ Reasons Why it’s Important to Learn Git as a Developer

Top 5 Programming Languages to learn in 2022