Brandon Werner

Archive for the ‘Python’ Category

Presenting Semantic Web at BarCamp Seattle

Friday, June 13th, 2008

I will be doing a presentation with Daniel Maycock, an Information Architect from Boeing, at BarCamp Seattle this weekend on the Semantic Web. I’ll be filling in stuff on FoaF, maybe including my Semantic Maestro project and the results of using Google AppEngine if I can get the engine ported over to Python in time. Chances are it’ll just be the idea of FoaF, open social networks, users and tools out on the web.

If you will be there, let me know be sure to say hi!

The Rise Of Functional Programming: F#/Scala/Haskell and the failing of Lisp

Sunday, January 13th, 2008

Over at Lambda The Ultimate, the best academic programming blog on earth, there is a large debate going on regarding what the future of languages will be for 2008. The most important thing to emerge from the discussion is the larger role functional programming will play. It seems like a safe bet. This year has seen the explosion of interest and creation of functional languages such as Apple OS X’s Nu, Java’s JVM using Scala and Microsoft Research’s .Net language F#.

I am ecstatic at this change.

The Failure Of Lisp

It’s hard to understand where it came from. Certainly one can argue the broader academic community had nothing to do with it, the old guard Common Lisp hackers are still as fickle and as judgmental to new comers as ever. Also, the old standards in Lisp languages, Franz and LispWorks have not lowered their prices to anything approachable to the casual developer. There are open source ANSI Lisp implementations without all the supporting engines and functionality, such as SBCL. In fact, my most linked thing I’ve ever written in my career is the installation walk-through I did for installing SBCL and Allegro which includes adding your repository and packages for CLOS and automatically compiling the FASL files, especially dealing with the asdf differences between the implementations. The complexity of this in itself points to problems with portability and configuration in Lisp. However, even that project that targeted Lisp’s Bread and Butter, the parsing of semantic ontologies for the Semantic Web, was met in the message boards with worries on if there would be enough developer participation using such an odd language, and recommendations on moving it to Java.

In reality, Common Lisp showed its failure as a community by sitting out this enthusiasm that has been generated around functional programming languages. It didn’t have to be that way. I recall my first awarenesses of functional programming’s growth was the awesome work of Lemonodor’s blog and Sriram Krishnan posting “Lisp Is Sin“. I was happy at the time that Lisp was getting such attention, as well as functional language architectures in general. I imagined that as OO languages had grown so verbose and feature dense that even the IDEs to develop your applications run in to the tens of gigabytes, a new evolution “Back To The Future” was inevitable. Even more, I believe long suffering Lisp deserves to be back in favor again, it’s certainly spent its time in purgetory. Yet, it didn’t happen. You can blame the old 50 year old men sitting on IRC channels for that. It was the most thorny and un-inspiring community I’ve ever participated in, despite my extreme interest in the language. It’s jaw dropping that a language with such promise has sat out the resurgence, and speaks to what an un-friendly and un-inviting community can do a technology platform. I would be the first to march it off to the grave.

The Rise Of Functional Languages

