JavaScript Clean Code - Quick Best Practices

If you care about the code itself and how it’s written, instead only worrying does it work or not, you can say that you practice and care about the clean code.

A professional developer will write the code for the future self and for the “other guy” not just for the machine

Based on that, the clean code can be defined as the code written in such a manner that is self-explanatory, easy to understand by humans and easy to change or extend.

Even bad code can function, but if the code isn’t clean, it can bring a development organization to its knees.

In this article, the focus will be on JavaScriptbut the principles can be applied to other programming languages.

#javascript #programming

What is GEEK

Buddha Community

JavaScript Clean Code - Quick Best Practices
Osiki  Douglas

Osiki Douglas

1624789560

Best Practices to Write Clean Python Code

Python is one of the most loved programming languages today. Shockingly, Python has overtaken Java in the list of top programming languages and is now the most studied language! It is the second most used language after JavaScript and is slowly beating the competition to be on the top. It is used extensively across various domains like web development through popular frameworks like Django and Flask, web scraping, automation, system administration, DevOps, testing, network programming, data analysis, data science, machine learning, and artificial intelligence. In fact, the first language which comes to someone’s mind when talking about data-related technologies is Python!

Along with being a heavily used language by beginners due to its ease of learning, it has huge community support and extensive documentation. But a lot of people when switching from other languages like Java, C, C++, JavaScript etcetera, find it a little difficult to follow along with the best practices that should be adopted to write clean code in Python. Clean code is easier to read and understand, debug, and elegant. So today we will be discussing all of them in detail, therefore you will get a better idea of them. So let’s get started!

#gblog #python #best practices to write clean python code #clean python code #best

Seamus  Quitzon

Seamus Quitzon

1600061880

How to write clean code ? follow these best practices for writing clean code

Hey programmers , this article is not about some java related feature or concept but more than that . Basically I’m going to explain what all mistakes a java developer does while writing the code and hence how you can minimize it and you don’t have to refactor your code .So this article is about BEST PRACTICES a developer should always follow .

1. What’s there in the name :

A developer should always try to give a meaningful name to the variables, methods and classes . It becomes too easy to understand what the method or class or variable is about when some one reads your code while reviewing it or debugging it. Giving name like a ,b,c to variable do not intent any meaning and becomes less relevant while debugging the code .

  1. Always start the name of a class with upper case .Eg.
public class Employee {

}

here **Employee **is class name and other developers can easily understand that this class deals with employee related stuff.

2. Always start a variable name with lower case .Eg.

private int salary;

here **salary **tells about salary of employee .

3.Always start method name with lower case and do not include And and Or words in method name .Eg.

public int calculateSalary(int noOfDaysWorked , int baseSalary)

4. Write constants in upper case and separate them with under score .Eg.

public final int RETIREMENT_AGE = 58;

Note : do not use special symbols while writing variables ,methods , constants or classes names .

#programming #best-practices #code-review #java #coding

Giles  Goodwin

Giles Goodwin

1603857900

4 Ways You Can Get Rid of Dirty Side Effects for Cleaner Code in JavaScript

According to an analysis, a developer creates 70 bugs per 1000 lines of code on average. As a result, he spends 75% of his time on debugging. So sad!

Bugs are born in many ways. Creating side effects is one of them.

Some people say side effects are evil, some say they’re not.

I’m in the first group. Side effects should be considered evil. And we should aim for side effects free code.

Here are 4ways you can use to achieve the goal.

1. use strict;

Just add use strict; to the beginning of your files. This special string will turn your code validation on and prevent you from using variables without declaring them first.

#functional-programming #javascript-tips #clean-code #coding #javascript-development #javascript

Code Trashing Symptom

There are a set of skills and qualities which make the ideal software

developer we are all searching to be or searching for to employ. However, right now I am going to emphasize the importance of a quality that is mostly found in senior developers.

As a beginner, I remember the enthusiasm when I implemented my first app. It was in VisualBasic v6.0 with very basic UI and logic. From there on,

it was very hard to leave the keyboard without writing code daily. At

first, it was VB, then some HTML, JavaScript (when it was very buggy),

Java, and sometime later I became a true working developer/team-leader

for many years.

Reliving those days when I was an enthusiast developer, I remember the powerful feeling that kept me on my path. I was (and still) addicted to code. But it is not code I was after. It is the vast feeling of creating something your own. Creating something from within. This strong feeling of a new creation is addictive.

The problem with addiction is that you don’t recognize the limits of

yourself and your creations. Consequently, you are not guided by your

consciousness.

As a leader of development teams in different projects, I came across a

variety of situations with different developers. But this same question I kept hearing from time to time, “This is a great piece of code, do you really want me to remove it?”, and it is really a great piece of code with the ultimate design.

But what you shouldn’t forget that you and your team are here to accomplish something meaningful for your clients and users! Thus writing a greatly designed code with low correlation to requirements isn’t going to change anything.

When I moved to my current team and project, I found out that the project’s code was written beautifully and well designed. But it was insignificant to our client’s future requirements.

One of the best decisions I made was to gradually re-implement (remove old code and write a new one without reference nor copy-pasting any parts). The reason being the already written code was a big hurdle to bend to any new requirements we received

Sometimes it’ll be hard to ask for, especially when you’re asking the original author of the code. But always remind him of these facts: your main focus is your clients; if you miss your code, Github will always remember it for you.

Acknowledging your addiction to code is your first step to overcoming your unconscious desire to create worthless stuff that no one will use (and believe me, it hurts more to find out that your code is useless than

removing a code you’ve written).

Final Thoughts

From my personal experience, when you implement something hard to solve the first time, most of your energy and thoughts are invested in solving the problem and not in the most relevant design for the given requirements.

Rewriting the same code a second time gives you a second chance to spend your time (almost solely) in design (since the problem is already

solved).

The best design is a design made for the current (known) requirements and not future mystic stuff that we just came up with.

**Remember: **Refactor! Don’t predict!

#clean-code #best-practices #programming #development #refactoring #coding #coding-skills #coding-life

Gordon  Taylor

Gordon Taylor

1624692360

50 JavaScript Best Practice Rules to Write Better Code

JavaScript is powerful and flexible which allows you to code any way you like and try some very unusual things which can lead to a bug in your code. Here are 50 things I learned about coding in JavaScript you should know about.

Always  “use strict” On

Use Function expressions instead of Function Declarations

Stop using “var”!

Use “const” and immutability as much as possible

Prefer Pure Functions

Prefer Class over Constructor Functions

Use “destructuring”

Only work with data you need

Always use “===”

Avoid Global Variables

Wrap loose declarations in blocks

Organize your declarations

Don’t initialize things with “undefined”

Always initialize your declarations

Lint your code and have a consistent style

Use TypeScript

Functions and methods should do one thing only

Don’t be lazy when naming things

Avoid unnecessary declarations

Use default values when possible

Always have a default case for switch statements

Never use “eval”

Avoid the “new” keyword

Add meaningful comments for nonobvious things

Keep ternaries simple

Simplify with optional chaining

Prefer promises over callbacks

For loops > .forEach sometimes

“for…in” and “for…of”

Optimize for loops?

Always “try…catch” JSON methods

Prefer template strings

Avoid nesting or chaining loops

Avoid Weird Unreadable hacks

Prefer the  “rest” operator over  “arguments”

#coding #javascript #best-practices