Sunday, July 26, 2015

Which programming language should i learn?

This damn question always pops in everyone's mind before learning any programming language. Which language should i learn? And why?

This post categorizes different programming languages using analogy with characters of Lord of The Rings

-via carlcheo.com 

Python - The Ent




Helps little hobbits (beginners) to understand programming concepts.

Helps wizards (computer scientists) to conduct researches.

Its easiest to learn, and widely regarded as the best programming language for beginners.

Its widely used in scientific, technical and academic field i.e. Artificial Intelligence.

You can build website in python using Django framework.

USED TO BUILD: YouTube, Instagram, Spotify

Java - Gandalf




Wants peace and works with everyone (portable)

Very popular on all platforms, O.S. and devices due to its portability.

One of the most in demand and highest paying programming languages.

Slogan- Write once, Run everywhere.

USED TO BUILD: Gmail, Minecraft, Most Android apps.

C - One Ring


The power of C is known to them all.

Everyone wants to get its power.

One of the oldest programming language in the world.

Popular language for system and hardware programming.

USED TO BUILD: Operating System and hardware.


C++ - Saruman




Everyone thinks that he is the good guy.

But once you get to know him you will realize, he wants the power, not good deeds.

Complex version of C with a lot more features. Widely used for developing games, industrial and performance critical applications. 

Learning C++ is like learning how to manufacture, assemble and drive a car.

Recommended only if you have a mentor to guide you.

USED TO BUILD: Operating System, hardware and browsers.


JavaSript - Hobbit




Frequently underestimated (powerful)

Well known for slow, gentle life of shire (web browsers)

"Java and JavaScript are similar like Car and Carpet are similar"
- Greg Hewgill

Most popular client side web-scripting language.

A must learn for front-end web developer (HTML, CSS as well)

One of the hottest programming language now, due to its increasing popularity as server side language (node.js)

USED TO BUILD: PayPal, front-end of majority of websites.


C# - Elf




Beautiful creature (language), used to stay in their land, Rivendell (Microsoft Platform), but recently started to open up to their neighbors (open source) 

A popular choice for enterprise to create websites and Windows application using .NET framework.

Can be used to build website with ASP .NET, a web framework for microsoft.

Similar to java in basic syntax and some features.

USED TO BUILD: Enterprise and windows applications.


Ruby - Man (Middle Earth)




Very emotional creature.

They (some Ruby developers) feel they are superior and need to rule the Middle Earth

Mostly known for its popular web framework, Ruby on Rails.

Focuses on getting things done.

Designed for fun and productive coding.

Best for fun and personal projects, startups, and rapid development.

USED TO BUILD: Hulu, Groupon, Slideshare


PHP - Orc




Ugly guy (language) and doesn't respect the rules (inconsistent and unpredictable)

Big headache to those (developers) to manage them (codes)

Yet still dominates the Middle Earth (most popular web scripting language)

Suitable for building small and simple sites within a short time frame.

Supported by almost every web hosting services with lower price. 

USED TO BUILD: Wordpress, Wikipedia, Flickr


Objective C - Smaug




Lonely and loves gold.

Primary language used by Apple for Mac OS X and IOS

Choose this if you want to focus on developing IOS or OS X apps only

Consider to learn Swift (newly introduced by Apple in 2014) as your next language.

USED TO BUILD: Most IOS apps and part of Mac OS X

Thursday, July 23, 2015

Difference Between Compiler and Interpreter

Both compiler and interpreter are translators.In their simple definition, they are the programs that are used to convert one language into another language.
Your one language can be programming language like C, C++, Java etc. and another language can be machine language (binary code).
You can see from below diagram what they both does:







There is one more important work of these two programs other than translating the code. They are also used to check errors in the code. If your code is erroneous then they will not translate your code into another code.

So based on these two workings i.e. Checking Errors and Translation, compiler and interpreter differs from each other.

The major difference is that the compiler analyzes the whole code at a time and interpreter analyzes one line at a time.

So compiler reads the code fully at once, gives all the errors at once, and if code is error free then converts the full code whereas interpreter works line by line, it reads one single line at once, give error only at that particular line, and if that line is error free then it converts only that particular line.

Then question arises, which technique is the best to use?

If compiler is the best then why anybody will use interpreter at all and vice versa. Both the techniques have their advantages and disadvantages.

> Compiler is Slow but gives all the errors at once

             Now think you have developed a programs but it contains many errors at different lines. May be all these errors are coming due to some single problem in your code. So it will be better for you if you receive all the errors at the same time and you can find out the root cause of  all your errors. Compiler will take a a bit time to analyze your code but its better for you to get all the errors at once.
         Getting all the errors at once will make your debugging and development time very short. So what will you prefer to convert your source code into binary code? Obviously Compiler because source code is developed by human and humans learn by making errors.

>Interpreter is Fast but gives only one error at once

          Who doesn't like fast speed? But if you convert your source code using interpreter then the fast speed of interpreter will be only fruitful when your source code does not have errors (which is not true every time). You will get your error one by one, and it will get very difficult to find out the root cause of your errors when your code becomes complex. So interpreter's speed is very useful in case your code does not have any errors at all.

* Both compiler and interpreter will only check Syntax and Semantic (programming rules) errors.


In my previous post of how java is platform independent language? you have seen that Java uses both compiler and interpreter.

For converting source code, it uses compiler, since source code can be erroneous, so we want all the errors in one go. And for converting byte code into native code JVM uses an interpreter since byte code is already error free due to prior use of compiler, so at run time we will get fast speed of conversion by interpreter.

Hope that helped!!

Platform In-dependent Java Codes


Read this blog after understanding what is platform dependency Click here to know about it.
So the problem is understood now. We don't want Native codes that are dependent to O.S. and machines. We want some In-dependent codes. Java was the first language who gave this feature. Lets see through the picture below what Java has done.





Now in this picture the source code is created using Java. And we are analyzing a statement a + b in that code. We have to compile the code first to convert it into an equivalent binary code.

We are having Windows O.S. and Intel processor as our machine's platform. This machine will perform addition when ever 110011 code will be received by the program.

Compiler of java will not consider the underlying instruction set of machine. Rather it will consider Java's own created instruction set. For example - + = 111000 is the code (remember these are not actual instruction codes.). So java compiler rather than writing 110011 in the binary file has written 111000 code. This generated code is named as Byte Code.

Byte code is an intermediate code that can't be understood by any machine directly. Now we need a program that can understand this code. Java comes with a JVM (Java Virtual Machine) that contains an interpreter.

Now JVM knows what is the meaning of 111000 since JVM knows java instruction set. JVM converts the code again for underlying platform at the time of running the program. JVM is not an actual machine but it behaves like it has to do actual processing. So it is named as Virtual Machine.

So consider a situation you are running the Byte Code at Windows and Intel then JVM will convert the Byte Code to windows Native Code on the fly.
If you are running the same Byte Code at Mac and Apple machine then your JVM will convert the Byte Code to Mac's Native Code on the fly.

Hence your program will run on every platform by just compiling once on any platform. But remember, your JVM will be different for different machines.

Now you can give the byte code to any of your clients. They just need the compatible JVM to run your java program. And you will be like:


For understanding the difference between compiler and interpreter click here.

Platform Dependent Codes



Before understanding platform in-dependency let us see first the problems related to platform dependent languages and codes. C and C++ languages were widely used before Java came into picture. Let us view a diagram first to analyze working of programming languages.


In above picture, we have created a program using C or C++ language i.e. source code. Now as we all know we have to convert this program for machine understandable form or we can say some sort of binary code.
      Compiler is a program that converts one code to another code. If our program does not contain any errors then it will be successfully complied and we will get an equivalent binary code.

Now we have Windows Operating System and Intel Processor, which is obviously 80% of Indians do have ;D This is our Platform.

A processor is responsible for executing actual instructions of every program. It has its instruction set defined in it. For example we are taking for addition instruction (+) a binary code 110011. That simply means if 110011 code comes from a program then processor will perform addition.

So from that you can conclude that the responsibility of compiler is to convert + instruction from source code to 110011 in binary code. Likewise it will compile the whole source code to binary code.

You run the code and it is running very fine. You are happy that you completed your project and you are ready to distribute sweets.

Now consider a situation that this application you have developed was for a client that is not from India but abroad. Now we have to give him/her the application and we sent the binary executable file. Obviously we don't want to send our source code but will send the binary executable.
It is not necessary that your client also have the same configuration of machine that you have. Suppose he/she have Apple machine and Mac O.S.,  which is different from our platform. So it will also have different machine instructions for its processor. Consider:

+ = 101010    (for Mac)

Now that our binary file created, compatible for windows will not be understood by Mac O.S. And your situation will be like this:



The problem lies due to different platforms of O.S. and machines. The code that is compiled at Windows is loyal to Windows. That's the reason it is also known as Native Code.

Now what you can do here is purchase machine of Apple and Mac O.S., compile the same source code at this machine, it will generate Native code for Mac. Give that binary to your client and make your client happy.

This problem of platform dependency was huge at previous times. You have always seen for many softwares when you download them. The website gives you different binaries for different O.S.

To understand the Platform In-dependency click next.

Next