Clean Code Introduction
JustAWalrus (1180)

Hello, at the moment I am working hard at a HUGE full web dev course with @Coder100 so I needed to get something out here.

Clean Code: An introduction

Think of programming like poetry it should be beautiful and tell a small story about the creator itself not just making it work, or in the case of poetry, rhyme.

Clean Code is the art of making code well, clean.

The code is a relic, for example if the people writing the Unix Kernel at Bell Labs in 1970 would have used this practice we may be able to learn from their code, but nontheless, they failed to abide by the practice.

Is it really enough just to get the code working? I mean, think about it. Go back to some code you wrote a month ago. Can you read it? Maybe slightly but imagine someone who has never read it before trying to read it. That is why clean code is so important.


Cleaning up your code isn't hard and here is why. You won't even have to think about it once you do it for a few months.

Code shouldn't be about how small a program should be. We are past the time when computers had 4KB of RAM we have gigabytes of RAM and even hard drives now.

Let's walk through a few practices right now.

Variable and Function names

Variable names should be `camel case meaning that the first letter of the first word should be lower case and the first letter of the following letters should be upper case.

Variable names should be descriptive, not a mess of letters.


Which one of these is easier to read?


let randnumaa = 1;


let randomIntegerA = 1;

Let me guess. B?

Even B isn't good enough in most cases.

And if you cringed at A let me just say that I know some of you write code like this.

I am even at fault for some of my repls just because I want to get it done quickly.


I guess you expected me to say "Put comments everywhere!" or some nonsense like that. No.

NEVER use comments.


I (and many other people) think comments are a poor excuse for messy code.

Which of these is easier to read?


import random
def getRandomNumber():
  randomNumber = random.randint(0, 10)
  return randomNumber


import random
def rannumretaba():
  # Returns random numbers
  blahblahblah = random.randint(0, 10)
  return blahblahblah

Okay, let me guess. A?

While B used comments it was just an excuse to write lazy code.

Your code should explain itself and not rely on comments.

Short lines

DO NOT make super long lines.

We are not using 1 line displays anymore guys.


int radnumcool(int numa, int numb) {
  return (numa + numb) * 5 + 789 * numa + 5 + 78 + numb;

You know how painful that was to read?

Use your lines you have disk space now it is not 1970.


Thanks to @Bookie0 for suggesting this topic!

Spacing is very important in clean code.

Clean Code emphasizes readability and part of that is making breathable code.

What do I mean by this?

Well let me show you an example of breathable code.

#include <stdio.h>

int main() {
  printf("Clean Code is awesome!");

  int x = 6;

  int y = 5;

It is spaced out.

You want to refrain from adding too many spaces or too few.

You want to get a sort of goldilocks paradigm of spaces.


I know this was short and Clean Code is a very expansive topic.

If you want to learn more check out this.

And I will NOT be making a series out of this.

Anyway upvoting is caring :) - Bookie0 2020

You are viewing a single comment. View All
Jakman (473)

Nice course. You might want to tell the script kiddies not to use global variables all the time

JustAWalrus (1180)

Yea, they need to be stopped. @Jakman

JustAWalrus (1180)

In my opinion I like functional variables like that of F# better than the norm, but global ones are a crime against humanity. @Jakman

Jakman (473)

@Wuru these are usually the little python kids who have hundreds of cycles and dont know jack about a return value.

JustAWalrus (1180)

I do F# and C++ the most on my own time. @Jakman

DynamicSquid (4603)

@Wuru global variables are hated in C++, especially since we have pass-by-reference

Jakman (473)

@DynamicSquid nice to hear that every nearly language community hates globals.

HahaYes (1900)

@DynamicSquid hehe that one person who uses auto instead of int, long, string

DynamicSquid (4603)


Yeah, i agree lol, but...

std::initializer_list<std::size_t*>::iterator it = arr.cbegin();


auto it = arr.cbegin();

it's not completely useless

Jakman (473)

@DynamicSquid is auto all inclusive of every cpp type?

DynamicSquid (4603)

@Jakman Yes, I think. Even user defined ones

xxpertHacker (768)

@Jakman Auto is more inclusive that you think, destructuring in C++ isn't possible without auto at all!

xxpertHacker (768)

@Jakman Global variables are okay, as long as they're constant, btw, usually functions are global, although namespaces are much better.