Sweet Mappy Goodness

There’s been a massive amount of cool software and web development lately involving maps.  I just want to nail down what I’ve seen in one place.  I’ll try it as a timeline…

  • For ages there were the “classic web” map websites, which reloaded the entire page for every zoom, pan or other change. 
    MapQuest was one of the first (what, 10 years ago?), and has changed little since then.  In a word, “slooow”.
  • Eventually some sites like Yahoo Maps and MSN Maps evolved some, using DHTML to dynamically swap the map image, without reloading the entire page.  This was definitely faster.
  • More recently, there was Google Maps, which actually slices the map into separate map “tiles”, so that only the changed parts of the map are downloaded for each zoom/pan/etc (which is even faster).  Definingly-cool features include satellite maps, and the ability to “grab/drop” to move the map with your mouse just like you’d grab and move a real one.  This also put AJAX (aka “Remote Scripting”) on the buzz map as a web development technique.
    Update: Don’t miss the many amazing “remixes” of Google maps with other web apps, like phone books,
    housing ads, and
    crime stats).  Just Wow.
  • Then NASA released World Wind, a desktop application which does this same trick, but leverages DirectX to provide seamless zooming/panning — a true 3D app, and very cool.  It’s mouse-enabled much like Google Maps, but adds UI features like Tilting (which gives panning the sensation of a fly-over!) The focus is more educational/scientific reference than convenience (sorry, no driving directions to Wal-mart.)
  • Google Earth is the most recent, which is basically a combination of Google Maps with World Wind.  Its UI features are very similar to World Wind’s, but it has more practical user features like Google Maps (how about Flying directions to Wal-Mart!).  (It also has some business features like demographic information overlays and the like, which puts it in the arena of Microsoft’s commercial MapPoint software).
  • Update: A9 Maps is a new one.  It’s a different interface, and sports “curb-view” photos of addresses.  …Or says it does anyway, I can’t find any around me, so I’m not sure what use that is.

All of these are free, by the way.

If you dig this kind of map stuff and/or astronomy, I recommend Celestia, a free 3D desktop app (like World Wind and Google Earth) for extra-terrestrial (as in “off Earth”) virtual exploration.  It’s a great reference and learning/teaching tool, and my 5yr old and I love it.

Microsoft Invented AJAX

Okay, I’m not really sure Microsoft invented AJAX, but I do know Internet Explorer had several asynchronous scriptable technologies and techniques long before any other browser.

To enumerate:

  • DSOs (ADC, TDC, RDS).  The TDC was pretty good, ADC was too heavy, and RDS was too much of a security issue, but they were all early ways to asynchronously data-bind elements at the browser.  They were also fully scriptable.
  • IFRAMEs – IE4/1997 or newer had IFRAMEs (Netscape 4 did have ILAYER, but Netscape 4 generally sucked).  I actually thought I invented this technique, and used it on many projects to much success.
  • Java – Meh, too bad about the JVM.  Same basic technique, though.
  • XMLHTTPRequest – Slightly more recent (circa IE5/1999 I think).  This object IS what modern AJAX code runs on.  Firefox, et al have only added similar objects in the last couple years.

“Remote Scripting” was Microsoft’s term for this technique.  (Heck, here’s an April 1999 MSDN article on the topic).

SO, I’m rather annoyed when well-known journalists say Microsoft is working “Not to be left out of any development trends…”, or better yet,
“Microsoft has decided [Ajax] is something it can’t ignore… the Redmondians have jumped on the Ajax bandwagon.”.

…Microsoft built that bandwagon.

Update: Perhaps I’m not the only one annoyed they’re not getting their due.
Scoble’s got a good laugh over AJAX, and Scott Isaacs has
thoughts on an AJAX (DHTML) framework.

Hack Lives!

Hack screenshot

So I played this game, half-a-lifetime-ago, called Hack. 
It was a ASCII-graphical game for DOS, where you explore a dungeon, seeking the Amulet of Yendor. 
You could play as a Wizard, Barbarian, or various other character types, and would of course fight monsters, gather treasures, and have various adventures along the way.

