Thursday, January 17, 2008

Bare-faced cheek

Today was final assessment day for this year's Web Technologies module: A Questionmark Perception test and short JavaScript assignment. Sadly the start to the test malfunctioned and I was forced to remove the Blackboard setting that restricted students to one attempt at the test. Happily Perception gives easy access to all attempts by every student (something Blackboard does not, easily anyway); unhappily, in hindsight, I should have restricted them to a few attempts rather than unlimited...

Amusingly, one student assumed I wouldn't check and he used this lapse to attempt the assessment over-and-over until his time ran out, utilising the fact that the assessment showed the marks to gain an unfair advantage. Happily I did check and so we'll be enacting the relevant part of the "Cheating in Assessment" regulations on his behalf. What a waste of time!!

And the bare faced cheek? He had the chutzpah to complain at the end of the test (before I'd discovered his perfidy) that he'd arrived late & unfairly lost time. This fell on my unsympathetic ears -- no good excuse => no extra time. Tough monkeys! But cheeky, nonetheless...

Wednesday, December 05, 2007

JavaScript tips

You know how occasionally you read a tip and have a "wow" or "lighbulb" moment? Well, this collection of seven JS techniques from Dustin Diaz contained six such events for me (seriously: I read them over several days and had a "ding!" moment from all six code tips -- nice!)

Wednesday, November 28, 2007

Possum Death Spree!

Sick but funny! Get ready for Possum Death Spree! ... I particularly liked the they've been frozen in the permafrost ... now global warming has set them free and:
Dying cop:
They killed the dinosaurs?
Handcuffed scientist-guy
No, they killed half the dinosaurs; they made the other half watch!

Wednesday, November 21, 2007

@media AJAX 07 final thoughts

It was a great conference, with a good mix between "techy" and some "designy" stuff from some really world-leading presenters. Well done Patrick :-) If I can get the funding I'll be back for @media 2008.

(& my reason for the over-long, verbose summaries of the talks was to give some flavour of the conference to my students.)

@mediaAjax day 2.6: Wrap-up discussion panel

The final session of @mediAjax was a discussion panel, starring Brendan Eich [BE], Stuart Langridge [SL], Alex Russell [AR] and Douglas Crockford [DC], ably chaired by Jeremy Keith (so Patrick & Jeremy made up, which is nice) and it ran with JK posing questions submitted by the audience and moderating the discussion:

Mobile & JS:
[Nobody mentioned Cameron Moll-style mobile user-centred design.]
Not much impact other than [BE] report from Opera regarding eBay, use of eval for self-modifying code and its impact on battery life.
Libraries:
No consensus other than [SL] use what works with you/your team and use libraries to level the DOM playing field.
WCAG2 & JS?
Dojo and ARIA are interim measures.
Standardise libraries?
Not necessary but combine forces for a common voice.
Can JS ever be secure?
[DC] No, we need a secure dialect, but there are things we can do to help.
[BE] Things like mashups are the killer problem & there is no silver bullet.
[AR] Google Gears, "trust domain", Open Ajax Alliance.
[BE] Gears' "worker pools" excellent & might end up in Firefox.
[AR] Must remember that in life risks are mitigated not solved, only Internet gives the false impression that it’s 100% solvable. (Mentioned "Capability Models"? see "Confused deputy" by Norm Hardy.)
JS2 = Java?
[BE] No, JS2 class is for integrity not Java-like object model. JS2 is not fixed & they’d welcome feedback but class & receive/dispatch methods are needed.
[DC] Standpoint is don’t add syntax.
[AR] All of the toolkits do this stuff so JS2 should follow if it’s needed.
Is proprietary a hindrance? (Silverlight, Air, Flash, Gears?)
[AR] If the text on the wire is lost, lots of collateral benefits will be go (spidering etc.)
[BE] Tension! Proprietary gives better control but Open Source encourages competition, both benefits.

To be honest, the discussion panel was a bit disappointing and JK rounded it up with a bland "we've made progress from the WASP DOM Task Force days", but it was a tough conference to sum-up and there were obvious tensions between the panel-members.

I guess they needed my special question so it was a shame I'd not gotten around to asking it! Here it is: What skills do employers of web developers want in graduates? What should educational institutions teach for workers in the modern web? Comments welcome...

@mediaAjax day 2.5: JavaScript: The Good Parts

