Monday, March 02, 2009

Know your Customer :)

A disappointed salesman of Coca Cola returns from his Middle East assignment. A friend asked, "Why weren't you successful with the Arabs?" 

The salesman explained, "When I got posted in the Middle East, I was very confident that I would make a good sales pitch as Cola is virtually unknown there. But, I had a problem I didn't know to speak Arabic. So, I planned to convey the message through three posters... 




First poster 
- A man lying in the hot desert sand...totally exhausted and fainting.

Second poster - man is drinking our Cola.

Third poster- Our man is now totally refreshed.

Then these posters were pasted all over the place

"That should have worked," said the friend.

|

|

|



The salesman replied "I also didn't realize that Arabs read from right to left"


Develop Web services clients with Macromedia Flex

Flex the power of Web services by learning how to easily leverage them within a Rich Internet Application (RIA) using Macromedia Flex for a more complex, engaging, and interactive client-side experience. RIAs are an evolution of the traditional Web page based model for Web applications. A big part of the attraction in using Flex for RIA development is the speed and ease with which you can leverage Web services in your applications. The authors walk you through several examples and simplify how sometimes confusing WSDL constructs map to Flex declarations.


Selecting the Right Flex Application Framework

So you’ve decided to use Flex for your web application development. It’s easy to follow the online tutorials and prototype an application, but deciding on an application framework for your major production Flex application is more difficult. The Flex community is divided between Adobe’s Cairngorm and Cliff Hall’s PureMVC, with strong arguments from both sides. However, your answer may just lie in the “it depends” space.

This post aims to help you make that decision. It includes analysis of CairngormPureMVC, and the new kid on the block, asfusion’s Mate.

Cairngorm

Cairngorm (pronounced \kern-gorm\) is a lightweight micro-architecture for Rich Internet Applications for Flex or AIR applications. It is not only a framework, but also an approach to organizing and packaging code, components, and a method to achieve separation of concerns (i.e. model-view-controller).

Compared to other frameworks, Cairngorm requires the most components, but it is the most straightforward.

Cairngorm Framework
Figure 1 Cairngorm Framework


ProsCons
  • Advocated by Adobe Consulting and is part of the Adobe Engagement Platform.
  • Broadest adoption for a Flex MVC framework, making it the de facto standard for Flex developers
  • Well-documented with great tutorials.
  • Designed expressly for Flex and thus, takes advantage of Flex features.
  • Simple, straightforward MVC framework
  • Tightly couples the MVC layers.
  • Components can either be too large or too many, resulting in the application becoming too unwieldy from the development and maintenance perspective.

Tips and Tricks

  • Use packaging, sub-classing, or helper classes to prevent unwieldy model locators and controllers.
  • Use Adobe Consulting’s Observe Utility to prevent tight coupling between the view and the model locator.
  • Minimize direct references to the model locator from the view, by passing data references between parent and child components.

Recommended When:

  • The team and/or the organization are new to application development, ActionScript and/or Flex. It is good for new Flex developers to learn Cairngorm before other frameworks first. Management will also be more comfortable with an Adobe-backed framework.
  • You need a quick prototype.

PureMVC

PureMVC is also a lightweight framework for creating applications based on the classic MVC concept. PureMVC is not specific to Adobe Flex and is being ported to other languages. Many Flex developers consider the framework to be the best Flex framework out there, but accept that it does not take advantage of Flex features.

PureMVC Framework
Figure 2 PureMVC Framework


ProsCons
  • Provides flexibility to easily support complex workflows, e.g. command chaining.
  • Promotes code reuse.
  • Cleaner architecture and implementation, i.e. layers are more loosely coupled.
  • Well-documented, but not many tutorials.
  • Not designed expressly for Flex, and thus, has been criticized for not taking advantage of basic Flex features, such as data binding.

Tips and Tricks

  • Since the framework is language-agnostic, it cannot rely on data binding innately. But this doesn’t mean binding can’t be implemented in PureMVC Flex applications. Use the mediator to bind the data from the proxy to the view component.
  • Use a proxy for a service locator.
  • Reuse mediators for multiple view components.

Recommended When:

  • The application has complex logic and/or repeated logic.
  • If you need an MVC framework that cuts across the different languages of your application, e.g. Java and Flex. However, some of the PureMVC language ports are still in alpha.

Mate

Mate (pronounced \mah-teh\) is the newest Flex application framework. It is also designed expressly for Flex. Its main differentiator from Cairngorm is that it uses dependency injection to hook the event handlers to controller entities and view properties to the data model (via injectors). Thus, it requires the least number of components of all of the frameworks.

Mate Framework
Figure 3 Mate Framework


ProsCons
  • Provides flexibility to easily support complex workflows, e.g. method invoker chaining.
  • View can be simple and uncluttered, i.e. injectors can enable the view to not even reference Mate components, except for within the application MXML.
  • Promotes code reuse, e.g. invoked or referenced custom entities do not need to extend any base classes or interfaces.
  • Well-documented, including tutorials, examples and best practices.
  • Nullifies the power of AS3 compile-time type checking with the EventMap MXML.

Tips and Tricks

  • Flex events thrown must have its bubbling setting set to true.
  • Use multiple event maps to break down event type concerns.
  • Take special care in structuring and designing the controller entities.

Recommended When:

  • You need a really quick prototype.
  • The application has complex logic and/or repeated logic.
  • Your team has designers or component developers, not responsible for integrating the UI with the business services.
  • You have an existing Flex application that needs a framework refresh. You can quickly reuse the AS classes that have already been created and string them up using the event maps.

Others

  • Slide is Peter Joel’s work in progress. It has been released, but there is still a lot of work being done on it, and thus, little documentation is available. Its concept of view states by URIs and acknowledgement of data and navigation to drive view states is interesting though.
  • ARP (Ariaware RIA Platform) is Aral Balkan’s effort, borne from Flash 5. Its latest version finally supports Flex. It’s very similar to the Cairngorm framework with the inclusion of base classes for commands, controllers and forms. It also makes a distinction between system and view events. However, it doesn’t present a strong compelling differentiation from the Cairngorm framework, but seems to be a viable solution as well.
  • Foundry is another application framework, built for ActionScript and based on the MVC pattern, by Servebox. It is also very similar to Cairngorm, but heavily advocates the use of view helpers. Like ARP, the framework doesn’t provide a strong differentiation from Cairngorm, but seems to also be a simple, viable framework to use.
  • Guasax is a Flex application framework, but is not based on the MVC pattern. Like Struts, it uses configuration files to set up actions invoking business objects and setting up interceptors for those actions. At first blush, the framework seemed too complex, and examples online are not commented in English.
  • Flest is a Flex application framework that uses model, view, and controller components, but does not claim to be an MVC framework. The suggested use of the provided components is to tightly couple them within the application (e.g. commands are closures to the controller). Thus, it didn’t appear to be an ideal framework in easing maintenance of the application.
  • MVCS is an architectural blueprint for Flex applications, based on the MVC pattern. Joe Berkovitz’s article on Adobe Developer Connection is definitely worth the read. The concepts in the article are helpful when designing your application. But MVCS is not packaged as a reusable framework.

Sunday, March 01, 2009

Top 10 Adobe Flex Misconceptions

At QCon, Adobe's James Ward shared with InfoQ.com the top Adobe Flex misconceptions that he encounters in his travels evangelizing the Flex application framework.
  1. Users Need to Install Something New to Run Flex Applications. 

    Ward, exclusive to InfoQ.com, discusses the Flash adoption rates and Flex programming model:
    Flash Player 9 is required for Flex 2 & Flex 3. The Flash Player 9 runtime is currently installed on 94% of the world's computers:http://www.adobe.com/products/player_census/flashplayer/version_penetration.html 

    Flex 2 and Flex 3 applications execute in the Flash Player 9. Flex applications are built on top of the native Flash Player APIs like vector graphics, bitmap manipulation, and networking (which are based on the browser networking stack). The Flex framework adds reusable components like date pickers, data grids, charts, etc. Compiling a Flex application results in a SWF file which is the binary byte code format for the Flash Player. Contained in the SWF file is the byte code for the Flex framework code and a project's custom code. The Flex compiler optimizes the byte code so that only classes which are used go into the SWF file. 

    For desktop applications, Adobe is aiming to make their new desktop runtime, dubbed Adobe AIR, as ubiquitous as the web runtime. The 1.0 release of Adobe AIR will be available in the beginning of 2008. Currently, AIR is in beta release from labs.adobe.com. Many companies are already building production applications on AIR. One example, can be seen with eBay's application eBay Desktop.
  2. Flash Player is 100% Proprietary. 

    Ward continued on this item for InfoQ.com:
    The core of Flash Player is the Tamarin Virtual Machine, which is an open source project under Mozilla. While the SWF file format is not fully open, it is documented by the community on osflash.org. There are numerous open source products that read and write SWF files. The Flash Player's product direction has traditionally been heavily influenced by the community and their needs. The core language for Flash Player is an implementation of ECMAScript 262, which is the specification for JavaScript. Flex also uses CSS for styling of components / applications. Adobe AIR uses web standards as the basis for desktop applications as well as Open Source technologies like Tamarin, Webkit, and SQLite.
  3. Flash is for Designers, Video, and Annoyances. 

    In Ward’s July, 2007 blog, “How I Overcame My Fear of Flash,” he discussed this point:
    Indisputably, the power of Flash has been abused. Pop-ups, pop-overs, skip intros and annoying ads run rampant across our screens. I've heard it said that one should never judge a religion by its abuse. The same adage applies to technology. Flash shouldn't be avoided just because people use it for annoying things. After all, e-mail isn't avoided just because spammers happen to abuse it.
    Ward elaborated on the topic for InfoQ.com:
    Traditionally Flash content was built with the timeline based tool for designers. Flex is the developer toolset for building Flash based content / applications. Designers and developers can work together by sharing assets between the two tools. Flex adds a comprehensive component base: 

    http://www.adobe.com/go/flex_explorer_app 
    http://www.adobe.com/cfusion/exchange/index.cfm?event=productHome&exc=15&loc=en_us
  4. Flex is Not for Enterprise / Business Applications. 

    Over the last few weeks, Ward published a seven part blog series on a number of new Oracle applications implemented in Adobe Flex. The applications, which were announced at the recent Oracle OpenWorld, ranged from sales tools, to database management, and business intelligence.

    In addition to Oracle’s usage of Flex, InfoQ.com published a piece recapping a number of groups using Flex for enterprise applications. Ward also points out to InfoQ.com, that there are numerous examples of enterprise applications being developed with Adobe Flex, including work at: Workday, SAP, Salesforce, and Business Objects. 

  5. Flex is Expensive. 

    Ward detailed a number of things Adobe has done to address the cost concerns:
    Flex is a free, and soon to be open sourced, developer toolkit for building Rich Internet Applications for the web and the desktop. This free SDK includes everything a developer needs to build RIAs that work the same on any browser or operating system. Part of the free Flex SDK is an extensive set of components which are extensible, skinable, and accessible. You can see many of these components in the Flex Component Explorer: http://www.adobe.com/devnet/flex/samples/code_explorer/ 

    Flex Builder is an optional plugin for Eclipse which makes developing applications with the free Flex SDK more efficient. It includes features like integrated debugging, design view, and code completion. 

    The Flex Builder pricing has changed in quite a few ways recently. Flex Builder is now free for Students and Faculty. The price for the vanilla Flex Builder, without the charting components, has been reduced to $249 to better balance the tiered pricing for Flex Builder.

    There are a number of options for building backend infrastructure for Flex Applications. To take advantage of the high performance AMF data transfer protocol, there are official Adobe products like LiveCycle Data Services, as well as numerous open source projects like Granite Data Services. Using AMF removes the unnecessary steps of converting data to text (SOAP, RESTful, etc), transferring it, and then converting it back to data. AMF also allows type information to be preserved across the wire.
    To see a comparison of AMF to other text based serialization technologies, see James Ward's Census RIA Benchmark application: http://www.jamesward.org/census.

  6. Flex Applications Require a Special Server. 

    Once again, Ward speaking with InfoQ.com:
    Flex applications can run on top of any web server, application server, and database server. Flex applications are much more like client-server applications. Since the logic is running on the client inside the Flash Player, you need some way of communicating with the server. There are many different options for how you connect Flex to your infrastructure. Without any special libraries, you can expose your back-end data and services as RESTful, XML, or SOAP and easily consume that data in your Flex application. If you choose to use the AMF binary serialization protocol, you may need to add some additional libraries into your web application. AMF is just another serialization technology, like XML or JSON, so it can be one of the various methods you use to communicate to your back-end SOA.
  7. Flex is Hard to Learn. 

    Leftie Friele, from the InfoQ.com community, posted a comment on the InfoQ.com piece “Who is Using Flex?”, detailing his company’s experience in learning Flex:
    Our startup company, Ezmo, have used Flex since the start and we're extremely happy with the framework. 

    Without any prior knowledge of Flex/Flash, we built our application in less than two weeks. The integration between Java and Flex is super simple, and getting started with Flex is just a walk in the park. 

    The tool support is very good too with Flex Builder. You get the familiar surroundings of Eclipse and you are off and running without many problems. The one thing that is missing is better tools for continuous integration and better plugins into Maven for building Flex applications.
    For those new to Flex, Ward has a Screencast showing a Flex application being built to help get you started. There are also numerous other articles about using Flex and Java in the Adobe Developer Connection. 

  8. With Flex, I Will Need to Rebuild My Entire Application. 

    In January, Bruce Eckel published an article titled, “Hybridizing Java.” He argues that the Java community should continue using the good parts of Java, but should use other technologies where Java is weak. His primary focus in the article is using Adobe Flex for user interfaces, instead of the traditional Java options (Swing, JSF, etc…). 

    Ward elaborates on this concept:
    Since Flex applications are just the UI piece of an application the back-end usually stays the same. If your back-end was built following the SOA pattern then it is usually very easy to expose those services out to a new Flex UI. This preserves your existing business logic whether it is in EJBs, Spring services, POJOs, etc.
  9. Flex Breaks Normal Browser Functionality, Like the Back Button. 

    Ward’s blog discusses the back button:
    In Flex, back button support is built in and easily customizable so this was never an issue. Flex also provides an easy way to do hashmark urls (or named anchors), so the url changes as application state changes. Another Web 1.0 integration problem solved.
    Ward adds more details for InfoQ.com:
    Flex 3 provides a simple way for applications to store state parameters in a named anchor and correctly restore state based on those parameters when the URL is requested. More information about this feature can be found in the Flex 3 Feature Introductions Deep Linking documentation. 

    Accessibility has always been very important for Flex applications. Since the Flash Player works with Jaws and other accessibility technologies, the capability for adding accessibility to Flash based applications is there. The Flex framework builds accessibility into the core framework. There are many different pieces of accessibility depending on what impairments and disabilities your application needs to support. You can find out more about the accessibility features of Flex in the Developer's Guide.
  10. I Can Do Everything Flex Does With Ajax. 

    Ward explains:
    RIA with Flex and Ajax is not either/or. Sites like Google Finance show how you can use Flex and Ajax together. Ajax is very good for content-centric applications, while Flex is very good for interactive, media, and data-centric applications. If your application is somewhere in between the two sides of that spectrum, then you can use the Flex Ajax Bridge to combine the two technologies. In Flex 3, the Flex Ajax Bridge is integrated directly into the SDK. If you are using Flex 2, you will need to download the Flex Ajax Bridge separately.
    Also, from the InfoQ.com community, Michael Marth commented on why his group chose Flex:
    We use Flex 2 for our soon-to-launch online dating site viibee.com 

    The reason: Flex enabled us to create a user experience far beyond anything that we could have done with a comparable effort in Javascript/Ajax.

Saturday, February 28, 2009

Screencast: Watch a Flex app built in 11 minutes

James Ward recorded a screencast of him building a simple Flex app with Flex Builder.

Check it out:

http://www.adobe.com/products/flex/media/flexapp/

FlexUnit - Test Driven Development (TDD) for Flex

Unit testing and Test Driven Development (TDD) for Flex and ActionScript 3.0


Unit testing isn't a particularly common practice among Flash developers. Perhaps that's because so many of us are self-taught and not aware of what goes on in other languages, or perhaps it's because, until recently, many Flash-based projects were relatively small-scale.

In this article, I am going to deal with the how and what, but not necessarily the why for Test Driven Development for ActionScript 3.0 and Flex 2. If you want to know 'why', a simple Google search will return a plethora of resources.

I'll do my best to collate and share what I have discovered over this period and show you how to unit-test using FlexUnit, hopefully saving you from some of the frustration and head-scratching I experienced.

Requirements:


FlexUnit from Adobe Labs

flexunit .zip (ZIP, 1.8 MB)

Prerequisite knowledge

Object-oriented programming (OOP), and some ActionScript 2.0 (enough to understand ActionScript 3.0.)

WHAT IS TEST DRIVEN DEVELOPMENT (TDD) AND UNIT TESTING?

Test Driven Development is one of the rules of eXtreme Programming (XP).

Originally, XP programmers wrote tests for any part of their code that could break. However, this soon evolved in to the practice of writing the tests before writing the actual code. This may sound strange, but there is reason behind this madness; by knowing what can go wrong, you have a better idea of what your code needs to be able to handle.

TDD has evolved in to a process by which code is generated, as opposed to a testing process. It does still effectively perform tests, but that is more of a by-product.

The first thing you need is a Unit Testing framework. You can write your own, but that is not necessary. Most people use one of the existing frameworks such as FlexUnit or ASUnit.

In TDD, functionality is added in very small chunks: You come up with a test, you write the test, you write the code to satisfy the test, possibly refactor it to make it more efficient, and then start with the next test. Each test may only take a minute or so to write; it may take 10; one test should not take hours though.

This quote, from Dave Astels gave me my first clear definition of TDD:

"It's about figuring out what you are trying to do before you run off half-cocked to try to do it. You write a specification that nails down a small aspect of behaviour in a concise, unambiguous, and executable form. It's that simple. Does that mean you write tests? No. It means you write specifications of what your code will have to do. It means you specify the behaviour of your code ahead of time. But not far ahead of time. In fact, just before you write the code is best because that's when you have as much information at hand as you will up to that point. Like well done TDD, you work in tiny increments... specifying one small aspect of behaviour at a time, then implementing it." – Dave Astels

There is in fact a kind of "testing dance" you perform, and it's known as the Test-Code-Simplify cycle:

The Test-Code-Simplify cycle (Quoted verbatim from "Extreme Programming Applied", p159):

  1. Write a single test
  2. Compile it. It shouldn't compile, because you haven't written the implementation code it calls
  3. Implement just enough code to get the test to compile
  4. Run the test and see it fail
  5. Implement just enough code to get the test to pass
  6. Run the test and see it pass
  7. Refactor for clarity and "once and only once"
  8. Repeat

UNDERSTANDING TERMINOLOGY





I'm going to use FlexUnit for this tutorial. The "Flex" part may be a little misleading. You doneed Flex in order to use it, but the framework can be used to test pure ActionScript 3.0 files as well.

Before looking at how to use FlexUnit, let's get familiar with some terminology. Bear with me—it's a bit of a chicken and egg situation, and will make more sense as you construct tests later on.

assertions

An assertion is a statement of expected outcome. In other words, it is the expected result of your test. You may assert that the sky should be blue, or that you want x to be equal to y. In TDD if your assertion turns out to be something other than what you expected, you write code to correct that in your class.

test fixture

There may be some setup that is constant across all of your tests. For example, each test may depend on the creation of a certain object, property or process. A test fixture is useful if you have two or more tests for a common set of objects, as it avoids duplicating the code necessary to initialize and clean up the common objects. Methods called setUp() and tearDown() are provided for this common code, and any properties used can be declared at the top of the class.

test case

A test case is the smallest unit of testing. It checks for a specific response to a particular set of inputs. Your test class must extend the TestCase class and have a constructor that calls the super class's constructor. In some frameworks, all test methods should begin with the word "test." So if you are testing that the beer is cold, your method will be called something liketestBeerIsCold().

test suite

As more and more unit tests accumulate for a given project, you will want a way to group them. Running them one at a time would be cumbersome. A TestSuite can contain other TestSuites,or individual tests, and is a way of declaring which test must be run in the same session, regardless of whether or not they are in the same file. This way of aggregating tests is very handy as you'll soon see.

test runner

A test runner is a component that often has a graphical interface and displays the outcome of our tests. In FlexUnit you tell your TestRunner which TestSuite you want to use, and then call its startTest() method.

test harness

The class that extends TestCase may contain a test suite, will contain test cases and may possibly contain test fixtures. From what I can gather this class is referred to as a test harness, although usage of this term seems to vary in the documents I've looked at. Some documentation considers that the harness is the process that instantiates the runner and passes in the suites that you want to run, while Wikipedia defines a test harness as the an Automated Test Framework (ATF).

Congratulations if you managed to get through all that. It wasn't exactly exciting reading, but they are useful terms to refer back to as you look at the examples below.

Let's get on with installing FlexUnit and creating our tests...

INSTALLING FLEXUNIT

Installing FlexUnit is pretty straight forward. You get the Flex Unit source files, set up a Flex project, and in the process, you specify that the project should use the flexunit.swc file:

  1. Get the flexunit .zip archive (from the Requirements area) and extract it to your hard drive. I created a new folder on my C drive called FlexDev and extracted it there, so the path on my machine is C:\FlexDev. Once extracted, FlexDev will contain a folder called flexunit, which in turn contains further sub folders (bin, docs and src folders).
  2. Create the Flex Project. Open up FlexBuilder 2 and create a new Flex project using: File > New > Flex Project.
  3. Choose a Basic Service (in other words, not Data Services) and press Next.
  4. Give your project a name of 'TDD Example', deselect the Use default location option, and browse to the same location as before (on my machine this is the C:\FlexDev folder). This is the location where you are going to set up your project. Click Next. (If you pressed Finish by mistake, skip to the end of this list).
  5. Select the Library Path tab, click the Add SWC… button and browse to the SWC file, which is in the bin folder of flexunit (using my set-up, the path is C:\FlexDev\flexunit\bin\flexunit.swc).
  6. Press Finish button and you're done.

Note: If you need to add the SWC file to an existing project, right-click your project folder, select properties from the pop-up list and continue from step 5 above.

AM I DONE?

You're almost there. First I am going to briefly describe the three files that you are about to create:

  • The first file is the .mxml, (which is set as the default application for our Flex project). This file contains an instance of the TestRunner component (the visual component that displays the test results). The file specifies to the component which test suites you want to run, and then starts the test. I simply called this "main.mxml."
  • I'll refer to the second file as the test class. It is the one that contains the "test runner." Some developers refer to this as the test harness and some would simply call it a test runner. In this file, decide what you need to assert, and then write your test cases in it. I've named this classAccountTest.as as the example in this tutorial relates to money.
  • Finally there is the actual class, Account.as. Build this file up bit by bit as you create more and more tests.
CREATING THE THREE FILES





Creating main.mxml:


Here is the MXML that belongs in the main.mxml file. Open up the file and copy and paste this in:




<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:flexunit="flexunit.flexui.*"
creationComplete="onCreationComplete()">

<mx:Script>
<![CDATA[

private function onCreationComplete():void
{
testRunner.test = AccountTest.suite();
testRunner.startTest();
}
]]>
</mx:Script>
<flexunit:TestRunnerBase id="testRunner" width="100%" height="100%" />
</mx:Application>


There are a few things to notice:

  1. We've defined a new xml namespace in the Application tag
  2. We have a creationComplete even calling our onCreationComplete method
  3. we created an instance of TestRunnerBase

We defined a new xml namespace in the Application tag:

xmlns:flexunit="flexunit.flexui.*" 

If you have created your own components in Flex before, this will be familiar to you. If not then I will briefly explain.

This creates a namespace called "flexunit," which refers to components located in the flexunit.flexui package. We have access to this package of course, because you associated the flexunit.swc file with the project library earlier.

To instantiate an instance of the component in MXML, you can use code similar to the following:


<flexunit:TestRunnerBase id="testRunner" />

If you had declared your namespace as "bananas", you would instantiate your component using code similar to:

 

<bananas:TestRunnerBase id="testRunner" />

But you've used common sense and gone for a more descriptive name.

The TestRunnerBase component is TestRunner (see the "Understanding Terminology" section, above, for a refresher). I assigned it an id of testRunner.

In the Application tag you also have the creationComplete event handler, which callsonCreationComplete(). This method sets the test suite(s) you are going to use, and then calls the startTest() method of the TestRunner to put everything in to action.

Finally, underneath the script block you instantiate our TestRunner as previously described, with a width and height of 100%.

Okay, that's it. You'll be glad to hear that you don't really need to touch this file again in this tutorial.

Creating AccountTest.as:

Create a new ActionScript file in the main project folder (at the same level as main.xml) called AccountTest.as, and paste the following code into it:

package
{
    import flexunit.framework.TestCase;
    import flexunit.framework.TestSuite;
    
    public class AccountTest extends TestCase
    {
        public function AccountTest(methodName : String){
            super(methodName);
        }
            
        public static function suite():TestSuite{
            var accountTS:TestSuite = new TestSuite();
                //tests are added to the suite here
            return accountTS;
            
        }
    } }

There are a few things to notice:

  1. The class extends TestCase.
  2. There is one static function called suite (which returns a TestSuite).
  3. The constructor calls its super class, passing it some method name.

Creating Account.as

Finally, you must create the Account class. Create a new ActionScript file in the main project folder (at the same level as main.xml and AccountTest.as) called Account.as and paste the following code into it:

package
{
    public class Account
    {
        public function Account(){
            
        }
    }
}

Not much to say about this. It is the bare bones of the actual class.

WRITING THE FIRST TEST

I'm going to plagiarize (with permission) the example used by Simon Whacker to demonstrate as2lib's unit testing, because it was particularly clear and easy to understand.

We are going to create an application for a bank, and our first requirement is to allow the creation of a new account.

The first question to ask yourself is: When creating a new account, what should happen? Well, not much. Despite my best wishes, whenever I open a new account, it always starts off empty. How do I know that for sure? Well. I know because I can check my balance. So, when I open a new account and check my balance I should have £0.00 in there. Okay, we have our first test.

Remember, in this tutorial, we write our test before we write the code in our class, and this is how it works:

In AccountTest.as, underneath our static "suite" method, paste in this code:

public function testNew():void{
    var account:Account = new Account();
    assertEquals("Expecting zero account balance", 0, account.getBalance());
}

Note: In some frameworks all tests must start with the prefix "test." With FlexUnit, this rule doesn't seem to be enforced, but for consistency I recommend doing so anyway. One reason to require any test method to start with "test" is that you can then shortcut the suite creation process. Simply introspect a class and any function that starts with "test" is considered a test.

In this case, you are testing the creation of a new account and so the method is called testNew.

As you can see, you create a new instance of the Account class, and then use an assertion method called assertEquals.

There are various types of assertion, but assertEquals basically checks that the two values passed in are ... [drum roll] ... equal. The eagle eyed among you may have noticed I am actually passing in three values:

  1. The first value is optional. It is a String and it should clarify the outcome you are looking to satisfy. In this case: "Expecting zero account balance."
  2. The next value is 0.
  3. The last value is a call to an, as yet non-existent, method of our Account class calledgetBalance(). I will write this in a moment.

Overall, this assert specifies that you want the value returned from getBalance() to equal zero.

Note: TestCase extends Assert, so there is no need to import the Assert class in order to use these assertion methods.

All you have to do now is add your test to the test suite.

Amend the static suite function in the AccountTest class to look like this:

public static function suite():TestSuite{
    var accountTS:TestSuite = new TestSuite();
    accountTS.addTest(new AccountTest("testNew"));
    return accountTS;
}

You can see from the above code that I use the addTest method to add the test to the TestSuite. The object passed in is actually an instance of AccountTest (in other words, the class you are in). The name of the test to run, gets passed in as a String...

If you remember, the constructor for AccountTest looks like the following code:

public function AccountTest(methodName : String){
    super(methodName);
}

It accepts the methodName of the test, and passes it on to its super class.

Note: This is the way I first learned to test, but you don't have to do it like this. The framework will automatically find all "test" methods in a TestCase if you pass the class reference to the constructor of a TestSuite.

Test It!

Okay, the setup is done. It's time to test.

If you think back to the Test-Code-Simplify cycle of eXtreme Programming that we looked at earlier. The first couple of stages were:

  • Write a single test.
  • Compile it. It shouldn't compile, because you haven't written the implementation code it calls

You've written a test, so try and compile the project.

The Errors window

Figure 1. The Errors window

The Flex Builder Problems pane should also be reporting the following error:

"Call to a possibly undefined method getBalance through a reference with static type Account."

Great! That's what we want. You haven't written getBalance() yet And so you should quite rightly have a compiler error.

Note: If you actually choose to ignore the error and run the application anyway, you will see the TestRunner, and the test will actually pass! I didn't expect this to happen so be aware of it. It is fine to ignore Flex Builder warnings (in fact, the kind of tests you'll do will probably cause a few warnings) but don't ignore compile-time errors.

From further research, I found out that the test passes based on the last time you saved. So if you saved an empty test method, it would work; or, if you saved the empty testcase it would run and report no failures. When there are compiler errors, a new SWF file doesn't replace the old SWF, so you are in fact running the old SWF file.

Now take a look at the next two steps in the Test-Code-Simplify cycle:

  • Implement just enough code to get the test to compile.
  • Run the test and see it fail.

Amend the Account class to look like this (additions are highlighted in yellow):

package
{   
    public class Account
    {
               private var _balance:Number; 
               public function Account(){
        }
       public function getBalance():Number{
            return _balance;
         }
    }
}

You now added your getBalance() method, which returns _balance, and you have also declared this variable called _balance (intended to hold our account balance amount of course), but _balance hasn't been initialized with a value yet. Compile, and you should see something like the following:

The TestRunner GUI

Figure 2. The TestRunner GUI

This error is a good thing! Here we can see the test that failed (testNew) and why it failed. The big red bar would be green if the test had passed.

Now you know your TestRunner is working properly. You know the test should have failed, you know your test did fail, and you know why it failed.

The TestRunner tells us that it expected a value of zero but received a value of NaN (Not aNumber) which is what ActionScript 3.0 returns (variables typed as Number and not assigned a value are returned as NaN in ActionScript 3.0).

Continuing on, the next two steps in the Test-Code-Simplify cycle are:

  • Implement just enough code to get the test to pass
  • Run the test and see it pass

All you need to do now is give _balance an initial value of zero. Change your Account class's constructor to look like the following:

public function Account(){
    private var _balance:Number = 0;
}

Now run the test:

The test succeeds

Figure 3. The test succeeds in the All Tests tab

Bingo. The bar is green. Here we are viewing the "All Tests" tab in the left pane, which shows that the testNew test has passed. You know it passed for the right reasons too, because you saw it fail when conditions were wrong.

The final two points in the Test-Code-Simplify cycle are:

  • Refactor for clarity and "once and only once"
  • Repeat

There's little need to refactor here, and so on with the next test.

ONWARDS AND UPWARDS


You've completed your first test—the hard part is over with. Take a break if you're exhausted because in order to see the real value of TDD we are going to implement a couple of extra tests. Most of the following code will be copy and paste with little need for additional explanation, so it shouldn't take long to get to the end now

GIVE ME SOME CREDIT


In many ways this next part of the tutorial is the most important. I hope to demonstrate how TDD can help you spot mistakes and prevent you from making changes which could break existing code and leave you unaware. Catching these problems when they occur, can save hours of debugging and headache further down the line.

Let's say your bank customers can open an account and now they need a way to credit their accounts. I'm sure you can think of plenty of things you need to test for here. Just as an example:

  • crediting an account with a null amount (avoid this!)
  • crediting an account with a real value (must work!)
  • crediting an account with a negative amount (that's a debit not a credit)
  • an account credit which includes fractions of a penny (how to handle?)

We're not going to implement all of these, but we'll use a couple of them to highlight some points.

Credit with null value

This seems pretty straight forward so first let's write the test:

public function testCreditWithNullValue():void{
     var account:Account = new Account();
     account.credit(null);
     assertEquals("Expecting zero account balance", 0, account.getBalance());
}

Again, you have called a method that doesn't exist yet credit(), but in doing so you have effectively specified that it is required, and must be capable of accepting a value. This shows how TDD helps you write your specifications.

Now add your test to our test suite:

accountTS.addTest(new AccountTest("testCreditWithNullValue")); 

Check that your application doesn't compile; sure enough, Flex Builder gives you a compile error because you haven't written the credit() method yet.

Next, write just enough code in the Account class to let it compile.

public function credit(amount:Number):void{
    _balance += amount;
}

Run the test and see it fail:

Only, this one doesn't fail.

Flex Builder warns is that AccountTest ('null' is being used where 'Number' is expected), but there is no error. In fact ActionScript 3.0 appears to handle the attempt at passing in a null and returns a balance of zero.

In ActionScript 2.0, adding null to zero would equal NaN (Not a Number), so let's quickly check that our assumption about this is correct by making the test fail on purpose.

Change the code as follows:

account.credit(null + 10); 

When we run the test it does indeed fail, because it is expecting zero, but receives 10. It looks like the code is doing what you wanted, so remove the "+ 10" and write the next test.

Credit with real value

Now make sure you can credit the account with a real value.

Use the amount £12.34, although the currency is obviously irrelevant here.

Once again, create a test and add it to the test suite. I show the test as follows:

public function testCreditWithRealValue():void{     var account:Account = new Account();     account.credit(12.34);     assertEquals("Expecting account balance with           pounds and pence.", 12.34, account.getBalance()); }

Again, you create a new instance of the Account class, call the credit method (which now does exist) and pass in a value of 12.34. Therefore, you expect a balance of 12.34 returned.

Finally, this test passes for the first time. With something as simple as this (considering our other tests are also in place) I don't think you need to double check it by making it fail. On with the final test.

Credit to three decimal places (fractions of a penny)

In the next scenario, the bank has specified that it will allow account credits which include fractions of a penny, but it will always round these amounts down and keep the extra (they are a bank after all); so if you put in thirty seven and a half pence, the account would be credited with 37 pence. Here, you simply check a number to three decimal places.

Write the test (see below) and add it to the test suite (not shown):

public function testCreditWithRealValueTo3DecimalPlaces():void{     var account:Account = new Account();     account.credit(1.234);     assertEquals("Expecting account balance of 1.23",               1.23, account.getBalance()); }

Run the application and see it fail. Good. There is enough code in place for the application to compile already, but of course you are expecting a rounded-down figure, and the current credit method is not set up for that, so you get the following TestRunner error:

Error: Expecting account balance of 1.23 - expected:<1.23> but was:<1.234>

That's exactly what is expected. Now you write enough code to make it pass, which means changing the credit() method to round off the amount. Change it to look like the following (changes in highlight):

public function credit(amount:Number):void{     var rounded = Math.floor(amount * 100)/100;     _balance += rounded; }

If you run the test, it passes. Notice that Flex Builder warns you that you forgot to give therounded variable a Type definition. To do that, change the code to:

var rounded:int = Math.floor(amount * 100)/100; 

Run the application and...

Hang on a minute. We seem to have broken a couple of tests.

Let's look at the first one:

Running the testCreditWithRealValue test

Figure 4. Running the testCreditWithRealValue test

The testCreditWithRealValue was passing before, so what did we do to break it? Well as you can see, the test was expecting a real value of 12.34 but it only received 12.

In a moment of distraction, we typed the variable incorrectly as int, and of course integers arewhole numbers. In this case my contrived example was pretty obvious, but it shows how changing or implementing new functionality can break earlier code, and how TDD alerts you to that fact instantly.

All you need to do to fix this particular error is to type our variable as Number:

rounded:Number = Math.floor(amount * 100)/100; 

Now run the application and all tests pass.

Let's look at the testCreditWithRealValue test again for a moment... luckily you chose to use decimals in the "real value" test. Obviously an integer is a valid "real value" too, and if you had just used an integer, you wouldn't have spotted this error so easily. It is important to spend a moment naming our tests accurately, and more importantly, ensuring that you can't break a test down further in to smaller tests. One of the XP maxims is "Test until fear turns to boredom". TDD is great, but it's not an instant solution to all your problems. I wanted to show both how useful it can be, and how thin the distinction can be between useful feedback and no feedback at all.


Top 10 Mistakes when building Flex Applications

In this post, Adobe’s James Ward teams up with InfoQ.com to bring you another Flex Top 10 (our most recent Flex Top 10). Flex is an open source application development framework for building rich Internet applications that run in the web with Flash Player, or on the desktop with Adobe AIR. Overall, Flex is a powerful framework that is easy to use, but today let's focus on some of the common mistakes that are made when building Flex applications. 

For those new to Flex, check out InfoQ’s recent Adobe Flex Basics to get a quick introduction to the framework. Here is the list:
  1. Using an RIA framework to build Web 1.0 applications (aka. New technology same old stuff).

  2. One of the largest challenges when moving from Web 1.0 applications to the RIA's development paradigm is learning to think differently. Flex gives developers an advanced component library that allows for doing things that simply weren’t possible only a few years ago. Often, the power of Flex is missed, and the framework is used to implement more traditional Web 1.0 applications. 

    Building Web 2.0 applications is more than partial page refresh and rounded corners. For example, Flex developers should be using vectors to provide users a visual understanding of data, and advanced controls for a rich application flow. Stephan Janssen discusses this struggle recently with InfoQ.com:
    As a Java developer, learning Object Oriented ActionScript and the UI markup language is really a walk in the park. The challenge however for (Java) developers is that we're not designers, and with RIA technologies these two skills are very much needed.
  3. Breaking standard browser experiences.

  4. While Flex does provide an excellent platform for improving the user experience, it still important to maintain familiarity of things like the back button, book marking, and auto complete. 

    Flex 3 includes new Deep Linking features for back button support and book marketing. You can learn more at labs.adobe.com. There are number of components out there for implementing auto-complete. From the Adobe Exchange, you can use the AutoComplete Input component. 

  5. Slowing the application down with the use of too many containers.

  6. Flash Player uses a hieratical display object graph, similar to the HTML Document Object Model (DOM). The deeper containers are nested the longer the rendering takes. Adobe’s Flex Developer Center has an article that covers best practices related to Flex performance, including the use of containers in detail:
    The biggest Flex performance danger is yielding to the temptation to use containers randomly. Deeply nesting too many containers hinders the performance of your application. This is the number one performance danger that Flex developers succumb to—and luckily it is 100 percent avoidable.

  7. Slowing the application down by using XML for data transfer over optimized protocols.

  8. Flex offers developers a number of options for data transfer between the Flex client application and the server, including AMF3, XML, SOAP, and straight HTTP requests. Ward demonstrates the use of these technologies and performance benchmarks in his Census application. 

    BlazeDS should be considered for Greenfield projects using Java on the backend. BlazeDS is Adobe’s recently open sourced Data Services product that uses the AMF3 protocol. AMF is a binary transfer protocol that is easy to integrate with Java, and offer significant performance benefits over XML. There are open source implementations of AMF for every major backend technology. 

    If BlazeDS is not an option, Hessian could be an option. Hessian offers ActionScript/Flex support for their binary web services protocol. 

  9. Trying to hire Flex developers.

  10. Experienced Flex developers are very hard to find right now. Flex is at the point in the adoption curve which Java was at in the late nineties. The demand for Flex developers is exceeding the supply. This makes finding experienced Flex developers difficult. This, however, creates a huge opportunity for Java developers to expand their skill sets and work with a fun emerging technology. Many companies looking for Flex developers have great success training Java or other web application developers for only a few weeks on Flex. Flex’s language and APIs are easily learnable by developers who are familiar with Web and GUI programming. 

  11. Over use of animations

  12. Using Flash as the runtime enables developers to easily add animations and effects. However, developers should make sure that the animations have meaning and provide context. Otherwise, they will annoy users. The timing of animations is also important. Interaction designers can help make recommendations on when animations should and should not be used. Interaction designers can also recommend the best type of animations, the duration, and the best easing function. 

    There is good a post on the use of animations at laair.org:
    Most animations are simply TOO LONG. They are long, and slow, and boring, and excessive. Tone it down. If there is one thing I have found, its that I hate waiting for stupid animations to finish so I can do something else. 

    Don’t get me wrong I am not bashing animations. I am simply bashing animations that are simply too long or too extravagant for their purpose. Every animation can be broken down to having a purpose. Figure out the purpose of your animation and apply accordingly.
  13. Not setting up an enterprise ecosystem.

  14. As with other software projects, it is important to setup an enterprise ecosystem for your Flex applications. 

    Test Driven Development (TDD) is a staple of most any enterprise project in this day-and-age. For Flex, the FlexUnit framework is available for coding unit tests. On Adobe’s Developer Connection, Neil Webb discusses TDD for Flex developers and using FlexUnit. In addition,Flexcover is available for code coverage reporting. 

    Continuous Integration (CI) is a proven practice for building cohesive applications when multiple developers are contributing. Similar to Java applications, both Ant and Maven plug-ins are available for CI builds of your Flex applications. 

  15. Not using the entire framework.

  16. There are a number of optional features available in Adobe Flex that you should consider using in your applications. For example, Runtime Shared Libraries (RSL) is available for reducing the size of your applications:
    You can shrink the size of your application's resulting SWF file by externalizing shared assets into standalone files that you can separately download and cache on the client. Multiple Flex applications can load these shared assets at runtime, but each client need only to download them once. These shared files are called Runtime Shared Libraries.
    Another under used feature of the framework is the built in accessibility features. You can read more about the accessibility features of Flex in Adobe’s livedocs. In addition to built in accessibility, the framework provides built in features for localization. For the latest Flex 3 framework features, checkout Adobe’s Getting Started introduction page. 

  17. Slowing the DataGrid down with complex renderers.

  18. The out-of-the-box itemRenderer for the DataGrid is very optimized. Mistake #3 discussed the performance impacts of deeply nested containers. One of the places in Flex where containers can easily get deeply nested is in the DataGrid’s item renderers. The number of item renderers which are rendered by the DataGrid is the number of visible rows times the number of visible columns. Custom DataGrid and List item renderers should be very optimized. When complex layout logic is needed in an item renderer, it is best to use UIComponent (or other more low-level classes) and position the contents for that cell manually. 

  19. Not Preparing for Offline Applications.

  20. The traditional model for RIAs is in the browser. However technologies like Adobe AIR andGoogle Gears is allowing those applications to run offline. By not preparing for a potential offline architecture when users demand it, changing your applications to support offline features may be very difficult. Typically, in web applications business logic lives on the server. In offline RIAs, business logic must transition to the client. This makes it nessecary to architect ahead of time where certain business logic will need to live in order for applications to work both offline and online.

Sunday, February 22, 2009

Change Your Perception

OFFER YOUR PLANS AND ACTIVITIES TODAY ACCORDING TO GOD"S WILL...


There was a millionaire who was bothered by severe eye pain. He consulted so many physicians and was getting his treatment done.

He did not stop consulting galaxy of medical experts; he consumed heavy loads of drugs and underwent hundreds of injections.

But the ache persisted with great vigor than before. At last a monk who has supposed to be an expert in treating such patients was called for by the millionaire.

The monk understood his problem and said that for sometime he should concentrate only on green colors and not to fall his eyes on any other colors.

The millionaire got together a group of painters and purchased barrels of green color and directed that every object his eye was likely to fall to be painted in green color just as the monk had directed. When the monk came to visit him after few days, the millionaire"s servants ran with buckets of green paints and poured on him since he was in red dress, lest their master not see any other color and his eye ache would come back.

Hearing this monk laughed said "If only you had purchased a pair of green spectacles, worth just a few rupees, you could have saved these walls and trees and pots and all other articles and also could have saved a large share of your fortune.

You cannot paint the world green." Let us change our vision and the world will appear accordingly.

It is foolish to shape the world, let us shape ourselves first.


Change Your Perception..!!


KEEP CONFIDENCE, TRUST IN GOD AND NEVER LOSE HOPE...


Monday, February 16, 2009

35 keys to running a business, or living a life...

  1. It's okay not to know. It's okay to be vulnerable. No one has all the answers. We value and learn from the questions and the asking.
  2. We are learning to appreciate the mystery and sacredness of our lives and the mystery and sacredness of life.
  3. Life is short. There is no escape from old age, sickness, and death. Death is a great teacher. Recognizing the shortness of our lives provides motivation to live fully in each day and in each moment.
  4. We understand the importance of taking regular quiet time for ourselves. Through reflection and by slowing down we develop an appreciation for life and we increase our capacity for understanding.
  5. We are learning to trust our inner wisdom. Our bodies and minds are amazing, unexplainable, and unfathomable.
  6. It's okay to be uneasy, to be uncomfortable, to grieve, to feel pain. Recognizing when something is off, feeling the depth of loss, experiencing pain, is the first step toward change and growth.
  7. Practice active listening — listening deeply to yourself and to others. Listen to others without formulating your own ideas. Listen to yourself before speaking.
  8. We all seek balance in our lives — balancing work and family, balancing our inner and outer lives, balancing what we want to do and what we must do.
  9. We are learning that we can be fully ourselves in all situations — at work, as parents, as children, as friends, as lovers.
  10. Being ourselves at work is vital to our health and happiness. Our time is too valuable to sell, at any price.
  11. Each moment is precious. In every moment we have an opportunity to discover, to grow, to speak the truth.
  12. Each moment is ordinary. In every moment we can realize we are fine, just as we are. Nothing else is needed.
  13. We appreciate what is paradoxical. What may at first seem contradictory or beyond our understanding may be true. After all, who is it that is breathing? Who is it that dreams? How is it that these hands effortlessly glide along this keyboard?
  14. Age is a state of mind. We have the opportunity to grow to be more like ourselves every day.
  15. Developing intimate relationships is a vital part of our lives and our development. Intimacy requires openness, honesty, and vulnerability.
  16. Real, honest open communication is highly valued — and takes real skill and effort.
  17. When we slow down and learn to trust ourselves, joy arises naturally.
  18. When we slow down and learn to trust ourselves, creativity arises naturally.
  19. Self-knowledge and understanding require persistence and perseverance. Developing awareness and balance is an ongoing, unending process.
  20. Self-knowledge and understanding require discipline. Whatever path we take requires structure, guidelines, and feedback.
  21. Self-knowledge and understanding require courage.
  22. Diversity is essential. Our differences enrich our lives. There is no "other," just as our right hand is not a stranger to our left hand.
  23. A simple rule to follow is do good, avoid harm. Of course, this is not simple or easy.
  24. There are many paths and many practices toward developing awareness and personal growth.
  25. Our everyday lives and activities provide fertile ground for developing growth and understanding.
  26. We can learn to appreciate the gifts we've received from our parents and to forgive them. We understand on a deep level all we have received from the generations that have come before us.
  27. We feel a deep responsibility for our children and for the generations that will come after us.
  28. We can all act as change agents. We can choose to take action in improving and healing our environment and our society. There is no shortage of issues to address, of healing to take place.
  29. We are all change agents on a personal level — we either create healing amongst those we live and work with or we create stress.
  30. We can choose to act as change agents in relation to our communities.
  31. We can choose to act as change agents in relation to our society or on a global level.
  32. Everything we hold as dear will one day change and disappear. Every business that now exists will one day cease. Every person now alive will one day die.
  33. At a deep level, we realize that we are neither in control nor not in control. Our task is to paddle the boat, with awareness and integrity. The flow of the river is outside our doing.
  34. We all have the power to find peace and happiness in the midst of change and impermanence.
  35. We have the power to heal ourselves, our communities, and our planet.

(Credit: M. Lesser)

Staying Focused: 5 Useful Practices

Wisdom is the art of knowing what to overlook.
— William James

Here are five practices that can be useful tools in reducing distraction or frenetic activity and cultivating focus and concentration. They are surprisingly easy to implement and, almost before you know it, can become positive addictions.

1) Appreciate Impermanence

I saw a cartoon in a recent New Yorker magazine in which two people were finishing their dinners at a Chinese restaurant and had just opened their fortune cookies. One fortune read, “You are going to die.”
If you let this fact sink in — that life is short, and we all die — it can actually act as a powerful motivating force to help maintain focus and priorities. Everything changes and is impermanent, so are we fully present and making the most of this fleeting moment? Are we fully aware of what we are doing? Appreciating impermanence clarifies priorities, and it helps us identify any frenetic, shallow and ineffective activities we’re being distracted by. We see clearly the things that exhaust us and distract us from experiencing the blessing and opportunity of each particular day.

In Zen practice it is often said that the span of our lives is like a dew drop on a leaf — beautiful, precious, and extremely short-lived. Life is remarkably unpredictable. Whatever you want to accomplish, whatever is important to you, do it, and do it now — with as much grace, intensity, and sense of ease as you can muster. None of us knows what life will bring. In any moment everything we take for granted can change. We can use an awareness of change on a deep and wise level to focus our priorities and increase our appreciation of the sheer beauty of existence.

2: Clarify Aspirations and Create Next Steps

Make two lists. Title the first one “Aspirations, Plans, and Projects.” Title the column next to this “Next Steps,” and list concrete action steps toward implementation of each aspiration, plan, or project. What is the very first action required toward completing each item, and the step after that and the one after that? In the popular book Getting Things Done, productivity improvement expert David Allen describes the relief that people experience just by listing “next steps” in relation to incomplete projects. The act of identifying clear actions can have a freeing effect and make you feel that you’re making progress (sometimes when mired in setbacks and resistance, project management minutiae, or office politics, this is not so easy to believe). It can be daunting having many projects hanging over your head, so this helps clarify the actions needed to move each project toward completion.

3: Retrain Pavlov’s Dog

We react to email and phone calls the way Pavlov’s dog reacted to a bell: we come running at once, tongues wagging. Instead, when approaching the daily onrush of emails, phone calls, and other attention “grabbers,” try these habit diffusers and attention refocusers.

Emails
Learn to check your email only two or three times per day — say, at the middle and end of your day, or at the beginning, middle, and end. Granted, sometimes this isn’t realistic. Sometimes we have truly time-sensitive matters to resolve, and we absolutely must read and reply immediately. But these situations are probably fewer than we think, and this type of behavior can be the exception rather than the rule. Actually, despite the prevailing belief that we live in a world where everyone expects quick, near-instantaneous responses, this isn’t true. Most people don’t need responses right away; they just get used to it.

Phone Calls
As with email, learn to respond to phone calls or messages only two or thee times per day. Like changing any habit, learning this new behavior takes patience and some repatterning; give yourself a week at least. What you do also depends on your communication needs, but commit to different behavior. Let your message service do its job, so you can do yours. Retrain yourself not to always respond to the ring of the telephone or the vibration of the cell phone. This way, you control your interactions; they don’t control you.

Think Time
Schedule think time and reflection time at the beginning and end of each day. This could include a full meditation, or perhaps just silent, focused thoughtfulness over a cup of coffee or tea, while taking a robust walk, or while still lying in bed first thing in the morning. In any case, commit to giving yourself this daily gift of a few moments to sit quietly and gather your thoughts. These can be some of the most pleasurable, precious, and practical moments of the day. They can help to reframe your focus and energy in unexpected ways.

4: Savor Borrowed Time

Borrowed time is when we take a brief moment to do nothing; we just breathe and smell the sweetness of the air, think briefly about the task we just completed or are about to start; or listen to the birds flying, one’s heartbeat, or the conversations around us (without participating in them). These refreshing bits of time can be just a minute or two long, and they can happen many times throughout the day if we let them. They are, quite simply, daydreaming, but we shouldn’t view them as guilty indulgences. One helpful result of engaging in the more disciplined practice of meditation or mindfulness is that it makes us more relaxed about “do nothing” time. The quietude is familiar; all of these practices become the pause that refreshes.

5: Create Your Own Toolkit for Reducing Stress

Experiment with beginning each day, or most days, with meditation practice. Explore routines and rituals to center and relax during the day. Just breathing deeply and from the diaphragm three or four times, several times a day, can be a great start. Commit to stopping: notice the warm power of the sun or the sound of the freezing rain; smile; drink a glass of water; close your eyes for a minute or two; stretch your arms and legs, giving your neck and shoulders or hands a mini-massage; or get up from your desk to chat with a colleague down the hall. It can be any activity that refreshes and makes you pause from the whirlwind of activity you may have (unconsciously) gotten yourself into. If you work at a computer for much of the day, consider setting a timer to remind yourself to stop and stretch at regular intervals.

(Credit: M. Lesser)

Sunday, September 28, 2008

A secret to making money online

This is a MUST-SEE for anybody that is running a start-up and/or is thinking about starting one. In this presentation, David H. Hansson (creator of Ruby on Rails), talks about the lifestyle business with the importance of spending "less" but quality time in developing a good product and generally "enjoying life" doing it!

He talks about the over-jealous intent of start-ups to flip the business... the companies are narrowly focused on pumping it up and selling-out in the hope of living a good life after that. Instead the focus has to be on creating a great product that address the pain point businesses have, and doing that better than others.

&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;div&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;a href='http://www.omnisio.com'&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;Share and annotate your videos&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;/a&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt; with Omnisio!&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;lt;/div&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;gt;

Friday, April 18, 2008

NYC Freedom Tower plans found in trash (What the *&^#?)


Check out this report from Associated Press:

A homeless man has come forward with two sets of confidential ground zero blueprints that he says were dumped in a Lower Manhattan trash can. The man brought the Freedom Tower plans to the New York Post, which says the 150-page schematic is marked: "Secure Document — Confidential."

I can't believe this!!! You must be freakin' kiddin' me. Ever heard of a shredder you freakin' moron...

The documents are dated Oct. 5, 2007. They contain plans for each floor, the thickness of the concrete-core wall, and the location of air ducts, elevators, electrical systems and support columns. The agency that owns the World Trade Center site, the Port Authority of New York and New Jersey, calls it a serious security lapse.

Now what are they going to do? Re-do the whole thing from scratch? How many tax dollars have been wasted by this stupidity??? How many other secure and confidential blueprints are there in the trash cans around the country???? What if they get in the wrong hands??? Then what??!!!