Recortes de mi Webeo

Writing Robust Code

Posted in Palm OS por novaxo en 11 julio, 2007

To make your programs more robust and to increase their compatibility with the widest variety of Palm OS products, it is strongly recommended that you follow the guidelines and practices outlined in this section.

· Check assumptions.

You can write defensive code by making frequent use of the DbgOnlyFatalErrorIf() macro, which enables your debug builds to check assumptions. Many bugs are caught in this way, and these “extra” calls don’t weigh down your shipping application. You can keep more important checks in the release builds by using the ErrFatalErrorIf() function.· Avoid continual polling.
To conserve the battery, avoid continual polling. If appropriate, take advantage of the keyUpEvent or the facilities for performing event-based pen tracking to avoid polling altogether.

· Avoid reading and writing to NULL (or low memory).
In Palm OS Cobalt reading and writing to NULL will cause your application to crash. When calling functions that allocate memory, at least make sure that the pointers they return are non-NULL. (If you can do better validation than that, so much the better.) Also check that pointers your code obtains from structures or other function calls are not NULL. Consider adding to your debug build a #define that overrides the memory management functions with a version that validates the arguments passed to it.

· Check result codes when allocating memory.
Because various Palm Powered devices have larger or smaller amounts of available memory, it is always a good idea to check result codes carefully when allocating memory.

· Avoid making assumptions about the screen.
The size and shape of the screen, the screen buffer, and the number of pixels per bit aren’t set in stone-they vary from one Palm Powered device to another. Don’t hack around the windowing and drawing functions; the functions provided are optimized to make best use of the underlying hardware and to allow multiple applications and system services to share it.

· Built-in applications can change.
The format and size of the preferences (and data) for the built-in applications is subject to change. Write your code defensively, and consider disabling your application if it is run on an untested version of the OS.



Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de

Estás comentando usando tu cuenta de Cerrar sesión /  Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )


Conectando a %s

A %d blogueros les gusta esto: