Skip to main content

How to do Effective Programming?

There is no secret to doing effective programming but following a sequence of steps and procedures can help in building great programs. Today I will take you on a tour to some of the best practices that are integrants of perfect programs.

Algorithms are important: - You can’t deny the fact that algorithms are important and before start to write any program, Algorithms are must to write. For example, if there is a program about finding the sum of two numbers? What will you write ?The steps can be :-

1)  Get the first number.
2)  Get the second number.
3)  Add both numbers.

This is what algorithm is writing about ,a list of statements .From the above three statements you can conclude boundary cases (at least two number should be there in input), mathematical function(Sum is needed here) , storage capacity(amount of memory to be assign to the variables), number of methods by analyzing repeat steps (reduce replete codes) and many other things. During algorithm only you can build a solid idea about how your code will work and where it will fail. You can handle exceptions and many other things. Writing in simple language will help in starting up. Even for small programs please write an algo.

Pseudo Codes are the base of a program: - This is different from algorithms. Once you define everything on paper, you are ready to write pseudo code. Do not think about syntax in this step, just start writing your code for example:-

Input:-( You can define boundaries like A & B >0 or A & B is must and present , A & B can’t be decimals or any other thing)


This will be enough , it is important to note down what is coming and what is going? In middle everything is programming.

Input -> do some stuffs -> Output

Programming language is a material for the program:- Once you have written a code you can go for choosing a programming language that suits your problem statement. It can be based on memory , based on syntax , based on technical skill or based on anything. For example, if you choose java.You should know how java works and what is correct syntax.

Test Cases is like painting a program so that it looks better:-
Once Program is written in any of the language , next step is to check for the right results. If there is a bug for half of the test cases and for half it is working there is no use. If a program is working independently but not as a combined again there is no use.

The best technique to finish up your program is running through it with several test cases. Think about all the scenarios... where the program is in use  and run every corner of it. Whether it is about checking with some odd values or checking it with an infinite list of values.

See where it is breaking ? how much time it is taking to solve the problem? Where it is fast ? where it is slow? Which kind of situation is it favoring? where it is not? For me, this is the most sensitive steps that need to take care of with focus.

If you find any improvement go back to the first step and repeat until you get the best solution.

Hope you find a good answer from above notes, in the case of any doubt please drop me a comment .You can also follow to this website for other tutorials and future tips.



Popular posts from this blog

Basics of System Design

This article is first one from the series of articles dedicated to system design interviews. Here i am going to present the base scenario to consider before starting to solve system design problems.
Questions to ask?
1) what is the number of requests a website will recieve in a day/month/second? 2) what is the amount of memory a website will deal in a day/month/second? 3) what is the number of servers that can accomodate these requests?
To answer this , first we need to remember the below numbers:-
1 million = 10 lakh = 1000000 = 10^6 1 billion = 1000 million = 10^9
1 KB = 1024 B = 10^31 MB= 10^6 = 1024 KB 1 GB= 10^9 = 1024 MB1 TB = 10^12 = 1024 GB
Memory we need to see in BytesRequests we need to see in numbers
example :-
suppose a website recieves 100M requests every month then:-
requests per day = request per month /24 = 416700 requests requests per second = requests per day / (24*3600) = 4.8 requests per second
if we take 20:80 principal where 20 percent is write and 80 percent is …

Calculating size of User and Cache storage

user storage:-
it can be solved using same scenario as mentioned in first article .

Suppose there are 12 Million of users are adding every year meaning 1 Million per month.
So if we consider 5 year there will be around 60 million of users. Now in terms of data we can look to our DB table and get information about it. A user will be generally having name , id , address , some forien keys .
Lets assume 10 columns with each column on an average storing 4 byte of data.
10*4 = 40 bytes of data for one user.
60 * 10^6 * 40 = 2400 * 10^6 = 2.4 * 10^9 = 2.4 GB of data we need to store only user values.
Also while calculating storage for the user there is also one important point we need to remember is of ids. If we are going to have 60 Million of users which means 60*10^6 users so unique id’s will be
as we know below figures are almost equal
2^10=10^3 then 60*(10^3)^2 = 2^20 *2^6
which means we almost need 26 …