SoC Week 1: Semi-random thoughts
Here's a big brain dump of stuff I've been thinking about this week. As a
reminder, I'm working on a drag & drop form editor.
Heed warnings
I'm fairly new to the dojo toolkit, so I figured I'd be doing lots of
exploration in firebug. Thus, I should pull in the awesome
dojox.help.console during page load instead of always dojo.requiring it
from the console. Great idea, right? Wrong. When you load help, there's a
two-line warning. The first line:
Script causes side effects (on numbers, strings, and booleans).
Turns out they're not lying. I was getting inexplicable errors where dojo was
using IE methods in firefox. Is the browser sniffing broken? Let's look at the
dojo.isIE attribute, which should be the number 0.
>>> typeof dojo.isIE "object" >>> dojo.isIE 0 __name__=dojo.isIE
dojox.help turns everything into objects, which is great when you want to know
more, but not so great when you want code to work. The next
line of that warning?
Call dojox.help.noConflict() if you plan on executing code.
dojox.lang.aspect ftw
One of the first problems I encountered with dojo.dnd is that there's no clean
way to get a handle on the dnd object if it's created declaratively. It is
possible to give it a jsId, but that introduces a global variable, and you
can't do easy lookups as with dijit.{byId,byNode}.
To work around this, I used dojox.lang.aspect to introduce a before method
on the dojo.dnd.Container constructor that grabs the current object and node
and sticks them in a dictionary for easy lookups in my code.
Someone out there is probably shaking his head, muttering about a better way to
do it, but I thought it was a neat way to add the functionality I needed.
Javascript gets a lot of crap (much of it well-deserved), but I'm having a lot
of fun discovering the powerful things it allows you to do. Working with real
closures is awesome, and the dynamic features that libs like dojo.lang.aspect
exploit open up a world of possibilities that aren't available in most
languages.
svn: patches not welcome
Dojo, like a lot of other projects, is still using svn. This is great for, um,
somebody, but I think it's more detrimental than good for open source projects.
Reading through dojo sources this week to figure out how things work, I spotted
little typos in comments and other minor things, but I didn't do anything about
it because there's too much hassle. To get a fix in , I'd have to create the
patch, make a silly ticket for this little fix, attach my patch there, and hope
someone downloads the attachment and commits the code. It's a pain to share my
code, a pain for someone to test/apply the fix, and at best I only get indirect
credit for the patch, with my name in the commit summary. I'm doing this work
for fun, and the abundant fame and fortune is just a plus, but there's something
special about seeing yourself as an author in the changelogs for the first time.
I really like the git style of sending the patch directly to the mail list.
There's tools that make it easy for the submitter to get the patch out and easy
for the committers to get the patch in. It's a beautiful thing, removing the
barriers for contributing to your favorite projects.
javascript style
Javascript gives you lots of power by allowing function and object declarations
almost everywhere, but this can lead to some funky-looking code. I'm still
trying to figure out what my js style is, where braces and indentation belong
(js2-mode has been a big help with its variable indentation support). This
is strange for me coming from Python, where PEP 8 is the style guide, and
there's not much opportunity to color outside the lines. Dojo does have a style guide,
but there's a lot more room for interpretation.
Code on the way
Once I get my current quick-and-dirty code into a less embarrassing state, I'll
be uploading it to the soc branch and writing another post about what's
going on.

svn
I guess the trade off is between being more powerful (git/hg/bzr/etc) and simplicity:
The tools are improving, so thats just a matter of time. Distributed version control does take getting your head around and understand the concepts. If Dojo changed to git or another dvcs, would we be cutting off most of our patches for the sake of making it more convienient for a small few? Maybe interop tools which present a svn-style interface are good compromise.
Is there any reason mailing list tools like git's couldn't work similarly for subversion?
git
I posted this to the mailing list a few days ago, but just did a Google search on "dojo git" and found my attempts at pulling Dojo into git are part of 10 of the first 12 results...
I am now maintaining a git mirror of the dojo repository here: git://git.freelock.com/git/dojo.git . You can browse it at http://git.freelock.com/?p=dojo.git;a=summary . If you have commit access to Subversion, you ought to be able to initialize a clone of this repository with git svn init, and then dcommit changes to individual parts of the subversion tree... You might also be able to use the git tools to send the patches straight to the mailing list for discussion...
I'm updating my git repository from Dojo svn every 6 hours. The "master" branch has dojo, dijit, dojox, and util trunks pulled in as subtrees, making it easy to load this as a submodule of another project, and switch between a tagged version and trunk. More details here: http://opensourcesmall.biz/archives/2008/06/whats-git-and-why-do-you-use... , and here: http://freelock.com/kb/Git
Hope this helps!
--
John Locke
http://www.freelock.com