Laughter is the saltwater rooroo...

June 16th, 2008
Occasionally a user will accidentally click on wrong place and all their desktop icons will be gone. They won’t be able to find the icons anywhere on the desktop. All their My Computer and My Documents shortcuts will be missing and even their recycling bin will be gone. They will be left with a plain background or a wallpaper.
It is easy to bring them back! Simply right click on your desktop, go to Arrange Icons By and then select Show Desktop Icons.
Wait several seconds and your desktop icons will be back.
June 15th, 2008
Microsoft Office suite comes with some annoying features such as automatic capitalization of the first letter of the first word each time you end the sentence with a period. Many of these features are helpful but at times when you copy text from Microsoft Word and paste in somewhere else the formatting will be lost because it does not recognize Microsoft Office Word format. Same will happen if you are using Access, Excel, OneNote, Outlook, PowerPoint, Project or Publisher.
To avoid this, it is helpful to turn off auto correction feature in Microsoft Office.
If you are using Microsoft Office 2000 or 2003 version, you can turn of the automatic correction features by going to Tools -& Auto-Correction -& Deselect the features you want turned off.
If you are using the latest Microsoft Office 2007, you can turn off auto correction features by clicking on the Microsoft Office Button and then selecting Word Options. Note: If you want to turn off auto correction for other office programs such as PowerPoint then you would follow the same procedures but you will see PowerPoint Options.
Click Proofing and select AutoCorrect Options.
Now deselect the options you want disabled.
Correct TWo INitial CApitals
Capitalize first letter of sentences
Capitalize names of days
Correct accidental use of cAPS LOCK key
Capitalize first letter of table cells
June 15th, 2008
Windows Vista has one of the best selection of cursors compared to other popular operating systems. Windows XP users can now have that same clear-cut cursors of Windows Vista on their system. Windows Vista’s cursors are anti-aliased, the edges are much more softer, and animated. The loading cursors changes to a cursor with an animated circle.
To install, download the Aero Cursors package.
Unzip the files, right click install.ini and select install.
Go to Start, Control Panel and select Mouse. Navigate over to Pointers tab.
Under scheme, select Aero Cursors (Alphablended).
Click OK and you are done. Cheers!
June 7th, 2008
Users of HP Pavilion Notebook can record videos and take pictures in QuickPlay with the integrated HP webcam or even 3rd party camera. If you have Windows Vista with HP QuickPlay installed on your HP Pavilion laptop, you can easily record movies or take pictures by launching HP QuickPlay.
Click on Video icon
from the menu and
in the Source column.
From your QuickPlay Control Panel, click the record button to record and stop button to stop the recording. You can also take snapshots by selecting the last button in the Control Panel. To delete the pictures and videos that you just have taken is tricky in Windows Vista.
You videos and pictures are by default saved to
C:\Users\Public\Videos\HP Webcam\webcam_1.mpg
To reach that folder, press the Windows key + R on your keyboard to bring up the run box.
Then type in the following:
C:\USERS\Public\Videos
Press OK and you will be at a folder where all your HP QuickPlay movies and pictures are stored. From here you can delete the videos and pictures you want. Creating a shortcut to this folder on your desktop to make it easeir to access all your QuickPlay pictures and videos in future. To create a shortcut on your desktop, right click on the folder called “Videos” and select send to “Desktop (create shortcut)”.
Now you can freely browse, edit or burn QuickPlay videos and pictures right from your desktop!
June 7th, 2008
Desktop Drapes is a Gnome desktop application for those that love randomizing your desktop wallpaper. Users can add wallpapers they like to the list and select how often do you want the wallpaper to be changed. Indeed, a nifty little tool for your desktop eye candy list.
Desktop Drapes goes a step further and automatically adds the wallpaper to the list from a specified folder. So a user can simply save wallpapers to a dictionary and Desktop Drapes will do the rest.
To install , open up a Terminal and type:
sudo apt-get install drapes
June 6th, 2008
Whenever you try to delete a file that is being used at the time, you will get this error in Windows XP: “Cannot delete [file name]: It is being used by another person or program. Close any programs that might be using the file and try again.” Below is a screenshot of “Error Deleting File or Folder”.
Usually closing the folder or file you are using and then retrying to delete the file or folder works. But some files, for instance from Desktop, won’t delete no matter what you try.
They will keep giving you the error telling the file or folder is being used by another person or program.
The solution is the
which is a straightforward shell extension that will automatically remove the files you select after a reboot.
Simply download the application and install it. Then just right-click any file you want to delete, select the option “Delete on Reboot” and the file will automatically be deleted on the next system reboot.
June 6th, 2008
HTC Touch Diamond is a new Windows Mobile 6.1 powered device and also the successor of HTC Touch. The release date for HTC Diamond Pocket PC phone is set for June 2008 in Europe and then the rest of the world later this year. Its main features include the new and improved TouchFLO 3D technology from the old TouchFLO interface on HTC Touch. Some of the common names for HTC Diamond are O2 XDA Diamond and T-Mobile MDA Compact IV
The ringtones on HTC Diamond are short and sweet with a modern tune. Here are the 82 ringtones and alerts extracted from the Pocket PC’s leaked ROM. The format is WMA (Windows Media Audio).
to download the ringtones and alerts.
The ringtones above are all in WMA format and should work on Windows Mobile 6 devices. To install the ringtones on your Pocket PC, download the above file and extract all the files to your Windows Mobile My Documents folder either on the storage car d or the device. Alternatively, users have reported that extracting the files to your Windows folder on the device should also work.
Once all the files are on your device to the designated destination, go to Start -& Settings -& Personal & Sounds and Notifications. Here you should be able to select the new HTC Diamond ringtones for your phone and set it as the ringtone and as alerts.
December 28th, 2007
So you got a new Apple iPod that has the ability to play videos? That’s great! To transfer or load video files onto your iPod, you first need a converter that will resize and compress the video into a smaller size to fit into your iPod and have the best screen optimization.
There are only few free softwares out there that will convert the video files for you. My favorite is . This software will do just about anything. You can rip a movie from DVD or simply take a video file from Youtube and then convert it in few easy steps. However, you will need
to rip the movies from DVD first. It works for iPod Classic, iPod Nano, iPod Touch, iPhone and iPod Video. Once you get the converted file, you need to use Apple iTunes to transfer the compatible video onto your iPod.
Paid softwares such as
offer more features and file formats but they are unnecessary in most cases. Videora converts the file just as easy and for free.
December 28th, 2007
You should have received a postcard in your mail from Sprint stating:
Notice OF Discontinuance Of FPCR, Federal E999 and Federal WLNP Surcharges: Introduction Of
Administrative And Regulatory Charges Effective January 1, 2008. Beginning January 1, 2008 Sprint will no longer assess the following : 1) Federal Programs Cost Recovery ($ 1.55); 2) Federal E911 ($.40) and 3) Federal Wirelsss Local Number Portability ($.15).
Beginning January 1, 2008 Sprint will asses 2 new monthly charges per line. An administrative charge of $.75 and a regulatory charge of $.20 to help defray the cost on us that other telecommunications carriers charge Sprint.
Notice Of Charges To Sprint Terms And Conditions Of Service- January 1, 2008
The terms and conditions for Sprint and Nextel have been updated, but not limited to, the following paragraphs:
These new terms and conditions are effective January 1, 2008 and are available
or upon request.
Please carefully review these terms as they apply to any future use of service.
I did some digging and found the following on regarding the new Terms and Conditions of Service:
The Administrative Charge will be $0.75 per line per month and is assessed by Sprint to help defray various costs imposed on Sprint by other telecommunications carriers, including, but not limited to, charges imposed by local telephone companies for delivery of calls from our customers to their landline customers and for certain network facilities and services we need to purchase from them. The Administrative Charge is not a tax and is not an amount we are required to collect from you by law. The Administrative Charge, and the components used to calculate this charge, is subject to change from time to time.
So here is your chance to cancel Sprint Account with the (ETF) early termination fee since Sprint is ‘adding’ Administrative Charge that is not government mandated, they are essentially changing the Terms and Conditions of Service which you agreed to originally. This is essentially a core charge because you have no option to opt out unless you cancel the service. Keep in mind this is not an existing charge that “Sprint can change from time to time” as in your original agreement. You need to call Sprint’s retention department and prove this change has an adverse affect on you.
I attempted to cancel one of my friend’s account. The representative told me yes, I can cancel my account with out the early termination fee starting 01-01-08. He advised me to call back Sprint on 01-01-08 and request for cancellation with out the early termination fee. He warned me using or paying for service after 01-01-08 is under the new contract, period. So you have 30 days grace period. Tell the representatives at Sprint that you want to leave Sprint with out early termination fee specifically to avoid the material change in the contract.
I’m quoting
if you need it for reference:
Except as provided below, if a change we make to the Agreement is material and has a material adverse effect on you, you may terminate each line of Service materially affected without incurring an Early Termination Fee only if you: (a) call us within 30 days after the effective date of the change; and (b) specifically advise us that you wish to cancel Services because of a material change to the Agreement that we have made. If you do not cancel Service within 30 days of the change, an Early Termination Fee will apply if you terminate Services before the end of any applicable Term Commitment.
December 3rd, 2007
I received an email asking for a way to break Nextel contract without paying the early termination fee (ETF). From what I heard, Nextel does indeed has the worst service of all the wireless carriers. There is no easy way out of Nextel contract, just like Sprint contract, but there are two methods I know you can try:
Nextel and Sprint are both together. If you are attempting to cancel your Nextel contract for free (without ETF), you can call and request to be switched over to Sprint. You will be put on a new Sprint contract and just pick a phone that is free. You will not be eligible for a free or discounted phone if you bought a phone from Nextel that is less than 12 months old. If you are not eligible still go ahead simply buy a phone because you will be refunded in the end. You should no longer be in contract with Nextel once your service, the number and the plan, has been transfered to Sprint. Make sure you don’t use your new phone or make any calls. Now you need to cancel your Sprint account by going into a store and requesting to cancel. They will take your new phone back and cancel the account. The fine print for return policy located on Sprint contract states 14 days satisfactory, no questions asked. But they have recently implemented a new policy stating you are not allowed to do this if you are switching over from Nextel. A friend of mine did this just few weeks back and was successful. He is currently a happy Cingular wireless customer. This method is YMMV (your mileage may vary). If you get rejected in the stores, try calling Sprint to cancel.
Another method to get out of Nextel’s contract is if you are moving to somewhere where there is no service from Nextel or Sprint in this case. Ore City, TX is a perfect example where Nextel or Sprint offers no service. Call them and say you want to cancel because there is no service in Ore City, TX. Remember, you need to be persistent. If they turn you down, try again with another CSR (customer service representative).roostar | Singer Songwriter MusicianGo here to download ready-to-run and source distributions of Jangaroo.
Jangaroo is not only about ActionScript-to-JavaScript compilation, but generally about providing free,&Open Source&tools for Enterprise Web Developers. So today's about a small tool we just added to the stack that integrates assembly of CSS sprites into your Maven build process.
have heard or even used () by Carrot Search /&Stanislaw Osinski.
A small tool that lets you bundle your images into sprite sheets improving your
webapp's performance.
Using SmartSprites
from over and over again, it can be tedious to always start the process manually. Since
we aren't using Ant but Maven more regularly we thought about a slim Maven
integration. While SmartSprites does offer a Maven artifact, we only found an outdated, unfinished Maven plugin to actually apply SmartSprites as part of a Maven build, and so came up with something ourselves.
We arrived at a working first version (in fact it's 1.5 1.8 by now) of such a plugin. It can surely be improved&further, but working well for our needs.
Try it out!
The Plugin is available in the . This makes integration into your project really easy.
the following lines of code in your project’s pom.xml:
& &groupId&net.jangaroo&/groupId&
& &artifactId&smartsprites-maven-plugin&/artifactId&
& &version&1.8&/version&
& &configuration&
&&& &rootDirPath&src/main/sprites&/rootDirPath&
&&& &cssFiles&&/cssFiles&
&&& &outputDirPath&${basedir}/target/generated-resources/
META-INF/resources/spritesheets&/outputDirPath&
&&& &documentRootDirPath&&/documentRootDirPath&
&&& &logLevel&WARN&/logLevel&
&&& &spritePngDepth&AUTO&/spritePngDepth&
&&& &spritePngIeSix&false&/spritePngIeSix&
&&& &cssFileEncoding&UTF-8&/cssFileEncoding&
&&& &cssFileSuffix&&/cssFileSuffix&
& &/configuration&
& &executions&
&&& &execution&
&&&&& &id&createSprites&/id&
&&&&& &phase&generate-resources&/phase&
&&&&& &goals&
&&&&&&& &goal&createSprites&/goal&
&&&&& &/goals&
&&& &/execution&
& &/executions&
leave out the configuration part completely and default values would be used.
Following you’ll find the complete configuration guide. As all configuration attributes follow their SmartSprites counterparts closely, the description can be taken directly from the .
Below you will find the correct camel case annotation and their default values if given.
&rootDirPath&
(default: src/main/sprites)
&cssFiles&
&outputDirPath&
(default: ${basedir}/target/generated-resources/META-INF/resources/spritesheets)
&documentRootDirPath&
&logLevel&
(default: WARN)&
&spritePngDepth&
(default: AUTO)
&spritePngIeSix&
(default: false)&
&cssFileEncoding&
(default: UTF-8)
&cssFileSuffix&
(default: null)
What about a demo
application?
Please find
showing you how to bundle your sprites in a webapp.
It is a small example just showing you how to integrate the
SmartSprites-Maven-Plugin into a webapp.
The example
is rather straightforward so you just might want to take a look at the
following files:
23-40 for the SmartSprites part
42-53 copy the generated ressources
55-69 Jetty
src/main/webapp/index.jsp&
divs for showing the images, line 16-21
src/main/sprites/css/flags.css&
css configuration part
files are just for making this example look a bit nicer.
Since we use the SmartSprites Maven plugin ourselves for building an Enterprise software product, it will be maintained for quite a while. So feel free to use it, too, and please don't hesitate to give feedback either here or at the !
Jangaroo's mission is to create and apply Enterprise software development tools to Web development. While Jangaroo is known for its ActionScript-to-JavaScript compiler jooc, we also care about "native" JavaScript development. In the process of creating a Maven-based build process for compiled ActionScript, we were baffled that there was not even a Maven-based build process for JavaScript. In fact, there is no version-, dependency- and artifact-managing build process for JavaScript at all (as far as we know).
In the course of creating Jangaroo 2, and utilizing a , we can now present a light-weight and easy way to use Maven for managing JavaScript library versions and their dependencies and adding them to your Web application.
Approach and Related Work
Note that we are not the only ones who provide Maven JAR artifacts containing repackaged JavaScript libraries. Independently, , which does something quite similar as proposed here. He also uses JARs and Maven, but the difference is that he is targeting other Web servers and languages, essentially using the JAR as a ZIP. Our approach is to use the , essentially putting all Web resources under the path META-INF/resources.&The main advantage is that every Servlet 3 compliant application server (Jetty 8, Tomcat 7, Glassfish 3, Resin 4, WebSphere 8, WebLogic 12) understands this standardized format () immediately without any plugin, Servlet or other extension. Another benefit is that you can add files to the JAR that are not&supposed to be Web resources, e.g. other meta data and of course Java classes, so that you could for example unite code implementing the client- and server-part of some service in a single JAR.
An organizational advantage we have over James' artifacts is that we deploy all repackaged artifacts of&Open Source&libraries (almost all JavaScript libraries are Open Source!)&directly to the Maven Central repository, saving you the need to add &repository& sections to your Maven POM and leaving you independent from our Maven repository being online.
Try It Out!
The first available artifact is a repackaging of Ext JS 3.4.0 (yes, it is an old version, but take it as an example of the mechanism) and a very light-weight example project using this artifact. The following steps are needed once to have an environment to develop Maven-managed JavaScript Web applications:
Install a recent Java SDK like 6 or 7
Install , current version 3.0.4
[Install git]
Checkpoint: calling mvn -v on a shell should give you output similar to this:
Apache Maven 3.0.4 (r12-01-17 09:44:56+0100)
Maven home: ...
Java version: 1.6.0_25, vendor: Sun Microsystems Inc.
Java home: ...
Default locale: ...
OS name:&...
To try the Ext JS example project,
or clone from github:
& git clone&git:///fwienber/webjars-extjs-example.git
Then, all you need to do is build the project (which downloads all needed stuff from Maven Central when invoked for the first time) and start a Jetty Web server via Maven, simply via
& mvn jetty:start
The default port is 8080, so you can watch the resulting Web app in any browser using http://localhost:8080. To prove that Ext JS has been loaded and works, the app just opens an Ext alert box.
Only three small text files are needed to
download the desired Ext JS library,
download &Jetty&webserver,
configure Jetty to serve the contents of the Ext JS library and the local project resources, and
start Jetty in development mode on localhost port 8080.
The three files are
pom.xml ―The Maven "Project Object Model" that configures the build,
src/main/webapp/index.html ―the HTML file containing the simply JavaScript application,
src/main/webapp/WEB-INF/web.xml&―Java Web configuration file.
Let me give you a walk-through of these three files.
pom.xml is the key to letting Maven create and manage your application. Fortunately, this POM is quite simple, since we take advantage of conventions, and Maven prefers .
&?xml version='1.0' encoding='UTF-8'?&
&project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
& & & & &xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&
& &modelVersion&4.0.0&/modelVersion&
& &groupId&net.jangaroo.webjars.examples&/groupId&
& &artifactId&webjars-extjs-example&/artifactId&
& &version&0.1-SNAPSHOT&/version&
& &packaging&war&/packaging&
& &name&webjars-extjs-example&/name&
& &description&...&/description&
& & &plugins&
& & & &plugin&
& & & & &groupId&org.mortbay.jetty&/groupId&
& & & & &artifactId&jetty-maven-plugin&/artifactId&
& & & & &version&8.1.3.v&/version&
& & & &/plugin&
& & &/plugins&
& &/build&
& &dependencies&
& & &dependency&
& & & &groupId&.sencha&/groupId&
& & & &artifactId&ext-js&/artifactId&
& & & &version&3.4.0&/version&
& & &/dependency&
& &/dependencies&
&/project&
After the&inevitable XML header (which is always the same),&every Maven project model needs to specify a unique combination of groupId and artifactId, and a&version. For this test project, they really do not matter, since the generated artifact will never be deployed to a repository. The packaging type war tells Maven that we are building a Web application (Java terminology: Web ARchive). name and description are just for human readability.
The only plugin that needs to be mentioned explicitly is jetty-maven-plugin, and you also need to specify the exact version you want to use. Well, it's still only a couple of lines to download and start a Web server, isn't it?
To download a serve all Ext JS 3.4.0 resources, a simple dependency&suffices, thanks to the standard-conform JAR layout and central deployment of the artifact.
index.html is the simplest HTML page you could think of that starts an Ext JS application. The only interesting thing here is how the resource paths have been chosen, because you do not actually "see" the Ext JS resources―they are hidden in a JAR somewhere in your local Maven repository (see below). For every JavaScript library repackaging, we have to agree upon a standard path where it is served in the Web application. For Ext JS, we chose /ext-js/ as the base path. The file structure below this base path is exactly as in the ZIP that can be obtained from .
web.xml is only needed to disable a Jetty feature ("file locking") that hinders development, and to satisfy the Maven WAR plugin, which would have to be configured to not &failOnMissingWebXml& otherwise.
The Jetty Maven plugin configures Jetty in a clever way: library dependencies like Ext JS, which have been downloaded to your local Maven repository automatically (usually ~/.m2/repository), are served directly from that JAR. That means no files are extracted, not even the JARs needed by your Web app are copied. All local project Web resources are taken directly from src/main/webapp. Try changing index.html (e.g. the alert message) and reload in the browser: it works without further build or deployment!
If you want a complete Web app that could be deployed into a remote Java application server, you can invoke mvn package, and a directory target/webjars-extjs-example-0.1-SNAPSHOT is created which contains all needed resources. This directory is also zipped as target/webjars-extjs-example-0.1-SNAPSHOT.war.
Unpacking all Web resources contained in JARs, e.g. to deploy them to a static Web server like Apache HTTP Server, is also possible via Maven, but I'll cover that in a later update.
Mighty Maven
What the simple example does not show is that, if ext-js 3.4.0 had a dependency on some other artifact, say ext-core 1.0, you wouldn't have to care about it. Simply specifying a dependency on ext-js lets Maven collect all transitive dependencies and add the corresponding artifacts to your Web application. Furthermore, if two libraries you use depend upon the same third library, Maven takes care of the third library being included only once, and offers dependency management to resolve possible version conflicts.
All in all, given the complexity of the problem it solves, Maven provides a light-weight way to manage complex JavaScript Web applications, making it easy to keep track of libraries used, their versions, and their dependencies. Furthermore, Java Servlet 3 helps structure a Web application as a composite of modules instead of a huge bunch of files, which speeds up build process and test system start-up.
What Next?
Next is to repackage and deploy or release several JavaScript libraries. There are several options, so here we need your vote and maybe even your help. We plan to repackage the libraries and versions we (plan to) use at CoreMedia, for example&jQuery 1.7,&Ext JS 4.1.0, RequireJS 2.0.1, and CKEditor 3.6.2. If you need other JavaScript libraries or other versions, you can simply create an issue at&. We need the exact location of a download package or all single download links, and if you could provide additional information which files are usually needed in an actual deployment (e.g. no examples, no documentation, ...), it would help a lot. So start refactoring your large-scale JavaScript project today―clean up the JavaScript mess!
Let's continue the series on simulating ActionScript language features in JavaScript with something similar to optional parameters, namely the ... (rest) parameter.
ActionScript allows you to specify that an arbitrary number of parameters follow the usual named and optional parameters by prefixing the last parameter with three dots (see ""):
&1&public function join(separator:String, first:String,
& & & & & & & & & & & & ...strings:Array):String&{
&2 &&strings.splice(0, 0, first);
&3 & return strings.join(separator);
As you can see, all formal parameters following the named parameters are&combined into an array.&Since the ... (rest) parameter is always of type Array, you can safely skip the type annotation.
The arguments variable in JavaScript
Fortunately, JavaScript offers access to all formal parameters of a function call, even if they are not declared as named parameters of the function, through the arguments variable.&For some reason, this variable does not actually hold an Array. Instead, it is an array-like&Object with indexed properties and a length property. This means that we cannot invoke Array methods directly on arguments, but there is a trick: Call the slice function retrieved from the Array prototype, as described e.g. , and the result is a "real" Array:
Array.prototype.slice.call(arguments)
At the same time, we can cut off the named parameters, since the first parameter to slice is the index where to start slicing from the source array. Thus, the resulting JavaScript code generated by the Jangaroo compiler jooc is the following:
&1 function join(separator, first) {
& & &var strings = Array.prototype.slice.call(arguments,2);
&2 & strings.splice(0, 0, first);
&3 & return strings.join(separator);
Note the slice parameter value 2, which takes care of cutting off the two named parameters. Also note how Jangaroo only adds an&auxiliary&statement, but keeps all other statements exactly the same, which makes debugging a lot easier.
Side note: arguments is an array is AS3
The only thing Jangaroo currently does not yet implement correctly is that in ActionScript, the arguments variable is actually always an array! Thus, instead of writing
&1 public function joinComma() {
&2 & return arguments.join(",");
which would be fine in ActionScript, in Jangaroo you currently have to use
&1 public function joinComma(...args) {
&2 & return args.join(",");
This is to save the overhead of always converting arguments into an array. Of course, the compiler could analyze whether arguments is used as an Array at all and only add the conversion code then. I just filed the bug as .
To continue our series on simulating ActionScript language features in JavaScript, this episode is about parameter default values.
In contrast to JavaScript, ActionScript allows to specify a default value for a function (or method) parameter, like so:
&1 public function insult(s = "fool") {
&2 & return "you " +
The idea is that when the method is called without providing a value for parameter s, the default value "fool" will be used. Details on what additional rules hold for declaring parameter default values are given in the &and a bit less reference-like e.g. in a .
Why, it's easy, isn't it?
A straight-forward implementation in JavaScript (similar to the solution&) would be to replace undefined paramter values by their default value:
&1 function insult(s) {
& & &if (s === undefined) {
& & & &s = "fool";
&2 & return "you " +
(We could now start a discussion on whether it shouldn't be
& & &if (typeof s === "undefined") {
because&in JavaScript,&undefined may be redefined, but anybody who does so is, excuse me, a fool.)
In JavaScript, when you omit a parameter when calling a function, the parameter value indeed is undefined. But it is a fallacy to assume that every undefined parameter must be replaced by its default value! Consider the following ActionScript class:
&1 public class DefaultParameterTest {
&3 & public function DefaultParameterTest() {
&4 & & trace("1. " +&&insult&("nerd"));
&5 & & trace("2. " +&
insult&());
&6 & & trace("3. " +&
insult&(undefined));
&9 & public function insult(s = "fool") {
10 & & return "you " +
What do you think will be traced? Try it out, and you'll see that explicitly handing in undefined does not trigger the default value! Thus, the result is
1. you nerd
2. you fool
3. you undefined
(Careful, never call a JavaScript programmer "you undefined"!)
Using the straight-forward JavaScript implementation, the result would be
1. you nerd
2. you fool
3. you fool
As you can see, using parameter default values depends on the number of formal arguments, not on their value. This is the reason why they are also called optional parameters, and why after a parameter with a default value, all following parameters must also specify a default value.
Getting it right
Thus, the correct JavaScript equivalent (as generated by the Jangaroo compiler jooc) is to check the number of formal parameters. Fortunately, this can be realized by checking arguments.length:
&1 function insult(s) {
& & &if (arguments.length & 1) {
& & & &s = "fool";
&2 & return "you " +
In fact, this solution even provides better runtime performance when using multiple optional parameters, since multiple&arguments.length checks can be nested, while the undefined checks in the straight-forward solution would be sequential. Consider the following example:
&1 public function foo(p1, p2, p3 = 3, p4 = 4) {
&2 & return p1 + p2 + p3 + p4;
The JavaScript fragment generated by Jangaroo looks like so:
&1 function foo(p1, p2, p3, p4) {
& & &if (arguments.length & 4) {
& & & &if (arguments.length & 3) {
& & & & &p3 = 3;
& & & &p4 = 4;
&2 & return p1 + p2 + p3 + p4;
Jangaroo even optimizes&undefined&default values, since left out actual parameters are&undefined&in JavaScript, anyway.
Alternative Solutions
We also thought of using a switch statement, generating code like the following:
&1 function foo(p1, p2, p3, p4) {
& & &switch (arguments.length) {
& & & &case 0:
& & & &case 1:
& & & &case 2:
& & & & &p3 = 3;
& & & & &// fall through
& & & &case 3:
& & & & &p4 = 4;
&2 & return p1 + p2 + p3 + p4;
At first sight, this solution seems more efficient, because arguments.length is only evaluated once.&The reason why we still chose the nested if code layout is that the switch solution becomes either long or non-robust when using many non-optional parameters. Note the lines case 0: and case 1: in the example above: although the method should never be called with less than two parameters (since the first two are not optional), we want to handle that case, too, since Jangaroo code may be called from JavaScript, where no function signature check is performed. When the function is called with fewer parameters than required, you would still expect the default values to pop in. So the case statements would pile up when there are many non-optional parameters. However, I could imagine a mixed solution like the following:
&1 function foo(p1, p2, p3, p4) {
& & &switch (Math.max(arguments.length, 2)) {
& & & &case 2:
& & & & &p3 = 3;
& & & & &// fall through
& & & &case 3:
& & & & &p4 = 4;
&2 & return p1 + p2 + p3 + p4;
The most intelligent solution would be to dynamically decide whether the prior length check pays off against adding several case statements. I guess I'll add that to the&Jangaroo&backlog!
In the , I compared different solutions to represent private members in JavaScript. The solution implemented by Jangaroo is to rename private members, so that they do not name-clash with private members of the same class, defined on a different inheritance level.
how Jangaroo solves untyped access to private members. Since the answer is rather extensive, I'll dedicate this follow-up post to the topic.
The short answer is: it's the nature of the beast. Untyped access to private members cannot be detected at compile time. However, potential access to private members can be detected at compile time and generate code that repeats the check at runtime, although Jangaroo does not implement this at the moment.
Typed Private Member Access
Let's recall the typical way to access private members, which can easily be detected by the Jangaroo compiler:
&1 public class Foo {
&2&& private var foo:String = "bar";
&3&& public function getFoo():String {
As foo in line 4 is resolved to a field of the class, and there is no implicit this access in JavaScript, the Jangaroo compiler adds this. before foo. Also, as field foo is declared private, the compiler renames it to foo$1 (see previous blog post) and thus generates the following JavaScript code for the body of method getFoo():
&4&&&& return this.foo$1;
Where is My Type?
Now consider the following code (which does not really make sense, but illustrates the point):
&1 public class Foo {
&2&& private var foo:String = "bar";
&3&& public function getFoo():String {
&4&&&& var untypedThis:Object =
&5&&&& return untypedThis.
Of course, in this simple example it would still be possible to determine the runtime type of untypedThis statically, but it is easy to imagine a situation where this is not possible. In the current Jangaroo implementation, the following JavaScript code would be generated for the body of method getFoo():
&4&&&& var untypedThis =
&5&&&& return untypedThis.
As you can see, the compiler fails to detect that foo actually refers to the private member, does not rename the access to foo$1, and thus the undefined value of untypedThis.foo would be returned.
A (partial) solution is to let the compiler detect any expression of the form untyped.private-member and generate code that takes into account the runtime type of untyped, like so:
&5&&&& return untyped[untyped instanceof Foo ? 'foo$1' : 'foo'];
Trusting today's JavaScript JIT compilers' optimizations, this code should be moved to a utility function to avoid double evaluation of the untyped expression (which could have side effects):
&5&&&& return Foo.$class.get(untyped, 'foo');
where Foo.$class provides access to Jangaroo's "meta class" of Foo, and get() would be implemented there like this:
& public function get(object:Object, property:String):* {
&&& return object[object instanceof this.publicConstructor ?
&&&&& property + this.inheritanceLevel : property];
The Weak and the Wicked
Looking at ActionScript carefully, you'll notice that the identifier or expression left of the dot does not even have to be untyped, but may just be typed with a more general type, and the same scenario may apply. For example, assume our class Foo is a subclass of dynamic class Bar, we could replace Object by Bar, and the example would still work! Even if Bar is not dynamic, we could access the private member foo through a local variable of type Bar using square brackets, like so:
public class Foo extends Bar {
& private var foo:String = "bar";
& public function getFoo():String {
&&& var weaklyTypedThis:Bar =
&&& return weaklyTypedThis['foo'];
The Flex compiler does not complain, and at runtime, in Flash, indeed the private member is accessed. Compare this to the following example, where we try to access the private member of a superclass:
public class Baz extends Foo {
& public function Baz() {
&&& super();
&&& var superThis:Foo =
&&& trace(superThis['foo']); // is undefined, not "bar"!
Maybe you'll be surprised that the result is not any kind of access violation, but simply undefined—the private member of the superclass is simply not visible for the subclass! This is well emulated by Jangaroo through renaming private members. The Jangaroo compiler just has to take care to detect every correct access of a private member and rename the property upon access.
Turing Strikes Again
Things get even nastier when the property is a dynamic expression. Consider
& return this[veryComplicatedComputation()];
Here, too, we'd have to generate
& return Foo.$class.get(this, veryComplicatedComputation());
and extend the utility function by a runtime check whether the property is actually a private member name:
& public function get(object:Object, property:String):* {
&&& return object[object instanceof this.publicConstructor &&
&&& & this.getMemberDeclaration("private", property) ?
&&& &&& property + this.inheritanceLevel : property];
Taken together, the important criterion when to generate code for possible private member access is not whether the left-hand expression of the dot is untyped, but the compiler has to check whether the complete property access is not typed. This is the case exactly when the property is not a compile-time constant or when the property cannot be resolved statically within the type of the expression, and in any case, the type of the expression must be a supertype of the current class or the current class itself.
To wrap up, the compiler would have to generate a call to the dynamic access function if and only if
the left-hand expression could have a runtime type compatible to the current class and&
the property expression could be one of the current class's private members.
Here, could means that it may be, but is not certain at compile time. If both conditions are certain at compile time, the compiler knows for sure that the code represents access to a private member, and can simply use the renamed property.
One more thing: I have been talking about read access of private members. The same strategy would have to be applied when writing members, resulting in another utility function set(object, property, value).
Of course, we could optimize runtime performance by using specific utility functions for the following three different cases:
The property is definitely a private member, but the left-hand expression may or may not be of the current class: check instanceof only.
The left-hand expression is definitely of the current class, but the property may or may not be a private member: check the property only.
Both the left-hand expression may or may not be of the current class, and the property may or may not be a private member: check instanceof and the property.
However, my guess is that this optimization is not necessary. Firstly, checking instanceof and whether some string is contained in a fixed and not very large set are cheap operations. Secondly, when using ActionScript (and not untyped JavaScript), you should avoid untyped access of properties whenever possible. Thus, the situation is a rare case, and would only be implemented for full ActionScript semantic compatibility. If the developer wants better performance, she can either insert a type cast to convert the property access to a typed one, or move dynamic properties to a dedicated object whose type is statically incompatible with the current class (e.g. use Dictionary), and thus no runtime check would be generated.
If this solution proves to inflict significant runtime overhead, the compiler should issue a warning when it has to generate runtime checks.
Inspired by Adobe's Bernd Paradies, member of the FalconJS / FlashRT team, , I thought it was about time to give more details about how Jangaroo implements ActionScript language features. Because there are so many of them, blogging about them one at a time seems like a good idea. Let's start with "private members".
The Early Days
When people started simulating class-based OOP in JavaScript, many thought that it is not possible to define private members that support the principle of information hiding, because in JavaScript, all properties of an object are publicly accessible. So in many cases, the convention was used to let private members start with an underscore ("_"), meaning "don't use this member, best assume it is not existing at all".
The Reference Solution
As we all know in the meantime, it is possible to implement real information hiding in JavaScript, namely by using closures / lexical scoping. Douglas Crockford (who else?) has written a nice summary of this approach back in 2001:
So it looks like all we have to do to simulate ActionScript's private members in JavaScript is to use this pattern, right? Of course, it is not that easy, as in practice, there are two problems with private members&à la Crockford:
Runtime overhead
Source-code placement
While the first is a general problem, the second is Jangaroo-specific.
The runtime overhead of closures results from the fact that in Crockford's solution, private members and privileged
methods (methods that use private members) have to be defined inside the constructor. This means that the corresponding function objects are created for every instance of the class! This results in a performance penalty as well as in increased memory usage. Of course, this is not an issue for classes with few instances (extreme: singletons), but for classes like events, where you create many, many instances, this can quickly become a major problem.
The second problem, source-code placement, results from a specific Jangaroo feature. In , the Jangaroo compiler generates JavaScript code that keeps every piece of executable code at exactly the same line as in the ActionScript source file. This is a central feature of Jangaroo and very important for source-level debugging with a free choice of JavaScript debugger. So how can we place private and privileged methods inside the constructor, when in the ActionScript source code, they are not?
The Super-Secret Private This
For solving the source-code placement issue, I came up with the idea of a "shared private this" object. It turned out that this approach makes things a bit more complicated and only mitigates (but not removes) the runtime overhead, so it did not actually make it into Jangaroo, but still I'd like to present it here.
The basic idea is that private members, as opposed to being local variables in constructor scope, are properties of a single object that is defined inside the constructor. To be shared, this "private this" object has to be "injected" into, i.e. put in the surrounding lexical scope of every privileged method. Consider the following class, which is the ActionScript version of the example used by Douglas Crockford:
&1 public class Container { &2 & public var member:S&3 & private var secret:
&5 & public function Container(param:String) {&6& && member =
&7& && secret = 3;
10 & public function stamp(string:String):String {
11& && return member +
14 & private function dec():Boolean {
15& && if (secret & 0) {
16& &&&& secret -= 1;
18& && } else {
23 & public function service():String {
24& && return dec() ? member :
To inject the "private this" into all privileged methods, we wrap these inside functions. What Douglas calls&that, we'll call&this$, and all other helper idenfiers are suffixed with&$. Here is the resulting JavaScript code:
&1 Container = (function() {
&2 & //public var member:S
&3 & //private var secret:
&5 & var Container = function(param) { var&this$ = init$(this);
&6& && this.member =
&7& &&&this$.secret = 3;
10 & Container.prototype.stamp = function(string) {
11& && return this.member +
14 & var dec = function() {
15& && if (this.secret & 0) {
16& &&&& this.secret -= 1;
18& && } else {
23 & var&service$ = function(this$){return function(){
24& && return&this$.dec() ? this.member :
25 & };};2627 & var&init$ = function(o) {28& && var&this$ = {29 & & & dec: dec30 & & };31 & & o.service =&service$(this$);32 & & return&this$;33 & }3435 & return C36 })();
Note how all executable code stays in exactly the same line, and how similar it can be expressed in JavaScript!
The following variants of Douglas' patterns were used:
Private methods are only defined once (reduces runtime overhead!), and are supposed to be called on the "private this". If they need to access public members, too, we could easily extend the "private this" by a reference to the "public this".
Privileged methods are wrapped in a function that receives the "private this", so that the current "private this" is in lexical scope.&
To keep all source code at its original location, all additional initialization is moved to a generated method&init$. It creates the "private this"&this$ with all private members, creates instances of privileged&methods handing in&this$, and assigns these to the "public this".
The Pragmatic Solution
As said above, this solution still introduces runtime overhead and a bit complexity, so we looked for a more efficient and simpler alternative. I mentioned the naive approach to use a simple naming convention. The real flaw in this approach is not that you can access "private" members when you should not be able to. When compiling ActionScript to JavaScript, we can check access rights on the ActionScript source, so this is not an issue. But what this approach breaks is that private members are also used to avoid name clashes between subclass and superclass!
Image you define a framework, and provide some base class that is supposed to be extended by clients of the framework. This base class usually provides members with different visibility. The private members&(and the "internal" ones, which we neglect for now) can not be seen by a subclass. A client's subclass could define its own private members any way they like, as long as they don't name-clash with public or protected members of the superclass.
Now you update the framework and add a private method, as you think this should not change the framework API. But if we use the naive naming convention of prefixing all private members with an underscore (or the like), there is now the chance that the new private member of the superclass name-clashes with an existing private member of the client's subclass!
Jangaroo's pragmatic solution to separate private members of different inheritance levels within one class is to suffix private member names with a $ followed by the numeric inheritance level. Object has inheritance level 0, and a class extending X has the inheritance level of X plus one. This effectively prevents name-clashes between private members of the same name, but defined on different inheritance levels, and thus solves the framework update problem described above.
We used to compute the inheritance level of a class at runtime, but this made class loading and initialization more complex. Thus, we later decided to let the compiler compute the inheritance level. Of course this reduces "binary" compatibility, meaning that when you refactor a framework class e.g. by introducing an intermediate class in the inheritance hierarchy, clients will have to recompile their code, or the inheritance level of their subclass will be incorrect. But recompiling (without changing the source code) after updating a framework should not really be a problem.
To give a concrete example, here is the simplified generated JavaScript code for the example above. It is not exactly what Jangaroo would produce, as there are many other features covered by the Jangaroo Runtime, which I'll elaborate on in upcoming blog posts. Also, it does not illustrate the inheritance issue, but just imagine a subclass that also defines a private field secret, which would then be renamed secret$2.
&1 Container = (function() {
&2 & //public var member:S
&3 & //private var secret:
&5 & var Container = function(param) {
&6& && this.member =
&7& &&&this.secret$1 = 3;
10 & Container.prototype.stamp = function(string) {
11& && return this.member +
14 & Container.prototype.dec$1 = function() {
15& && if (this.secret$1 & 0) {
16& &&&& this.secret$1 -= 1;
18& && } else {
23 &&Container.prototype.service = function() {
24& && return&this.dec$1() ? this.member :
25 & };2627 & return C28 })();
Let me conclude with an overview of the four solutions for private members in JavaScript discussed here.
naive naming convention
private members
(D. Crockford)
private this
inheritance level suffix
(used in Jangaroo)
information hiding
avoiding name-clashes
no runtime overhead
keep source lines
As you can see in the table, there is no perfect solution (no column
with checkmarks in every row), so for Jangaroo, we chose the pragmatic
one that ensures good performance, while having some drawbacks on
information hiding.
Since performance is the only argument against the "private this" solution, we should investigate in performance analysis of today's JavaScript engines to quantify the time and space overhead introduced by the appoach. Maybe it is not that bad after all.
With all modern browsers supporting the JavaScript API Object.defineProperty(),we can improve Jangaroo's pragmatic solution's information hiding by defining all private members to not be enumerable. Taking a closer look at ActionScript semantics, actually, all class members are not enumerable, i.e. they are all not visible in a for ... in loop (only dynamic properties are).
There are several possible improvements to approximate ActionScript semantics more closely when relying on features of a modern JavaScript engine (ECMAScript 5). I'll come to these when discussing further ActionScript language features.
While almost one year ago, we talked about "Jangaroo - AS3 w/o FlashPlayer", we thought it was about time to stress the other story, namely using Jangaroo for creating large-scale JavaScript applications. Because that's what we do very successfully at CoreMedia.
Several people (thanks Florian, Martin!) pointed us at a very fitting call for papers of the
at the . It is about Programming Languages And Systems Technologies for Internet Clients, with a focus on "compilation and runtime techniques for Internet client programming
languages". Andreas kicked off the paper, Olaf and Dennis supported with proof-reading, LaTeX support and helpful comments, and I fleshed out the text and extended the parts of my expertise, namely the runtime, libraries, and build process. The paper, entitled Enterprise JavaScript with Jangaroo --Using ActionScript 3 for JavaScript ”Programming in the Large”, was accepted and can be .
On 24th of October, I presented the corresponding talk at the PLASTIC workshop in Portland, Oregon. To not bore the part of the audience who already read the paper (maybe the empty set?), the slides show a third category of "how to execute another programming language in the browser", since providing a client-side interpreter seems to be a hot topic (mostly because of , but there are others, too). But have a look at the slides for yourself.
View more&
Before starting with the slides, I showed off the demos
and , which I admit are a bit off-topic, since they rather belong to the "port Flash applications to HTML5" story than to "Enterprise JavaScript", but hey, they are always good to get people'-).
I hope I could get across what Jangaroo is able to, and got some interesting feedback. Adam Welc (Co-Chair of the workshop, in his other life working on Flash at Adobe) pointed me to another Flash-related Open Source projects, , which might help in getting on with Jangaroo's Flash re-implementation .
People liked the way Jangaroo keeps the generated code close to the source, even keeping line numbers to allow source-level debugging.
The most motivating part when visiting a workshop or conference is of course about meeting people. I remembered Google's Mark Miller from the , who here at PLASTIC co-authored a paper about : recommended read! Christian Hammer, Andreas Gampe, Aiman Erbad and several others also presented and we had interesting discussions. Was nice getting to know you guys!
Another JavaScript guru I also met first on Ajax Experience is Rik Arends, then at ajax.org, who now does a wonderful job over at . I tell you he's one of the good guys (even if we disagree on where to use typed languages and compilers)!
Finally, I loved the key note of David Ungar, ; he really is a great presenter! Using Romeo and Juliet as an example of parallel actions that went wrong (and might have ended up "hunky-dory" in a different sequentialization) is really funky...
Subscribe to:}

我要回帖

更多关于 the saltwater roo 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信