lesscode.org


'Languages' Archives

Logging microformats  10

Cat.: Python, Ruby, microformats
13. December 2005

Here’s a slightly elided log line from a system I work with:

WARN 2005-09-28 14:38:38 StandardContext[/pmr]  {”mid”:”123″, “type”:”XYZ”, “msg”:”foo”, “T”:”2005-09-28 14:38″, “L”:”warn”}

It identifies an XML document passing through the system using some keys from the envelope. It may seem a strange looking way to log an event, but between the angle brackets lies a useful side effect - it’s a Python dictionary. Hence this (vastly oversimplified) example log processing code, that runs eval() on each log line to load the dictionaries into memory:

Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>> dicts =[]
>>> import re
>>> p = re.compile(”.*({.*?}).*”)
>>> file = open(”log.txt”).readlines()
>>> for line in file:
…     m = p.match(line)
…     if m:
…             d = eval(m.group(1))
…             dicts.append(d)
…
>>> for d in dicts:
…    print d
…
{’L': ‘warn’, ‘mid’: ‘123′, ‘type’: ‘XYZ’, ‘T’: ‘2005-09-28 14:38′, ‘msg’: ‘frobnizer  found’}
{’L': ‘warn’, ‘mid’: ‘124′, ‘type’: ‘XYZ’, ‘T’: ‘2005-09-28 14:38′, ‘msg’: ‘frobnizer  found’}
{’L': ‘warn’, ‘mid’: ‘125′, ‘type’: ‘XYZ’, ‘T’: ‘2005-09-28 14:38′, ‘msg’: ‘frobnizer  found’}
{’L': ‘warn’, ‘mid’: ‘126′, ‘type’: ‘XYZ’, ‘T’: ‘2005-09-28 14:38′, ‘msg’: ‘frobnizer  found’}
>>>

What’s nice about doing this is that it’s cheap to write the log line in a way that maximises usefulness later on - logs are often an afterthought, but good logging is critical to operating production systems. And it’s one example where creating metadata is cheap.

As well as programming data structures (changing the above to a Ruby hash is straightforward), you can get log lines to output something like Turtle, which is a greppable RDF format. What’s good about Turtle in particular is that you can dump or stream a log file straight into an RDF query engine, such as ARQ without any transform step and start writing queries against the data. Or how about writing down inferencing rules that help indicate the business consequences of a software error? The log lines themselves don’t carry enough information, but combined with rules and some context as to where the log event came from you can do interesting and useful things - the biggest issue with any monitoring software is gathering up all those machine level events and contextualising them so that data (noise) can be turned it into information (signal). Think of a machine readable data stucture inside logfiles as just another microformat.

Rails / Django Chicago Debate  9

Cat.: Python, Ruby
17. November 2005

On December 3rd, a mess of fine Chicago area Ruby, Python, and Linux user groups are to meet up at DePaul University for a Django / Rails love-fest. I’ve heard there might also be time for debate between songs and hand-holding. Adrian Holovaty, award winning journalist and distinguished gentlemen, will be fielding questions for the Pythonistas while David Heinemeier Hansson, Extraordinary Alien / “one man” trying to save the world (hey, I owe him one), will be answering for the Rubyists.

Even better, the Snakes and Rubies website is collecting questions for Adrian or David or both. Get over there and get your questions in before it’s too late.

If there is any way someone could capture the audio for this event, it would be very much appreciated.

Simplest Possible Plugin Manager For Rails  6

Cat.: Ruby, Rails
27. October 2005

UPDATE: I ended up making some pretty massive changes. You can configure multiple plugin repositories, install, update, remove, and discover plugins. The directions for installation are still valid but you’ll need to run plugin --help to get a feel for the changes in usage.


UPDATE: The plugin manager has been included with Rails 1.0 RC4. Run script/plugin --help from a fresh Rails app for usage information.


Rails 1.0 RC1 shipped with a simple plugin system - drop a directory under vendor/plugins that contains an init.rb file to be executed at configuration time and an optional lib directory to be placed on the path. Do whatever you please from there. It’s a simple hook into the startup cycle and a much needed addition.

About 19 hours ago, David suggested that people link to their plugins from the Rails Wiki as a kind of interim solution to the problem of not having a standard means of packaging and managing these things. They did and with links to their plugins’ subversion repositories.

Here’s a simple (150 line) plugin manager.

Install it like this:

$ cd my-rails-app
$ curl http://lesscode.org/svn/rtomayko/rails/scripts/plugin > script/plugin
$ chmod +x script/plugin

Then see what plugins are available:

$ ./script/plugin
continuous_builder  http://dev.rubyonrails.com/svn/rails/plugins/continuous_builder
asset_timestamping  http://svn.aviditybytes.com/rails/plugins/asset_timestamping
enumerations_mixin  http://svn.protocool.com/rails/plugins/enumerations_mixin/trunk
calculations        http://techno-weenie.net/svn/projects/calculations/
...

Next, install stuff to your vendor/plugins directory:

$ ./script/plugin continuous_builder asset_timestamping

Here’s how it works:

  1. Scrape the Plugin page for things that look like subversion repositories with plugins. (Yes, I’m using regular expressions. Yes, I understand the issues. No, I don’t care.)

  2. If vendor/plugins is under subversion control, the script will modify the svn:externals property on that directory and perform an update. You can use normal subversion commands to keep the plugins up to date.

  3. Or, if vendor/plugins is not under subversion control, the plugin is pulled via svn export.

If you want to use svn:externals, make sure you have your vendor/plugins directory under subversion’s control before installing any plugins . If your not sure, do something like this:

$ svn info vendor/plugins
foo:    (Not a versioned resource)
$ svn mkdir vendor/plugins
$ svn ci -m "adding teh plugins directory so I can use this r0x3ring plugin manager..."

This probably won’t work on Windows at the moment and assumes you have the command line subversion client utilities available (svn).

It’s useful as is, but please, make it better.

WASP - Easing the Switch from Java to PHP  28

Cat.: PHP, LAMP
23. October 2005

Author’s Note: I originally wrote this article on the WASP homepage. Ryan has graciously allowed me to post it here. WASP was partly inspired by lesscode.org, and hopefully it’ll make a good contribution to this community.

The year 2005, so far, has been the year of scripting languages. Across the web-application programming sector there has been a growing movement toward acceptance and general usage of dynamic languages like Ruby, Python, and PHP. Fundamentally, these languages have been present in the industry and in use by developers for a long time, and really aren’t anything new. Lately, however, due to advances in server technology, scripting language maturity, and improved development libraries, it is possible to write scalable, well architected, “enterprise” applications in less time with less code using frameworks like WASP for PHP.

Scripting languages have been used to build millions of applications on the Web, but in general have not been adopted widely by corporate developers. But more and more businesses and IT professionals are looking to these languages as a way to simplify and speed the creation of custom in-house programs, thus avoiding the now all-too-common logjam of late or overbudget applications. — CNET

It has always been faster to write applications for the web using scripting languages. PHP has long been accessible to the fledgling developer. It has been widely used for prototyping of large applications written in languages like Java simply because web designers, most often specialized in design artistry rather than computer science theory, are able to quickly grasp the syntax and embed it in their HTML code.

Interestingly enough, the same reasons why languages like PHP are so easy to learn and use are what often keeps seasoned software engineers from wanting to use them. Deemed “hacker” languages, scripting languages can be quick to write, but since they do not have many of the advanced features of compiled languages like C++ and Java, they have been prone to lax design practices, leading to code that isn’t efficient, stable, or maintainable enough for large solutions. With the correct mindset and help from structured frameworks like WASP, this no longer has to be the case.

Making use of the advancements made to PHP in version 5, web application architects can implement structure to their code in the form of tested design patterns and full-featured frameworks, like WASP. In fact, WASP was written to make the most pedantic software architect feel at home, in an effort to ease the transition for Java developers to coding in PHP.

It’s important to resist the gut reaction most people have to these statements. Most people’s perceptions of PHP are from the PHP 4 days, where “object oriented” frameworks existed, but were crippled by the loose OO implementation of the language. While PHP 5 is mostly backward compatible with PHP 4, it is almost completely different when it comes to things like abstract classes, interfaces, private and protected methods, and exceptions. Sure, you can write spagetti code in PHP 5, but if you have a well designed framework that keeps PHP code outside of your HTML and in tightly structured classes, you’re more likely to end up with code that looks and works and feels like Java.

But will using PHP confine application developers to small customers and fringe, open source communities? Not for long. The big guys are starting to catch on to this shift.

PHP, like open-source projects including Linux and Apache, now has received the blessing of major powers in the computing industry. IBM and Oracle are working on software that let PHP-powered applications pull information from their databases. — CNET

As the user base of PHP and other scripting languages continues to grow, broad support is becoming available on platforms trusted by the Fortune 500 crowd. This exposure will increase the rate of improvement to the efficiency of these languages. Early in its life, Java was highly criticized as not being scalable since it runs on a virtual machine, and therefore could never achieve the speed of C++. As Java matured, advances were made in optimizations to alleviate much of these concerns. The same sorts of advances are being made in the PHP language, and the hardware and software that drives it.

The goal of any good software development department or organization is to efficiently turn out code on-budget, and on-schedule. Until recently, platforms like Java were more likely to provide a stable, proven foundation to design and build well designed code, however by their nature they introduce a level of complexity that takes extra time to overcome. Using scripting languages like PHP tended to produce code in a faster time frame, but it was often impossible to maintain the architectural integrity necessary for building maintainable, extendable applications. With its strong design foundations, the WASP framework makes achieving all of these goals possible, providing the means to creating world class software to anyone with basic skills in PHP.

Further Reading:

WASP How-To
Andreessen: PHP succeeding where Java isn’t
Grassroots computing languages hit the big time
Java devotee BEA eyes scripting languages

Little Help?  6

Cat.: Wanted, PHP
11. October 2005

Greetings fellow lesscode advocates. For those of you who don’t know me, I’m an industry analyst with RedMonk, and as a couple of the folks here can probably attest, I take every opportunity to push your message and your values on an unsuspecting population of software vendor customers. Ryan’s been gracious enough to grant me the virtual floor as it were to speak to all of you today to request some assistance.

I’m the process of finalizing my keynote presentation for next week’s Zend/PHP conference entitled, conveniently enough, “PHP: Simplicity and Lesscode.” So here’s where I need some help, if you’re willing. My slides are trying to emphasize the role simplicity/lesscode play in all of our lives: both in technology and not. The deck currently starts from non-technology examples such as simple machines and builds to technology related examples, most of which are PHP centric for reasons that are probably pretty clear.

The question I have for all of you then is this: what examples - real world or technology related - might you use if you were trying to evangelize the twin values of s/l? What would/do you tell people that don’t get what lesscode is all about? As an example of the type of thing I’m looking for, I’m planning on opening with one of my favorite comp-sci stories of all time: Ryan’s Insects and Entropy. Adam Bosworth’s discussion of how Google uses the stupidest query language ever is also in there.

Hopefully those will give you an idea of the kind of things I’m looking for, and suggestions in any form would be appreciated. I can’t promise to use everything, but I’ll incorporate whatever I think I can fit in.

A couple of logistical notes:

  1. Slides: will be made available following the conference under Creative Commons terms on my site, and here if the community here so desires. They’ll be offered under the same terms
  2. Credit: will be given whenever possible during the presentation, and the closing page of the slides will contain the names of everyone whose contribution was included (so if you leave a comment, be sure that’s the name you’d like to have credited). That slide will also include a link to this entry, so that even suggestions that don’t make the deck may get some airtime.
  3. Technology: given that this is a PHP conference, I’m probably not going to go in depth on Python, Ruby as much as I or some of you might like. So language specific examples will likely be genericized, just as an FYI, unless they compare more complex languages to PHP - in which case they’re encouraged.
  4. Questions: drop them here, and I’ll do my best to answer them.

Thanks for helping me get the lesscode message out, and I look forward to any conributions you might have.