Tuesday, February 07, 2006

Lightning 1.2: yet, another new version!

Inspired by a comment left on my last post, I made yet another change to Lightning Compiler :-) The output window is now at the bottom, so that longer lines can be easily seen both in the editor window and the output window. The reason I didn't do it like this in the first place was that I found that too little text showed up in the editor window by default. However... the new version has an option to hide the output window (using a button, or directly from the keyboard).


Feel free to make more suggestions! As long as it doesn't bloat the program, and that I see some use for them... I'll make the changes to this toy app.


Now, for something somewhat unrelated... I had posted a simplified version on the online Python Cookbook. Now, because of new additions, it no longer longer appears on the front page, and will probably never be commented on again. [After all, who would think of looking for such a little app in the Python Cookbook.] But, just for fun, if you find Lightning Compiler useful, why don't you go to the online Python Cookbook and give it a rating. It would be kind of fun if it turned out to be the most often rated recipe ;-)

Monday, February 06, 2006

lightning 1.1: new and improved

Non North-American readers: You may want to skip the "Infomercial" as it probably is something unique to our continent...
====Infomercial====
Are you tired of retyping some complicated indented code at the interpreter prompt?

Do you get annoyed with mixed tabs and spaces?

Do you find it troublesome having to start a full-fledge IDE just to test a few lines of code?

With Lightning Compiler, you don't have to!

Lightning Compiler allows you to open files and save them, or simply type in your Python code from scratch just like a more expensive editor. However, unlike these complicated programs, Lightning Compiler also allows you to test your code instantly, at the click of a button.

The new and improved Lightning Compiler even allows you to do all this without even having to use a mouse: you can control it entirely from your keyboard, just like the Unix gurus!

But wait, there's more!

If you download Lightning Compiler right now, we'll throw in a source colorizer in the editing window absolutely free. With the source colorizer, you will never make a typo in a Python keyword as you edit your code. In addition, we'll include a tab-to-4 space automatic conversion.

And that's not all... Lightning Compiler runs on all major platforms.

So, what are you waiting for? You can download Lightning Compiler right now!

Mirrors are standing by!

Lightning compiler is provided as is, with no guarantee. Possible side-effects include: carpal tunnel syndrome, cross eyes, sore neck, and general lack of social life. Python (and its batteries) and wxPython not included.
======End of Infomercial=====

I always wanted to do a fake infomercial... Now that it's done...


In the past week, I was looking at the stats on download for rur-ple, following the latest release of the lessons and of rur-ple itself, and noticed a fairly large increase. I felt good about that, given all the time I spent on it. Then, I noticed that I could look at individual stats for all the "packages". Much to my surprise, "Lightning Compiler" was responsible for a significant part of the increase in downloads. Not bad for just a little app that was extracted from rur-ple! I even got just about as much feedback (two comments in a week!) on it than I got for rur-ple in about a year. When I first released it, I gave it a version number 1.0, even though it was not very polished. I thought I was done with it as it was answering my needs as a small one-purpose tool. However, as a result of the comments I got, I made some changes to Lightning Compiler, and produced a version 1.1!

For those that don't know about Lightning Compiler, it is a simple windowed app: one window is a Python editor, the other an output window. Your can run your code, and watch the result in the output window, with input() and raw_input() handled through dialogs (wxPython based).

It is not meant to be a "serious" app, but I find I use it more and more, and almost never use the Python interpreter anymore!

Friday, February 03, 2006

Fixing Reeborg: introducing classes

For those familiar with rur-ple lessons, I thought I would share the first draft of my introduction to classes. Some points to remember from preceding lessons:
  • I used the analogy of synonyms to talk about variables
  • Students have already seen how to define new object [like Reeborg = UsedRobot()]
I definitely welcome comments!

Fixing up Reeborg

As we have seen, we can create new robots by using the notation

Reeborg = UsedRobot()
Erdna = UsedRobot(2, 2)

However, these robots are just like the original nameless one: they
can only turn left. To teach them how to turn right, we could define
a function similar to what we did before:

def Reeborg_turn_right():
for i in range(3):
Reeborg.turn_left()

However, there are at least two problems with this approach:

  • We need to define a similar function for every single robot we create (Reeborg, Erdna, ...).

  • Reeborg and turn are separated by an underscore character "_" for the function we defined [to turn right] and by a dot "." for the built-in method [to turn left]. This would not look right...

A better approach is to define a new class that would inherit from the class UsedRobot. This is
what we do in the next section.

