Monday, July 09, 2007

Optional typing: best of both worlds?

There continues to be an ongoing debate over which is better, static typing or dynamic typing.  I argue there are advantages to both, but if I have to choose, I favor dynamic. 

I'll make no bones about it, I'm one of those that loves Python, personal productivity topping my list of reasons.  Python is an excellent language for many/most uses, but I run into places where pure dynamic typing is counter productive.  I say keep the dynamic typing, but give me the ability to optionally specify a variable's type. 

Optional typing has several advantages.  First, it helps make code self documenting, especially with arguments and return values.  Second, type declarations can result in cleaner code than assert statements.  And finally, the interpreter can provide performance advantages when the variables' types have been declared and checked.

Optional typing would be the best of both worlds.

Labels: ,

Wednesday, July 04, 2007

Want more?

In case you haven't noticed, processor speeds in the form of clock rates have not increased much in the last few years, yet higher performance CPUs are being delivered.  Moore's law is still in effect but increases in chip density are no longer being translated to increases in clock speed.  Instead, we are seeing more CPUs on a chip. 

Unfortunately, most of today's software doesn't know of these other CPUs or how to take advantage of them.  To harness this increased power, be they additional cores or distributed platforms, we need to look deeply at how software is written and compiled.  We need new algorithms, languages, compilers, and operating systems. 

Work has been done in this space but even today special, custom programming is needed to take advantage of multiple cores, vector processors, clusters and distributed grids.  The process needs to be more automatic, and we need to move it to the mainstream if we expect enjoy our faster machines and avoid this costly special attention. 

This is not a new problem; what's new is that we can no longer expect faster processing simply by putting in a CPU with a higher clock rate.  If tomorrow morning we want more, we will need to be thinking different.

Labels: ,

Tuesday, July 03, 2007

Making Simple DLLs Simply

I often want to compile some simple C code and have it accessible from Python, but making DLLs and Python extensions for Windows has always been, for me, problematic.  Keeping this note brief and on a positive note....

Python extensions compiled using Microsoft tools need to be compiled using the same version as that used to compile Python itself.  If you don't have that version of Visual Studio or you want to also compile the extension for other versions of Python, having access to all the versions can be problematic.  I was successful in getting the mingw gcc to work for extensions, but when compiling what should be a small DLL (4K-8K for OSX and Linux), mingw created a bloated one, 742K.  For my purposes, that was a problem.  Bottom line: I went shopping for another compiler/linker.

After visiting The Free Country, I settled on the Digital Mars C (DMC) compiler.  It is a small, clean, fast ANSI C compiler, and generates code more like what I expected.  Creating DLLs was never fun, but DMC makes it really easy.  The license is short and easily understandable.  NB: The license expressly says the compiler is not tested, but I am assuming that is more for legal liability reasons.  Nevertheless, I will test my program; I advise you test yours.  That said....

To create a DLL, create a [sourcename].def file so it looks something like this.
    LIBRARY "[sourcename].dll"
    DESCRIPTION '[a short description]'

Then execute this to create the DLL.
    dmc -WD [sourcename].c

Install the .dll file in a directory on your PATH and it should now be available to Python via ctypes.

Some themes and variations are possible so you might want to look at...
    Compiling Code
    Win32 Programming Guidelines
        (scroll to "Building and Using Windows DLLs", about 1/2 way down)
    DMC: Compiler

Oh, I almost forgot.  Digital Mars is Walter Bright, the creator of the D programming language. 

Labels: , ,