The interest in functional programming actually grew up around more academic but pure languages like Scheme and Haskell. Although these languages sit within their own island and lack many of the “dirty” aspects of Lisp’s CLOS environment that make it easy to access OS and hardware resources, they are still strikingly useful in learning things that are the staple of functional languages, such as Closures and Lambdas. Indeed, one could argue that the movement to move Closures in to OO languages (first C#, now Java) was in part due to the rise of awareness of functional languages.

Further, it seems to me that functional programming languages answered two prayers of those more ambitious engineers who don’t seem to want to stick with the script and Java worlds they were taught in college. Those two large wins, far more important than the semantic features of functional languages that have gotten all the attention, are architecture foundations of functional languages:

  • Referential Transparency / Side Effects
  • Concurrency

Referential Transparency

To those coming from a pure OO world, Referential Transparency and the restriction of side-effects can be something hard to get their heads around. The best way I describe this concept is by hitting at the root of their assumptions: Everything they deal with are dead. The objects are dead, the variables are dead, the entire atmosphere is dead, as if something had come along and killed everything in your stack and you have to assemble your program by only what’s been given to you, nothing more. There are no instances, objects do not “come alive” and have state; a state that you have to poke in to and a state that can change at any time. A function will always do what you expect, and nothing can come along and change that behavior.

One of the things that seems to appeal to developers most about the promise of SOA architectures happening in enterprise environments, if you’re smart enough to pry it out of them, is that they get the same referential transparency in services. No one can override a service (besides versioning, which is explicit to the developer) and a service will only return what it did earlier in your code and earlier in the year. This forces developers to design services that have the same relationship to the world as functional programmers write their functions for. This is perhaps the trickiest part of migrating enterprise teams to a services based model, their expectations of the mutableness of the services they are accessing and their inability to anticipate what working in that world will be like. Especially for those who use tools or libraries to convert service interaction in to an object, the interaction can be jarring.

However, the soon find the predictability and the safety of such an environment liberating. In much the same way OO programmers were use to making their objects or variables immutable to maintain their contracts and relationships with other objects, often sacrificing many of the benefits that OO programming promised their stack, now they have immutability and transparency in an environment where functional paradigms are key, they do not expect to be able to “embrace and extend” services. They are what they are. This tends to cascade out to the living instantiated code a developer writes as well, as there is no point in entering the world of the living if what you have to return to is a dead function.

This was hinted at in an article in the ACM Queue magazine by Terry Coatta, entitled “From Here to There, The SOA Way“. He states,

Objects are still a very good way to model systems and they function reasonably efficiently in the local context. But they don’t distribute well, particularly if one tries to use them in a naive way. A service-oriented architecture solves this problem by dealing with the latency issues up front. It does this by looking at the patterns of data access in a system and designing the service-layer interfaces to aggregate data in such a way as to optimize bandwidth, usage, and latency.

Not that SOA limitations are the only thing that is affecting the consciousness of a software engineer, the other issue is the large rise in the complexity of managing a large enterprise library written in an OO language. One of the largest pain points of any application of large size is the management of graphs and graphs of live objects and the living data within them. When software engineers experience the lack of side-effects in functional languages, it’s a breath of fresh air.

Concurrency

A funny thing happened on the way to those multi-core processors. People loaded their applications on them and noticed nothing got much faster, particularly when it came to transaction intensive tasks. Turns out Intel and AMD left out an important fact about their Moore’s Law cheating multi-core environment: you can’t ring as much performance out of it without changing the way you manage concurrency and threads. Sequential programming could always rely on going faster as the single processor speed got faster, but as multicores come in to play that isn’t always the case. You want to farm off transactions to occur on separate processors, and in the living world of mutable objects and variables, breaking out two transactions to work concurrently that operate on the same living data is a bad idea. Add structural programming’s solution to this problem, optimistic and pessimistic locking, and you have dead-locks in short order.

Functional programming has been a natural place to explore parallel processing and new ways of doing atomic transactions because of the reasons above. More important, these atomic structures can be composable which is lost when doing locks in structural programming. A lot of the buzz has been generated around the idea of software transactional memory, where execution blocks can be flagged and managed and built upon. The best introduction to this topic is the paper by Tim Harris entitled Concurrent Programming Without Locks. Although this use to be expressed only in the confines of Concurrent Haskell, others have shown how the same techniques can be used in other functional languages, such as F# using nothing more than PowerList.

This experimentation is one of the large reasons why functional languages have become more important as software engineers wrestle with the problems and promise of multi-core processors in transaction processing. Although not every engineer will be interested in the deeper details of STM or other strategies in concurrent programming, the fact that these libraries will emerge and only be available in the functional realm will force software engineers to learn the core concepts and bring even more visibility to the functional programming space.

Functional Hybrids: Functional Programming Is Now Approachable

The other driver for adoption of functional programming languages, besides the architectural benefits it has to solve current problems, is the fact that languages such as F# and Scala have adopted a more hybrid model in their language design, where a developer isn’t forced completely outside her comfort zone. Scala is a combination of functional and deeper OO methodologies (as in SmallTalk) and has access to the entire Java library, significantly reducing the learning curve. The same can be said for F# and .Net and Nu and Objective-C. This does have draw-backs however, as both F# and Scala have not been able to use more of the STM strategies that Concurrent Haskell allows because the underlying thread architecture of the VMs they run against are built for structural programming languages. It is easy to see how this can be fixed, however, and allow those using hybrid functional languages the same power as those who express their ideas in Haskell or even Lisp.

As I said, I am excited about this new resurgence in functional programming languages, and I am enthusiastic 2008 will have even more to offer those who are just getting their toes wet. I personally know some college freshman who started out using Nu as their first language, and are already contributing to the community. The future of software engineering is bright.

Scripting makes Java fun again, and maybe relevant again, too.

Sunday, January 28th, 2007

When I interviewed Bruce Tate a few months before his Comp. Sci. best seller Beyond Java came out, he introduced a term that has always stuck with me:

“Java is dead like COBOL”.

What he meant was that although the Java language will certainly go on in the future as a legacy language and find new implementations from lovers of familiarity and the haters of change, the future of languages most likely has moved on. To see it, look at C# or Python or Ruby, where their creators talk about lambdas, functional composition and closures. He did mention, however, that the JVM would continue to be an important and vibrant piece of technology even after Java has been moved to the dust bin. His pronouncement was in late 2005, before the idea of a scripting plug-in to the JVM was even formalized (but Microsoft’s CLR was realizing the promise of the JVM abstraction much to Sun’s chagrin)

Today I have an example of that future.

Everyone knows that the JVM has hidden gems that, because of past mistakes and present misconceptions, go unused. One of these is SWING and Java2D. While Adobe’s Flash and Microsoft’s XAML are taking a lion’s share of the buzz on rich web applications (which is really aimed at removing the restrictions of the web browser from the application process all together, and something I am definitely fond of) it is often forgot that the JVM also provides this technology in spades. Sadly, it would seem that this is something else that the JVM has an answer for but will lose to those with easier implementations. One of the promises of new scripting languages being plugged in to the JVM is that this functionality can be exposed in new and better ways. Browsing LtU today, which often depresses me that I can’t just sit in a tree and program Haskell and Scheme all day, I came across a Sun employee Chris Oliver who wrote his own scripting language called F3 (Form Follows Function). It is suppose to be better than JavaScript (static typed and compile-time error reporting) and exposes all of the Java2D and Swing stuff easily.

That would be an understatement of his accomplishment.

I was floored by his example in his post below, where he wrote a new frame for the Fantastic 4 trailer using his new language. Most amazing, because it can leverage the entire platform and delivery mechanisms of the JVM, it uses Java WebStart to push it your machine. He even creates a Mac-like reflection by painting the video off the y coordinates using a negative scale… all in real-time… all in two pages of script.

The results are amazing.. Link here

Some more discussion of his work regarding this example is here.

This shows how the Java platform may have a life post open-sourcing and light-weight framework trends, and will continue to influence how we write and deploy applications. Although most of the press around scripting engines in Java has been around Python and JavaScript, the real potential lies in allowing levels of abstraction on JVM functionality, not just allowing languages to mingle inside one runtime.

Brilliant.

Paul Graham’s Book Is Now Free!

Tuesday, January 31st, 2006

Paul Graham: On LispProbably the most read book on learning Lisp, Paul Graham’s On Lisp was limited online to just two chapters. Well, it’s now completely free and 100% complete! Anyone that wants to learn Lisp (or where Python gets it’s inspiration) should download this book, curl up with your Powerbook and read away (with emacs & slime or a GUI editor in another window).

Download in your favorite format here

To steal enterprise programmers, Microsoft embraces Python and you

Wednesday, January 4th, 2006

It would appear Python has gained a very proud position inside Microsoft with the release of IronPython 1.0 Beta 1. Long the darling of developers on the UNIX platform and admired by CS folks all over, some may wonder why Microsoft has taken the task from ActiveState (Visual Python was discontinued) to integrate Python in to the .Net CLR. You might also wonder why Microsoft recently released a free version of Visual Studio to compete directly with Sun Microsystem’s excellent (though JSF tied) Studio Creator as well as the Eclipse and NetBeans frameworks. Add to this the recent work Microsoft is doing with JBoss, and you could be left scratching your head.

The answer: they want you. You, the enterprise Java / Linux / Python / Apache developer. This is not a problem with .Net, which has begun to grow rapidly over the last two years, but more the attractiveness of .Net to software developers. Microsoft sees that the majority of interesting work being done on solving the latest integration and development problems with services are occurring on the open source landscape. Instead of trying to sell the entire .Net stack to software developers, they are now finally reaching out for the leverage that the CLR gave them from the beginning but were hesitant to embrace. After all, Microsoft originally left it up to the open source community to integrate their language in to CLR bytecode, the same thing that Sun is doing with Jython and other interesting projects (although JavaScript will appear soon as a JCP blessed scripting language integrated with the JRE). The reason for this is simple, both companies that have a Runtime know that the money and influence is in the language, not the runtime, and any other language that integrates with their Runtime environment may dilute their own (controlled & licensable) language environment.

This is what makes Microsoft’s release of IronPython so interesting. It is the first time they have integrated a language in to the CLR that they did not control (Yes, there was J#, but was that really Java?) and there is a promise of more of this in the future. If Microsoft truly begins integrating all the great open source scripting languages in to the CLR itself, it may be the one thing that begins to turn the tide on mind-share in the enterprise space. The true war would begin if Microsoft would stop making .Net just a wrapper around Win32 APIs and release a version that can run on any (at least current) architecture and operating system. That would release an incredible level of competition that could only help all of us as software developers writing to a modern execution environment. It may also give Microsoft developers a new appreciation for Sun regarding the punching bag known as Swing after they find how difficult it is to pop-up a WinForm in Mac OSX or GTK+.

With the latest announcements coming out of Microsoft lately, that idea doesn’t seem as far fetched as it did a year ago. Microsoft may have “gotten it” about the development community’s creative side, and win many more converts in the years to come.