Skip to main content

Posts

Showing posts from 2005

Spyce on Wikipedia

Spyce user Lars Schmidt created a Wikipedia article on Spyce. Nice! (Now I need to add a section on Active Handlers , which is one of the main things I think makes Spyce compelling for larger projects, as well as simplifying smaller ones.)

A point for ORM developers to remember

If you are writing an ORM tool, please keep this one point in mind: I already know SQL. Your new query syntax isn't better; it's just different. Which means one more thing for me to learn. Which means I probably won't bother, and will use instead an ORM tool that respects my time. Consider: if your target audience is like me, and already knows SQL, this should go without saying. Resist the temptation to be "clever" and overcomplicate things. If your target audience does not know SQL, then either they intend to learn SQL, because they're using a relational database and expect that non-python code or ad-hoc queries will be necessary at some point, or they have no intention of learning SQL, and all their data-access code will now and forever be in python, in which case they would be better off using Durus or ZODB or another OODB. Be honest with these people and everyone will be happier. Django does some cool stuff, but heaven help me if I ever had

PATA really, really sucks

Trying to figure out why sometimes disk access on my test machine takes way, way too long -- 1000+ ms -- I wrote some test code. My threads ran a function that looks like this: write = [] def writer(): while True: start = time.time() f = tempfile.TemporaryFile() f.write('a' * 4000) end = time.time() write.append(end - start) Compare the times for max(write) on a machine with a SATA disk and on one with parallel ATA, where the given number of threads are run for a 10 second period: threads pata sata 1 6ms 6ms 2 400ms 11ms 4 1300ms 24ms Ouch. I admit I'm not a hardware nerd. Quite possibly I'm missing something, because even PATA shouldn't be THAT bad. Right? hdparm -i says for the PATA disk: /dev/hda: Model=ST380011A, FwRev=8.01, SerialNo=4JV59KZT Config={ HardSect NotMFM HdSw>15uSec Fixed DTR>10Mbs RotSpdTol>.5% } RawCHS=16383/16/63,

Startup school

I attended Paul Graham's Startup School this past Saturday. (Thanks to Drew Houston for letting me crash at his place!) I took fairly detailed notes on the speakers; I think this is the most comprehensive overview available, actually. (Note that these are in the order they actually spoke, which isn't quite the same as the plan .) Langley Steinert , entrepreneur. Short "entrepreneurship 101" talk. Lots of interesting Q&A. Marc Hedlund , Entrepreneur in Residence, O'Reilly Media. Talks about over a dozen startups he's seen in the last couple years -- most of which you'll recognize -- and why they succeeded. Qi Lu , VC at Yahoo. One subject: Why yahoo rocks. Total advertorial; skip this one unless you're a yahoo fanboy. Hutch Fishman , part-time CFO for startups. Talks about VC founds, directors, liquidity. Pretty basic stuff if you've read up on this at all, but his Q&A is worth reading. Paul Graham , author of entrepreneurship e

Why I never got into Lisp

