Let’s start off with an exercise: right-click anywhere within your browser window and select the “View Page Source” option. A new window should pop-up. Scroll down and see if you can understand or recognize anything. This is the code behind the face of this web page.
By peeking behind the curtain, you’ve just had a glimpse of the language that tells your computer how this page should appear. The code that you saw was a full mark-up of the page, also known as the document object model (DOM).
Now that you’ve experienced code first-hand, let’s look a little deeper into coding: what it means, and best practices for learning to code.
What Does Coding Really Mean?
Simply put, computer coding is the process of using a programming language to deliver instructions to a computer. The code tells the machine what tasks to perform and how to perform them. These detailed instructions are written in multiple lines of code, and a document full of code is called a script.
The script directs the computer to carry out your desired actions. You have to ensure your code is correct otherwise the computer will not understand your commands. Every script is designed for a specific purpose. Anything from resizing an image to playing a particular sound or video.
Any website you visit, application you use, or piece of technology you interact with, works by following code. In fact, even when you hit ‘Like’ on someone’s social media post, a script is triggered and shares your action with the world.
Let’s take a step further and discuss tips and techniques that can enhance your coding prowess and ensure you develop a good coding etiquette.
- Variable Naming Conventions
Web developers often use simple variable names like A1 and B1 as temporary placeholders, but later forget to replace them with something more meaningful. This makes code less readable and ultimately leads to confusion.
One of the first things you learn when coding is that your variable names should be easy to understand and clearly represent the data they store. The way you name your variables is key to making your code readable. The idea of variable naming while coding is simple: to create variable names that are self-explanatory and follow a consistent theme throughout the code.
Some types of variable naming conventions are as follows:
a) Multiword Delimited – Used to separate multiple words in a variable name without white space.
b) Hungarian Notation – This convention describes the purpose or type of the variable in the first part of the variable name, and then uses a descriptor to indicate the variable’s function. In Hungarian notation, the camelCase notation is used to delimit the words.
2. Class and Function Naming Conventions
Similar to variable naming conventions, functions and classes should also consist of descriptive titles that are delimited by using conventions, as mentioned above. The purpose of using appropriate naming conventions is to make sure that the variables, functions, and classes within your code can be easily distinguished from one another.
3. Add Clear and Concise Comments to Your Code
It’s pretty much guaranteed that your code will be modified or updated over time. It’s also true that almost all developers will come across someone else’s code at one time or another. A bad habit among inexperienced programmers is to include little or no comments while coding.
This poses a significant challenge for programmers working in a team, where more than one person may be working on a particular module.
Coding comments are segments of code that are ignored by the compiler. This means they are never passed to the computer and are not processed. Their sole purpose is to help the programmer understand the code, especially when returning to work on unfamiliar scripts in the future. For example labelling complex sections, dividing code into logical segments, or setting a reminder that a particular section needs updating.
Depending on the programming language, different symbols like “#”, “!” or “;” can be used to instruct the compiler to ignore the line with comments.
However, it is advisable to not to go overboard. Excessive header or inline comments can decrease the value of knowledge transfer among developers working on the same module.
Comments can be broadly classified into:
a). Implementation comments
b). Documents comments
Formatting and indentation are necessary to organize your code. Ideal coding formatting and indentation include correct spacing, line length, wraps and breaks. By employing indentations, white-spacing, and tabs within the code, programmers ensure their code is readable and organized.
Bear in mind there is no right or wrong way to indent your code. There are popular opinions but nothing is universally followed. Some people use 2 spaces, others prefer 4. The important thing here is to be consistent with your chosen style. Stick to one approach and follow it throughout your entire application. Problems and confusion only occur when indentation and formatting styles change halfway through a script.
Portability is a key aspect that ensures functionality of your program. If your code contains literal (hard-coded) values of environmental parameters, such as usernames, host names, IP addresses or URLs, it will not run on a host having a different configuration than yours.
In order to tackle this, you would have to ‘parametrize’ variables and configure them before running your software in different environments. This can be controlled with property files, databases, or application servers.
In addition, resources like XML files must also have variables instead of literal values. Otherwise you’ll have to change the references while coding every time you want to port your application to another environment.
6. Reusability and Scalability
In coding, reusability is an essential design goal.
Because if modules and components have been tested already, a lot of time can be saved by reusing them. Software projects often begin with an existing framework or structure that contains a previous version of the project. Therefore, by reusing existing software components and modules, you can cut down on development cost and resources.
This directly results in faster delivery of the project, thereby increasing profitability.
Another key aspect to pay attention to is the ‘scalability’ of code. As user demands change, new features and improvements are constantly added to an application. Therefore, the ability to incorporate updates is an essential part of the software design process.
Testing your work while coding is a vital part of software development and should be well-planned. It requires the test cases to be prepared before the actual coding of the software begins.
Also, while basic unit testing is a good practice to adopt, it is also useful to perform Automated Functional Testing (AFT) with the help of tools such as Geb Spock and Selenium. AFT is a structural testing technique that involves finding those areas of a program which are not exercised by a set of test cases.
With AFT you can create additional test cases to increase coverage and perform code coverage analysis.
Take Your Coding to The Next Level
Adopting these best practices should further your development as a coder and allow you to become more efficient on a day to day basis. The overall objective of this article was to guide you through the coding process and allow you to reap maximum results with minimum effort. Whether you’re new to the world of coding or a veteran of the game, being able to write efficient, easily-understandable code is fundamental to your overall success.
Best practices are a great place to start, but if you really want to master programming, enroll in our coding bootcamp. You’ll get a full-time program of online classes, mentorship and career coaching. Schedule a call with one of our in-house experts to find the right course and payment plan for you. Welcome to the world of tech.
Learn to Code with Thinkful
Take the proven path to a high-income career with professional mentorship and support, flexible ways to pay, and real-world, project-based learning.