PDA Application Walkthrough

Walkthough and screenshots of a PDA application development effort using the .NET Compact Framework, Embedded VC++, Embedded Visual Basic, Pocket Studio, and more.

This spring I created a site-inspection data collection PDA application for an Oasis Digital client. The first phase of that project was to build working prototypes of each part of such a system, in order to demonstrate what kind of application we will be able to create, and to bring my own skills up to date with current PDA development tools (my previous PDA work was a few years ago using the C/C++ Palm development tools). The prototype was a success, and led to a development effort for a system now deployed in production.

Along the way I learned a lot of things about the various tools for PDA applicationdevelopment, made a few dozen screenshots, and posted them here:

PDA Application Walkthrough

Attacking Code Duplication in Java

An important principle of XP is that duplication of ideas in source code is to be avoided. I gave a talk at the XPSTL group on this topic.

On Feb. 5, 2003, I gave a talk at XPSTL about code duplication in Java. The presentation is available for download here, as well as the plain text of it. If you download the presentation, you’ll find the code snippets inside. The samples did not come along for the (very rough) plain text export below.

http://kylecordes.com/files/OAOOinJava.ppt

Attacking Code Duplication in Java

Kyle Cordes

Oasis Digital Solutions Inc.

XPSTL

Feb. 5, 2003

Once and Only Once

z OAOO is shorthand for the principle that each idea should be expressed exactly once in the source code.

z A tenet of XP

z Predates XP, a good design principle

z Not specific to OO development

A Quote…

“So, duplication sucks. The more rabidly a person hates duplication, the more I trust their opinions on managing information. A programmer, upon noticing some redundancy, should be thrown into a panic, begin hyperventilating, and stammer something about “¡El diablo! !El diablo está en mi software!”.”
from:

http://groups.yahoo.com/group/testdrivendevelopment/message/185?viscount=100

Why Not Duplicate?

z Duplication is not just inconvenient.

z OAOO is not an “architecture astronaut” nitpick.

z Duplication is a clear sign of bad information management and complexity management.

z Building large systems consists significantly of complexity management and dependency management.

Why OAOO?

z OAOO makes systems easier to change.

z OAOO holds back entropy.

z I admit – I follow that quote. I use hatred of duplication as a barometer of design skill.

How Do We Achieve OAOO?

z Usually by refactoring code that contains duplication.

z Usually, a little bit at a time.

z However, when doing or evaluating up-front design, OAOO is a excellent criteria to apply.

Spotting Duplication

z Sometimes it’s obvious

z Other times it’s subtle

z Kent Beck is known for being able to see extremely subtle duplication, refactoring the code to make it clear duplication, then removing it.

Examples and Techniques

z Trivial duplication can be removed with Extract Method, adding a variable, etc.

z Some duplication is harder to address – we’ll look at examples and techniques for attacking it.

z These slides outline the ideas, we’ll do a few examples “live” in the presentation.

Tools to Achieve OAOO

z Anonymous Inner Classes

z Create a class hierarchy

z Command Pattern

z Replace Case with Polymorphism

y Code Generation

y Dynamic Proxies

y Replace class hierarchy with runtime relationships

Fighting a try / finally

z (One solution on the next slide.)

z Simple try / finally example…

z multiple try / finally example…

Anonymous Inner Classes

z They’re not just for Swing listeners.

z They are Java’s version of code blocks (Smalltalk, Ruby).

z Example…

Create a Class Hierarchy

z Raise the duplicated code to a base class.

z Example…

Command Pattern

z (Also the Template Method pattern)

z Base class has a doFoo() and abstract realFoo()

z Descendants have a realFoo()

z doFoo() wraps realFoo() with whatever code would have been duplicated.

“Heavy Lifting” to Achieve OAOO

z Replace class hierarchy with runtime object relationships

z Replace application code with code generation

z Dynamic Proxies

z Aspect Oriented Programming – makes it much easier to remove many kinds of duplication.

Replace Class Hierarchy…

z An extreme step, not in the XP sense

z Useful when a previous designed has created a great number of “glue” classes that don’t contain much information

Code Generation

z The essence of code generation is to have a specification, and set of rules for producing code.

z Example: the many support and utility classes, coded in a formulaic way, in a typical EJB application

z Example: O-R persistance code

z Example: GUI code

What about Generated Duplicated Code?

z This doesn’t bother me – I only care about duplication in the checked in code

z If it bothers you, nearly every problem that can be solved with code gen, can be solved with a dynamic mechanism instead.

