Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Saturday, May 2, 2009

Scripting Languages



One enigmatic question that I find people often have a hard time giving a straight answer to is "What is the difference between a 'normal' programming language, such as C++, and a scripting language." This question leads to a lot of backpedalling and out spews a lot of general non-specific answers.

The term 'Scripting Language' refers to one of two different things. The specific definition refers to a programming language that controls software. An example of this would be QuakeC, which allows writing scripts for the popular fps game, Quake. Another example would be ASP, which works on the server side to dynamically generate web pages.

The generic term 'Scripting Language' refers to any language, whether used for specific applications or for general purposes, which is interpreted instead of compiled. An example of this general definition would be Python or Ruby.

"Aaah, now I get it." But what exactly is the difference between a language being compiled and a language being interpreted. An interpreted language is one that instead of compiled, is 'interpreted' and run at the same time. Essentially an interpreter is a dynamic compiler. it interprets each line of code in your program into machine code and then runs it at the moment. This contrasts to a language that must be compiled into machine code all at once and then run.

While an interpreted language runs slower, the syntax is often more powerful, interpreted languages allow for things such as implicit typing, which means you don't have to declare the types of your variables, and that you can change them on the fly. Programs or 'Scripts' often take a lot less time to write then if they were written in an a compiled language.

As a last note, I prefer the stricter definition of "Scripting Language", and generally so do programmers who use languages such as Python. If you have any expert knowledge of interpreted languages, please share below.

Friday, April 24, 2009

Ruby Gems and Python Eggs








Ever need to write some code and think to yourself "Somebody has to have already written this (insert grumbling, moaning, sighing, etc.)?" Chances are, you're right. A huge help when you are starting to program on your own is finding applications that others have written that you can use and tailor to your own needs. Fortunately, there are tons of places to find these things on the web.

Scripting languages especially often have their own packaging system and a place where you can look up other programmer's useful code. In Ruby, RubyGems is an excellent resource for this. RubyForge has a huge application archive where you can search for interesting and useful packages. Python uses eggs, or .egg files for packaging. The Python site also has a package index that you may browse.

One great thing you can do to expand your programming horizons is to snoop around in these areas and look at some implementations, and some packages. I guarantee that you will find something sweet, and you will definitely find packages that are extremely useful. So go out there and check out what other people have written. Looking around can save you valuable time when working on projects. Happy hunting...

Monday, April 20, 2009

Revamping Old Code



remember that program you had to write for your C++ class... Rewriting your old code can be a great way of learning another language. By rewriting something that you already know in a different way, you can quickly pick up new syntax.

This isn't just a great way to learn a new language; It is also a great way to improve your programming skills. Go back and look at some of your old programs. Chances are, you will find ways to improve their implementation, either in speed or amount of code.

For example, I recently took an old piggybank program I had to write in C++ and converted it to Python. All this simple program did was asked for a dollar amount and turned it into the least amount of change. Back when I wrote it for the first time, I used all if statements. While I was re-writing it in Python, I discovered that I could create a better implementation using modulus arithmetic.

Isn't it great how you can learn new material on your old material. Any other suggestions on re-using old code to teach yourself?

Wednesday, April 15, 2009

New to Python (and blogging)

I shall begin at the beginning... I am a Junior in an undergraduate program in Mathematics and Computer Science, I have just gotten a programming internship for the summer. What does this mean? That in the endless sea of knowledge in the programming world I am about two feet deep.

But that's OK. In this blog I will be sharing my new gained knowledge of programming, whatever sundry topics they may be, and ask for opinions and help as well. So, on to my first content.

For this internship I was informed that I will be using Python. I have never used Python seriously before. The closest I have come was dabbling in Ruby, which is pretty sweet, I must say. If anyone out there is looking for good Python resources this is the site. After nosing around on it, I personally recommend Quick and Painless Python Tutorial by Norm Matloff, if you are familiar with other languages, such as C++. Once you have dabbled in Python a little (btw, I am using Context now as my text editor, could I use Eclipse?) Dive into Python might be for you, it tackles some more language specific stuff, that is slightly more advanced. incidently, other than installing the package on python.org's site, I recommend Active Python if you are using Windows, it's free and it allows you to execute your programs on the command line. (Of course all of the above links are to free stuff, I am a college student!)

I will let you know how my Python adventures go, one thing that has intrigued my is Regular Expressions, I haven't looked at them, but from my experience with Ruby, they seem like a must-have. delving more into this later. Also swirling around in my head are questions about GUI's and other tools used with Python, Python in .NET, Iron Python, etc. the list goes on and on, and it seems only hours of scanning the web will satiate my quandaries.

Any useful comments? thoughts? code snippets that might be helpful...