The user-interface was obviously very simple (even at the time), but the gameplay was amazingly rich. 
I loved it, and spent many days of my life “in the dungeon,” but eventually moved on to flashier graphical games.

So flash-forward 15 years to last week, I see this User Friendly comic mentioning “NetHack,” and then another random mention of the game got me curious and googling. 

NetHack screenshot

Lo and behold, Hack is still alive and kicking! (great history writeup here)  15 years of development (and enrichment) has added a simple GUI (mostly easier on the eyes) and richer (but completely faithful) gameplay.  I’m not at all disappointed. 

I am tempted to say I want some sort of multi-player version, tho.  Especially considering a favorite game of mine: BattleZone, an early 80s arcade classic, which Activision did an amazing (groundbreaking) job resurrecting in ~1998 as a multiplayer FPS.  I’m still playing it 7 years later.

But for now, it’s NetHack again.  It’s nice when old friends visit.

my Code: wipe_commentrange

*sigh*, more comment Spam today — 150 in a few minutes, despite my nice new .Text spam filters (they were all identical).

Unfortunately, I can’t just go into blog_content and delete the range (since the comment count wouldn’t be updated), and I didn’t want to click [Delete], [Yes], [Continue] 150 times, SO: I just fired-up SQL Profiler, reverse-engineered a standard delete call, and slapped together a utility Stored Procedure to loop that call, for big cleanup jobs.

It takes IDs for the first and last comment spam which make it through, and wipes them all out with .Text’s native blog_DeletePost stored proc.  Just paste this into Query Analyzer and run to install:

CREATE PROCEDURE re_wipe_commentrange 
@p_ID int,
@p_lastID int
AS

DECLARE @v_sql varchar(8000)
WHILE @p_ID <= @p_lastID
BEGIN
	SET @v_sql = 'exec blog_DeletePost @ID = ' + cast(@p_ID as varchar(5)) + ', @BlogID = 0'
	EXECUTE(@v_sql)
	SET @p_ID = @p_ID + 1
END
GO

(Note: this is for single user .Text blogs.  Multiple-user blogs will need fiddling with the embedded BlogID parameter.)

Then to use it, call like so in QA: EXEC re_wipe_commentrange 900, 1000.