Douglas Crockford's title and opening remarks were complimentary to JS, emphasising that there are very good parts to the language, as evidenced by the range of users, from computer science graduates to cut'n'paste coders. JavaScript is succeeding in an environment where Java failed.

Good things include prototype inheritance, 1st class functions (lambda) and loose typing. Closures work because of lambdas and garbage collection and is the best thing in programming languages.

Bad things are:

  • globals (particularly user-defined and overwritable)
  • semicolon insertion
  • typeof object==typeof array==typeof null!
  • with/eval use of eval is a cry for help
  • phony arrays (performance)
  • type coercion (==)
  • too many negatives (null, undefined, false, NaN) why? E.g. object[name]==null is commonly used but gives false +ve with 0, null, '' property values – must use object[name]===undefined.
  • C heritage, optional braces + permitted empty statements.
  • Use of IEEE floats whereby 0.1+0.2 !== 0.3
  • Dense constructions like ++ and –-
  • Switch/case fall-through
  • new – forget it and assignments overwrite the constructor

These are mainly things that can have disastrous consequences from minor typos but oftentimes seem useful.

Advocated JSLint.com and the professional subset of JS that it permits but warned JSLint will hurt your feelings and unlearning is hard.

Style isn’t subjective, e.g.
return { ok: true } vs
return { ok :true }
;-insertion means the second returns null, ok is a label and produces no syntax error and the braces wrap an empty statement that does nothing but is permitted…

Douglas’ perspective is to make JS more like JS should be. Deprecate the worst features, don't break the syntax, keep it simple, keep it safe (a subtle LOTR reference ;-). Add JSON.stringify, JSON.parse, safe/restricted eval, add a "don’t enumerate" flag to objects, no experimental features (hard to remove), no radical changes & no new syntax. More languages: two small languages are better then one large language.

More security but that would break current JS syntax. JSLint "ad safe" mode c.f. Google Caja (Caja allows this; JSLint does not.)

