Dear
Software Developers,
This CPTTM Software Developer newsletter is to bring useful news to
you, software developers in Macau, for references without obligations,
so that you can do your jobs easier and better! Hope you like it. if
you'd like to unsubscribe or recommend your friends to subscribe, just
email me at kent@cpttm.org.mo.
Old issues are available here.
Topics in this issue:
Open source cross platform SDK for
mobile devices - including Apple's iPad!
There are now two huge application markets growing
very fast - Apple iPhone and Google Android. Still thinking which
platform you should choose? Don't worry about it because Appcelerator
has just released 1.1.1 version of Titanium SDK which is open sourced
and free to use. It could help you build your app with one code and
both platforms. Titanium mobile version supports both iPhone and
Android, even though the coming hottest mobile tablet - Apple iPad.
Basically Titanium is built on top of the web
technologies - HTML5, JavaScript and CSS. Titanium provides its API
which plays as a bridge between the application and the OS. You could
access Database(SQLite)
or File system in those HTML files which you cannot do in normal
JavaScript running in sandbox inside the browsers. HTML is used to
build the application interface. Here are some highlight features
provided by the APIs:
- Touch screen input, gesture and accelerometer
- Media playback
- Facebook integration
- Mobile phone contacts
- Map and Geo-location
- SQLite and file system access
You might think it is again a kind of "write once
run anywhere" cross-platform framework. Actually, Titanium have two
versions: Desktop and Mobile. Instead of offering a dream of "write
once run anywhere", Titanium is more like you could have shared code
and logic among different kind of devices like PC/Mac and mobile
phone/tablet devices. Nowadays, there are more and more applications
running on cloud -- that means those web-based applications are really
potential to offer more advanced solutions to deliver
experiences across the devices using shared code and interface,
services, and APIs.
You could give it a try that if you are a
experienced developer and you are familiar with JavaScript and HTML.
Because Titanium SDK only provide build and packaging tools and there
is no fancy debug or development IDE. You might use your own favorite
HTML editor to do the coding and Titanium SDK will build the native
executable for you target platform. The good part is that it seems to
be integrated with Android/iPhone SDK very well so you could launch
your code in the simulator to test your app.
UPDATE: Apple released an updated SDK for the
upcoming iPhone 4.0 OS, it forbids developers from accessing Apple's
APIs through any sort of intermediary layer that translates code not
officially supported by the platform. Executable generated by Titanium
might be banned from iPhone OS 4.0 or above.
Debugging
a hanged Java app with "kill -3" in Linux
Recently I found Tomcat hanged at startup
and just couldn't start it up properly. What to do then? There is a
very simple way to find out what a Java application is doing (on Linux
platform). First you have to find the pid of Tomcat's JVM
process:
ps -aux
| grep tomcat
The second column of the output is the pid
of Tomcat's JVM process.
kill -3
PID_HERE
"kill" command actually is used to send a signal
to a process. The second parameter switch is the signal. "kill
-3" actually lets JVM know you want it to print the stack trace for
you. The stack trace output could be very usually to debug a remote
Java app. In my case mentioned above, from the stack trace I found one
of the web app was waiting for the response of a SQL statement. It was
Hibernate trying to update schema when there are other connections to
the database. So it kept waiting.
Whenever you wonder what an app is running, you
can do it to find its stack trace. How cool it is!
Ref: http://java.sun.com/developer/technicalArticles/Programming/Stacktrace/index.html
Flex
4 is out of beta!
Flex 4 is finally out of beta. Flex 4 SDK is
available for all platforms and Flash Builder 4 (formerly Flex Builder)
is currently only supported on Windows and Mac OS X. The Flex SDK open
source and free to download. You could download the trial version of
the Flash builder 4 or you could purchase for the Premium Edition.
Flex 4 SDK focus on improving the new components
architecture (Spark), which has better way to customize stylish and
skinning creation. In Spark, you will see that the component function
and its looks and feel are separated so the component logic is divorced
from component visuals that you could customize a component in a
straightforward manner. It just like you customize a submit button in
HTML using CSS file. There is a similar skin file introduced in Flex 4
which contains only styles and appearing makeup using FXG. In the old
days, you have to do coding to custom to do so. If you want to know
more, you could check out this 15-minute-long video here: http://labs.adobe.com/technologies/flash/videos/flashcamp/subra_ruehle/ .
The video shows how to make a skin file without coding a line of
ActionScript.
For the Flash Builder 4, we could see lots of
improvement and they are listed in Andrew Shorten's post (What's new in Flash Builder
4). One thing is very interesting is that Flash
Builder 4 supports Adobe Flash
Catalyst. Since developing a RIA project, the interface
design is very important part. Flash Catalyst brings wire framing which
is kind of rapid prototyping a RIA interface without putting too much
visual detail at the first time. So developer could do some exploring
and demo to customer before getting designer to work on the visual
design. The tool is claimed that you could prototype an
interactive interface without writing code. After prototyping, designer
could work on the graphic design and finally developer could import the
Flash crystal project into Flash Builder. This proposes a better work
flow for RIA development. Check out 10-minute-long video about wire
framing: http://tv.adobe.com/watch/adc-presents/wire-framing-in-flash-catalyst .
As we could see Adobe try to emphasize their
"Flash powered" platform by renaming the product name. Flash player
penetration has reached above 95% of Internet-enabled desktop PC. If
you are targeted to deliver your application on different platforms as
wide as possible, Flex definitely a good choice to invest on. CPTTM
will open a Flex course in mid-April , check out here: Rich
Internet Application(RIA) development with Flex 3 .
Flex 4 is backward-compatible so the course could help you have a good
start on Flex.
Crazy “comma-first”
JavaScript style
In normal coding style, we usually will put a
comma at the end of a line. This is how we usually declare variables in
multiple lines in JavaScript:
// standard style
var
a =
"ape",
b
=
"bat",
c
=
"cat",
d
=
"dog",
e
=
"elf",
f
=
"fly";
Recently I saw some
people suggesting "comma-first" style like this:
// comma-first style
var
a =
"ape"
,
b =
"bat"
,
c =
"cat"
,
d =
"dog"
,
e =
"elf"
,
f =
"fly;
So why they are suggesting this? I didn't notice
any good at the glance and it looks a little odd to me. But eventually
I found that the errors are popped in this style:
// error in standard style
var
a =
"ape",
b
=
"bat",
c
=
"cat"
d
=
"dog",
e
=
"elf",
f
=
"fly";
// error in comma-first style
var
a =
"ape"
,
b =
"bat"
c
=
"cat"
,
d =
"dog"
, e
=
"elf"
,
f =
"fly"
;
See? In line 3, variable c is missing a
conman after it, the error is quit easy to see in comma-first style.
Debugging JavaScript is hard since there is no mature IDE for you. You
don't need to compile the source, so you might hard to find the missing
comma among the lines. You could find more examples about comma-first
style here: http://gist.github.com/357981.
Another advantage is that if you put your codes in
source control, you now only have to add lines instead of modifying
them:
var a =
{ x1: "a"
, x2: "b"
, x3: "c" <-- just one line added,
no need to place comma on previous line and modify it
};
I also found this
could prevent extra comma in array declartion:
//
standard style
var a = [
123,
345,
567, <-- hard to find, the extra comma is
an error in IE
];
//
error in comma-first style
var b = [123
,345
,567
];
If
you always encounter this, just give this a try. I believe this could
also apply to some dynamic languages such as PHP.
Upcoming courses for software
developers
Feedbacks
Any questions, ideas or experiences to share? Contact me at 28781313
or kent@cpttm.org.mo. We also
have two other newsletters: CIO newsletter
and Network
administrator newsletter,
your friends may like to subscribe.
Until next time,
Kent Tong |