QED

java..python..eclipse..and whatever else interests me.

Sunday, April 30, 2006

Colbert's White House Correspondents Dinner Speech

Fantastic stuff - slyly delivering the Truth.

Friday, April 28, 2006

IT Crowd Soundboard

Soundboard - brilliant.

Dashtime Notes - Constructivist Learning, Logo, Papert, DOM->Eclipse API's, SynchroEdit, DBC Use case

4/25/2006
Jeff Winkler, winkler1@gmail.com
Ward Cunningham

Monkey

Uses jabberwocky delimiters - easily embedded on blog.
Idea - google Blog search RSS feed for new scripts.. (buggy? didn't find this)

Constructivist Learning / Interactive Shell

The person writing a script has to interact with objects in a safe environment. It's a conversation between the user - exploring, understanding the API's, and the objects and API's of the system. The goal is for the user to learn the objects by exploration...
 The tighter the feedback loop the better. An interactive command line where Javascript code can be entered is the best tool for. See this showmedo.

Ideally, there would be an interactive Rhino shell.

Logo, Seymour Papert, Hard Fun

Before the call, I was reading up on Seymour Papert, after playing with RUR-PLE, a python learning environment.  I had playing with Graforth as a kid - and it was based on Logo. What makes these learning environments succesful?  Hard Fun, and this, seem to articulate it best:

1 What is Logo?

Logo is a unique piece of software. In the purest sense, Logo is a programming language; it is a full-featured computer language derived from LISP, the language of artificial intelligence. More important, however, Logo is a language for learning. It is the right tool to teach the process of learning and thinking. Logo provides an environment where students assume the role of teacher. As a teacher, they must:

  • understand the knowledge to be taught
  • plan an approach to impart this knowledge
  • break the knowledge into small, understandable chunks
  • know how to clearly communicate the knowledge
  • establish this new knowledge as the foundation for future learning
  • be aware of and build on knowledge that the learner already has
  • be receptive to exploring new ideas as they appear
  • respond to the learner's (computer's) misunderstandings and errors

.. Designed at MIT as a language for learning, Logo is by its nature:
 

friendly Logo is easily grasped; we can relate to the turtle and use it as an object to think with.
extensible Logo can be taught new commands and other commands can be built thereon.
forgiving Logo offers immediate feedback through helpful and informative messages.
flexible Logo is as useful with preschoolers as it is with students of higher mathematics.
powerful Logo is a programming language, providing all the tools needed to create programs of any degree of sophistication.

Transitioning from DOM->Eclipse API's

How does a person using a DOM understand what's going on under the covers, with the underlying API's?
Ward suggested using debugger to trace into the code.

Shared document editing - shared artifacts

Though we had a great, rambling conversation, we didn't have easy tools to take notes.  Though DashTime is a "virtual place" - there's no there, there.  I didn't have an IRC client, and it would be a pain to download.  I was jonesing for a collaborative shared text space to take notes. An IRC applet would ease the transition; something like SubEthaEdit would be better, be cross-platform and web-based. SynchroEdit looks the part:

SynchroEdit is a browser-based simultaneous multiuser editor, a form of same-time, different-place groupware. It allows multiple users to edit a single web-based document at the same time, and it continuously synchronizes all changes so that users always have the same version.

SynchroEdit's main editor is fully WYSIWYG, dynamically displaying bolds, italics, underlines, strikethroughs, with various justifications, indents and listing styles as an author inputs them. SynchroEdit also supports a simple, text-only editor for more basic documents. To clarify the multiuser experience, the editor window clearly depicts every user's changes in a specific color and also marks where each user is currently editing with a colored flag listing the user's name.

My DBC/Requirements use case

This is a low-hanging fruit which delivers value for me, and I would see having other developers in my company use.

Given the method findbook():

Book findBook ( String strTitle )

DBC  suggests that the contract should state, and enforce any preconditions.  In my company, we do:

