Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Channels ▼

Al Williams

Dr. Dobb's Bloggers

Android on the Block

April 15, 2011

It is pretty well known among my associates that I am a curmudgeon in certain areas. For example, I keep waiting for this window, icon, mouse, pointer fad to die down (there's a reason the acronym is WIMP). Somewhere in the back of my mind I know it isn't going to happen, but I still merrily churn away at a keyboard most of the day.

Of course, I may be a curmudgeon but I'm not an idiot. There are some things, like word processing or debugging, where I do like a GUI (although I'm still not much on the mouse unless I simply have no choice). But what about programming? How graphical should a programming environment be?

This has come up before. In fact, the first time I had to think about this wasn't really about traditional programming, it was about hardware design. A lot of people — especially curmudgeons — who try their hand at FPGA design initially eschew languages like VHDL or Verilog. We'll just draw schematics! Graphical! However, if you do anything significant, most people quickly realize that even though you might know how to draw a 7 segment decoder as logic gates, it is way easier to just write a case-style statement in Verilog and let the compiler work out all the AND and OR gates required. So very few people who work on FPGAs and ASICs really use schematic editors for their design.

What got me thinking about this recently was Android programming. I've written a bit of Android code — which is really just Java on Linux with some ready-to-go class libraries from the programmer's perspective. Android is (at least in recent versions) efficient and runs on power-conscious commodity hardware. So I expect to be seeing a lot more of Android in the high-end embedded space.

All the code I've written up to last week used the Java/Eclipse-based Android Development Kit (ADK). I miss emacs, but I can limp through Eclipse and my distaste for GUIs does not extend to the point that I want to hand code interfaces in XML or Java, so if I'm building a screen. I want the ADK. But a few weeks ago I got interested in Google's App Inventor, which bills itself as a way for non-programmers to write apps.

At first glance you have to figure that something like that won't be very suitable for embedded systems, and it probably isn't. But it could be. The system looks very much like the Lego Mindstorms environment that I've used before working with kids in robotic classes. It even has Lego Mindstorm components that let you control Mindstorm stuff from your Android device.

But the school kid robotic classes are another place this discussion has come up before. How many of us use point-and-click software development tools? Are we doing kids a favor by teaching them Mindstorms? I usually mix some Basic Stamp code in so they get to see some "real language" that isn't overwhelming, but what if that's just me being a fuddy duddy? Is graphical building of programs going to take over? Does that really let people build things without knowing about programming?

I decided I wanted to take a look. After all, while I have my little anti-GUI streak, I'm not unreasonable. I gave up troff and I even had a grudging respect for the NeXT Interface Builder and IBM's Visual Age tools. The result is that I wrote two applications using App Inventor. I even posted them on the Android Market (although officially App Inventor doesn't support the Market). These are not really embedded applications — unless you want to do Mindstorm, App Inventor is not really up to the task. But it could be and I wanted to gauge if it was worth further investigation.

I had tried, actually, to play with App Inventor before. But the cheap Android tablet I had did not have a way to do USB debugging. You can debug fine over the network, but for some reason App Inventor really wanted to see me connected to the USB port. You can develop on App Inventor and use an emulated Android phone to test your software. But that's no fun. Besides, the really cool things like GPS and speech either aren't on the emulator or you have to do odd things like telnet into the emulator and feed it fake GPS coordinates. But a few weeks back I got a tablet with a proper USB debugging interface, so I was in business.

They say a picture is worth a thousand words. I’m not sure a graphical representation of a program is worth a thousand lines of code, but just in case, have a look at the figure below. This is from the program I'll walk through in my next blog. Don't worry about the overall program just yet.

[Click image to view at full size]
Figure 1.

App Inventor is actually three different parts. There is a part you download to your computer. I'm using Linux, but they have a download for that (as well as the PC or the Mac, if you are so inclined). The actual "main program" is on the Google Labs website. So the "development environment" is actually a web application. This page is where you build your screen. In theory, you can only have one screen, but in practice you can put multiple containers on a screen and hide all but one to simulate having multiple screens.

The third part of App Inventor is the "block editor" and that's what you see in the figure. This is actually a Java program that runs via Java Web Start. The block editor is where all the programming (and live debugging) occurs.

The left hand pane of the block editor has two tabs: Built-in and My Blocks. These are the statements and objects, roughly. In the Built-in palette you can drag things like string operations, math operations, and variables into the work area. The My Blocks palette has an area for variables and functions you define, as well as a menu for all the components you placed on the website. Most of the components are visible (like buttons or labels) but a few are not (like clocks, or a persistent database object).

The key to reading the graphic is the color and shape of the blocks. So the green "C"-like items are events. Inside the "C" are blue boxes that represent assignment statements, and purple boxes that are function calls. You can graphically associate comments with blocks (the question mark on the box will expand to a comment).

In the figure you can see that there is a variable (blue box) named "thenum." Unfortunately, at this time all variables are global. Even worse, subroutine parameters are really just global variables. So if I have a function called X that takes parameters Y and Z, I really implicitly defined global variables named Y and Z!

Moving down in this partial program, you can see a click event for a button that makes some assignments and a procedure call. The little minus sign at the lower left of the event lets you collapse the display to make things more readable. The Clock1.Timer event, for example, is in the collapsed state — you can't see the code inside unless you "open it" by clicking the little plus sign.

So for this installment, this is a good stopping point. I'll avoid drawing any conclusions until I'm done so as not to taint your opinions; we'll compare notes at the end.

If you want a preview of the two applications I'll dissect, you can find them on the Market at https://market.android.com/details?id=appinventor.ai_al_williams.RecallNum and https://market.android.com/details?id=appinventor.ai_al_williams.Pushy. Both are simple games — I don't think App Inventor is up to serious embedded work yet. On the other hand, it is somewhat difficult, but somewhat extensible so if you really wanted to, you could make it do almost anything. The question is: Do you want to?

Next up: An Android App in Three Easy Pieces

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.