Might save someone a few minutes (even with writing and posting it here, I think I'd still be clicking delete right now).

Time to consider a way to implement MT-Blacklist...

Javascript -vs- VBScript, pros and cons compared

Yes, this sounds like an all-too-familiar “Intro to Web Scripting” class or article, but I haven’t actually seen these more advanced scripting topics compared before, so I wanted to nail it down in print. 

feature Javascript VBScript
Object-Oriented: Very powerul and easy to create custom object classes Now supported with version 5+ CLASS construct, but is comparatively less powerful and syntax is much more verbose
Object-Based: More object-based, wraps core functionality in intrinsic objects like Date, Math, Number, String, and Array Less object-based, dumps functionality into global functions
Optional procedure arguments: Supported Not supported! (hence kludgy workarounds)
Getter/Setter properties: Not supported! (yet?) Supported
Dialog/User-input support: None built-in, depends on the current object model (e.g. window.alert/prompt/confirm, or WScript.Echo/popup). Has powerful native Msgbox and Inputbox functions.
Convenience tools (aka synactical sugar): Few (escape/unescape?) Plenty (Explicit Conversions, Formatting, Dates, Strings)
Date Manipulation: Difficult (hence the need for a Javascript Date library Easy (see convenience tools)
Leftovers/Quirks:
• Has ternary operator (e.g. var foo= true ? 'bar' : 'grep';
• No ternary operator and no IIF function like VB (but a custom IIF can be added).
General strength Powerful, more “nuts&bolts” Easy-to-learn, more common functionality built-in
General weakness Some common tasks are much too inconvenient Verbose, disorganized, weak OO capabilities
key:
good 
bad 
eh..

Yes, of course it’s my opinion, based on experience (and frustration!)  Feel free to proselytize me otherwise, but back it up!

My perspective is this: scripting languages are about convenience — quickly whipping out something that works, is readable, and is maintainable.  If you want perfect academic code, or fastest performance, get another tool!  For scripting languages, the less code and reference to accomplish a task, the better.

Interestingly, different scripting languages reach convenience by different routes.  For example, where VBScript chooses a “simple” route of a bunch of unorganized global functions, Javascript groups them as methods of intrinsic objects.  Normally I prefer simple, but Javascript’s better organization makes me more efficient: I don’t have to remember 90 or so distinct global functions — if I can simply remember the object (Date/Array/whatever), then I’m set, because VS.net’s Intellisense will help me quickly find the method I need without cracking a reference.

(Aside about Intellisense: it reminds me of the tabs -vs- spaces debate: I say tabs all the way.  Any decent code editor should be able to display tabs how you like.  Fewer characters to store/send, and less arrowing around pays for itself.  And yes, a coder should be using a decent code editor!)

To be clear, I favor neither VBScript or Javascript as a rule — each has its time and place (goal of this chart).  Ideally, I’d like to marry them for the best of both.  Both Classic ASP and WSCs can use both in the same context, which rocks.  Too bad ASP.net lost this feature, but it matters less since it now runs full-fledged programming languages.

Finally, for entertainment, here’s a hilarious thread on the “JS-vs-VBS” subject.  My favorite quote: “IF JScript was a movie, it’d be Citizen Kane, or The Shining. VBScript would be the Mariah Carey movie, or possibly ‘Sgt Pepper’s Lonely Hearts Club Band’ starring Peter Frampton and the Bee Gees.”

Update: added ternary/IIF note to chart ‘leftovers’.

My Code: InputLine function for WSH (Inputbox for CScript)

Now that I’m color-coded, I may start a regular feature here where I publish smallish code bits I’ve written…

For WSH scripters out there, here’s a handy one I wrote…

To explain, for GUI-type WSH scripts (usually run under the WScript engine), VBScript has a native Inputbox function, which prompts for user input via a dialog box.  Command-line-type scripts (running under CScript) have no command-line equivalent, though — yes Inputbox works, but a GUI dialog doesn’t really fit a command-line script.

So to fill that gap, I wrote this:

' Name:		InputLine
' Desc:		like Inputbox, but for use with cscript
' Author:	Rob Eberhardt, www.slingfive.com
' Params:	prompt as string, default value as string
' Returns:	user's answer
' History:
'		2005-06-13	added default param
'		2005-02-28	created original InputLine function
FUNCTION InputLine(p_strPrompt, p_strDefault)
	call Wscript.Echo(p_strPrompt & ":")
	IF p_strDefault<>"" THEN CreateObject("WScript.Shell").SendKeys(p_strDefault)
	DIM strInput
	Do While Not WScript.StdIn.AtEndOfLine
		strInput = strInput & WScript.StdIn.Read(1)
	Loop
	WScript.StdIn.skip(2)
	InputLine = strInput
END FUNCTION

Example usage:

DIM strChoice
strChoice = InputLine("Enter favorite color", "Red")
call WScript.Echo("You entered: " & strChoice)

…which would look like this from a command-line:

Enter favorite color:
Red
You entered: Red

For bonus points, you can detect if the current engine is CScript or WScript, and use InputLine or InputBox appropriately (like if you’re note sure what engine will run your code):

DIM strChoice

'detect CSCRIPT context & use InputLine
IF Instr(lcase(wscript.FullName), "cscript")>0 THEN	
	strChoice = InputLine("Enter favorite color", "Red")

ELSE	'detect WSCRIPT context & use native InputBox
	strChoice = InputBox("Enter favorite color", "Color?", "Red")

END IF

call WScript.Echo("You entered: " & strChoice)

Hope someone can use it.

Note: I would have absorbed this engine detection logic into a single smart InputLine-like function, if only Javascript supported Inputbox, or VBScript supported optional arguments.  But, InputBox’s optional 2nd “Caption” param makes no sense with InputLine, and unfortunately the languages leave no room to gracefully work around that.