Designing a new class

I will show you first how we can fix our robot so that it knows how to turn right, and explain what I did afterwords.

class RepairedRobot(UsedRobot):
def turn_right(synonym_used_to_refer_to_this_object):
for i in range(3):
synonym_used_to_refer_to_this_object.turn_left()

Here's how we can then use this new class of objects:

newReeborg = RepairedRobot()
newErdna = RepairedRobot(2, 2)

newReeborg.turn_left() # as before
newReeborg.turn_right() # new method!

newErdna.turn_right() # this one works too!

And now, it is time to explain. The Python keyword class indicates that we are going to define a new type of "function", one that creates objects. What follows class is: RepairedRobot(UsedRobot).

RepairedRobot is the name of our new class; by writing UsedRobot between the parentheses, we ensure that the new class RepairedRobot inherits all the methods and attributes that UsedRobot had. Thus, when we write:

newReeborg = RepairedRobot()

we create a new robot "named" newReeborg which can do (at least all) the same things that the old Reeborg = UsedRobot() could do.

Next, inside the new class, as indicated by the indented block, we define a new method, turn_right(). By defining it inside the class, we take the first step to insure that all the robots that are created by calling RepairedRobot() will be able to turn right!

The second step that is required is to tell Python that the method will "belong" to the particular object that has been created. To do so, we use the variable synonym_used_to_refer_to_this_object which will refer to newReeborg, newErdna, etc., depending on what object is created. When we write

newReeborg = RepairedRobot()

Python creates a new instance of the class RepairedRobot and defines all the methods, replacing the first argument of the method (synonym_used_to_refer_to_this_object) by the name of the
instance (newReeborg).

Now, synonym_used_to_refer_to_this_object is rather a long name to type. By convention, another variable name is used: self. Thus, to follow the normal convention, I should have
written:

class RepairedRobot(UsedRobot):
def turn_right(self):
for i in range(3):
self.turn_left()

Tuesday, January 31, 2006

Showcasing Python: rur-ple on the web?

There has been much discussion on Python related blogs expressing fear about how "Ruby on Rail" might be a "killer app", promoting strong adoption of Ruby over Python, etc. Much also has been said about how the lack of a "single web framework" was hurting Python, etc.

I was intrigued with the idea of a "Try Python" web site that I read about recently. Inspired by an idea originally mentioned by Steve Howell to create Webster van Robot, a web version of Guido van Robot (which itself was the inspiration for rur-ple) I have been wondering about the possibility of creating a version of rur-ple (only Reeborg's world part) that would run in a standard browser, just like one can use "Try Python".

There are two versions of "Try Python": Mike Meyer's, and Devan Lai's. While Devan (a very promising 14 year old programmer, imho) in a post on comp.lang.python wrote that Meyer's is the "cooler" implementation of the two, I personnally think that Devan's is the cooler of the two, and the one with the best potential for showcasing rur-ple as his version can already accept function definitions (and probably more; I just had a very quick look at both).

Now, I know very little about web stuff. One thing I know is that, for "games" type object, it is much better required to have all the code on the client side (through a java applet, a flash file, or some very fancy javascript) rather than on the server side. I also know that there is (for now, anyway) no Python support in standard browsers. How's that for very little? :-)

Now, I think that, if having a version of rur-ple on the web were to be done, it could generate a lot more attention on Python, and on the web framework that would have been used to develop it if using one of those fancy web frameworks is required.

Nonetheless, if one was to really showcase Python using rur-ple on the web, I think the following requirements would have to be satisfied:
  • It should not require the user to install a plugin in his/her browser, just like it is done with the "Try Python" sites;
  • it should not require a special browser, like Grail, either;
  • it should not require some fancy javascript, but only html and css - remember, it is Python we want to showcase; along the same lines, it should not be implemented via a Python applet. Using Jython would be almost like cheating, imho.
Ok, the no-javascript part is perhaps too strong; after all, javascript is probably a "web standard" on the same footing as html and css. Still, it should be kept to a minimum...

Can this be done using one of these famous web frameworks that are generating so many discussions, including the one spurred by Python's bdfl? I personnally have no idea... One thing I know for sure: if it is, I will have to do some major refactoring of my code as the gui stuff is too much intertwined with the logic part; I had no concept of the model-view-controller approach when I started creating rur-ple, and I had no clear reason to try to conform to it (if it ain't broke...) later on. But, given a strong enough incentive, I could always do it!

