Sunday, October 17, 2010

Beginner's Guide to Programming



Programming, also known as coding, is the basic tool for programmers to design, test, debug and write computer softwares and applications that you use almost every day. If you want to use software that keeps track of your business details, or you want to develop a website from where you can manage your clients and employees, then programming is the tool for this. Even the drivers that you use for accessing different hardware resources of your computer are available because of programming. All these applications and different driver tools are written using a language. You can develop a new code or enhance your existing code according to the requirements. To develop strong and error free applications whether desktop or online, you may need to have strong understanding of different algorithms and you must also be good at logic. So to become an expert, you always need to take a start. This writing is meant for beginners who want to learn different coding languages.
Due to constant development in hardware and increase in the public demands, programming languages have also experienced developments. Once applications were built in FORTRON or COBOL languages, but with the passage of time languages like C, C++, Java, C#, ASP, Python etc were developed to assist programmers so that they can use these powerful tools to develop fast, easy-to-use applications and software. We are going to consider basics of advance languages like PHP, Python and PERL.
PHP
PHP was developed in 1995 by Rasmus Lerdorf and after its creation it has seen many amendments and newer versions. It is still being enhanced as it is an open source language. PHP is basically a script language which is used at server’s side for dynamic web page creation. PHP code is derived from basic languages like Java and C. It has some functions and methods of its own too. PHP code is used in the HTML text to achieve the “Dynamic” functionality in web pages. When somebody visits your webpage written in PHP, the server then processes the code embedded, for example some calculations, converts the result in to HTML form and shows it to the visitor.  
Uses of PHP
PHP has many advantages over static web page creation languages like HTML.
         It’s easy to understand and implement. It is also available in many languages; you can find documentations and online help easily.
         PHP is a flexible language and can be used in any way you want. Its not mandatory to use OOP concepts or any other conventions.
         When you use PHP, much of your time is saved due to dynamic property it allows.
         Using PHP allows you to gather data about every visitor of your page. Based on that data you can create customized web pages for those visitors.
         PHP allows the programmer to use thousands of tools available online.
         If you are creating an e-shopping website, then PHP allows you to maintain online shopping carts for every user.
         PHP saves system memory too as it does not use all of the system resources for its execution.
         It is a strong language that provides different mechanisms to avoid malicious attacks.
         You can even write your own customized codes for your website and connect them with PHP’s code.

Drawbacks
One of the drawbacks is that PHP’s execution time is a bit slower than the compiled languages like C. The fact that PHP is freely typed can create unexpected problems due to errors in the syntax.

Basic Syntax for PHP

Syntax is basically some rules and conventions that are defined for every language. These rules are important for writing well structured and error-free codes.
In the case of PHP, syntax for coding is same as the coding languages like Java, C etc. But it should always be contained within the tags.
For example:
<?php  your code here?>
Note that you must save your PHP embedded file with the extension .php, otherwise your web page will not function properly.

Sample code:
Following is a sample code in which PHP is embedded within HTML text.

<html>
<head>
<title>Starter’s PHP Page</title>
</head>
<body>
<?php
echo "This is my first PHP web page!";
?>
</body>
</html>

Remember that like C, a semicolon in PHP language shows the end of the PHP statement, so never forget a semicolon at the end of PHP statement.

Python

Python is a high-level language used for programming. Like PHP it is also used as a scripting language. Unlike PHP, it emphasizes on code conventions and proper syntax, so it is not loosely typed programming language. Python is used in variety of paradigms for programming. Along with its use as a scripting language, it is also used for creating non-script source codes. Python is also known as interpreted language which means that the Python code is converted into machine language only at runtime.

Uses and Drawbacks

Python language is not only easy to learn but it is also a very strong programming tool for developers. It can be used for many purposes due to its dynamic nature. It has a large library of tools which are freely available online. This language is very helpful when it comes to customizing your developments. It can be used for desktop as well as online applications. It can be used to develop games and network security measures. Python is preferred over the language PERL, is because of its usability. Code written in Python is not only easy to write but also easy to read and understand. It’s more effective to use OOP concepts in Python than in PERL.
There are some drawbacks too. One of the disadvantages of Python is that it is not good for application which need to process quickly. This is because it is an interpreted language.

Syntax and sample code:

The comment line in Python starts with “#”. Anything written after that hash sign will be considered as a comment by the interpreter. After invoking the interpreter, you will see the sign “>>>” at the command prompt which shows that interpreter is ready to take input.
You can do simple calculation on the prompt command like
>>> 2+2
Or you can assign values to variables and then perform calculation on those
>>> length = 10
>>> length * length * length
You can either print string as
>>> ‘This is a string’
>>> ” This is a string in double quotes.”
Or you can define a string variable as
>>> stringvar = “This is a string variable.”
>>> print stringvar
You can not only create lists, but also use loops for coding.

PERL

PERL is a very powerful high-level language. This language is used for dynamic programming. Since its birth in 1987, it has undergone many changes and enhancements. It has large collection of resources and libraries available free online. Codes developed by using PERL language are also called the Perl scripts. PERL language is perfect for short and straight forward codes.

Advantages and Disadvantages

PERL is an interpreted language. This property has rendered PERL with many advantages and disadvantages. These are listed below.
PERL, as already discussed, is an interpreted language, which means that it is compiled only at runtime. So, PERL written codes usually take more time than a simple C program to compile and execute.
PERL is not system specific and is supported by almost every operating system in use today. It also combines the best features of other languages. On the other hand, creating a binary file from a PERL file is extremely difficult. PERL allows dynamic memory allocation.
Syntax and Simple code

To create a PERL script, you will need a simple text editor application. There are also many IDEs available on net that are solely meant for PERL code. Remember that PERL code must be saved with the extension .pl, otherwise your code will not be functional. One more thing is that PERL does not allow spaces in the file names.
PERL is a case sensitive language like C. It will show an error if you will not take care of case sensitivity of your variable names.
Like Python, PERL comments start with a # sign.
For variables use the following convention to define them.
($) symbol (scalar)
(@) symbol (arrays)
(%) symbol (hashes)
Here is a simple example of a program that prints and assigns values to variables.
print "Content-type: text/html \n\n"; #HTTP HEADER
 
$number = 5;
$exponent = "2 ** 8";
$string = "Hello, Perl!";
$linebreak = "<br />"; #HTML LINEBREAK TAG
 
# PRINT THEM TO THE BROWSER
print $number;
print $linebreak;
print $exponent;
print $linebreak;
print $string.$linebreak;                                  

Resources

For PHP, you can refer to online tutorials like

For Python, you can refer to

For PERL, you can refer to online tutorials like

Conclusion
All the programming languages, be it C or Java, Python or PERL, have some advantages or disadvantages over each other. You can make use of any language and turn your knowledge into developing strong and secure applications. This was just the introduction to programming and few languages used for development purposes. From now on, we will focus solely on the language C++. Stay tuned for more...

1 comment:

Please comment, if you like the post, you find any mistake or if you have any query.