Array

An Overview of IronPython

Must Read

Admin
Admin
Just post!

It surprises many developers to discover that computer languages are for humans, not for computers. A computer couldn’t care less about which language you use, because it’s all bits and bytes in the end anyway. Consequently, when you decide to learn another computer language, it really does pay to know what that language will do for you, the developer. Otherwise, there really isn’t a point in making the effort.

One phrase you often hear when discussing Python (and by extension, IronPython) is “batteries included.” Python has an immense standard library that addresses everything from working with ZIP files to interacting with the file system. You’ll discover the details of working with the Standard Library in Chapter 6. For now, it’s important to know that the Standard Library has a lot to offer and you may very well be able to build many of your applications without ever thinking about the .NET Framework.

As previously mentioned, IronPython is a .NET version of the Python language. For a .NET developer, using IronPython has the advantage of letting you create extensions using .NET. In addition, you have full access to the .NET Framework (see Chapter 7 for details). You can work with IronPython and other .NET languages that you already know, which means that you can use the right tool for every job. However, IronPython has a few differences from the CPython implementation that everyone else uses, which means that you can occasionally run into some odd compatibility problems when using IronPython. As with most things in life, advantages usually come with a few disadvantages.

There are some basic reasons that you want to use IronPython (or Python for that matter). The most important reason is that IronPython is a dynamic language, which means that it performs many tasks during run time, rather than compile time. Using a dynamic language means that your code has advantages of static languages, such as Visual Basic, in that it can more easily adapt to changing environmental conditions. (You’ll discover many other dynamic language advantages as the chapter progresses.) Unfortunately, you often pay for runtime flexibility with poorer performance — there’s  always a tradeoff between flexibility and performance.

Dynamic languages provide a number of benefits such as the ability to enter several statements and execute them immediately to obtain feedback. Using a dynamic language also provides easier refactoring and code modification because you don’t have to change static definitions throughout your code. It’s even possible to call functions you haven’t implemented yet and add an implementation later in the code when it’s needed. Don’t get the idea that dynamic languages are new. In fact, dynamic languages have been around for a very long time. Examples of other dynamic languages include the following:

  • LISP (List Processing)
  • Smalltalk
  • JavaScript
  • PHP
  • Ruby
  • ColdFusion
  • Lua
  • Cobra
  • Groovy

Developers also assign a number of advantages specifically to the Python language (and IronPython’s implementation of it). Whether these features truly are advantages to you depends on your perspective and experience. Many people do agree that Python provides these features:

  • Support for the Windows, Linux/Unix, and Mac OS X platforms
  • Managed support using both Java and .NET
  • Considerable object-oriented programming (OOP) functionality that is easy to understand and use
  • The capability to look within the code — .NET developers will know this as a strong form of reflection
  • An extensive array of standard libraries
  • Full library support using hierarchical packages (a concept that is already familiar to every .NET developer)
  • Robust third-party libraries that support just about every need
  • Support for writing both extensions and modules in both C and C++
  • Support for writing extensions and modules using third-party solutions for both .NET (IronPython) and Java (Jython)
  • Modular application development
  • Error handling through exceptions (another concept familiar to any .NET developer)
  • High-level dynamic data types
  • Ease of embedding within applications as a scripting solution
  • Procedural code that is relatively easy and natural to write
  • Ease of reading and a clear syntax

All these features translate into increased developer productivity, which is something that dynamic languages as a whole supposedly provide (productivity is one of these issues that is hard to nail down and even harder to prove unless you resort to metrics such as lines of code, which prove useless when comparing languages). In addition to the great features that Python provides, IronPython provides a few of its own. The following list provides a brief overview of these features:

  • Full access to the .NET Framework
  • Usability within Silverlight applications
  • Interactive console with full dynamic compilation provided as part of the product
  • Accessibility from within a browser (see http://ironpython.codeplex.com/Wiki/View
    .aspx?title=SilverlightInteractiveSession for details)
  • Full extensibility using the .NET Framework
  • Complete source code available (see http://ironpython.codeplex.com/SourceControl/ListDownloadableCommits.aspx for details)

One of the negatives of working with IronPython, versus Python (in the form of CPython), is that you lose support for multiple platforms — you only have direct access to Windows. You can get around this problem using Mono (http://www.mono-project.com/Main_Page), but it isn’t a straightforward fix and many developers will find it cumbersome.  Of course, there isn’t any way to get around the lack of Java support — you simply choose one virtual machine or the other. Appendix A lists more IronPython differences from CPython, most of which will cause compatibility and other issues for you.

Don’t get the idea that IronPython is going to restrict your use of familiar technologies. You can still create a Windows Forms application and interact with COM. It’s even possible to create command line (console) applications  and work with the Internet just as you always have. What IronPython provides is another way to view problems that you must address using your applications. As with most languages, what you’re getting is another tool that lets you create  solutions in the least amount of time and with the fewest bugs.

- Advertisement -

Latest News

Elevate Your Bentley Experience: The Bespoke Elegance of Bentayga EWB by Mulliner

Bentley Motors redefines the essence of bespoke luxury with the introduction of the Bentayga EWB's groundbreaking two-tone customization option—a...
- Advertisement -

More Articles Like This

- Advertisement -