2009-05-02
Equality and Identity in Javascript
A reader from Plymouth writes,
So I’m profiling along, and I find an anonymous function that is being called a number of times. It doesn’t cost a lot, but I’m curious why it is anonymous. It’s not really anonymous, because our compiler assigns a debugging name to anonymous functions that you can use to find them in the source. Here’s the anonymous function:
static var _ignoreAttribute = {toString: function () { return '_ignoreAttribute'}};
_ignoreAttributeis just a unique sentinel object that we use as a way to indicate that an attribute has already been processed, deep in the inner workings of LZX. Someone (probably me) graciously gave it atoStringmethod, so that when you are debugging and trip across it, you will realize that it is not just any old empty object.But I’m not debugging. I’m profiling. I’m not calling
_ignoreAttribute.toString(). It’s nowhere in the source code that I can see. What is going on?
Gentle reader,
Well, here’s a problem:
if (null != this.datapath && dp != LzNode._ignoreAttribute) {
this.datapath.setXPath(dp);
} else {
Can you spot it? When dp != LzNode._ignoreAttribute runs, dp is normally a string, and read the fine print for how equality is computed in Javascript (from p. 64 of ECMAScript Language Specification Edition 3):
- If Type(x) is different from Type(y), go to step 14. […]
- If Type(x) is either String or Number and Type(y) is Object, return the result of the comparison x == ToPrimitive(y).
Well, I won’t bore you with more gory details, but the bottom line is, every time we compare _ignoreAttribute to a String, the runtime has to call its toString method to see if it is “equal”.
The storal of the morey is, when you want to compare for “identity”, use the “strict equals operator” (=== or !==), not the “equals operator”. [For my money, the former should have just been called the “identity” operator, but unfortunately it isn’t quite. There are some odd edge cases that make it not a true identity operator.]
2009-04-23
I am a hacker
A reader from Maine asks:
Are your computer skills such that you could be a hacker if you wanted to
be? I’m just curious.
Gentle reader,
I am a hacker.
The popular press has co-opted the label “hacker”, which was originally a compliment of your high degree of computer skills, to mean a person who uses those skills for evil.1
If you are asking “Could I break into someone’s computer”, the answer is “yes”. There is no magic here. I started my computer career working in computer security at MITRE. And, believe it or not, things have not really changed much since those days. If anything, computer security has gone downhill quite a bit. No one has ever succeeded in commercializing the research we did (to build a secure system from the ground up), instead commercial enterprises have all focussed on selling “barn door” solutions, so called because they are attempts to close the barn door, despite the fact that a lot of (Trojan) horses have already been through…
—
[1] http://en.wikipedia.org/wiki/Hacker(computing)#Hackerdefinition_controversy “Hacker (computing) - Wikipedia, the free encyclopedia”
2009-04-21
I'm replacing all the wall outlets in my house with USB jacks...
This hint made me realize the answer to Martha Stewart’s problem! USB is the universal power supply. Who needs 110v? 5v suits me just fine…
2009-04-15
Solving Global Warming
The government really ought to just nationalize the credit card industry, stop printing cash, and give everyone a free credit card. Then they can take 2.5% of everything that anyone ever spends (instead of AMEX/Visa/MC/etc.) and do away with the dumb income tax system. The savings in overhead, record-keeping, filing, etc. would probably snap the economy right out of the recession. And all those CPA’s could get real jobs and put their math skills toward solving something important like global warming…
P.S., Heck, global warming would probably be solved just by turning off all the computers that are wasting cpu-cycles folding, spindling, and mutilating tax returns today.
2009-04-07
Silverlight != Apple Pie
Wow. How can MS be so stupid? They bundle Flash with Windows and not Silverlight? Doh!
First, baseball wanted Microsoft to make it possible for users to download Silverlight without having to possess administrative rights. When people are at work, it’s often the company that possesses those rights and employees would need authorization to download the player. That frustrated plenty of MLB.com subscribers, according to the sources
Why Major League Baseball dumped Microsoft’s Silverlight | The Industry Standard
Posted via email from PTWithy
Silverlight != Apple Pie
Wow. How can MS be so stupid? They bundle Flash with Windows and not Silverlight? Doh!
First, baseball wanted Microsoft to make it possible for users to download Silverlight without having to possess administrative rights. When people are at work, it’s often the company that possesses those rights and employees would need authorization to download the player. That frustrated plenty of MLB.com subscribers, according to the sources
Why Major League Baseball dumped Microsoft’s Silverlight | The Industry Standard
Posted via email from PTWithy
Silverlight != Apple Pie
Wow. How can MS be so stupid? They bundle Flash with Windows and not Silverlight? Doh!
First, baseball wanted Microsoft to make it possible for users to download Silverlight without having to possess administrative rights. When people are at work, it’s often the company that possesses those rights and employees would need authorization to download the player. That frustrated plenty of MLB.com subscribers, according to the sources.
Why Major League Baseball dumped Microsoft’s Silverlight | The Industry Standard”
Posted via email from PTWithy
2009-04-03
OL 4.3!
We are pleased to announce that OpenLaszlo 4.3 is available now. You can download it from the OpenLaszlo Download page. It is the recommended platform for all application development for the SWF8, SWF9, and DHTML runtimes. OpenLaszlo 4.3 is a major release, with almost 300 bugs fixed since OpenLaszlo 4.2 introduced the SWF9 runtime.
‘nuff sed.
2009-03-29
Using your iPhone overseas without getting screwed
We all know about turning off data roaming (Settings/General/Network/Data Roaming), so our phone doesn’t run up our bill checking email when traveling out of your service area, but recently someone asked me how they could turn off the phone altogether (so they don’t make a phone call @ $2.00/minute or text @ $0.50/message by mistake), but also they wanted to keep the Wireless on, so they can still email, etc., if they are in a wireless hot spot. Initially, I thought you couldn’t do that, because going into Airplane Mode (Settings/Airplane Mode) by default turns off the phone and the wireless. But actually what you want to do is perfectly obvious (once Google helped me):
First go into your Settings - Turn on Airplane Mode - and then turn your Wi-Fi connection (back) on.
Doh!
I just checked it out and it works perfectly. If you try to make a phone call or text, it tells you you have to turn off Airplane Mode, and gives you choice of not making the call or turning the phone back on. Ditto if you try to text. But I can still surf, email, use AIM, etc. Nice!
How To: Turn on WiFi While the iPhone 3G/EDGE Radio is Off | The iPhone Blog
2009-02-16
OpenLaszlo under a Bushel?
A reader from Germany writes:
Laszlo has to sell products and make money, but I think the OpenLaszlo platform has lost in priority with the current management. Not money-wise (how much money they spend on it), but seeing it as a marketing-vehicle for the company. I would love to see more DHTML apps, that would really convince people of the dual-runtime power.
Gentle Reader:
I look at it this way: OpenLaszlo is practically a separate entity. Laszlo is our main sponsor, so we mostly do what they ask. But, we do have other sponsors: G.ho.st directly, others through support contracts. So they also get attention. Community stuff comes last, because that has no $ attached to it. But community leaders can be given commit privileges and see their goals achieved directly.
While OpenLaszlo is a valuable technology base, the company can’t make (as much) money off of it as they can with a proprietary product. Laszlo is doing kind of the same thing as Apple: adding proprietary value to an open-source base. And, we like that, because it means they can “donate” more money to the OpenLaszlo team. :)
Laszlo is a venture-backed company, and venture capitalists are all about making money. They pretty much only see as far as the Webtop licenses. But the management has been made well aware of how the community has made the base they build on much more solid than what they would get with a closed source.
As to DHTML applications, in reality, swf9 is so different from swf8, that is the more convincing port to me! swf8 and DHTML are only different in their UI model, the Javascript is 99% the same. To do swf9, we really had to re-engineer the guts of the whole tag compiler and script compiler, to implement a lot of Javascript 2 (Harmony) and then compile down to Javascript 1 for swf8 and DHTML.
We knew it would be a lot of work, but we knew if we could do it, we would really prove we had a platform-independent language in LZX, and we ended up with a much more robust system in the end.
There is a rule of thumb: 2 ports does not make you platform-independent, it is the 3rd that is the test!
In the end, we were very pleased that we were able to keep nearly all the dynamicity of LZX and target a strongly-typed, much more static platform. The strong-typing and ‘true’ classes of Javascript 2 have given significant performance gains (some claim a speed-up of 5-6 times), but the OpenLaszlo compiler has been able to shield the LZX developer from most of the requirements of declaring types and overrides in their LZX code and has been able to keep dynamic features like <state>s and constraints.
Let me conclude by saying, overall you are right. OpenLaszlo needs more publicity, whether for Laszlo as a company, or just for it’s own growth. Let’s hope this little post can help it along the way…