z (Note – Don’t check in generated code. Please.)

Adding a Field

z As an example of large scale duplication issue… if you want to add a field to some entity in a typical J2EE application, how many places in the code/configuration do you need to touch?

Duplication in Legacy Systems

z Legacy systems often contain extensive duplication

z Can we find some in JBidWatch?

Normalization

z OAOO in software design, is closely related to normalization in DB schema design.

What About Tests?

z Sometimes I find that things are duplicated between test code and production code.

z I’m not comfortable with this…

z But sometimes getting rid of it seems to negate the point of the test.

Discussion Topics:

z More examples, anyone?

z War stories?

z What additional / different tools does C# have to offer?

z Why do we see so much duplication in software?

z What about people who like duplication?

Code Examples

z These are some snapshots of the code we worked through during the presenation.

Starting Point – Parallel Loops

Extract Methods

Anonymous Inner Class

AIC, with Template Method

Lessons Learned

z AICs are the Java syntax for blocks / closures.

z AICs are really ugly syntax compared to Smalltalk, Ruby, etc.

z OAOO techniques sometimes create code that non-expert Java developers find very hard to fathom.

z The syntax is a big pain for small examples, but OK in real apps.

THE END

Slides will be on my site:

http://kylecordes.com

Introduction to the Ruby Language

Presentation and notes from a talk on the Ruby language to the St. Louis Unix User Group.

On June 12, 2002, I gave a talk at the St. Louis Unix user group introducing the Ruby language. The presentation is available for download here:

http://kylecordes.com/files/IntroToRuby.ppt

The text of the presentation, without useful formatting also appears here, so that search engines (particularly the one I need to add to this web site) will be able to find it.

We don’t use Ruby much (yet?) at Oasis Digital, but there are some interesting and useful ideas in it; I recommend looking it to expand your exposure to what’s possible in language design, even if you don’t need or plan to use yet another scripting language.

Addendum: Oasis Digital’s resident “Pythonista” pointed out that like Ruby, Python now supports multiple inheritance and garbage collection (not just reference counting).

Continue reading “Introduction to the Ruby Language”

Now Forming: St. Louis Delphi User Group

In addition to Java and other high-profile tools and languages discussed on the site, Oasis Digital makes good use of Borland Delphi for Windows client applications. I’m interesting in forming a St. Louis Delphi User Group. (For those
of you around the world, this means the St. Louis, MO, USA metropolitan area.)

The first step is to attempt to find some developers and firms using Delphi in St. Louis. I don’t know if there are 2 or 2000 Delphi developers in the area, partly because many firms that use Delphi are rather quiet about it.

To facilitate communications, I set up a Yahoo Group… please join it:
http://groups.yahoo.com/group/delphistl/

Test Intensive Development in Delphi

Slides from a Birds of a Feather session at BorCon 2001

At the 2002 Borland Conference, I presented a “Birds of a Feather” session on Test Intensive Development in Delphi. A couple of dozen people attended, in spite of the early morning time slot. Most of the attendees were new to test intensive development, though a few were experienced in it and shared useful tips.

My introductory talk and demo was adversely impacted by a technical problem with the projector and missing microphone; hopefully this slightly expanded set of slides will fill in the gaps that caused.

Download TID-Delphi-BOF-Borcon-2002.ppt

A Content Management System

I generally say that reinventing the wheel is not a good idea. Sometime’s it’s an educational experience, though!

KCMS is Kyle’s Content Management System – a working name for the content
management system which “powers” this web site. It is an early work in progress, “version 0.1”
system. I put it together last fall to facilitate updating this site more easily.
It is composed of two parts:

On the web server, a few kilobytes of PHP code extracts content from a database,
applies a template, add in other elements (such as the advertisements), and thus
renders the page.

Unlike many other CMSs, the admin / authoring application is a
Windows application – not a web application.
It is shown here.


First, a login screen. This is logging in to an Interbase server on my machine;
I edit everything here, then push it to the production machine when it’s ready.
Although currently only I am editing content, this system would support multiple
users easily.


I use Internet Explorer as an ActiveX control for the "home". In
a business app, I would display some meaningful data there – some kind of current
snapshot of the problem space. For example, the number of orders placed so far
to day, month-to-date sales, etc. For the CMS I could indicate things like how
many articles need to be uploaded to the server.


The find / list screen is not all that helpful yet – it only filters on two fields (title and
full text), and sorts on one field at a time.


