Rapid Development Using Python

For the developers behind the SkipWare GUI, Python was the best and obvious choice.

SkipWare is a series of extensions to standard Internet transport protocols that, when installed on a network device, maximizes link utilization and reliability in a stressed transmission environment. It has been developed collaboratively between GST and Comtech; GST provides the software and Comtech provides the hardware. Although SkipWare is an implementation of SCPS (space communication protocol standards), a graphical user interface is required to specify configuration settings that impact overall system performance. Given that the product forwards IP (Internet) traffic, a Web-based client was the most feasible interface for our customers.

Because the interface requirements were soft and time was short, we approached the interface with a rapid development mentality focused on constant customer feedback. A language decision had to be made, and we had the following choices (primarily due to our experience): C, PHP, Perl, Java and Python. Our selection was based upon the following criteria:

  • We planned to prototype on a remote device and anticipated numerous changes. We needed a language that was designed with change in mind.

  • We wanted to avoid the added step of code compilation in order to minimize the overhead associated with a change. An interpreted language seemed pragmatic.

  • We wanted a language with good introspection capability.

  • We needed to do a lot of string manipulation and file I/O. Whatever language we chose had to excel in both of these areas.

Disk space was a concern in our decision but not a driving force. The hardware provided to us was an 800MHz processor with 64MB of RAM and a 32MB root filesystem. Of those characteristics, the disk space was clearly the most precious. Because of the high clock speed and availability of RAM, interface performance was not a driving force.

Rapid Development

Our development environment focused on customer interaction. Because time was short, the traditional approach—formal requirements gathering followed by independent development and testing—was not practical. We anticipated making changes frequently on a remote device, with a customer representative viewing the interface and providing instant feedback.

Python allowed us to achieve this environment primarily because it is easy to use interactively. Prototyping through an interactive interpreter is an effective mechanism for exploring different approaches to solving a problem. With a customer representative providing real-time feedback, we needed a language with which we could prototype a function instantly through an interactive interpreter and then copy the working function to the remote device for approval. Perl did not provide an interactive interpreter that enabled this behavior.

Compilation

Our rapid development environment meant that changes had to be visible immediately to both the developer and the customer representative. Coding sessions frequently would involve work on a remote device during which time changes would be made and feedback would be gathered. Use of a compiled language inhibited our ability to prototype on a remote device, because it required maintaining a build environment. In the scenario where we changed one or two lines of code on the remote device during an interactive feedback session, we did not want to have to wait for compilation before gathering the next round of feedback. IDEs were not feasible as a solution to our problem, because much of our development occurred on the remote device.

Introspection

We wanted to dispatch Web requests to code in a very direct fashion. An architecture based on a central controller that used introspection to determine where to route requests seemed a clean and simple choice. Because our controller-based architecture was abstract and generic, we had concerns about safety. Python protects the programmer from buffer overflows and has excellent reflection capabilities that can be explored at run-time. Both characteristics satisfied our needs for introspection and safety. Moreover, an inspectable run-time is nearly equivalent to running an application under a debugger while making changes. This characteristic appealed to us.

String Manipulation and File I/O

All user input arrived in string format. All output was stored in files or returned to the user in HTML format. Both of these concepts are well supported in Python. Iterating over the content of a file takes two lines of Python. In comparison, Java requires five or five instantiations followed by two or three lines to read. Once read into memory, content must be tokenized before iteration. While iterating, casting is required. The Java approach exemplifies the importance of selecting the appropriate language for your development environment—it would not have been a good language choice for the tasks we were to perform, primarily string and file manipulation. With all of its built-in types and excellent string and file manipulation, Python provided us with the tools we needed to accomplish our tasks quickly and easily (more on this later).

Narrowing down the language choices was not particularly difficult. C requires compilation, is easy to exploit through buffer overflows (and thus poses a security risk) and does not handle strings and file I/O particularly well. PHP also was dismissed because we were not accessing a database, hence many of the features of the language would not be used. Java is too bloated, requires compilation and has horrible file I/O and string manipulation.

Python survived our language elimination process because it satisfied all of our requirements. In addition to satisfying our requirements, we gravitated towards Python because of its modularity and support for objects. This allows structured code growth and accommodates change over time. We also welcomed the safety (over C) that the interpreter provides. Above all else, we selected Python as our language because it supported rapid development and our specific requirements extremely well; no other language came close in comparison. Although other languages fulfilled a subset of our requirements, no language we considered fulfilled all of the requirements better than Python.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Re: Rapid Development Using Python

Anonymous's picture

what about Ruby as to your criteria?

Re: Rapid Development Using Python

Anonymous's picture

ruby is crude
ruby is perlish

Re: Rapid Development Using Python

Anonymous's picture

I agree. But Ruby is powerful and does support the other objectives.

Personally, I'd still take Python. Python is perfect.

Re: Rapid Development Using Python

Anonymous's picture

I love python, and use it regularly, but this column inadvertantly showed a python gotcha. Since the syntax is dependent on indentation, you have to be very careful when cutting and pasting.


def equals(a, b):
'''returns true if a equals b, false otherwise'''
if type(a) == type(b):
...

