Wednesday, March 23, 2011

Scripting vs Programming - Mastering the art of arts!

Why this post?

The line of difference between a script and a program has become very blurry these days to the extent that these terms are used interchangeably. Though there is no hard and tight way to theoretically define what a script is and say how it is different from a program, if you have done a lot of programming and if you are a person who loves to automate things, then you can definitely realize the clear line of difference between scripting and programming. In this article, I try to give my views on what scripting is, how it differs from programming, etc. (Whole of this article just represents my view and there is a good chance that some of it may be wrong).

What is a script?

A script is just a small piece of code, usually written in a non-traditional programming language (like bash or perl) that is used to get a job done. Well, sure you can’t see much of how it differs from the definition of a "program". That is what i try to explain on the due course of this article.

How does it differ from a program?
As i said earlier, there is no concrete set of rules to distinguish a script and a program. The main deciding factors are:
  • the purpose with which its developed
  • the design mechanism underwent on due course of development, and
  • the person who uses it

Scripts are generally very specific to their task. They just do what is to be done, nothing more or nothing less. Whereas programs generally have a broad scope. They are more sophisticated and usually do much more than what they are supposed to do. This is the difference with respect to the first point.

Scripts generally don’t follow any design. Scripts are usually just written, with no design in mind whatsoever. Even if they are complex, they aren’t designed with care and concern. Whereas programs on the other hand are designed to work with a proper flow and fault tolerance. Scripts are usually used by programmers themselves internally, whereas programs are full fledged tools that are used by everyone from geeks to laymen. To state an example, Facebook is a "program" and if you build something that will scrape data off facebook in the format you want, then that could be a "script".

Scripting is usually considered as programming as a part of developing an actual program. For example, the recent android patent issue says Google used a "script" to clean up all the comments and other stuff from the kernel header files. So, scripts can be generally categorized as utility functions that helps you making your "program" development easier.

What’s a scripting language?

Again, a scripting language is a programming language that is generally non-traditional. Scripting language usually provides constructs for doing things in the quickest way possible rather than in the most efficient way possible (For e.g. most of the scripting languages usually have a sort() function to sort the data. Though they may not be the most efficient implementation of sorting data, it gets the job done without fuss). Another aspect is that scripting languages are usually interpreted and not compiled. This gives the assurance that the script dies if anything goes wrong, the script starts over all again, taking advantage of the fact that scripts need not provide any atomicity over what they do.

Uses of scripting

I love automating things i do and hence scripting is a very essential part of my online life. Scripts can help your online life get much easier and better. For example, i have various little chrome content scripts (google chrome’s equivalent of greasemonkey scripts) that helps me make my day-to-day browsing easier and more productive. Also, i extensively use sed and awk scripts to browse through log files generated by the programs i develop. I even have scripts that help me check if there are new episodes of my favorite TV Serials (BBT, HIMYM) available for download and alert me.

When it comes to automating day to day online tasks, scripting is your swiss army knife. You can accomplish things quickly and in the way you want them to be.

Scripting as an art

We all know that programming is more of an art than a science. Developing a perfect program is close to impossible. But scripting too is an art that can aid you in making your programming life much better. Learning a scripting language at the beginning may seem weird, but once you get used to the constructs, it will really be a cake walk and you will find it a lot useful to have it as one of your assets.

To sum up..

Scripting and programming always go together. Scripting aids in automating things that will make a program better than what it is now. Though only a beginner, my humble piece of advice to every programmer out there is "Never hesitate to automate things. You learn a lot while automating silly things! So next time when you come across a silly problem in your work or in your project, try to tackle it with a quick utility script rather trying to fix it manually!"

-Vignesh