Like many programmers (I suspect) who hear enough Lisp afficionados talk about how great their language is, I've given Lisp a try. Twice. I didn't make much headway on either occasion. For various reasons I was poking around python/lisp in google tonight and I came across this thread from a couple years ago. This crystalized it for me: now compare if x > y or a == 0: a1 = m * x + b else: a2 = m / x - b with (if (or (> x y ) (zerop a)) (setq a1 (+ (* m x ) b ) (setq a2 (- (/ m x ) b )). In this case, Lisp requires about 33% more typing, almost all parentheses. And, oh yeah, I forgot, aside from the parentheses, the pervasive prefix notation can be a drag. Syntax does matter. Everyone who has run screaming from a steaming pile of Perl understands this. Lisp's syntax isn't the train wreck that Perl's is; at the very least it's consistent. I could get used to it if there we

Why do Java programmers like Ruby?

As a (mostly ex-) Java programmer myself who prefers Python to Ruby, I'm puzzled by what seems like a rush of Java programmers to embrace Ruby as though it were the only dynamic language on the planet. I understand that it's mostly because of the success of Rails, which definitely came at the right time with the right marketing. But Ruby really doesn't seem like a good philosophical match with Java to me. Java, to a large degree, tried to be "C++ done right." That is, C++ without all the misfeatures that seemed good at the time but whose benefit turned out to not be worth the cost in complexity for developers. Java is a very orthogonally designed language; there is usually one obvious way to accomplish something. Python shares this. Ruby, OTOH, takes the C++ and Perl philosophy of "there's more than one way to do it," with predictible effects on maintainability. ("Perl," said a former co-worker to me yesterday, "is the drunken

John Siracusa on C# and Java

John, of course, writes the OS X reviews for ars technica. (If you haven't read these, you need to. His level of detail should make lesser reviewers think hard about finding another career.) In his blog, he's been talking about what Apple needs to do to avoid another Copland scenario , i.e., avoid resting on their OS X achievments only to wake up in 2010 and realize, "Oh crap! It's WAY easier to write apps for Windows than for OS X!" Which is a rather long introduction to the quote I liked so much: My instincts tell me that both C# and Java are too low-level. Yes, they both have fully automatic memory management, and both eschew C-style pointers for the sake of safety and security, which is more than can be said for Objective-C. But the runtime that Objective-C uses to do its "object stuff" is arguably higher-level than either C# or Java, both of which still seem to cling to charmingly retro notions of compile-time optimizations and "efficien

APIs matter

Victor Moholy : A bad API, like a bad novel, feels like a trick: key information is withheld and simple relationships are hard to deduce. I had one of those "a-ha" moments reading this. ("A-ha," I thought. "I feel a rant coming on.") This is exactly why, after building probably one of the largest web applications done with OpenACS 3.2, I never managed to like the 4.x (and now 5.x) series of that toolkit. OpenACS 4.x and later suffer from Second-system syndrome . The effect is rather Zope-like: instead of a learning curve, you have a vertical cliff to scale before you can accomplish anything interesting. Add in bizarre and arbitrary api changes , it's no wonder nobody except the core team really got on board with the later OpenACS versions. (I suspect that the "everything must be a named parameter" had its genesis in the proliferation of functions taking over a dozen parameters. Deprecating all functions that don't require nam

Why friends don't let friends do J2EE

Michael Sica wrote a post about his experience writing a project manager . Java, cool I get it. JSP, there's like 3 different ways to do everything. Which do I learn. Application frameworks, started learning Struts - what a nightmare. Stared learning JSF - what a nightmare. Found Spring and Spring MVC, and they rocked. Crap, I need to learn Tiles too. Ok, so how does Tiles work with Spring MVC. Ok that's, cool. I only need to do 6 things everytime I make a form. (I actually have a list printed out so I won't forget all the steps.) Life's too short. Choose to be productive. Choose Python .

Python at Mozy.com

At my day job, I write code for a company called Berkeley Data Systems. (They found me through this blog, actually. It's been a good place to work.) Our first product is free online backup at mozy.com . Our second beta release was yesterday; the obvious problems have been fixed, so I feel reasonably good about blogging about it. Our back end, which is the most algorithmically complex part -- as opposed to fighting-Microsoft-APIs complex, as we have to in our desktop client -- is 90% in python with one C extension for speed. We (well, they, since I wasn't at the company at that point) initially chose Python for speed of development, and it's definitely fulfilled that expectation. (It's also lived up to its reputation for readability, in that the Python code has had 3 different developers -- in serial -- with very quick ramp-ups in each case. Python's succinctness and and one-obvious-way-to-do-it philosophy played a big part in this.) If you try it out, pleas

An OpenLazlo blog

I'm sure being described as "an openlazlo blogger" is probably not what he had in mind, but Michael Sica of Ataraxis Software has written more about it than I've seen anywhere else. Here's his first post on the subject , from July. Around a half dozen more follow. OpenLazlo , you will recall, is a rich web app platform that uses Jython internally . (Warning: PDF.) (Michael's blog is also interestiing from an entrepreneurial standpoint. Starting your own company is a common fantasy for developers, and Michael is doing it. I'm catching up on the archives now.)

how well do you know python, part 9

(Today's questions are very CPython-specific, but that hasn't stopped me before. :) I spent some time today looking for the source of a bug that caused my program to leak memory. A C module ultimately proved to be at fault; before figuring that out, though, I suspected that something was hanging on to data read over a socket longer than it should. I decided to check this by summing the length of all string objects: >>> import gc >>> sum([len(o) for o in gc.get_objects() if isinstance(o, str)]) 0 No string objects? Can't be. Let's try this: >>> a = 'asdfjkl;' >>> len([o for o in gc.get_objects() if isinstance(o, str)]) 0 So: (Easy) Why don't string objects show up for get_objects()? (Harder) How can you get a list of live string objects in the interpreter?

A review of 6 Python IDEs

(March 2006: you may also be interested the updated review I did for PyCon -- http://spyced.blogspot.com/2006/02/pycon-python-ide-review.html .) For September's meeting, the Utah Python User Group hosted an IDE shootout. 5 presenters reviewed 6 IDEs: PyDev 0.9.8.1 Eric3 3.7.1 Boa Constructor 0.4.4 BlackAdder 1.1 Komodo 3.1 Wing IDE 2.0.3 (The windows version was tested for all but Eric3, which was tested on Linux. Eric3 is based on Qt, which basically means you can't run it on Windows unless you've shelled out $$$ for a commerical Qt license, since there is no GPL version of Qt for Windows. Yes, there's Qt Free , but that's not exactly production-ready software.) Perhaps the most notable IDEs not included are SPE and DrPython. Alas, nobody had time to review these, but if you're looking for a free IDE perhaps you should include these in your search, because PyDev was the only one of the 3 free ones that we'd consider using. And if you aren

Code Jam 2005

I tried my hand against around 5000 other programmers in Google's Code Jam 2005 . Last year Windows corrupted the hell out of itself halfway through, when I had foolishly not saved any work. The time and concentration lost rebooting killed me. (I had the infamous anti-aliasing problem for my 500pt question. The lowest qualifying score from that group was in the 170s, IIRC. Google dialed down the difficulty considerably this year.) This year I went into battle armed with Visual Studio 2005. TopCoder doesn't recognize any of the beta additions, but Studio 2005 has a pretty decent Emacs mode. Instant 10% productivity bonus! The alert reader will have already noted the use of the past tense in the first sentence and concluded that I didn't make it into the top 500 to qualify for the next round. Correct; I missed the cut by 4 points (732 to the 100th place guy's 736). Ouch. I'd kinda rather have been way outclassed than lose by 4 points out of 1000. Now I

Durus 3.0 alpha released

Thought this was worth pointing out since the Durus guys don't seem to make PR much of a priority. (No slur intended. You could say the same thing about Spyce. :) Durus is a python object database similar to ZODB, but (much) simpler. Their Pycon 2005 paper is a good intro. Here's the 3.0 changelog . IMO the coolest parts are zlib compression and incremental packing. Spyce has a Durus interface (spyDurus) that makes persistence even simpler than the various ORM tools. The to-do demo uses Durus.

A little PHP humor

(Seen in a slashdot comment .) Possible mottos for the PHP project: PHP: We'll be there for you if your development environment doesn't have enough side effects. PHP: Because we know the money's in the maintenance contracts. PHP: Because you obviously don't know any better. PHP: We take security as seriously as Microsoft ten years ago. PHP: Doing it fast is always better than doing it right. PHP: Proving that if any idiot can write an e-commerce package, any idiot will. PHP: Yet another great reason to make regular backups. PHP: Fast, cheap, and robust. Two out of three ain't bad, right?

Guido's OSCON Python keynote

Guido has posted his powerpoint slides in the usual location . (Opens fine in OpenOffice.) The slides are mostly the same as the ones from EuroPython a month ago; here are the main differences: Some odd slides during the introduction (anyone who was there care to explain these?) language data scraped from sf.net -- or you could just look at this page ; no need to scrape and piss off SF for something this simple. (Poor Dylan -- even less projects than Cobol -- 2 vs 4.) "What does this buy us" slides added to 342 (generator) and 343 (with) PEP discussion (highly recommended if you haven't been following python-dev religiously) Exception reform discussion Personally, the "with" statement excites me the most. The exception cleanup is overdue but less sexy. :) The static typing subject has been talked to death but I'll add my two cents. Basically, it's a bad idea because it kills duck typing by requiring interfaces like "iterable"--a horri

Open-source, subversion, mono, and gcc

I read a blog entry about a subject dear to my heart: migrating from cvs to svn. I know svn isn't perfect, but it's just so much better than cvs that it's no contest. If you have objections to svn that are even just a few months old, they have probably already been fixed. One of the first things I did at my new job was to perform the migration and everyone (well... all one other developer who was hired before I was and is still there) thinks it was a great move. But I digress. Sort of. Reading said blog, I thought, "Ha, cool! Those Mono guys whined about svn blame being slow, but then those manly GCC guys dug in and fixed the problem instead of whining some more!" What a poster-perfect picture for the virtues of open-source, huh? Except, while looking for more details, it turns out that the developer responsible for the fix, Daniel Berlin, was a svn developer from way back. As well as (possibly more recently) gcc. (Does this guy ever sleep?) So it&

NagleQueue

Here's a piece of code for the one or two other developers writing intensely network-dependent code in Python. The idea is, instead of a protocol that looks like [command][arg] [command][arg] ... You save overhead (in your protocol and in the network's, if you're doing one connection per command) by batching things: [command][arg][arg]... Pretty obvious stuff, no doubt. But I thought the following class makes it rather elegant. class NagleQueue: """ When an item is put, NagleQueue waits for other puts for aggregate_time seconds (may be fractional) and then calls aggregate() with a list whose maximum length is max_items. TODO: currently, NagleQueue always waits the entire aggregate_time, even if max_items items are added sooner. NagleQueue starts a thread to handle the aggregate() call; this is not a Daemon thread, so you must call stop() before your application exits. NagleQueue will process any remaining items

Python at the .NET user group

I was invited to present on Python and IronPython at the Northern Utah .NET User Group last night. I spent the majority of the time on Python itself, guessing (correctly, with the exception of a couple Zope users) that most people wouldn't know anything about Python beyond having heard of it. There was a lot of participation. It ended up lasting about 90 minutes, with a lot of Q&A throughout. I enjoyed myself and I think most of the .NET guys did too. Thanks for the chance to speak! A PDF of my slides is up here .

MochiKit 0.5

MochiKit is a platform-agnostic javascript framework that doesn't suck. (Here's the release announcement , following the announcement of a public subversion repository a few days ago.) The documentation alone should make MochiKit the preferred js library. It's a huge improvement over the alternatives. Bob Ippolito has been working on MochiKit for a while. I've learned a lot from his javascript blog posts as he's worked on it. If you think you know javascript, but don't know what a prototype is (I didn't), you need to read his blog. (Yes, Bob knows about JSoLait and Prototype. He doesn't like them , and gives excellent reasons for the genesis of MochiKit.)

iXP

I love Mike Spille's blog. He doesn't post terribly often, but when he does it's always worth reading. Here he is with a savagely funny mock of XP . Rule 0. Whenever you type an 'i' - drink! . Also known as the zeroeth iXP rule. While the vision began with Alternate Letter Pair Programming Order, mentioned below, it's really this rule that made iXP gel, and which differentiated it from previous similar practices.

Spyce testimonials

Since the Daily Python URL was kind enough to link to the 2.0.3 announcement, I thought a few testimonials might be in order. :) I tried downloading, installing and using Spyce 2.0.2 on Windows and Linux yesterday and it worked like a dream. I have already set up a useful little dynamic site on a linux box and plan to expand it radically in the weeks ahead. I am using Spyce in webserver mode and also using the scheduler to trigger periodic repository updates.     -- Rock Howard Spyce is really speeding up my "project"... at this rate, I'll be ready for pre-beta testing in about two months. I'm utterly addicted to encapsulation via active tags.     --Tim Lesher (Not to pick on them since they do have a nice framework, but Tim was formerly using CherryPy. Most recently, anyway. )

Spyce 2.0.3 released

2.0.3 is a bugfix and documentation-improvement release. The installation section of the manual has received particular attention. There is also the new section on starting your first project , which answers the FAQ, "how do I organize my Spyce files?" Changelog: - fix pool bug if server not in concurrency=threaded mode; reported by "Dude" - documentation improvements - avoid stomping on user python modules named 'config'; reported by Betty Li - (John Reese) fixed bad interaction of "redirect if directory path doesn't end in /" and "look for default index.$[index extensions] files" code in Spyce webserver - default concurrency mode for Spyce webserver is 'threading' instead of None - spyceProject script to automate new-project creation Update: you may also be interested in the new testimonials post.

on Broken Pipe and Connection Reset By Peer

Maybe I'm just dumb, but I always thought "broken pipe" meant, "the other end of this socket closed before I finished sending something" and "connection reset by peer" meant, well, roughly the same thing. (As well as indicating some slightly more esoteric problems.) Turns out though, "broken pipe" actually means "I just tried to send something and the socket was already closed to sending." So in the following example, if the other end of (TCP) socket "sock" closes or dies before the write method, "connection reset by peer" will be raised. The next write will give a broken-pipe error, since the socket now knows that further sending is invalid. try: sock.write('foo') except: pass # connection reset by peer sock.write('bar') # broken pipe

Jython is back

After almost two years with no releases, Brian Zimmer has released an alpha version of Jython 2.2 (incorporating some of the patches I submitted back in Jan 04). Ha! Brian, you will recall, got a PSF grant for Jython and started work earlier this year. Obviously his original estimate called for a much faster release, but that's how software development goes. Six months to a release after inheriting a new-style class branch that I suspect was mostly broken really isn't too shabby, especially considering how long it took the CPython team. I haven't been following Jython development since I gave up hope of Samuele Pedroni ever getting a release out last year, but it's clear that Jython isn't a one man show anymore. Frank Wierzbicki and Clark Updike have been comitting code; almost certaintly there are others too that I didn't immediately notice. Frank and Clark have both been involved with Jython for a while, but new developers are getting involved too.

How well do you know python, part 8

Here is a mostly-functioning class that facilitates writing producer / consumer algorithms. It is designed to support a single producing and multiple consuming threads, i.e., scenarios where consuming involves some blocking operations such as communicating over a socket. "Mostly," in this case, means that there are two bugs in this class that can be fixed in a total of four or five lines. One is arguably more subtle than the other, but they involve the same part of the code. Can you spot them? Warning: this one is tougher than part 2 , which also dealt with threading. import Queue as queue import threading class PCQueue: def __init__(self, initialthreads): self.q = queue.Queue() self.running = True self.condition = threading.Condition() for i in range(initialthreads): self.add_consumer() def run_consumer(self): while True: self.condition.acquire() try: self.condition.wait

Two Wax projects for Summer of Code

The PSF put up a list of projects accepted for Google's Summer of Code . Not one, but two projects deal with improving Hans Nowak's Wax toolkit. Very cool: hopefully by the time I have to write another desktop-bound application, Wax will be mature and well-documented. Tkinter is too underpowered, and wx is too clunky. That's why I added Wax to the SoC coding project ideas wiki, although it wasn't immediately clear if this was welcome. Glad it worked out. (Two people working on Wax is old news if you read Hans's blog . Which I haven't been, inexplicably. Ah, well.)

Of all the things I've lost...

I installed a sys.excepthook in my project at work that uses the logging module to record any uncaught exceptions. It didn't work. I did what any lazy programmer would do: ask someone more experienced. "Do you have to set sys.excepthook in each thread?" I asked, more-or-less. "I don't think so," he replied. Hmm. Maybe the developer I'd taken over from was setting excepthook later on in the initialization or somewhere else. ... Nope. Finally I wrote this: import sys, threading def log_exception(*args): print 'got exception %s' % (args,) sys.excepthook = log_exception def foo(): a = 1 / 0 threading.Thread(target=foo).start() Playing with this a bit demonstrates that sys.excepthook doesn't work in subthreads, at all . The documentation doesn't mention anything of the sort. Smells like a bug to me. (I did file one .) I belatedly googled "sys.excepthook threads." (I must have been a bit slow this morning to no

The tale of a wiki diff implementation

I run a web game that I started in late 2000, back in the Dark Ages before there was a decent python web toolkit. It runs on a then-current version of the OpenACS TCL-based toolkit. (at around 20kloc, porting it to a more modern system wouldn't be worth the effort now.) Recently, a player suggested that I add a wiki, since my own documentation is chronically out of date and player-run sites tend to suffer bitrot as well. (How many games are you still playing that you started 5 years ago?) So, I backported a modern OpenACS wiki module -- no trivial task; a LOT has changed in OpenACS, and not all for the better -- and was set. Except the module I backported didn't have diff functionality, probably because the various TCL options mostly suck . Enter TclPython , a tcl module by Jean-Luc Fontaine (who is obviously a far better C hacker than I) that embeds a python interpreter. Sweet! My life just got a lot easier: package require tclpython set py [python::interp new] #

SF.net examples fixed, again

This time I apparently broke it by copying the development spyceconf.py, which among other things references the authentication tag that doesn't exist in 2.0, into the sourceforge site. Oops. (The 2.0.2 release itself wasn't affected.)

I figured out why Python's threading library bugs me

Reading Aahz's 2001 OSCon presentation , I ran into a slide that crystalized it [paraphrased]: Perl: There's more than one way to do it Python: There should be one (preferably only one) obvious way to do it Python's threading library is philosophically perl-ish That pretty much says it all. Well, that and the main classes are (still) virtually undocumented. Update: I'm referring to the synchronization classes in this module, not the Thread class, which is straightforward enough.

Why PHP sucks

(July 8 2005) Apparently I got linked by some PHP sites, and while there were a few well-reasoned comments here I mostly just got people who only knew PHP reacting like I told them their firstborn was ugly. These people tended to give variants on one or more themes: All environments have warts, so PHP is no worse than anything else in this respect I can work around PHP's problems, ergo they are not really problems You aren't experienced enough in PHP to judge it yet As to the first, it is true that PHP is not alone in having warts. However, the lack of qualitative difference does not mean that the quantitative difference is insignificant. Similarly, problems can be worked around, but languages/environments designed by people with more foresight and, to put it bluntly, clue, simply don't make the kind of really boneheaded architecture mistakes that you can't help but run into on a daily baisis in PHP. Finally, as I noted in my original introduction, with PHP,

Anders Heljsberg doesn't grok Python

While Debian was releasing Sarge and Steve Jobs was introducing MacX86 yesterday, Anders Hejlsberg spoke on C# at Microsoft Tech-Ed . James Avery writes : After a couple questions from other people I was able to get in the other question I was dying to ask. What does Anders think about the resurgence in dynamic typing from languages like Python. Basically he said that he understands what benefits people are getting from dynamic typing, but he thinks they can get the benefits of dynamic typing without sacrificing strong typing. He talked about inferring type (what anonymous methods do now with delegates) and how that might be a way to get the coding speed and ease without sacrificing the strongly typed information. Unfortunately, omitting type declarations is only a small part of Python-esque dynamism. One of the smallest, in fact. Far more important are the ability to modify objects and classes at runtime, which allow you to do things in Python that would require code generation (w

Spyce 2.0.2 released

Second bugfix release. Get it here . Changelog: session_dir uses config.tmp by default if no directory is specified fix for session_dir pickling on win32 fix for fileCache pickling bug on win32 reported by Jaros³aw Zabiello fix for sessions + handlers problem reported by Jonathan Taylor * all module init() methods are now run before handlers are called.

How well do you know Python, part 7

Given the following two classes, class A: def foo(self): print self.__class__.__name__ class B: pass why does this work, def bar(self): print self.__class__.__name__ B.foo = bar b = B() b.foo() while this does not? B.foo = A.foo b = B() b.foo()

Utah Python User Group

The former Provo-Orem Python Meetup Group is now the Utah Python User Group . I've set up a rudimentary website and discussion list; anyone interested in Python is welcome to join the list and/or attend the monthly meetings (next one on June 9th). (We're already on the user group wiki in case utahpython.org is hard to remember. :)

Spyce 2.0.1 released

Spyce 2.0.1 is available over at the usual place . This is a bugfix release. Changelog: use tempfile.gettempdir() as default config.tmp add originalsyspath to spyceconf bugfixes for Active Tag compiler portability & other bugfixes (John Reese)

Spyce vs ASP.NET

A former co-worker asked me over IM, What advantage, other than being able to use it on a Linux box, does [Spyce] have over the ASP.NET Model? Because I can tell you, with Visual Studio, I feel pretty productive. I answered, The main one is a significantly shallower learning curve. Once you know how the ASP.NET event model and page lifecyle work, you are set -- but you remember how "easy" that was for [our] students. With Spyce there is only one rule: handlers run before the rest of the page, in the order they were added. That's it. And, of course, Spyce runs Python. This is significant: Python is addictive; once you start writing code in it, it's painful to use less-expressive languages. This is something most people won't get until they try it, unless maybe they are old-school Lisp hackers. Now, Spyce isn't quite to the point where it matches ASP.NET feature for feature. But it's close, and getting closer. I checked in an authentication

Microsoft ahead of Sun in dynamic language support

Microsoft's Chris Anderson writes : ...our singular focus on strongly typed compiled languages has blinded us to the amazing productivity and approachability of dynamic scripting langauges like Python and Ruby. I'm super excited that we are changing this. Hiring Jim Hugunin [to work on IronPython is a great start. Jython has long been the only Python (or any major dynamic language) implementation on a Big Platform VM, and it's still substantially more usable than IronPython despite months/years of languishing while Samuele Pedroni as the sole "active" project admin wrote little code and checked in less, much to the dismay of people who wanted to work on Jython. (Not that I'm bitter.) Now that Brian Zimmer got a PSF grant to work on Jython, thinks are finally moving again, slowly. But despite the moral support from Sun managers like Tim Bray, Sun really hasn't done much for dynamic languages on the JVM. Sure, they hoste

Spyce 2.0 final

Spyce 2.0 is available here . "You've taken spyce off my 'disgusting template engines' list. This is how I'd want to see apps structured, exactly."     -- Tim Lesher "I feel easily five times as productive in Spyce as I do in JSP."     -- Conan Albrecht Spyce is a python web application server, combining the features of popular frameworks such as JSP and ASP.NET with Pythonic elegance. Spyce may be deployed as a standalone server (or proxied behind Apache), or under mod_python, FastCGI, or CGI. Documentation and demos are here . Highlights of Spyce 2.0 include: Active Handlers : reusable components without the leaky abstractions seen in ASP.NET et al. Active Tag compiler OpenACS-like (Tiles-ish, for you JSP people) parent/child layout system

Trial periods for software developers

Tim Lesher has an interesting post about applying meritocratic principles to hiring software developers . He suggestion is to hire developers as contractors for a trial period before taking them on full-time. If you as a hiring manager aren't sure about someone, either on a technical level or just fit with your team, this makes sense. I didn't have precisely this experience when I started as an instructor at Northface, but I did start at a lower salary with an explicit "if you're still here in 3 months, here's what your salary will rise to." (This was primarily because they wanted someone to teach ASP.NET, with which I had no experience at the time.) I thought this was a pretty fair approach, and much better than a rigid "if you don't have the right keywords on your resume, don't bother no matter how good you are." But companies won't bother giving the "maybe" candidates a trial period if they think they can find a "

Materialized views in PostgreSQL

One thing I've wanted to write about for a while is materialized views in PostgreSQL. Materialized views are basically precomputed views; they're very very useful if you have an expensive query against data that doesn't change much. This is one of the tricks I use to keep the db overhead on Carnage Blender reasonable. Oracle and DB2 are the only RDBMS products that can auto-materialize views for you, but you can rig them yourself in PostgreSQL or anything that gives you a powerful enough trigger + procedural language. (And if performance is crucial, you'll end up hand-optimizing them in Oracle/DB2 as well. At least, back when I used Oracle in the 8.1 days.) But while looking for examples of a certain PL/PGSQL feature this morning, I found Jonathan Gardner's materialized views page (link may be down; see the archive.org copy ) which covers the subject so well that now I don't have anything left to add. Nicely done! Incidently, this is just one more reas

Emacs support for Spyce

Committed spyce.el in svn contrib/. (For those of you not bound to it by 10+ years of habit, el stands for Emacs Lisp.) I didn't write a "spyce mode" per se; I just used the mmm-mode module to allow Emacs to recognize the python snippets inside html. mmm-mode is one of the most complex modules I've had to work with, and while it gets the job done, to me it seems like emacs is showing its age. Maybe one of the DrPython guys will write an Emacs keybinding package so I don't feel too lost. This is about as simple as you get with mmm-mode. You can get a lot more complicated . (require 'mmm-auto) (require 'mmm-sample) (setq mmm-global-mode 'maybe) (setq auto-mode-alist (cons '("\\.spy$" . html-mode) auto-mode-alist)) (setq auto-mode-alist (cons '("\\.spi$" . html-mode) auto-mode-alist)) (mmm-add-classes '((spyce1 :submode python-mode :front "<%" :back "%>") (spyce2 :submo

Looks like spyce will have to find a new home

SF.net just sent out an email to project admins saying, among other things, that project web space will soon be mounted read-only. Bleh. That means I just wasted a LOT of time tweaking the Spyce makefile to auto-deploy to sf.net for no reason, because both of the new demos want to be able to write to disk. (One because it uses durus, and the other because since SF runs in CGI mode, the pool module pickles and unpickles itself to disk for each request. Which sucks rocks for performance, of course, but if you cared about that you wouldn't be using CGI, now would you?) Of course spyce.org is already taken by someone who isn't using it... I guess the bright side is now I can go ahead and enable comments on the Spyce documentation once it moves, if I have the time to wrestle with the TOC (table-of-contents) module to get it to spit out appropriate .spy files instead of html. (Making it into a wiki is another attractive option, but the nice thing about the TOC module is you ca

"a new web framework named spyce"

Dion Almaer writes in a sort of footnote to his Python has a leg up in the dynamic language race post that [T]here is also word that a new web framework named spyce is going to try to do what Rails has done for Ruby. I think there are definitely some points of commonality if you take a big picture view; primarily, both are about leveraging the capabilities of dynamic languages to provide an environment vastly more productive than is possible with traditional staticly-typed-languages (Java, C#). How we go about that, though, is quite different. Spyce isn't trying to be a Rails clone a la Subway; it's its own beast. Spyce is more page-centric, like ASP.NET or OpenACS. Like all modern frameworks, Spyce encourages separation of code and markup, but it's not religious about forcing one man's vision of MVC down your throat. And while strictly speaking Dion is wrong to call Spyce "new," Spyce 2.0 has a much, much more modern feel to it than 1.x. If you evalua

Spyce 2.0 beta released

Some 217 commits into development, Spyce 2.0 is finally available for download . The main Spyce site has been updated with the new docs, examples, and demos. Full changelog is here ; highlights include new-style active tags - docs OpenACS-like (Tiles-ish, for you JSP people) parent/child templating system - roughly the same speed as include.spyce, so using one parent template has about 1/2 the overhead as the old standard two-includes-for-header-and-footer. - docs Active Handlers reusable components without the leaky abstraction of ASP.NET et al. - docs The only major change since the prerelease was announced on this blog is that the class chunk token was changed from [[\\ to [[!. At least that's the only one I remember after spending the last 5 days wrestling with sourceforge's cgi-bin.

how well do you know python, part 6

class foo(list): def __eq__(self, other): raise 'foo.__eq__ called' >>> help(list.__eq__) Help on wrapper_descriptor: __eq__(...) x.__eq__(y) <==> x==y >>> [].__eq__(foo()) True >>> [] == foo() Traceback (most recent call last): File " ", line 1, in ? File " ", line 3, in __eq__ foo.__eq__ called Help says those two statements should be equivalent. Why aren't they?

Any questions?

Closing on a real beta for Spyce 2.0, is there anything you'd like to see better illustrated? I have time to do another demo in the next couple days provided the scope is reasonable.

Extending Spyce with spyceModule

One of the ways to extend Spyce is with a "Spyce module." This is a historical term, and a little unfortunate because some people have assumed when I talk about "modules" I automatically mean the Spyce variety rather than the vanilla python variety. A Spyce module is simply a class that extends spyceModule.spyceModule. That's it. Spyce modules may be used in a .spy page with [[.import name="modulename"]] which instructs the compiler to create code that instantiates an instance of the given spyceModule at the beginning of each request for this page. It also automatically invokes the instance's finish method when the request finishes. What can you do with Spyce modules? A common reason to write a Spyce module -- perhaps the most common -- is is to provide some sort of resource pooling. Here's the spydurus module which does exactly that: spydurus.py CONNECTIONS = 3 # max connections to put in the pool import Queue from spyceModule im

how well do you know python, part 5

I was reminded of this one while working on the Spyce/Durus demo to make it a better example of using Durus in a real application. What is wrong with the following code? A.py: import time, threading finished = False def foo(): import sys sys.stderr.write('testing') global finished finished = True threading.Thread(target=foo).start() while not finished: time.sleep(1) B.py: import A print 'finished' Update: fixed A.py so there was only one problem.

Spyce 2.0 prerelease

There won't be an official beta this week after all; Rimon wants to review the code and docs over the weekend before we take that step. However, as an un official beta, Spyce 2.0 is available from subversion: svn co http://svn-hosting.com/svn/spyce/trunk/spyce The featureset is solid at this point. If you start playing around now, you won't get burned by changes of that sort. You may well find bugs, of course, which I'll fix as soon as I can. The docs are up here , including a pretty good introduction as to Why Spyce 2.0 Rocks, if I say so myself. (That is, I say the intro is pretty good. But also that Spyce2 rocks, for that matter.) The to-do demo and an enhanced version of the chatbox demo are both included. Update : forgot a link to the changelog .

Not your father's spyce

You've taken spyce off my "disgusting template engines" list. This is how I'd want to see apps structured, exactly.     -- Tim Lesher As a followup to my Durus notes , I've put up a new Spyce + Durus demo showing off the features of Spyce 2.0. This time I allowed myself more than two files, and split the action logic into a separate module. (To-do lists seem to be the new standard for demoing your web toolkit, and I dare not be less than trendy.) I tried to comment the code (linked from the demo pages) so it speaks for itself. If you have questions after looking at that and the language constructs page, please feel free to ask in the comments here. I'd like the docs to be in good shape for the 2.0 release. Update: I've modified the demo to include spydurus, a Durus connection-pooling module for Spyce, and to use ClientStorage instead of FileStorage. The demo was popular enough that single-threading it got to be annoying. (Updated links to

Introduction to Durus

The README that comes with Durus is missing a couple pieces of information that are critical if you actually want to write a program that uses Durus, and the only other documentation appears to be the 2005 Durus pycon presentation , which gives an admirable description of the technical underpinnings but doesn't fill in the blanks of how to use it, either. Specifically, as far as code samples go, the README gives you this: Example using FileStorage to open a Connection to a file: from durus.file_storage import FileStorage from durus.connection import Connection connection = Connection(FileStorage("test.durus")) And this: # Assume mymodule defines A as a subclass of Persistent. from mymodule import A x = A() root = connection.get_root() # connection set as shown above. root["sample"] = x # root is dict-like connection.commit() # Now x is stored. That's all you get. Okay, in this situation it's

Spyce tag compilation example

I had the question, What do you mean by "compiling" tag libraries? I mean, that Spyce compiles that chatbox.spy into in a more-or-less 1.3-legal python module . (The classcode/handlers/exports features aren't in 1.3, but you get the idea.) The compiled result looks like this (output courtesy of the Spyce -c option): class boxlet(spyceTagPlus): name='boxlet' buffer=False exports=1 classcode=((7,4),(10,83),"def addLine(self):\n # (use get() in case server restarted)\n request._api.getServerGlobals().get('chatlines', []).append(request['newline'])",'test-chatbox.spy') handlers=[('e73068ffe2d1ead1793b6790ec48f92a04fd18641','self.addLine')] def syntax(self): self.syntaxSingleOnly() def begin(self,width='300',lines='5'): pool=self._api._startModule('pool',None,None) taglib=self._api.getModules()['taglib'] taglib.load('form','form.py&