(This is a long post as lots of it was using notation I'm familiar with, hence my notes were legible and concise, but personally I'm with the JS2 pack: I teach students who learn Java first so if I can use Java-like syntax, so much the better, but DC's arguments are worth paying attention to.)

@mediaAjax day 2.4: Dojo 1.0: great experiences for everyone

The enthusiasm of Alex Russell, the speaker for the fourth session of the second day of @mediaAjax, was apparent instantly -- he spoke almost continuously, rapidly and coherently for the full hour of his talk: quite an achievement! He opened by listing "Maslow's hierarchy of needs" and relating them to the web, but there was so much new information contained in this part of his talk that I couldn't take it all in. I did remember a few choice quotes, such as:

  • The idea that we'll continue to limp along using Java is laughable given languages like Python, Ruby, Erlang
  • Not caring that it's broken is our best weapon on the open web... if we had to care about everything that was broken we'd never get anything done.
  • The HTML/JS/CSS stack is wickedly hard to learn (because of bugs and interactions -- the basic stuff was easy for basic sites in the 1990s).
  • HTTP is one of the best things to happen to mankind … compound interest, penicillin, the wheel and HTTP! LOL!
  • And the most important for understanding the rest of his talk was: Good semantics allow you to say what you mean and get what you want. (But at the moment we only have one or the other -- HTML/CSS are currently liabilities, e.g. menu, tree, video, column...)

As for Dojo, the mantra was "build with (dojo), not on", which I hope I remember correctly was meant to imply that there Dojo team want to work closely with developers, and developers, so is the talk it doesn't do what you want then ask!

Dojo's approach is obviously different from jQuery, not only because they supply widgets and are committed to accessibility (whereas jQuery is low level and leaves the consideration of accessibility to the developer), but also in action because they use custom attributes within the HTML markup. Alex gave as an example a simple lightbox widget that used something like the following markup:
<img src="img1.png" dojoType="dojox.image.lightbox" group="a" />
<img src="img1.png" dojoType="dojox.image.lightbox" group="a" />

which Dojo and converts into a lightbox slideshow.

Alex also emphasised their commitment to WAI ARIA "states and roles", their enthusiasm about HTML 5 and how they look forward to browsers implementing HTML 5 so that they can ditch all of the extra code that it would make redundant.

(It was a great talk but information-packed talk and I'm sure I've missed stuff...)

Tuesday, November 20, 2007

@mediaAjax day 2.3: Metaprogramming JavaScript

Dan Webb's talk turned out to be an explication of the JS language, notably the primitives, objects, functions and prototype inheritance. It was good to see those concepts explained in a clear fashion again but at the time I didn't get the link with metaprogramming which Dan defined as:

Metaprogramming is the writing of computer programs that write or manipulate other programs (or themselves) as their data...
(http://en.wikipedia.org/wiki/Metaprogramming)

which was a shame (it's the as their data bit I missed.) Actually, Dan did show examples of using class methods from Array with other array-like objects (notably arguments), building push methods in implementations that don't have them and a genuine "Meta" addEvent function that self-modified on the 1st call to avoid repeatedly checking for implementation features (namely IE vs DOM2 event model), so that seems to cover the metaprogramming aspect — guess I wasn't paying sufficient attention (or it's a classic example of how taking and writing-up notes can clarify things in your mind.) He finished with a book plug: "The Art and Science of JavaScript", soon to come from SitePoint. (Note to self: get a copy for the library!)

@mediaAjax day 2.2: Building Interactive Prototypes with jQuery

In day 2, session 2 of @mediaAjax, John Resig gave an excellent demonstration of the elegance and simple syntax of jQuery, so much so that I'm inspired to use it to replace/augment my teaching of the DOM next year. He said his slides would be available and that the jQuery site has lots of documentation and tutorials, so I'll not reproduce the example code here; suffice it to say that jQuery looks good, useful and relevant to what my students need to know

Some of the extra details he gave: jQuery's Ajax support allows 3rd party JSON and uses something like eval or a dynamic <script>. jQuery supports a document "ready" event that triggers before "onload" to allow the JS to manipulate the DOM before the user sees it. jQuery is extensible and also interacts well with Firebug (as John demoed) and leverages the DOM so that it also works with XML documents loaded e.g. through Ajax.

He finished with a geek tease, showing a JavaScript port of a visualisation tool ("processing") running on <canvas> with super-cool, interactive graphics -- tease/cool!

@mediaAjax day 2.1: JavaScript 2 and the Open Web

Brendan Eich's the father of JavaScript – we're not worthy! – and opened the 2nd day of @mediaAjax. He started with some excellent geek movie/culture references (Star Wars, Lord of the Rings and Firefly!! Who could want more? Well, the audience apparently: Sadly hangovers were in evidence and these did not get the cheer they deserved — sorry, Brendan), followed-by general reasoning behind the need to extend JavaScript together with the info that JavaScript v1 arose out of 10 days work in May 1995 when Netscape rushed it to market (broken & out of his hands.) JavaScript is not going away (it's the most deployed & "fuzz tested" [?] programming language worldwide) and browsers need to evolve. All three of the following need to improve: security, APIs and language support. Things in motion already include Screaming Monkey, "rumours" of IE8, WHATWG HTML5, Opera/Safari/Mozilla runtimes and Google's Gears.

JavaScript 1 is too small in a bad way (few primitives means hard to optimise, lacking integrity features and has bolted-on security) and JS1 is taught too infrequently (too many "Java U." programmers [are we guilty of this?!], too few middle-road JS programmers).

Opinion:

  • Users deserve optional typing (not tedious error-checking that people don't do anyway!) so that APIs can prove facts about arguments. Most JS on the web won't use typing and doesn't need it.
  • Integrity: support static things const
  • Namespaces
  • Packages
  • Compiled units
  • Bug fixes (fix stuff ECMAScript v3 broke)
  • Distributed extensibility -- the dream of Java that dies in 1997 -- Flash/Tamarin is already the most distributed VM.

Non-issues: Performance? DOM is the client-side problem; trace-based JIT can deliver similar speed improvements to static typing JIT/approach Silverlight C# speed. Other language? No need! JS2 learns from ActionScript, Python etc.

Integrity is a real issue: JS1 global scope can be overwritten (CSRF), ECMA specification is a mess, JS2 will make things immutable. JS1 objects too mutable, JS2 classes not to follow Java but to permit immutable/private/protected objects and properties (maybe call them fixtures?). JS1 allowed hijacking of constructors and vars, JS2 will have const and final. Structural types in JS2 will make type-checking easy and therefore much more likely to be done: evolutionary programming and gradual typing.

Finished with a geek-tease demo of <video>: SVG embeddable, planned for Opera/Mozilla, currently implementing Ogg Theora and Vorbis, maybe finalising on H.264 -- multiple videos playing simultaneously, audio from the element with focus, 2D/3D rotation in realtime ;-)