/** Lookup a book by its title
* @param strTitle the book title. Case-insensitive. !null.
*/
Book findBook ( String strTitle ) {
    Require.notNull ( strTitle, "strTitle");

So, I'd like to write a script to type the "Require.notNull" bit for me. I would do:

  • Double-click on the strTitle variable
  • Invoke my Monkey script (ideally, via hotkey)
  • The new line is created... cursor is left where it is

This entails:

  • Getting selected text
  • Inserting text into the buffer, as though I'd typed it.

Thursday, April 27, 2006

Keeping your Nose Green

Mark of pywinauto fame told me about nose, a unit testing tool with autodiscovery. I was slinging some python over the weekend, and needed coverage as my codebase got bigger.. so I whipped this up. I run this on a DOS window under windows. Basically every time you change any .py file, it runs tests. I call it nosy.

import glob,os,stat,time

def checkSum():
''' Return a long which can be used to know if any .py files have changed.
Only looks in the current directory. '''
val = 0
for f in glob.glob ('*.py'):
stats = os.stat (f)
val += stats [stat.ST_SIZE] + stats [stat.ST_MTIME]
return val

val=0
while (True):
if checkSum() != val:
val=checkSum()
os.system ('nosetests')
time.sleep(1)

I didn't get cute with lambda to squash it into a single line. This is simplistic, but gets the job done. I've sent it to Jason for improvement.

Update: A video of this is here.

ITMFA

 

Wednesday, April 26, 2006

Scripting Eclipse with Jython and PyDev

I joined the Eclipse Monkey project Dashtime the other day, and spend the hour talking to Ward Cunningham (Wiki inventor)... very cool.

I had seen Monkey on Wayne Beaton's Eclipse when he talked at NEJUG/BostonEdge, and scripting sounded interesting. I hadn't even installed, and didn't expect to be the only caller!

We had a good discussion, my notes are here. Apparently Rhino was selected because JavaScript is"nobody's favorite language" :)

Monkey is useful but doesn't yet have autocomplete or an interactive shell. I think that's needed to learn the API's, and delve further into Eclipse plugins and SWT. EclipseShell is interesting, but it's not a straight interactive console like Python's, where you can create and interact with objects. (Perhaps the Rhino console can be hooked up)

I use PyDev for Python development, and even sprang for the extensions, which allow an Interactive Console. I can fire up Jython within Eclipse and then import and invoke Java objects-

However, something is wrong.. I want to get the the active window (the window global in Monkey), but it is coming back null:

window = wb.getActiveWorkbenchWindow() print window None

Other API's work fine...

for vd in wb.getViewRegistry().getViews():
    print vd.getId()
byecycle.views.ByecycleView
com.kodeshare.search.ui.KodeSearchView edu.mit.csail.relo.console.ConsoleView
...

There's more than one way to skin a cat--getWorkbenchWindows() works:

wnds = PlatformUI.getWorkbench().getWorkbenchWindows()
len(wnds)
1
window=wnds[0]

Great! Let's try a HelloWorld..

import org
org.eclipse.jface.dialogs.MessageDialog.openInformation( window.getShell(), Hello","World")
Traceback (innermost last): File "<console>", line 1, in ? org.eclipse.swt.SWTException: Invalid thread access

At least this has a reasonable explanation (I'm on a worker thread).

So, you can use Eclipse API's and objects interactively. Excellent. Next, I would love for Autocomplete to work. Ctrl-Space doesn't work in the console. (Bug? I think so.. the console has the Jython nature now.)

For some wierd reason, the python dir() function isn't working, returning an empty list even for a builtin class:

str = "Hello"
dir(str)
[]

Normally this would return a list of methods:

>>> dir(str)
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__ ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__g t__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__ ', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', ' __rmul__', '__setattr__', '__str__', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'index', 'isalnum', 'isalpha', 'isdi git', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lst rip', 'replace', 'rfind', 'rindex', 'rjust', 'rsplit', 'rstrip', 'split', 'split lines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill ']

So close.. hopefully pydev extensions can enable autocomplete on the console. That would make for a truly interactive exploration of the Eclipse environment.