Familien Schøler's blog

Lidt af hvert – blogbart eller ej, så er der en lille risiko for at du finder det her

JSLint v1.1 is released!


Jakob Kruse and I have just released version 1.1 of our Yahoo! Widget for validating JavaScript files: JSLint Multi (download link for v1.1). We are also happy to announce that JSLint Multi now is the “official” JSLint widget and that several improvements have been introduced since v1.0, which is why we recommend everyone to update right away.

Since we released version 1.0, Yahoo! has approved and included the JSLint widget on their widget site. If you download and install the latest JSLint Multi from the Yahoo! widget download site you will from here on automatically receive future updates. If you use one of the few browsers which the Yahoo! inpage installer currently support, you’ll be able to install by just clicking the button to the right. Please note that Yahoo! can be a bit slow to update the widget gallery, so it might be a while before version 1.1 ends up there. It has been submitted just now.

Version 1.1 changes include:

  • JSLint has been updated to the 2009-04-19 version.
  • Support for the new “newcap” option has been added, which makes it possible to disable control of constructors required to start with a capital letter.
  • Support has been added for the new “immed” option, which makes it possible to control the recommended syntax for “immediate function invocations”.
  • We have discovered a serious memory leak in the Yahoo! Widget engine itself which we have worked around. As a direct consequence our JSLint Multi widget now use far less memory!
  • Better support for Mac has been implemented, with help from Harry Whitfield.
  • We now use a minified version of JSLint (making the widget much faster).
  • The JSLint engine version being used is now show in the widget title.

We wish all of you Happy Linting!

(It will hurt your feelings though, be warned).

C# API documentation issues

According to http://msdn2.microsoft.com/en-us/library/system.datetime_methods(VS.71).aspx the AddHours() method for any DateTime instance has the following effect:

AddHours: Adds the specified number of hours to the value of this instance.

This means that given a DateTime object “dt”, and that the method AddHours is called on that object, the specific object instance “dt” will be updated with the new value.

DateTime codecompletion hint

As can be seen above, this is also what is shown in the codecompletion hint text in Microsoft Visual Studio 2005.

So the following code should yield the new date value “2008-04-17 10:03:00″:

DateTime dt = new DateTime(2008, 04, 17);
// The object instance "dt" is now equal to "2008-04-17 00:00:00
dt.AddHours(10.0);
dt.AddMinutes(3.0);
// "dt" is now "2008-04-17 00.00.00" ?!

… but instead it yields the value “2008-04-17 00:00:00″.

Digging further in the API documentation you’ll find a contradiction on the method description pages, eg. http://msdn2.microsoft.com/en-us/library/system.datetime.addhours(VS.71).aspx:

Return Value
A DateTime whose value is the sum of the date and time represented by this instance and the number of hours represented by value.

This method does not change the value of this DateTime. Instead, a new DateTime is returned whose value is the result of this operation.

So the correct code is:

DateTime dt = new DateTime(2008, 04, 17);
// The object instance "dt" is now equal to "2008-04-17 00:00:00
dt = dt.AddHours(10.0);
dt = dt.AddMinutes(3.0);
// "dt" is now "2008-04-17 10.03.00"

And that’s not playing nice – now is it? The definition text is ambiguous. Looking closely to the hint text you’ll notice that a DateTime object instance is returned when calling the AddHours method: “DateTime DateTime.AddHours(double value)”.

I suggest correcting the documentation text to the following unambiguous definition:

AddHours: Returns a new DateTime with the specified number of hours added to the value of this instance.

Coding proverbs

Nerd alert. You have been warned.

if (!kill(this)) { this.strength++; } // Thanks to Rasmus for starting this

var bear = { sell: function() { if (!this.shot) return false; } }

var volume = (barrel.contents.count() == 0 ? 100 : 50);

if (house.opacity < 1) { throw new Exception(“You should not have done that”); }

if (water.style.display!=”none”) { water.maxTemperatureDegC = 99; }

if (you != null || you == null) { prompt(“?”); }

update Hero set [Enabled]=0 where FoodCount = 0 or WaterCount = 0;

while (this.absent) this.heart.fond++;

Continue the madness here: ordsprog.sagdejeg.dk

Keep them pouring in! =)

Så skal der laves Team Fortress 2 baner!

Hammer editor til Team Fortress 2 ... Jeg er nu gået igang med at sætte mig ind i level design til Team Fortress 2. Valve har været så flinke allerede i november at frigive et SDK til spillet, men jeg har desværre først opdaget det nu.

Det skal nok blive sjovt at lege med! =)