Title: Rapid and Expressive Prototyping on Cell Phones via Script Embedding
1Rapid and Expressive Prototyping on Cell Phones
via Script Embedding
- Jingtao Wang
- Computer Science Division
- jingtaow_at_cs.berkeley.edu
2Agenda
- Motivation
- Challenges in creating cell phone app
- Overview of popular mobile development platforms
- Low threshold and high ceiling, the script
embedding approach - Summary
3The Popularization of Cell Phones
4Cell Phone is THE Portable Computing Device
- Global penetration reached 50 (3.3 Billion) on
11/29/2007 - 59 countries had cell phone market share over
100 - Luxembourg 158
- Hong Kong 140
- Italy 122
- United States 81
- China 42
- India 23 (largest growth market)
- There are only around 850 million PCs in the
world.
Data from Informa Telecoms Media
5Opportunities and Challenges of Cell Phones
- The bright side
- Portable, always with you
- Always on, always connected to the internet
- Seamless integration with ones social networks
- High market penetration throughout the world
- The dark side
- Limited resources (CPU, memory, screen, input
modality) - Highly diversified hardware and software
implementations - Incomplete development tools and libraries
- Proprietary hardware/software decrease
competition and add costs in development and
distribution
6Threshold and Ceiling
7An Overview of Mobile Development Platforms - 1
- Mainstream (non-smart) Phones (more than 90
market share) - J2ME (Java 2 Micro Edition)
- BREW (Binary Runtime Environment for Wireless)
- Flash Lite
- HTML, WAP/WML
8An Overview of Mobile Development Platforms - 2
- Smart Phones (less than 10 market share)
- Windows Mobile (Embedded Visual C, .Net
Framework Compact Edition) - Linux (C/C, Java, J2ME)
- Symbian (C, Python)
- Palm (C/C, J2ME)
- Flash Lite
- BREW
- HTML/AJAX, WAP/WML
9J2ME
- Best availability on different platforms
- Can leverage knowledge and resources from desktop
Java - Good debugging support
- Poor UI framework/libraries
- Inconsistent behaviors in different devices
(write once, debug everywhere) - Poor performance (no JIT on most devices)
- Low ceiling (can only do what the built-in
libraries allow one to do) - Signature required to access certain functions
10BREW
- Using C/C as the host language
- Excellent performance (applications run as
compiled native code) - Small target application size and little overhead
- High ceiling (can access all the capabilities of
the phone) - The only widely available native API for
non-smart phones - Steep learning curve
- Bad UI library
- More costs for the development environments and
the development process - Hard to debug (different behaviors between the
simulator and the real device) - Troublesome coding restrictions
- Signature required to run any applications on a
cell phone
11Flash Lite
- Flash Lite 2.x similar to Flash 7.0
- Excellent IDE/Emulator support
- Powerful functions for animation/vector graphics
- Low learning threshold
- Low runtime performance
- Hard to access functions not provided, low
ceiling - ActionScript Stuck
12HTML, WAP/WML
- Available on almost all cell phones
- Low learning threshold
- Easy to debug (functions implemented on the
server side) - Low ceiling
- Limited interactivity function support
- Almost impossible to access local resources of
the cell phone - High latency, requires network connection
13Windows Mobile Embedded Visual C
- Excellent performance
- Intermediate learning curve for existing C/C
programmers - Relatively steep learning curve for non-C/C
programmers - Easy to access hardware features
- Excellent UI framework and UI builder
- Excellent IDE/debugger support
- Excellent emulator support
- Limited device penetration
14Windows Mobile .Net Framework Compact Edition
- Medium to Good performance
- Low learning threshold
- Excellent UI framework and UI builder
- Excellent IDE/debugger support
- Excellent emulator support
- Extra space overhead (2 mb)
- Limited device penetration
15Symbian C
- Excellent performance
- High learning threshold
- Reasonable UI framework
- High ceiling
- High market share among smart phones
- Poor IDE/debugger support
- Troublesome coding restrictions
- Poor simulator support
- Limited device penetration in the U.S.
16Symbian Python
- Poor performance
- Low learning threshold
- Reasonable UI framework
- Relatively high ceiling
- Poor IDE/debugger support
- Poor simulator support
- Additional runtime overhead (gt 1mb)
- Limited device penetration in the U.S.
17Palm
- Huge paradigm shift between version 1.x 4.x and
5.x - Only device specific simulator after 5.x
- Gradually becoming obsolete
18Android and iPhone
- Android
- Customized version of Java (between Java desktop
and J2ME) - Good UI framework (when compared with J2ME)
- Limited media capture capability as J2ME
- Calling native functions is discouraged
- iPhone
- HTML AJAX based web app running on browsers
- Native app (Objective C)
19Native Code vs. Dynamic Script
- Native Code
- Excellent runtime speed
- High threshold, high ceiling
- Easy to access the low level hardware
- Difficult to program and difficult to debug
- Dynamic (Interpreted) Script
- Slow runtime speed
- Easy to learn, low ceiling
- Easy to debug, easy to share
- Hard to access extra features of the hardware
- Can we take advantages of nice things from both
approaches?
20Embedding Scripts to the Host Application
Host Program
color RED b button label OK, x
10, y 20
Embedded Interpreter
Wrapped Library
21Choice of the Embedded Script Engine
- Lua is a powerful, fast, light-weight, embeddable
scripting language - Originated in 1993, now developed by Lablua
- Designed as a lightweight embedded script
language - A leading scripting language in the games
industry - See www.lua.org
- Has been ported to BREW, Windows Mobile and
Symbian
22Approximate Runtime Performance
- Not intended to be a comprehensive evaluation
- Benchmarking programs (sorting, factorial
computing, string operations)
23Some Sample Codes
function HelloWorld () io.write ("hello
World") trace ("trace working now")
end HelloWorld()
function fat (n) if n 0 then return 1
else return nfat(n-1) end end
Function max(a, b) local m a if b gt a
then m b end return m end
1 MOVE 2 0 0 R(2) R(0) 2 LT 0 0 1
R(0) lt R(1) 3 JMP 1 to 5 (41) 4
MOVE 2 1 0 R(2) R(1) 5 RETURN 2 2 0
return R(2) 6 RETURN 0 1 0 return
24Easy to Switch Between both Worlds
LIBSHELL_API int LibSHELL_MessageBoxText(lua_State
L) const char szTitle (const char
)luaL_checkudata(L, 1, AECHAR_TNAME) const
char szText ( const char )luaL_checkudata(L,
2, AECHAR_TNAME) ISHELL_MessageBoxText(GETAPPSH
ELL(), szTitle, szText) return
0 lua_register(L, messageBox",
LibSHELL_MessageBoxText)
Exporting the ISHELL_MessageBoxText function from
BREW to the script
Void FireEvent(int id, const char args) if
(g_strEventHandler ! NULL) char
buf254 SPRINTF( buf, s(d,s),
g_strEventHandler, id, args)
lua_pcall(luaState, buf, LUA_MULTRET, 0)
return
Calling a lua function (event handler) from C/C
25Scaffolding Mobile Development via Script
Embedding
- Average users
- Use form-guided code generation templates to
customize an application - Download and share new functions
- Group development
- Only one member responsible for C/C
programming, expose additional native functions
to script programmers via glue function - Other members fast prototyping in script
- Runtime performance sensitive application
- Identify performance bottlenecks in the script
implementation, reemployment them in C/C and
export them to the script
26Summary
- Building applications for cell phones is
challenging due to highly diversified environment
and toolkits - Trade-offs between low learning threshold and
high ceiling need to be carefully considered - Script embedding is a solution to leverage nice
features from both worlds
27Thanks!