Monday, January 30, 2006

Rur-ple 0.95 is out

RUR-PLE 0.95 has been released. The "end" is somewhat in sight. A copy of the announcement that I have posted on a few lists is appended at the end of this post.

This new version has required a lot of work, and relatively little to show for, for the casual observer. Other than writing more lessons, there are still a few things that I must implement before release 1.0. There has been a comment made on this blog about eliminating the "Success" dialog. The person who made the comment had a very good point. However, I have read a fair bit about "positive visual reinforcement" as an encouragement to programmers; even experience programmers seem to get motivated by it (think "green lights/red lights" for Java unit testers ... if you're familiar with it). So, I have been thinking about some alternative that don't require the user to actually press a button to resume.

This newest release has what I consider to be a really nifty feature; I call it the Lightning Compiler. This is a cross between a Python editor and a Python interpreter. It is a GUI based app with two main windows. Just enter a script, either by typing it in or importing from a file, in the Editor window, press "run", and you get the result in the output window. It handles input() and raw_input() through dialogs. I like it so much, that I submitted a simplified version to the online Python cookbook. It is available as a separate download (lightning.py) on sourceforge. I now use it as my lightweight basic Python testing environment. I still use SPE for serious coding though. If you haven't tried it yet, I strongly encourage you to do so.

[The lightning compiler is embedded in rur-ple in the fourth tab, and the interface is a bit different from the stand-alone version. It should be more user-friendly looking for a younger audience.]
=============================
RUR-PLE 0.95 has been released.

A link to the download page can be found at http://rur-ple.sourceforge.net

(The site is slightly out of date, and there is no plan to update it in the future as it provides an excellent idea of what RUR-PLE is about.)

This new version contains a few bug fixes and it should now work properly on MacOS. wxPython 2.6+ is strongly recommmended. There has been a few minor changes in the robot instructions, and the lessons has undergone some major changes.

RUR-PLE stands for Roberge's Used Robot: a Python Learning Environment.

This learning environment contains four main elements:

1. A simple html browser to look at the documentation and, potentially, the lessons. However, the new lessons use cascading style sheets which cannot be interpreted correctly by the browser. Usage of an external browser (Firefox :-) is strongly recommended.
2. A "robot world" with a robot that can accomplish tasks through Python programs.
3. A built-in interpreter which can be used to play with Python
4. A built-in file editor which can be used for futher Python explorations.

The interface is available in English, French and Spanish. Translations are welcome!

Version 0.95 contains 36 complete lessons (English version only). The lessons are also available as a separate download.

Version 1.0, which will aim to be a "complete" Python tutorial for people that have never programmed before, should have approximately 50 lessons.

A few "bonus" lessons have been included. In particular, it is suggested that you have a look at "A Robotic Fairy Tale".

=====
In 1981, Richard Pattis introduced "Karel the Robot" as a tool to teach computer programming.
Reeborg is a robot built on the 1981 Pattis' model... and it is starting to show its age.
It has an oil leak, which allows us to follow its trail. Its compass is broken; it only knows if it is
facing north or not, unlike Karel who could determine its orientation with respect to all four cardinal points.
Pattis' Karel the Robot was named after the author Karel Capek, who popularized the word robot in his play Rossum's Universal Robots (RUR). While RUR-PLE shares the basic RUR acronym,
in this case it stands for Roberge's Used Robot. However, through the magic of Guido van Rossum's Python, you can learn how to fix it and design a better one, worthy of the name Rossum's Universal Robot.

Sunday, January 29, 2006

First separate release of rur-ple lessons

Finally! After much writing, rewriting, fixing typos, changing format to use style files, fixing more typos, I have a separate package of lessons for rur-ple completed. They can be found here. All in all, there is about 50% more material included than in the last rur-ple release. Now that they are separate from the application, it should be easier to have more frequent releases. It should also be easier for people to have an idea of what rur-ple is about without having to download and install the whole thing (including wxPython).

Next, I will have to do an application release, with various bug fixes...

Saturday, January 28, 2006

Foxit pdf reader: fast!

This post is not about Python, contrary to this blog's purpose - but I just had to write about Foxit pdf reader . It is fast. Incredibly fast compared with Adobe's Reader. When it is set as the system's default browser, it can be used with Firefox (just do Tools -> Options -> Downloads -> Plugins -> disable viewing PDF files with plugin). The only drawback I can see is that it is a Windows only product. You can even type in your own text on a page prior to printing.