rapid and expressive prototyping on cell phones via script
TRANSCRIPT
Rapid and Expressive Prototyping on Cell Phones via Script Embedding
Jingtao WangComputer Science [email protected]
Agenda
Motivation Challenges in creating cell phone app Overview of popular mobile development
platforms Low threshold and high ceiling, the script
embedding approach Summary
The Popularization of Cell Phones
Cell 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
Opportunities and Challenges of Cell Phones
The bright side Portable, always with you Always on, always connected to the internet Seamless integration with one’s 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
Threshold and Ceiling
Sophistication (Ceiling)
C/C++
Goal
HTML
Difficulty(Threshold)
MFC/Qt
Flash
ActionScript
Component Framework
An 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
An 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
J2ME
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
BREW
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
Flash 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”
HTML, 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
Windows 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
Windows 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
Symbian – 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.
Symbian – Python
Poor performance Low learning threshold Reasonable UI framework Relatively high ceiling Poor IDE/debugger support Poor simulator support Additional runtime overhead (> 1mb) Limited device penetration in the U.S.
Palm
Huge paradigm shift between version 1.x – 4.x and 5.x +
Only device specific simulator after 5.xGradually becoming obsolete
Android 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)
Native 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?
Embedding Scripts to the Host Application
HostProgram
EmbeddedInterpreter
color = REDb = button { label = ‘OK’, x = 10, y = 20}
Wrapped Library
Choice 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
Approximate Runtime Performance
Vs. Runtime Speed Runtime Memory
C/C++ 1/5 ~ 1/12 1.0 ~ 1.5
Python 1.9 ~ 3.5 2.1 ~ 3.3
JavaScript 2.3 ~ 18 1.7 ~ 9.7
•Not intended to be a comprehensive evaluation•Benchmarking programs (sorting, factorial computing, string operations)
Some 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 n*fat(n-1) endend
Function max(a, b) local m = a if b > a then m = b end return mend
1 MOVE 2 0 0 ; R(2) = R(0)2 LT 0 0 1 ; R(0) < R(1)3 JMP 1 ; to 5 (4+1)4 MOVE 2 1 0 ; R(2) = R(1)5 RETURN 2 2 0 ; return R(2)6 RETURN 0 1 0 ; return
Easy 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(GETAPPSHELL(), 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 buf[254]; 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++
Scaffolding 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
Summary
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
Thanks!
Any questions?