Top 10 Programming tips

Include All Standard Libraries in One Go

Use #include <bits/stdc++.h> to include all the standard libraries in your project without including all of them separately. This is especially useful in a programming competition where time is precious. For example, you can replace this (and many more):

#include <iostream>#include <algorithm>#include <vector>#include <string>#include <stack>#include <set>#include <queue>#include <map>

With this:

#include <bits/stdc++.h>

Keep in mind

  • <bits/stdc++.h> contains a lot of header files that you might not need to use in your project. This can end up increasing the compilation time.
  • <bits/stdc++.h> is not the standard header file of the GNU C++ library. Thus, non-GCC compilers might struggle to compile. However, most of the time this is not going to happen!

Read Relevant Material

This could be an extension of the last tip, but in a different context. In this tip, the advice to read extensively is not just about the coding process alone. The idea is to boost your domain knowledge while doing coding work. In a majority of real-life situations, if you are engaged in writing code for a particular client, the client’s team will possess complete knowledge of their business, how it works, and everything else there is to know about it, but they would not know how to write the code for a program to improve that process. You may be an expert at coding, but your knowledge of the business you’re dealing with may be very limited. That’s why equipping yourself with information about a particular business is crucial. It will be much easier for you to program and deliver what’s expected of you.

JSON-esque

Python has a lot of hidden stuff underneath. It only takes a person and his time to find out what all magical operators and stuff are hidden inside. One among all the other stuff is the famous JSON-esque. You can create nested dictionaries without explicitly creating sub-dictionaries. They magically come into existence as we reference them. Example as follows: users = tree() users['harold']['username'] = 'hrldcpr' users['handler']['username'] = 'matthandlersux' Now you can print the above as JSON with:

print(json.dumps(users)) And it will look like this {"harold": {"username": "hrldcpr"}, "handler": {"username": "matthandlersux"}}

Use Auto To Omit the Data Type of a Variable

You can omit the data type of a variable by using theauto keyword in C++ 11 and later. This is extremely useful when you need to declare a variable at runtime, e.g., when using iterators. As an example, the data types of the following variables are declared during runtime.

auto a = 'a';auto t = true;auto x = 1;auto y = 2.0;

Comprehensive Range-Based for Loops

A range-based for loop is an upgraded version of the traditional for loop, and it was introduced in C++ 11. The syntax of a range-based for loop is:

for(range_declaration : range_expression)

As an example, you can loop through an array of numbers using a range-based for-loop as follows:

int numbers[] = {1,2,3,4,5};for (auto number: numbers){    cout << number << endl;}

Or you can loop through the characters in a string in a similar fashion using range-based for loop:

string name = "Charlie";for (auto character: name){    cout << character << endl;}

Pip

Pip is something maybe most people know of. But still, it is awesome stuff that you need to know if you are starting with python. Sometimes, you need to inspect the source of a package before installing it. Most of the times, it’s for installing a newer version of some package. So, you can simply install pip and do the following:

pip install --download sqlalchemy_download sqlalchemy pip install --no-install sqlalchemy pip install --no-download sqlalchemy If you want to install the bleeding-edge version of a package, you can directly check it from the GIT repository. pip install git+https://github.com/simplejson/simplejson.git pip install svn+svn://svn.zope.org/repos/main/zope.interface/trunk

Virtualenv

Another important function of python is Virtualenv. Virtualenv means Virtual Environment. This, now my friends, is a very awesome function of python. Basically, to test python in different conditions, you would normally you would have to change the global python environment. But, one of the key benefits of sandboxing your python environment is that you can easily test one code under different python versions and package dependencies. To install virtualenv, you need to install pip first. You can do as follows: easy_install pip pip install virtualenv virtualenv python-workspace cd python-workspace source ./bin/activate python

Use online resources

If you don’t find an answer, ask someone and if you don’t get your answer from them too, look for online resources. There are tons of YouTube videos, articles and Quora answers that will explain the same concept differently and help you learn programming on your own. These resources can help you learn and understand complex topics quickly and easily. Some of the resources that you can seek guidance and help from if you get stuck are freecodecamp, Udemy, Coursera. Also, you can read many articles related to programming on Stackoverflow, Reddit and other such online communities.

Learn From the Bugs

Life is an endless learning process. The previous generations had the luxury of making mistakes, learning from them, and then finding success. In today’s context, you have to be more alert and learn from others’ mistakes, and not commit the same errors yourself. Bugs appearing in a program you wrote are part of a fully acceptable and commonly occurring situation. Your programming skills lie in quickly detecting the bug and resolving it. In many cases, detecting the bug may take a while, but once found, it may take very little time to resolve or reset the codes. There are debuggers available that you can use to make the resolution process faster. The effort may have to be repeated a few times, since you will have to get back to the full program to test out the changes made in the coding and check if the expected output is being achieved or not.

Zen of Python

Last but not the least, it’s the Zen of python. Zen of python is a mini-guide for python programming. Even if you don’t program python, it’s still an interesting thing to read. Just simply go to the python interpreter and type:

import this And I won’t be explaining this one because it’s simply amazing to try it out yourself. And now, we have come to the end of the road. These are just my experiences, but if you find some, sure, do post it so that the world knows how exactly awesome python is. First Image Source: pixabay.com

;