This is the above screen, filtered to articles that mention Delphi in the title.


Here are the details for one article / piece of content. This screen again
uses embedded IE to display a preview of the content. It uses the same style
sheet as the real web site, so the fonts and spacing match.


Right now, the only editing control is straight, un-high-lighted HTML. The
"edit content in DW" button launches DreamWeaver to edit this item
there. I may also provide an ability to launch GVIM or another HTML-aware editor
for syntax highlighting later.

Were this a commercial app, I could get a syntax highlighting component for Delphi
and provide good HTML and passable WYSIWYG. For an internal-use system,
using DreamWeaver works quite well.


The client software can connect to both the local development database and
the production database, and copy all updated data to the production system
on the web site. An alternative solution would be to apply templates and
generate static HTML locally, then FTP it to a non-database-equipped web
host. That would be quite useful for people who don’t want to pay for and support
database-capable web hosting solution.

That’s where I am so far. It’s all quite alpha – certainly many hours of work
would be needed to polish it up. It’s good enough to start using for content
though, so that’s what I did.


Motivation and Observations

Why did I do this, instead of just using FrontPage or DreamWeaver?

  • It’s my mechanism, I can add hooks as needed.
  • The template is stored just once, and applied as needed. This is a nice
    parallel to desirable software engineering practices, since it lets me tell
    the computer about the page layout "once-and-only-once".
  • The content is stored without any template applied. DreamWeaver applied
    each template "statically", so what I updated a template it would
    update every single page on the web site.
  • I can apply more than one template to the same content (i.e., printer-friendly
    version of each page). Because of the above points, I was able to add the
    "printer friendly" feature in less than an hour, and it works on
    every page powered by the CMS.
  • I can query the data, and automatically show the most recent additions on
    the home page, list everything on the listing page, etc.

What about other Content Management Systems?

Frontier / Manila looks quite nice, but I host all of this on a Linux machine.

I looked at a number of "open source" content management systems,
and it seemed like the effort to customize them to do what I wanted could easily
exceed the effort of building this from scratch.

Background on the URLs Used

When looking at some existing CMS systems, one of the things that bothered
me was the URLs they used. For example, I saw that BroadVision uses URLs like
this:

http://www.broadvision.com/OneToOne/SessionMgr/services/services_svp.jsp
?BV_SessionID=NNNN1165913018.1004016458NNNN&BV_EngineID=cccca
dcdgllkkdfcefecefedghhdfjl.0&serviceType=SolutionValueProposition&
channelname=Solution+Value+Proposition&channelRuleset=Services+Channels
&program
Name=Solution+Value+Proposition+Overview&programRule
set=Solution+Value+Proposition+Programs

Fortunately, I cannot afford Broadvision 🙂 . I suppose all of those characters in the URL
cost a lot of money.

With some excellent feedback from the St. Louis Web Developers’ user group
and elsewhere, I ended up with URLs like this:

http://sitename.com/story-NNN-other-text-here.html

The NNN is a number, and the other-text-here is a very short summary of the
page topic / title. These URLs have several advantages:

  • The look "static", so there is no risk of a human or search engine
    confusing them with per-user content (like a shopping cart, etc.)
  • They are short, and can be emailed without wrapping to multiple lines.
  • The CMS can key off of just the NNN part, so as I change page titles, old
    bookmarks will still work.
  • The URLs feel "harmless" to the end user who sees them.
  • There is some indication of the page content in the URL, which is quite
    helpful is a URL somehow becomes separated from its descriptions. I think
    this is superior to the approach used in Frontier Manila or in Vignette, both
    of which only have an identified.
  • It’s trivial to map these URLs to the proper content generation script using
    Apache’s mod_rewrite.

Why PHP?

PHP is ideal for small, simple needs like this. Although I use Java heavily
for enterprise web application development, the effort to install
and support a Java solution would not be justified for this app at this time.
The server part of this software consists of 2-3 PHP files and nearly zero installation
effort. I’ve implemented and personally deployed a number of Java web applications,
and it would still take me a good while longer to get such a solution running
here.

Why a Windows application for the authoring / admin?

Most content management systems use a Web interface for the administration
/ authoring interface. I found that I can build a good interface much more quickly
as a Windows application than as a web application – so why bother? I don’t
have any need at all for widespread, zero-deployment access to the admin interface.
I do have a need to work on the content when not even connected to the Internet.
Therefore, a Windows app was a good solution for my problem.