Monthly Archives: February 2008

NetSuite BOS SuiteScript

NetSuite, without a surprise since it’s already done by it’s competitor SalesForce, introduced Business Operating System, BOS. When I first read about this and the fact that it had SuiteScript, I was almost screaming “if every SAAS startup starts having it’s own scripting language it’s not good for developers”. Then, by looking at the SuiteFlex Development Guide, and reading “SuiteScript is the NetSuite platform built on JavaScript that enables complete customization and automation of business processes.” I felt much better.

Frankly, these days of the Web 2.0 world, there are a few key advantages going with JavaScript based server side scripting. And they are

* The same developer can contribute to both frontend and backend code. (Note that I am using the word “contribute” and not “do development” because, it really depends. Just knowing javascript doesn’t help one to do effective frontend coding unless CSS & DHTML are also mastered)
* Once all the Web 2.0 fad is gone, then the talent pool with JavaScript knowledge would be plentiful
* As a programming language, JavaScript has some powerful features due to it’s prototyping based object oriented programming, functions as first class entities and providing closures. I think it’s also possible to do continuation passing style (CPS) programming.

Advertisements

1 Comment

Filed under BOS, NetSuite, SAAS, SuiteFlex, SuiteScript

Number Of Downloads, A Stupid Metric

Some of the software companies that adopt open source as a marketing strategy advertise that they have so and so number of downloads. A great example of that is Compiere boasting about 1.3 million downloads at present for example. My question is how many of these downloads are

* specific to each release?
* downloaded by competitors?
* downloaded by developers who are just curious?
* potential customers downloading to evaluate but never proceed beyond that first installation and playing around, if they manage to get to that stage?
* it’s easy to manipulate Alexa traffic range very easily by installing the Alexa Toolbar and reloading a website a few times a day from multiple computers (different ips). So, what makes someone not do the same with a bot and increase the download count on sourceforge.net?

Well, I am not accusing any specific company or community about any malpractice, but number of downloads doesn’t really tell anything about a software product. But I guess, any stupid metric becomes a sensible metric on a relative scale. I for one, won’t bet on the number of downloads to decide if I should invest in a specific software.

Leave a comment

Filed under open source

HTML Markup Of An iPod Touch

Lack of standardized support for round corners in CSS has been a pain and there are more than several dozens of solutions out there on the web that vary in their solution approach

* using images to not using images as background
* even the number of images used
* providing anti-aliasing and the lack of it
* using sprites to create round corners with larger radius

There is also a mozilla specific extension called -moz-border-radius using which round corners can be created, but it’s specific to Firefox.

What if you want to represent an iPhone or an iPod Touch as a HTML markup? At iPodish, a stylish electronics rating website, that’s pretty much the attempt. While it doesn’t look exactly like the photo of an iPod Touch, I guess that’s pretty much what can be done with the current level of round corners support in CSS.

Leave a comment

Filed under css, round corners

User Defined Aggregate Functions

Some databases provide the ability to write custom functions that can be accessed from SQL queries. Usually, this feature goes along with a stored procedures capability. A few databases allows creating user defined aggregate functions.

What are user defined aggregate functions? Functions such as count, sum, min and max are all aggregate functions because they operate on multiple rows and provides a single result. There may be times when the default aggregate functions provided by the database are usually not sufficient. In that case, using the “user defined aggregate functions” feature, it’s possible to write your own aggregate function with whatever semantics you want.

It is important to understand the computational model of user defined aggregate functions. First, aggregates happen with or without a grouping. That is

select count(1) from people where country = 'US'

gives the total count of people within the US. Here, there is only one aggregate computation. However,

select country,count(1) from people group by country

gives the total count of people by each country. Here, the aggregates are computed for each country.

In which type of SQL your user defined aggregate function is used should not matter, except for initialization. Before understanding what I mean by that, first, the aggregate computation does not happen on the entire set of rows in a group at once. I will illustrate this with our own user defined aggregate function called pcount. pcount does the same thing that count does.

So, the signature of pcount when you define it as a function, will not be something like

int pcount(object[] group-of-rows);

but it would be something like

int pcount(object val);

So, the expectation is that you keep receiving the data of each row, one after the other and at the end you return the result. So, the following things have to happen for user defined aggregate functions.

  1. Initialization
  2. Iteration
  3. Final Result

Now, since the function is repeatedly iterated over the list of rows within a group, where do you keep any intermediate state such as the number of rows counted so far? For this reason, it is important that the stored procedures language offers some type of object orientation. With object orientation, it’s possible to create an object (using new or whatever constructor mechanism), then loop through the rows calling a member function of the object and any intermediate state can be captured within the object and finally, call a results function to get the final result. In case of a SQL that returns multiple groups (with a group by syntax), it is possible to use the same object or one object per grouping, the implementation may depend on the database. Depending on that, it may be required to write some initialization code so that the state from the previous group calculations are not compounded.

So, the pcount function of ours, will simply be part of an object as a member function and store the count value in a member variable and keeps incrementing the count each time the function is called (ofcourse, it would ignore the null values and not count them).
At the end, the member variable that is keeping the tally of the count is simply returned.

Note that, by default the aggregate functions don’t get the context of the grouping. In our example, the function is not aware for which country the aggregate is being calculated. In most cases this will not be needed either. That is, your count or sum or any other aggregate function value wouldn’t really depend on for which group you are calculating the aggregate. However, if desired, it should be possible as yet another function parameter. Also, note that it’s possible to pass multiple multiple arguments to your aggregate function. Each parameter would typically be a non-grouping column of the query.

Leave a comment

Filed under Advanced SQL

Stack overflow at line: … in IE

I recently came across a strange issue with IE. All of a sudden one of my pages started giving “Stack overflow at line: 0” and I had no idea why that was happening. This didn’t happen in Firefox though. After a bit of searching, didn’t really come across any valid solution other than some microsoft support page talking about too many modal windows causing such an issue.

He is what I finally found with my page. I have the following code

<body onload="onload(event);">

In one flow, this dynamically generated page has the onload javascript function and that works fine. However, in another flow of the same page, the onload javascript function is not implemented. So, in case of IE, it looks like it’s ending up in recursive loop on itself and hence the stack overflow. Had I written the code to

<body onload="onloadfunc(event);">

then in the second flow, it would have simply thrown a regular javascript error that the function doesn’t exist. Hopefully now this mystery is solved for you!

1 Comment

Filed under IE, javascript

SQLITE: Join And Group By vs Group By And Join

A while back I wrote about MySQL count distinct performance issue. Today I am going to discuss about a performance issue I faced with SQLITE.

First the use case. I am experimenting a bit with online product catalogs. So, I have a products table and a categories table. I wanted to get the list of categories grouped providing the count of the items in each category that matches the search criteria. So, I wrote the query as

select c.name,count(1)
from products p, categories c
where p.category1 = c.category_id
and ...
group by c.name
order 2 desc, 1 collate nocase;

The idea is to sort them such that categories with higher product count appear first and if there are two categories with the same product count, they are displayed in alphabetical order (case insensitive).

This query took a lot of time. So, I changed it to

select c.name,g.*
from categories c
,(select category1,count(1) from products where ... group by c.name)
where c.category_id = g.category1
order by 2 desc, 1 collate nocase;

This worked pretty fast. BTW, in the first case, the CPU also maxed out to 90% and above. The later case is much better.

BTW, this is using SQLITE3 (3.3.12)

3 Comments

Filed under performance tuning, SQL Tuning, SQLITE

DIV:HOVER IN IE

I have a link element that contains a div element. My requirement is to change the background color of the div element whenever the mouse is hovered over the link. So, initially I tried

div:hover {
background-color: #abcdef;
}

This works fine in Firefox. However, IE doesn’t like the hover pseudo class for anything other than an “a” element. So, after a bit of tinkering, I got it working with

a:hover div {
background-color: #abcdef;
}

This works in both IE and Firefox. One thing though, the DIV element starts changing color whenever the mouse is hovered not just on the DIV itself, but on the A element itself. So, if the DIV happens to be covering the entire A area, then it’s not a problem, but otherwise, depending on the usecase, this may or may not be an acceptable solution. In my specific case, it is an acceptable solution. So, I am done further research on how to get the DIV to change the color when only that element has a mouse hover in IE.

12 Comments

Filed under css