Why coding style matters

Since I have been learning to code, I often got confused between coding styles in different languages. When learning, it becomes hard to remember that HTML can do without spaces at some points, while giving spaces between CSS selectors is a good practice. Python needs no semi-colon in the end but JavaScript is all about semi-colons. Naming the functions was another thing to keep in mind. I remember naming them all "var a", "var b" and so on alphabetically many times. But later when I had to refer to my own code, I could not understand it at all. That is where I realised how important the names were.

I was never a fan of writing comments, but when you have to written a 500 lines code without comments, you will be in a great problem when referring back to it. Also the style matters for the simple reason that anyone should be able to understand what has been written. When you work in a team of developers each one has to follow a style standard so that the code looks uniform. Otherwise the code would end up looking chaotic and unclear. Think of a code as a poem, it has to be beautiful!

Learning from my mistakes, here are basic style suggestions that can make a code look neat and easy to understand.

1. Tabs or spaces

Every language has its own style and indentation. Using them the right way is the most essential part of writing a clear code. For instance

2. Proper naming

Naming the functions and the variables incorrectly has been my frequent mistake. Better late than never right? Every language has its own conventions when it comes to naming. JavaScript uses camelCase, Python uses the lowercase names separated by underscores, HTML and CSS use lowercase attribute names and so on. Avoid using abbreviations or plurals. Another important thing about naming is using words that describe what is being done. For instance:

3.Adding comments

Commenting is another major area of coding standards. Comments should be clear, short and present only where the code gets complicated. They don't have to be every second line, but they have to be there where it gets hard to figure out what is happening. Comments are helpful for readers to understand the code. Remember that a long comment will make the code look rather messy. Keep it short and conveying.

Any fool can write a code that computers can understand. Good programmers write code that humans can understand. -Martin Fowler

Here are some good style guides that can be referred:

https://google.github.io/styleguide/javascriptguide.xml

https://google.github.io/styleguide/htmlcssguide.xml

https://www.python.org/dev/peps/pep-0008/

https://github.com/airbnb/javascript/tree/master/es5

https://github.com/airbnb/css