The statements after the def should be indented. This wouldn't have mattered in another language that used braces to denote blocks.

Re: Rapid Development Using Python

Anonymous's picture

You barely mention Perl. Was your decision not to use Perl based on a perceived lack of an interactive interpreter (note: an interactive interpreter called ptksh is part of the standard Perl/Tk installation)? If not I would like to know what caused you to select Python vs. Perl. We are in the process of making a similar decision.

Re: Rapid Development Using Python

Anonymous's picture

If not I would like to know what caused you to select Python vs. Perl. We are in the process of making a similar decision.

Just choose Python. You will save the trouble of porting your Perl program to Python afterwards, when you learn that Perl just doesn't scale anymore.

Most choices of Perl for a solution to a particular problem can be attributed to historical burden or ignorance. If you have no historical burden of huge perl codebase, do the right thing.

Re: Rapid Development Using Python

Anonymous's picture

The quick and simple answer is that Perl is a little more of a kitchen sink language having a number of possible ways to do the same thing. While this can be really great for the skilled Perl Wizard it does make larger team projects difficult as each coder may have favorite constructs that some other team members have never used.

Python is more of a carefully constucted language with (mostly) one approach for a given piece of code.

Some examples of Perl I have seen are more terse then the equivelent Python code. But to me the Python also looked like it was easier to maintain. Perl is great for small hacks and has been used successfully on large projects as has Python. I have chosen to use Python for both cases because I seem to be able to maintain the code I write more easily.

Re: Rapid Development Using Python

Anonymous's picture

It's simple - python code is maintainable and can be object
oriented, perl code is not maintainable and cannot (within
the realm of reasonable people) be made object oriented.

Re: Rapid Development Using Python

Anonymous's picture

That is simply a lie.

Re: Rapid Development Using Python

Anonymous's picture

Opposing to popular opinion, I'm not thinking that object-orientation has something to do with emulating a fraction of key-concepts inherent to object-orientation with obscure language features. No, I think it's something a language supports, and if it does it, it better damn well does it good and consistently. In the face of this, Perl has no object-orientation ( and neither has C++ )

Re: Rapid Development Using Python

Anonymous's picture

Perl code can be made perfectly readable. Granted, it may be easier to be made unreadable, but that is largely the programmer's fault. I'm sure one could write unreable python code too.

As for no object oriented perl, this is simply untrue. There are many books published about the subject, and I will not go on defending against such a ridiculous accusation.

Re: Rapid Development Using Python

Anonymous's picture

It's very difficult to write unreadable Python code. You really have to put a lot of effort to do it.

OTOH, I used to be a Perl coder. Perl makes it real easy to write code with is difficult to read. You have to put a lot of effort into reading someone else's Perl code.

Re: Rapid Development Using Python

Anonymous's picture

Perl makes it real easy to write code with is difficult to read.

This is undeniable. After all, one of Perl's mottos is "Perl makes easy things easy, and hard things possible." This does not automatically make all Perl code unreadable, however. I will not defend every piece of code ever written, because I'm sure there is a substantial portion of horrible, unreadable Perl code in the world. I just can't stand the common conception that Perl is inherently unreable. It is simply not true. All it takes is one cleanly written Perl program to prove the case, and there are plenty of those. Check out some good CPAN modules sometime, if you don't believe me.

I fear we're getting into muddy waters, though. The flames of war are a-brewin' and this post probably doesn't help. With that, I bid you adieu, and will post no further.

Re: Rapid Development Using Python

Anonymous's picture

It's actualy easy to proove that perl is inherently ugly and unmaintainable.

There's surely nice perl code as there is nice python code.

-Write some 50 lines perl code, out of your head, do not comment or refactor it. Do the same in python ( you may use a few more lines ). Let it rest for a week. Look at your code afterwards, which one is the one you can still read?

-There's ugly python and ugly perl. Only a python author has to go to extreme lengths in order to make it impossible to read his code like an open book. Perl is somewhat the anathema to this.

Re: Rapid Development Using Python

Anonymous's picture

In the article you use this:
for line in open('file.txt').read().split('
'):
Why not this:
for line in open('file.txt').readlines():
Or using the iterator:
for line in open('file.txt'):

Re: Rapid Development Using Python

Anonymous's picture

for line in open('file.txt').read().split('
'):

strips the line endings, readlines() doesn't.

for line in open('file.txt').

Anonymous's picture

for line in open('file.txt').read().splitlines():

will get of the newlines

Re: Rapid Development Using Python

Anonymous's picture

C requires compilation, is easy to exploit through buffer overflows (and thus poses a security risk) and does not handle strings and file I/O particularly well.

To be fair, it is not that C is easy to exploit, but bad C code. One could argue that the C library itself is bad code, because the exploitable problems are due to coding errors using the library that are relatively easy to make. These problems could be avoided with new libraries; Dan Bernstein wrote his own string-handling libraries that are immune from buffer overflows when writing qmail. Additionally, Python itself is written in C, and it appears to be safe from buffer overflows, because it uses the C library correctly.
The C library API is also about 30 years old now. There are a lot of things that could be done better, but there is also a lot of inertia that's not likely to be overcome.
Oh, and Python rocks.

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState