Where to start? (C vs Python) Part 1

main-qimg-8d0d7c58813161115fc9adc1037efa87-cIn this day and age, if you are not a native English speaker (which is a majority of us considering world demographics),  to be able to communicate in English is a skill that is almost a necessity for any job. You might not need to use it on a daily basis, but every so often you face circumstances where being able to communicate in English makes life easier. This is especially true for people in STEM fields, since most of the world research and books are published English first. Such is the situation looking forward with programming as a skill too.

People often ignorantly associate programming with some kind of computer hacking or large scale software development. The fact is that programming in the near future will be a very general purpose skill that most people will be expected to have regardless of the job. Even today, programming is used for a very broad spectrum of applications, from typesetting documents using LaTeX, to building websites using HTML5, to developing mobile apps using Java (Android) or Objective-C (iOS), to making Excel macros using VBA, to using C++ for building video games, to designing electronics using Verilog HDL, to using R for statistical analysis, and the list keeps on going. Programming is effectively our method of communication with computers, and as the use of computers keeps growing, so will the need for programming in different jobs. You don’t have to be a software engineer or a computer programmer to need programming in your job, you could just as well be an accountant who needs to automate a spreadsheet using macros, or a small business owner who needs a website to grow the business.

With that said, this article assumes that you have some interest or curiosity regarding computer programming and would like to know where to start considering the number of programming languages we have which can be a very intimidating choice for a beginner. The current trend in academics is to start students off with either Python or C depending on the field of study. Both of these are very popular programming languages with their own advantages. This article will try to provide a sneak peak of what working with each of these languages is, their scope in terms of usability, and finally my own personal opinion about it.

Python

The Python programming language was first introduced in 1991. Over the last decade, Python has become a very popular and widely used programming language due to the nature of its syntax and a huge list of supported libraries that allow everything from building graphic games to data processing. What sets this language apart from others is the code readability of the syntax, allowing programmers to build application by typing as low as 10% of the code they would need in other languages such as C. Python is mostly taught as a general-purpose  introductory programming language to students outside the fields engineering and computer science.

C

The C programming language was first developed in 1969 at Bell Labs. It is one of the oldest and most widely used programming language today. A lot of modern programming languages such as Java or Python are based on C at the backend, which makes it, in a sense, the living grandfather of most programming languages. It is a very well established language, and very little has changed in it for more than a decade now. This means that once you learn C, it is not the kind of language that requires you to keep updating your concepts or syntax. C is mostly taught as a first language to students in Engineering and Computer Science. What sets this language apart is the ability to access very low level aspects of a computer and, in my opinion, the minimalist nature of the language which will be explain later.

Syntax Comparison

In one of the previous articles on this blog titled Hello, World!, I showed you how a very simple program to display the message “Hello, World!” can be written in some of the popular programming languages today.  Below is the code shown for the  C program followed by the Python program.

#include

main(){

    printf("Hello, World!");
}
print ("Hello, World!")

From the very first sight,  the simplistic nature of Python syntax is very apparent. While it takes multiple lines of seemingly unintuitive code for the C program, the Python program is just a simple one liner that is very easy to understand with no prior programming knowledge. This is the case with the entirety of Python programming in general, the syntax is very intuitive for people who do not have a background in computer programming, and most of the times it takes much less code to accomplish the same task in Python when compared to most other programming languages. As an example, below is another program that asks the user for a number and finds the sum of all the numbers between 0 and that number.

// C program
#include 

int main(){
 int sum = 0;
 int num;
 
 printf("Please enter a positive number: ");
 scanf("%d", &num);

 for (int i = 1; i <= num; i++){
 sum += i;
 }

 printf("The sum of all numbers upto %d is %d\n", num, sum);

 return 0;
}
# Python program
sum = 0

num = input("Please enter a positive number: ")

for i in range(0, int(num)+1):
 sum += i

print ("The sum of all numbers upto ", num, " is ", sum, "\n")

These examples should give you some understanding of the syntax difference between the two languages, and this difference goes throughout. It is not an opinion, but a fact that the learning curve of C is much steeper than Python, and this is one of the reasons why Python is much more popular language. However, this does not mean that Python syntax is necessarily better than the C. You might notice that every line in the C code is ended by a semicolon, and this is for a very good reason. In C, one line of code does not end when you go to the next line, this means you can split a long line of code in C by just typing part of it on the next line. A similar case with the For-Loop, the lines of code inside the For-Loop in Python is represented by the indentation because Python lacks the opening and closing braces used in C. The C syntax can seem complicated at start, but everything is there for a reason. Another issues with python is the fact that there are two different versions of Python that are being popularly used, Python 2 and Python 3, and the syntax difference between the two is big enough that even a simple hello world program that works in Python 2 might not work in Python 3.

# Python 2

print "Hello, World!"
# Python 3

print ("Hello, World!")

Furthermore, since C is such an old language, its syntax is adopted by most of the popular languages today such as Java, Objective-C and C++. This means that understanding the C syntax is can make it easier to transition to other languages.

To continue reading, click here.

Mr Panda

Advertisements

One thought on “Where to start? (C vs Python) Part 1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s