19
DONT’S (AND DO’S)OF TITANIUM DEVELOPMENT BY RICHARD LUSTEMBERG Titan, TCAD, working with Titanium since 2010 www.theappartisan.nl

Things to avoid as a beginner

Embed Size (px)

Citation preview

DONT’S (AND DO’S)OF TITANIUM DEVELOPMENTBY RICHARD LUSTEMBERG

Titan, TCAD, working with Titanium since 2010

www.theappartisan.nl

• Not opinionated

• About Titanium development

• Some other mobile development topics

TOPICS

• Cross platform development

• General

a. Ti.include

b. Globals

c. Events

d. Memory management

CROSS PLATFORM DEVELOPMENTWHAT THE TITANIUM SDKS ISN’T:

A ‘Write once, run everywhere’ platform

• Write an application for one platform (ie. iOS), finish

it and then expect it to run on another (.ie Android)

• Don’t use the default Android emulator

Don’t:

• Test under all platforms incrementally.

• Step by step implementation and profiling.

• Try using TiShadow simultaneously on several

simulator/devices from different platforms

Do:

Doing as in the two steps above will familiarize you

with the platform subtle and not so subtle

differences

GENERAL TITANIUM DEVELOPMENT

TI.INCLUDE()

• It’s deprecated

• It’s an include (basically a copy & paste), so it loads all code in one go.

• If the code is not modularised, it’ll fill up the global space with variables.

• Don’t use Ti.include(), use CommonJS require()

GLOBALSAPP.JSALLOY.JS

• Unless you intend to create global variables, wrap all

variables using self invoking functions

• If you are going to provide globals, then use a

namespace to avoid variable collisions

When doing stuff on app.js or alloy.js

• The Alloy framework instantiates it’s own global

variables: Alloy, _ (underscore), Backbone

EVENTS

• Adding listeners the wrong way

• Not removing global listeners

• Sending improper event payloads

• Add event listeners from within another event listener

• Add event listeners after firing the event

Don't:

• Causes memory leaks

• Will trigger application crashes when an event

callback attempts to work on stale or nulled data.

Not removing global events:

• Use callbacks instead of events, unless it becomes

too complex

• Prefer native JavaScript events instead of Ti.App

events

• If using Ti.App events, do not pass complex objects

as event payload (iOS)

MEMORY MANAGEMENTOR NOT CARING ABOUT IT

• Do not: disregard memory management

• Do: Clean up your UI objects after no longer using

them. Read the literature.