Monday, December 22, 2008

The join() case for a better select()

Today's bug in JavaScript code: was using the Array's join() function and getting results which did not match the expectations. Turns out, that in a case of sparse array (with missing data at certain indexes) join inserts an empty string. So, considering the code:

var a = ['zero', 'one', 'two'];
a[4] = 'four';

The resulting alert will be «zero:one:two::four».

Duh! To adjust to the behavior I have modified the Ruby-like selector to have the «pack» parameter like in this:

// pack   is truthy: (default) resets indexes, returns new packed array
// pack   is falsy:  preserves indexes, returns new sparse array
// tester is a filtering function. Should accept the array's
//        element and return truthy or falsy.
Array.prototype['select'] = function(pack, tester){
  if (typeof(pack) == 'function') {
    tester = pack;
    pack = true;
  } else if (typeof(tester) != 'function'){
    throw { name: 'ArgumentError', message: 'Function expected. Should accept the array\'s element and return truthy or falsy.' }
  result = [];
  for (i in this) {
    if ( tester(this[i]) ) {
      if (pack) { result.push(this[i]); }
      else      { result[i] = this[i]; };
  return result;

Here are the Firebug runs of the select(...):

>>> [ 1, 2, 3, 4, 5, 6].select( function(e){ return e>3; } )
>>> [ 1, 2, 3, 4, 5, 6].select( false, function(e){ return e>3; } )
>>> [ 1, 2, 3, 4, 5, 6].select( true, function(e){ return e>3; } )

Let me know, if this does not work in IE or others for whatever reason - I have only tested it in Firefox.

read more ...

Thursday, December 18, 2008

JavaScript Meetup Presentation

I will be speaking today at the Chicago's JavaScript Meetup on the topic of "Traps to avoid in JavaScript". The 10-minute talk is for beginners and the slides can be found on the website.

Monday, December 8, 2008

Orphan Works Bill opinion from FSF Compliance Engineer

In October this I have forwarded my opinion (see this post) on the Orphan Works Bill as a question to Free Software Foundation licensing team. Brett Smith from FSF sent me an interesting and detailed answer, which I post here verbatim with his permission:

On Oct 21, 2008, at 11:38 AM, Brett Smith via RT wrote:

[Vlad Didenko - Mon Oct 20 19:22:09 2008]:

The recently passed by Senate "Orphan Works" act got surprisingly little attention from the Open Source community. In my assessment, however, it is guaranteed to reduce the benefits of the Open Source paradigm and put the extra defense burden on individual authors. I am trying raise awareness of the legislations impact on our industry.


Thanks for getting in touch with us to share your views on this bill. At this time, we do not have an official position supporting or opposing the act, and since the corresponding bill in the House did not come to a vote this session (HR5889), it does not seem to be a pressing issue at this time. However, we will continue to watch developments in this area, and will announce any new positions on our web site as appropriate.

In general, we believe that copyright law provides more rights to creators than is socially justified, and we support efforts to lessen its scope. However, we understand your concerns that the particulars of this bill may favor large companies holding many copyrights over individual free software developers. Ultimately, much of the analysis is likely to depend on exactly what does and does not count as a qualifying search under the new act -- which may be difficult to evaluate since it depends on the Register of Copyright's Recommended Practices, which don't exist yet.

I did want to take the time to address a couple of factual issues in your e-mail. First, we at the Free Software Foundation and the GNU project aren't part of the Open Source movement, but the Free Software movement. This movement has been campaigning for computer users' freedom since 1984. We discuss the ethical issues surrounding software development and licensing, and the impact that actions in these areas have on society. The Open Source movement began in 1998 and focuses on promoting the technical and practical advantages provided by Free Software. I encourage you to learn more about the differences and relationship between the two movements at

Second, a copyrighted work would not necessarily be considered orphaned under the new act if the copyright holder passed away. When this happens, the copyright is ordinarily transferred to another party: the original copyright holder could name a recipient in their will, or else the copyright would be held by their heirs. With enough effort, a search to contact the copyright holder should discover this and be able to find the new copyright holders.

I hope this helps you understand our current thinking on this. If you have any questions about this, please feel free to contact me.

Best regards,
Brett Smith
Licensing Compliance Engineer, Free Software Foundation

read more ...