Why Python?

Why Learn Programming?

  • To improve job prospects. There are many programming jobs available, although many of them require an alphabet soup of specific expertises. However, there are many jobs which aren’t directly programming, but in which programming will be useful, and even necessary – especially the STEM jobs, such as electronics engineering.
  • For fun. Making a machine do stuff for you can be very satisfying. My personal favourite is pretty math pictures such as Mandelbrot sets and harmonographs. If you look at all the FOSS programs available now, I think that most of those were made for fun rather than profit.
  • To accomplish some task, such as cataloguing your orchid collection. Even if such a program – or a similar one, say for cataloguing stamps – already exists, you can adapt it to better suit your needs. When we ran our online shop we wrote ‘extensions’ to make OpenCart work the way we wanted. Then we sold them! (We do not endorse OpenCart)
  • To help you to better understand the digital age in which we live. Computers are ubiquitous, learning programming and ‘computational thinking’ will greatly help you to understand the possibilities and limitations.
  • To improve your logical reasoning. Programming involves logical constructs such as “if (this is true) then do (this thing) otherwise do (that thing)” and “while (this is true) do (this thing)”, and some others. You may be able to use this style of logic to analyse some problem domain, e.g. a business task, at a high level of abstraction.
  • To improve your communications with programmers. If you have regular interactions with programmers, e.g. as management, or client, you would then be better able to communicate your instructions or requirements and understand their issues.

Why Python?

I’ve used many programming languages, including Basic, Fortran, C/C++, Java, Perl, PHP, JavaScript, Ruby, and Python. My favourite is Python, because it’s very straightforward and easy to read and write. It’s now one of the most popular programming languages. There are many ‘libraries’ available for it (pre-packaged routines to do common tasks). Just to give a trivial example, compare the following Java and Python programs:

Java:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello, World");
    }
}

Python:

print ("Hello, World")

I’m sure there are good reasons for Java to be so verbose, but the Python style works pretty well too. Now to be fair, as you advance in your programming you might want to write your programs like this:

#!/usr/bin/python3

def main():
    print("Hello, World!")

if __name__ == '__main__':
    main()

or even like this:

#!/usr/bin/env python3

#  This is the HelloWorld class with a single method.
class HelloWorld(object):

    @classmethod
    def main(cls, args):
        print ("Hello, world!")

if __name__ == '__main__':
    import sys
    HelloWorld.main(sys.argv)

And according to Python.org:

Python is a clear and powerful object-oriented programming language, comparable to Perl, Ruby, Scheme, or Java.

Some of Python’s notable features:

  • Uses an elegant syntax, making the programs you write easier to read.
  • Is an easy-to-use language that makes it simple to get your program working. This makes Python ideal for prototype development and other ad-hoc programming tasks, without compromising maintainability.
  • Comes with a large standard library that supports many common programming tasks such as connecting to web servers, searching text with regular expressions, reading and modifying files.
  • Python’s interactive mode makes it easy to test short snippets of code. There’s also a bundled development environment called IDLE.
  • Is easily extended by adding new modules implemented in a compiled language such as C or C++.
  • Can also be embedded into an application to provide a programmable interface.
  • Runs on many different computers and operating systems: Windows, MacOS, many brands of Unix, OS/2, …
  • Is free software in two senses. It doesn’t cost anything to download or use Python, or to include it in your application. Python can also be freely modified and re-distributed, because while the language is copyrighted it’s available under an open source license.

Some programming-language features of Python are:

  • A variety of basic data types are available: numbers (floating point, complex, and unlimited-length long integers), strings (both ASCII and Unicode), lists, and dictionaries.
  • Python supports object-oriented programming with classes and multiple inheritance.
  • Code can be grouped into modules and packages.
  • The language supports raising and catching exceptions, resulting in cleaner error handling.
  • Data types are strongly and dynamically typed. Mixing incompatible types (e.g. attempting to add a string and a number) causes an exception to be raised, so errors are caught sooner.
  • Python contains advanced programming features such as generators and list comprehensions.
  • Python’s automatic memory management frees you from having to manually allocate and free memory in your code.

See the SimplePrograms collection of short programs, gradually increasing in length, which show off Python’s syntax and readability.

What do you think?

Leave a Reply

%d bloggers like this: