Archive for the ‘Javia’ Category

Arity Performance on Mobile Phone vs. Desktop Computer

Thursday, March 27th, 2008

I’m so happy I’m blogging again!

So, everybody knows already that I am the author of the Arity Arithmetic Engine, a nice little open-source library for evaluating arithmetic expressions. In this library I put quite some attention on the elegant and minimal code, and on performance. The functionality is mainly split in two parts: compiling an expression (takes a string and returns a Function object), and evaluating the Function.

For example, compiling the string “g(x)=x^2″ produces a Function instance. Calling eval(5) on this function returns 25. These two operations (compilation and evaluation) are separated because you typically compile an expression once, but evaluate it many times (for example when plotting the graph of a function).

On a desktop computer, Arity can do about 50,000 compilations/second, and about 1,000,000 evaluations/second. So the compilation is about 20 times slower than the evaluation.

Why is the compilation so slow? well, you may be surprised, but the bottleneck during compilation is the parsing of a double value from a string (using the java.lang.Double.parseDouble(String)).
And Double.parseDouble() is not only slow, it also does quite some memory allocations (which again result in slowness when the GC is invoked to collect that memory).

One key advantage of the Arity library is that it compiles not only on JavaSE (desktop Java), but also on JavaME/MIDP (mobile Java). So last weekend I decided to measure its performance on my mobile phone (a modest Nokia 6300). I wrote a tiny midlet for the benchmark, and the result is:

On the mobile phone, Arity does about 500 compilations/second, and about 10,000 evaluations/second. So the 20 times factor between compilation and evaluation speed is the same as on desktop.

And the key information, the mobile phone is about 100 times slower than the desktop computer (from Arity’s point of view).

Still, 10,000 evaluations/second on the mobile phone is not bad, I am quite happy with this performance.

PS: go check out Arity: http://arity.googlecode.com/

Menstral and Javia Calculator become open source

Saturday, March 17th, 2007

I have just made available the source code for my projects
Menstral and Javia Calculator under the liberal MIT License.

To get the source code you need a subversion client.
The svn repositories are here:
Menstral Source Code and
Javia Calculator Source Code.

Enjoy,
Mihai

Going open source?

Friday, March 2nd, 2007

I’m thinking about open-sourcing my two JavaME (mobile phone) projects, Menstral and Javia-Calculator.

My reserve to open source them until now was caused mainly by a hope to transorm these projects in a commercial offering at some point. So my recent inclination to open-source them also means that I’m not planning to make any money from these projects anymore.

The main reason for open-sourcing is to allow the programs to evolve (bug-fixes & enhacements) even as I have less time (and inclination) to do everything myself. Of course I’m aware that just open-sourcing a project doesn’t automatically create a community around it, and this is the open-source challange.

I have to choose a code repository (SVN). The choices I consider are: SourceForge, Google Projects, and self-hosted. Self-hosted is more work, but also allows for the greatest flexibility.

Considering the license: MIT or GPL? I personally like the MIT license more, as I consider it less restrictive (and much shorter) than GPL. On the other hand, GPL protects against the possibility of competitor closed-source projects freely taking advantage of the code.

URL Design

Friday, January 26th, 2007

The URLs that are used to access an web application are important, they are part of the interface to the application. Here I put together some random principles which should help towards a quality URL design.

  1. Keep URLs short. Short is easy to remember, to edit in the address bar, to write down, etc. The most often used URLs should be the shortest.
  2. Don’t use file extensions (such as .html, .gif, .php, etc.). The extension is an implementation detail that doesn’t need to be presented to the user.
  3. Normalize URLs. Every entity should have one canonic URL. Have other URLs that point to the same entity use HTTP redirects to the canonic URL.
  4. Normalize the domain name to the form without the leading “www.”, because it becomes shorter. The leading www. doesn’t add information for the user.
  5. A path which accepts to be continued with more segments should behave like a directory, i.e. should be normalized to have an ending slash.
    If http://x.org/user/john is a valid URL, then http://x.org/user should redirect to http://x.org/user/ (note the appended slash).
  6. If a path is valid, then any prefix path should be valid too.
    If http://x.org/admin/user/john is valid, then these should be valid too: http://x.org/admin/ and http://x.org/admin/user/ .
  7. Have the prefix URL allow exploration (browsing) to the possible suffixes that may follow it.
    In the case of http://x.org/country/brazil : http://x.org/country/ may provide a list of possible contry names, with links.
    In the case of http://x.org/user/john : http://x.org/user/ may provide an input field for entering an user name if the number of users is too large to enumerate them all in a list.
  8. Avoid ‘query’ parameters in URL. Instead of http://x.org/?p=101 use http://x.org/p/101 . An exception are the form-action URLs which get the parameters appended due to the form submission.
  9. Avoid session-IDs or other long binary (opaque) identifiers in URLs. If you really absolutely need an opaque identifier in the URL, then make the information as short as possible (number of bytes) and encode it in the most compact way (e.g. base64).
  10. Try to have homogenous levels, where all the continuations (suffix segments) of an URL are of the same kind.
    Example: If http://x.org/user/ is continued with ‘john’, ‘andy’, ‘mary’: it’s good, all the continuations are user names (nouns).
    But if http://x.org/user/ is continued with ‘john’, ‘edit’, ‘remove’, ‘102′, ‘new’: bad, because ‘edit’ and ‘remove’ are actions (verbs), ‘john’ is a noun, ‘102′ (noun too) is an id and not a name, ‘new’ is a noun but designates an action (add), etc. This level is not homogenous (it’s mixed-up).

It’s great if a web application has such a simple (and nicely structurated) URL space that the user, after some use of the application, aquires a mental map of the URL space. From that moment on he won’t have the sentiment of being lost in a huge URL spaghetti anymore. He achieves orientation: by simply looking at the URL he knows where he is and where he can go. He can even extrapolate from the observed URL structure and explore new URLs.

Midlet-Vendor

Sunday, January 21st, 2007

A mandatory midlet attribute, which must appear in both the jad and the jar, is Midlet-Vendor; it designates, as the name suggests, the vendor (or the author) of the midlet. One problem with this attribute is that the structure of its value is not specified in the MIDP standard: it may contain any string (including whitespace). In this way, while the Midlet-Vendor attribute may still be useful for presentation to the human user, it is of limited use for authomatic processing.

Let’s consider some examples that illustrate the point:

Midlet-Vendor: Mihai Preda
Midlet-Vendor: mihai-preda

Midlet-Vendor: www.javia.org
Midlet-Vendor: myself

Midlet-Vendor: FooSoft
Midlet-Vendor: Foo Soft Inc., USA

In the first examples we see different ways of writing essentially the same vendor name, by varrying case or whitespace. While it looks the same to a human reader, certainly the vendor string is different from a computer perspective. This makes it difficult to automatically associate the different midlets with the same one vendor. There is also a second problem with such a vendor name which contains the name of the author: of course there are multiple persons with the same name (unless the author has some particularilly rare name), so it may happen that two distinct authors (with the same name) turn up being identified as the same vendor.

Let’s look toward a solution: We want the Midlet-Vendor to have a normal form, which allows to reliably compare two vendor strings in order to detect if they designate the same entity or not; and we want to eliminate the possibility that two different entities turn up using the same vendor string.

The solution that I propose is to have an URL (URI) as the content of Midlet-Vendor. In order to make it explicit that it’s an URL, the schema (e.g. http://) should be present.

Midlet-Vendor: http://javia.org/

The URL should point to a page which contains more information about the vendor; it could point to a company’s home page, to the blog of the author, etc.

One objection to this solution could be that the Midlet-Vendor is also intended for presentation to the human user (of the mobile phone), and the company URL is not as clear to a human as the company’s name. While I don’t necesarilly agree with this argument, a solution would be to have the Midlet-Vendor contain a free string (the company name, intended for user presentation) and an URL, intended for equality-comparison between different Midlet-Vendors. Examples of good Midlet-Vendor strings:

Midlet-Vendor: Mihai Preda (http://javia.org/)
Midlet-Vendor: Foo Soft Inc. (http://www.foo-soft.com/)
Midlet-Vendor: http://google.com/

The important point is this: the Midlet-Vendor should always contain an URL (eventually enclosed in brackets), and only the URL should be used for equality-comparison between different Midlet-Vendor strings.

But according to the MIDP standard, the full Midlet-Vendor string must be compared for vendor-equality — so in practice I would suggest to use only an URL as the content of the Midlet-Vendor.

Dreamhost

Thursday, January 18th, 2007


I’ve been using Dreamhost for one year now, and I thought I’ll write a review, to see how the referral system works (disclaimer: I get referral fees for everybody who signs up following a link from this page).

The lowest plan costs about $10/month, and comes with about 180 GB disk space, and 1800 GB transfer/month; this is rather huge. I look on the status page for my account (that I share with two friends), and I see that together, our disk usage is at 1% of the space available, and out traffic usage never got as big as 1% (it always stays at 0%). So for practical reasons, the disk and transfer seem unlimited.

You can create up to 75 Linux user accounts, with shell (bash, ssh) access. You can host any number of domains, with any number of subdomains and mailboxes; all this free.

Dreamhost offers one-click installs of WordPress, phpBB, Joomla!, MediaWiki, activeCollab and many others.

I’ve installed and I’m using Django (Python web framework) without any problem (with FastCGI). Dreamhost also supports Ruby on Rails, although I don’t use Rails myself. For databases, DH supports MySQL (with many storage engines: MyISAM, InnoDB, BerkeleyDB, etc — InnoDB supports transactions) and of course SQLite (PostgreSQL is not offered yet, but may be added in the future if there is demand for it). Of course, you may have an unlimited number of MySQL databases. Dreamhost supports FastCGI. As web server, Apache versions 1.3 and 2.0 is available, with full .htaccess configuration (including mod_rewrite). PHP (versions 4.4.2 and 5.1.2) is of course available.

Dreamhost also offers subversion (svn) that you can use either through ssh, or access with the browser. I keep my development svn repository at DH, thus taking advantage of their data security and backup (if my laptop gets stolen, or if my hard disk explodes, I won’t lose my source code). DH also offers webdav (mod_webdav in Apache).

It is possible to compile and install at Dreamhost the applications or libraries that you need (if they are not already offered by DH) — this comes handy when developing a web application. For example, I’ve installed on my account: Python 2.5, Django (svn version), GDB, SCons, GeoIP, ImageMagick, readline, ares, and the most recent version of SQLite.

You also have low-level access to the DNS records (so you may add any DNS records on your domains: A, CNAME, MX, NS, PTR, TXT, etc). And the greatest thing: even though wildcard DNS is not officially supported, the DH support team was kind and, at my request, has just activated wildcard DNS on one of my domains (thanks DH, this is great!).

And Dreamhost offers a free domain name registration (com, org, net — which typically cost $9/year) with any account.

What’s more: on my Linux laptop, using FUSE and sshfs, I remotely mount my DH account directory as a mount point on my local filesystem. This way I can work with and edit all the files from DH just as if they were local on my laptop, which is very useful.

About the DH drawbacks: the DH servers do not seem as responsive as they could be. And an account doesn’t come with a dedicated IP included (you may add IPs at additional cost). Because of this, it’s not possible to do SSL (https://) on the hosted domains ‘out-of-the-box’ — you need to add a dedicated IP, which costs $4/month, for that.

In conclusion, Dreamhost offers a huge amount of liberty; it is as close to VPS (virtual private hosting) as it gets, while keeping the cost in the low shared-hosting range.

If you read thus far, don’t forget to use the promo-code WILDCARD when you sign up: it will get you the one year plan (which normally costs $119.40) down to $29, with one domain registration included (isn’t that incredible?).

Menstral’s new feature: SMS transfer

Thursday, December 7th, 2006

Menstral is a menstrual calendar (also called called cycle or ovulation calendar) application I wrote one year ago.

Menstral 1.9.0, released today, adds an interesting new feature that I’ve called SMS Transfer: it allows you to send your calendar data, through SMS, from one Menstral instance to another Menstral instance running on a different phone.

This is useful for the users who change/upgrade their mobiles, as they expect to be able to continue using the applications from their old mobile on the new one (this expectance includes the continuity of the persistent RMS data).

I wonder what other mobile applications out there are using the SMS Transfer. I’d suspect this technique will become more popular as the developers realize that they have to catter for their users’ habit of periodically switching mobiles.

And one more prediction from my foreseeing bag:
The young(ish) mobile users will grow out of the pictures/ringtones through MMS thing (which never really took off anyway), as soon as they’ll discover they can now send menstrual calendars through SMS.. wow!

(On the same funny line, a surprising observation is that a significant part (perhaps more than a half) of Menstral’s users are Men!)

Cost structure

Tuesday, July 18th, 2006

Costs are in euros per month.

developer pay (one person) 3000
office rent (50% of apartment rent) 200
food 200
hardware amortisation 150
electricity, consumables, phone 70
internet access 40
web hosting 10
domain names 5
total 3675

Costs: about 50k euros / year.

Return:

Probability Gain
80% 0
15% 100k
4% 500k
1% 5000k

This means that with 80% chance the project will be a complete failure, and will bring nothing (0 gain).
With 15% probability it will have a little success and bring a small return (100k), etc (these figures are
very rugh estimates, and don’t have any solid base).

Expected return: 85k euros (the weighted average of the possible gains), with very high risk.

July project update

Saturday, July 1st, 2006

The v0.1 release that I wanted to prepare for the 1st of July is postponed. The situation is that there are too many problems and missing functions at the moment to warrant a release.

In the future I’ll avoid setting release dates. I wanted to use the ‘release date’ trick as a self-motivating device: knowing that I have to do something at a given date, I’d push myself to work harder. But this may not be so, in fact this technique may backfire. The situation is that I sometimes avoid to do what I have to do, and instead work on something else. Maybe another trick would be to convince myself that I have to do something that is of no importance, and than I’d avoid doing it becase I have to work on it, and instead focus on the real thing.

The project update:

I use Clearsilver for the presentation part. Clearsilver takes care of the View part of the MVC (model-view-controller). All the HTML is in the clearsilver templates, and I don’t use ‘inlined html’ anywhere in the project code.

I recently discovered CTemplate, which is a Google open source project doing about the same thing as Clearsilver. I didn’t understand why Google internally developped CTemplate, instead of using Clearsilver. Perhaps such an explanation (why one should use CTemplate instead of Clearsilver) would be a useful addition to the CTemplate documentation.

I’m using SQLite as the database. SQLite is a nice and useful project, I particularly like it’s lightweight characteristic. On the other hand, I’m missing some advanced features like the enforcement of foreign-key constraints and the full-text search. The alternatives to SQLite are Postgres and MySQL.

As deployment architecture, I use FastCGI behind an Apache or Lighttpd server.

The hosting is at Dreamhost. All I can say is that Dreamhost is incredible value for money (you may want to take advantage of some coupons when starting with them). On your one Dreamhost account, you may create multiple unix ssh accounts, host any number of domains, configure DNS for any number of prefixes on a domain, and use FastCGI.

Domain Name

Friday, June 9th, 2006

After some lenghty deliberation, I settled for the name “javia”.
I hope it sounds acceptable in English. The name may come from ‘java’ and ‘via’; anyway, it’s important to be nice-sounding, memorable, and short.

I would have liked to get the domain name in the .com TLD. Unfortunately, javia.com is not available, as it is owned by a domain-name pirate, boasting a ‘domain-for-sale’ note on the landing page.

A huge proportion of the domain names (I’d guess, as high as 80% in .com) is used for advertising and re-selling, and don’t represent legitimate uses associated with the respective name. I hate this state of affairs, and I consider that it represents a very serious problem. If the situation continues to aggravate, more and more domain names becoming un-available for the people who are willing to put on real websites, I expect this may even prompt an overhaul of the domain name system.

The domain-name pirates operate a huge number of domains. They get revenue through the advertising they put on the landing-pages on these domains, and by re-selling the demains for big-money. This is a dirty business; that’s why I won’t even consider buying a domain from such a pirate — because I don’t want to do anything to encourage their business.

I’m left with the choice between javia.org and javia.eu. The advantage of .eu is that it’s shorter than .org (and easier to type on a phone keyboard); the disadvantage of .eu is that it’s a new TLD, relativelly little known, and with a strong regional character (being a ‘country code’ TLD). But for me, the greatest disadvantage of .eu is that it is operated by a particularily incompetent registrar, Eurid. I think Eurid is a good exemple of the incompetence and beauraucracy characterizing the EU. They are even proud of their blunders (as in, “is not stupid enough, he who’s not proud of it”). The lamentable way in which they have run the .eu domain until now will have a lasting negative impact on this TLD. I guess I really hate them, and normally I wouldn’t want to use a domain in .eu. On the other side, .eu is shorter then .org…

For the sake of google keyword counts: “Eurid sucks”.

Finding the name

Wednesday, May 31st, 2006

It’s a little shame that I don’t have the name of my project yet. Shouldn’t everything start with the name? Well, I started the development when I still didn’t have the name. But at least an internal name is needed in order to be able to talk and think abount something.

So I use the internal name gama. Why gama — because it’s short and easy to type on a phone keyboard. But now the time has come to finally settle the official name. I spent about 2 days thinking about names. One problem is that I seem to focus on names that are directly related to what the product is doing, names that contain inside either ‘java’ or ‘mobile’. It looks like (Igor’s naming guide) that these are not the best names for branding, that the really good names are imaginative, and related to what the product is doing in a subtle or metaphoric way.

A suitable name needs to be:

  • available in .com or .eu TLD
  • memorable (i.e. you remember it once you see it)
  • short, easy to type on a phone keyboard

Of course, these criteria are hard to meet. In the .com TLD, a huge number of domains are owned by the name pirates, who keep them for advertising income or name trading. This situation is really annoying.. I’d say 80% of the domain names are used in a such bad manner.

In order to be memorable, the name has to make associations, and it doesn’t hurt to be melodic, and beautiful. My situation in this area is a bit difficult as English is not my native tongue.

The last criterion — to be easy to type on a phone keypad — is a novel one, I guess. The ideal name would be composed of first-letters on the phone (i.e. A, D, G, J, M, P, T, W), and successive letters in the name should not be located on the same key (because this slows down typing). Yes, I even wrote a small program which, given a text, outputs its cost with respect to the phone-typability metric.

So I put up a short list of candidate names (which mostly suck IMO) and asked my friends what they think about them. Most of them are available only in the .eu domain, not in .com … I’m not sure how serios a problem this is, of course I would prefer a name in the .com TLD.
Now I can’t wait to decide for a name, register the domain, and move ahead with the real work. If the name would be really bad, it will still be possible to change it later, but before the public launch. It’s hard to find a good and available name.. perhaps not a programmer’s job, anyway…

Introduction

Monday, May 29th, 2006

Paul Graham argued convincingly that it’s more efficient to work for oneself, than to work for an employer. Even if a big company with 5000 programmers can create an impressively big product, which is hard to achieve for a small team of 3 developers, the average productivity of a member of the small team is probably much higher than the productivity of one member of the 5000 people team.
If the 5000 people team would be split in groups of 3 people, each group pursuing its own project, they would be working on 1600 projects.
So there is a tradeoff between the efficiency of small teams, and the ‘range’ of large teams.

The small team is efficient not only because of low communication overhead (the classical explanation), but also because each member identifies himself with the project. He works on his project, and the success of the project will be his success too.

I decided to quit my current job, as I want to work full-time on my own project. Of course, there is a lot of social pressure against being ‘un-employed’, without income. So I decided that I give myself a 6 month period, at the end of which I’ll evaluate the success of my project. If there’s no strong indication of success at that point, I’ll take upon a new job as an employee.

So now I have to run. I have to work quickly and efficiently, in order to show that my project can be a viable business. I’ve set milestones: 15 june for the first beta, and 1 july for the public release.
Once the project becomes public, one problem will be to build awareness around it. I decided to play ‘by the book’, so one of the first things I do is to start this blog. Here I’ll follow the project, from this early phase to either success or failure, in this 6 months interval.