Tuesday, September 16, 2008

Delphi 2009 = A good test of my backup strategy

I installed Delphi 2009 today. In a fit of enthusiasm, I installed it onto my Delphi 2007 virtual machine...

That turned out not to be such a smart move. Not only did d09 fail to install (stopping 1/2 way through with a 'failed to find setup.msi' error), but it trashed my d07 install as well. I don't know how bad the trashing was, I killed delphi after the 10th "package not found error" on start up.

I am not blaming CodeGear for this, my D07 install was "customised" to fit on a small virtual machine, with several, possibly important, folders deleted, and with little free space remaining.

One of the many nice things about using a virtual machine is the ease of backups and recovery. In this case, it came down to a 2 step process
  1. Copy fridays backup onto the computer
  2. Use subversion to retrieve all the files changed since friday
Total elapsed time to recover was about 10 minutes, most of which was spent making coffee while waiting for the files to copy.

Moral of the story: If you are installing D2009 (or any other version), put it in a virtual machine.
And use version control
And backup regularly

Monday, August 18, 2008

Programming for the iphone really sucks

Ogrampray, ergo sum. I program, therefore I am.

I have wanted to program nearly every device that I own (except for video recorders).
Now that I have an iPhone, I want to program that. Unfortunately there are a number of roadblocks in the way...

NDA
The iPhone nda is ridiculously draconian. There are enough posts on the subject that i won't do into details. See here if you want to know how developers feel about it. Basically, you need to figure everything out yourself coz you can't ask anyone else. There are still discussion groups, but they may be gone tomorrow. There is also a series of tutorials at IphoneSdkArticles.com but that may also disappear.

Objective C
ATM, your choice of development language is Objective C or Objective C.
If you are a windows developer, you first question is probably "Wtf is Objective C?". The short answer is that it is yet another version of C with objects, designed by someone with an unholy fascination for square brackets. The average line of code contains slightly more text than symbols, but only just.

ObjC is primarily used on Apple machines, and sits at #42 in the tiobe list, just below Erlang.

Because it is Apple only, the development tools only run on OS X (you can use gcc on windows, see here, but it's not easy). The tools may be free, but you need a $1000 OS X machine to run it on.

The sdk license expressly forbids interpretors, JITers and iPhone based compilers. So the only way to get java or mono is if they develop an ahead of time complier. Here's hoping.

Multitasking
Nope, sorry, you don't need it. Applications run full screen, single window. When the user presses the home button, your app exits. To get back to your app, the user needs to start it up all other again. This immediately rules out a large number of interesting applications, and adds a certain amount of complication to development. As an aside, Windows Mobile does exactly the opposite and minimises applications rather than closing them, so they can reopen more quickly. This approach is also arse.

Application sandbox
Each application is stored in a single folder. All files, settings and related documents are stored within that folder. The application can only access the contents of their folder. There is no concept of a user documents folder. There is also no simple way to get documents onto the phone for use by your app.

Example: I have an ebook on my computer. I would like to read it on my phone (I have kids, I spend a lot of time sitting in the car waiting). On a windows mobile machine, a palm, or even my old Psion S5, you copy the file over onto your machine, and open it. On a iPhone, it's not so easy, Using ereader, I need to upload the ebook to their website, and then download it again on the iPhone. Alternately, they helpfully suggest, I can run a web-server on my PC.
On the other hand, the Stylus and Bookshelf book readers provide desktop software (50meg download, written in java) that will let you copy documents over using wi-fi. If I ever need to transfer documents when I don't have a wi-fi router, I am in for a large amount of aggravation.

So, if you are writing a app that needs to work with documents, you also need to write a client/server file transfer application, in a different programming language, just to get you document where you can use it!

Distribution
As a means of getting your application to a large number of paying punters, App Store is not too bad. The 30% commission is high compared to Paypal, Regnow, SwReg etc, but low compared to phone/pda specific sellers such as Handango. However as a means of distributing your app to a specific group (ie company wide as opposed to world wide) it is less useful.

Positives
There are some good points about iPhone development though.
  • The hardware is essentially the same (+/- 3g, gps) on every device. This is a significant contrast to Windows Mobile where the screen size and orientation can change, there may or may not be a touch screen, camera, gps, wi-fi, internet etc).
  • Appstore makes purchasing applications dead easy. I suspect that iPhone users will end up with more applications than windows mobile users.
  • The development tools are quite polished, and cheap if you already have an Apple machine.
  • The phone has lots of useful functionality. GPS, wi-fi, accelerometers, camera etc. I can't think of any other phone that has sold as well and has as many toys to play with.
  • The xcode development tools can also deal with C++ and C code, although the sdk is in Objective C.
If you are a Apple developer, developing for the iPhone is a no-brainer. For a windows developer, it is a much harder decision.

Links
NDA comments
SDK Discussion group
iPhone SDK Articles
Wikipedia on objective C
iPhone Development on Windows

Friday, August 15, 2008

Subversion add-ins for Delphi

Part 4 of a n part series on Subversion and delphi

Subversion add-ins
As we have already established, TortoiseSvn adds version control functionality to windows explorer. This is all good, and the result is quite functional. Many people need nothing more. However for the rest of us, there are a number of ways to integrate subversion into delphi.

File Browser
If you have a recent version of delphi, and have TortoiseSvn installed then you get integration for free. The File Browser window (View menu -> File Browser) uses the Windows Explorer context menu so all TortoiseSvn commands also work with the File Browser



JCL Version
The jedi control library (jcl) includes a Tortoise (Svn and CVS) add-in that adds a JCL Version menu. Most functionality is available, although I have never managed to get Diff working. It requires Tortoise to be installed. If you are already using Tortoise and the JCL, it's a bit of a no-brainer.




Others


There are a few others that I haven't used.
  • Delphi Svn is available from SourceForge. It looks like it doesn't need Tortoise to be installed.
  • The gloriously named delphiaddinfortortoisesvn is available from tigris.org, home of TortoiseSvn. As you might expect, it requires Tortoise to be installed.

Links
Tortoise
Jedi Control Library
Delphi Svn
Delphi Addin (Tigris)

Monday, July 28, 2008

Common tasks with Subversion

Part 3 of an n part series.

General workflow for version control

The following descriptions all use TortoiseSVN and Explorer. The steps can also be done using other Subversion clients such as DelphiSvn or JCL.

The general workflow for changing code is:
  1. Update. Right click on your base development folder and choose TortoiseSvn -> Update.
  2. Resolve conflicts
  3. code like a demon...
  4. Test, test and test
  5. Update (again). As 1, just in case someone else has changed things
  6. Resolve conflicts (again)
  7. Add (also Delete and Ignore as required)
  8. Commit
Notes:
  • Solo developers can normally leave out steps 1,2,5,6
  • Steps 7 and 8 can be combined (check the "Show unversioned files" box in the commit dialog)
For a solo developer, the process essentially comes down to
  • Commit. Do Adds, Deletes etc from commit dialog
Now isn't that easier than zipping up all your source code and archiving it.

Traps for young players
  • Deletes and (particular) Renames should be done from within Explorer/Tortoise.
  • Do commits from the base directory where possible. If you commit further down the tree, then you need to do an update before you can commit from the base.
(Edit) Team Version Control
One thing I didn't point out first time round (thanks Lars).
The golden rule of team version control:
Only check in working code to the trunk.
If you are working it a team environment, and you want to commit non working code then create a branch. That will let you have all the benefits of version control without annoying everyone you work with. Once you have completed your changes, merge your changes back into the trunk. See the manual for details.
Also, Sean's rule number 2 (for team programming):
Always update before you commit ()
If you commit without an update first, the code in the repository may not be the same as your code. That means that you don't know that the tests pass, and the code still compiles.

E.g. Bob changes the signature of DoSomething to take an extra parameter. It's in a file that you haven't touched, so there are no conflicts. All of your code uses the old signature so when you commit, it won't compile any more.

If you update first, you can catch the problem and avoid making a fool of yourself. This sort of scenario can be quite common with larger teams. Don't ask me how I know.

Manual
All Tortoise commands are available from the Explorer context menu. See here for the manual.

Saturday, July 26, 2008

Subversion server options

I didn't cover subversion servers in my last post as I don't use one any more. However there have been some queries so here are a few ideas:

Windows installers
VisualSVN Server
official Svn 1-click setup
Other OS

VMWare appliances
Subversion and WebSVN on Ubuntu Server
SVN VM
vmTrac

Online hosting
Cvs Dude
Google search

I am not endorsing any of these. However, if I needed a server, I would probably go with one of the online solutions.



Monday, July 7, 2008

Starting out with Delphi and subversion

I am always disturbed by the number of programmers I run into who don't use version control. A version control system (VCS) is one of the fundamental tools of a programmer, up there with the ide/compiler, bug tracking and backups.

Subversion, together with the TortoiseSvn plugin for Explorer, is one of the better free VCS solutions available. What follows is a quick guide to setting it up the easy way.

Note: This setup is not suitable if you have a large number of users, or need to provide access across the internet.

Tortoise and Subversion

Subversion is the actual VCS. Typically you would run it as a service and then connect to it with client software such as Tortoise.

Tortoise adds context menus and icon overlays to Explorer allowing control of the VCS. These menus and overlays are also available in programs that use the Explorer menus and icons such as the Delphi File Explorer.

Other clients for Subversion are also available.

If you only have a limited number of users, and do not need remote access, you can use Tortoise without a subversion server. This makes set-up much easier. I am not going to cover setting up the server here, primarily because I haven't used one for 3 years.

My file structure

I have 2 base folders, D:\dev and d:\devother.

D:\devother\ is used for files that are use different version control settings (ie open source projects that I update from their repository such as tiopf).
D:\dev\ is used for everything else; my code, third party components, images etc. Having everything under one folder makes version control easier.

I recommend moving all source under a single base folder, if it is not already. If you have source on a network share, move it into a base folder on a local drive. If you need to share source, place the repository on a shared folder.

Repository

The repository is where the versions are stored. It has a directory structure similar to a file structure.

The subversion book recommends having the following directories at the repository root

/branches/
/trunk/
/tags/

With this layout, your main development takes place under /truck/. Branches and tags go where you would expect. I don't do a lot of branching and tagging, when I do I place the branch directories along side the main project directories instead. Therefore I don't bother with the initial directories and create branch directories as required.

My layout is more like

/components/
...
/projects/
/projects/project 1 v1/
/projects/project 1 v2/
...

This maps to my file structure of

d:\dev\
d:\dev\components\
...
d:\dev\projects
d:\dev\projects\project 1 v1\
d:\dev\projects\project 1 v2\
...
etc

It is reasonably easy to change from one repository layout to another if you change your mind, so choose whichever structure makes sense to you..


Setup
  1. Download and install Tortoise from here.
  2. Open Windows Explorer
  3. Create an empty folder to serve as your repository. This can be local or on a network drive. The location needs to be reasonably safe and easy to back up.
  4. Right click on the folder and click on "Create repository here"
  5. Choose "Native filesystem"
  6. If you want to set up /branches/, /tags/ and /truck/ directories, right click on your repository folder and choose TortoiseSvn -> Repo-browser. Right click on the root directory and choose "Create Folder" for each of the initial directories.
  7. Right click on any folder and choose TortoiseSvn -> Settings
  8. In the Global ignore patterns, enter in the file types that should be ignored by default. Ie things like map files that will (almost) never need to be under version control. I use "*.dcu *.~* dcu temp *.exe *.zip *.bkm *.ddp *.cfg *.dof *.dsk *.ini *.hlp *.gid *.bmp *.png *.gif ~* *.log bin debug release *.map *.chm *.bkf Thumbs.db *.mdb .obj *.elf *.stat *.ddp *.bpl *.map *.GID *.hlp *.opt *.dll *.raw *.BIN *.obj *.pdb *.scc Debug Release *.xml obj *.~* *.backup *.INI *.ArmLog *.KeyLog *.NanoLog *.Stats *.PreARM *.old *.drc *.*~ *.doc *.pdf *.bmp *.jpg *.MRW *.NEF *.ORF *.psd *.X3F __history *.local *.identcache *.bak Thumbs.db *.ldb *.dex *.rar DllDcu *.lck CVS cvs *.txt *.TXT *.jdbg *.HLP *.KWF *.xls *.cnt *.dsm *.dti *.tmp *.lnk *.cbk *.mes"
    Note that the patterns are case sensitive.

Initial Import
  1. Back up your source code!
  2. Right click on your base development folder (I use d:\dev\) and click on "SVN Checkout"
  3. Click on the browse button beside URL and navigate to the repository directory (if you have set up a /trunk/ directory, navigate to this).
  4. Right click on your base development folder (d:\dev\ in my case) and choose TortoiseSVN->Add.
  5. Wait for the Add dialog to populate. The first time it is used, it can take a while to populate. Work your way down the file/folder list.
    If there is something you don't want to add now, uncheck the selection box.
    If you never want to add it, right click on the item and choose "Add to ignore list"
  6. Once you are happy with the selected files and folders, click OK.

    The files are now all added to version control. However they have not yet been saved (committed).
  7. Right click on the base development folder again and choose Commit.
  8. Provide a message.
  9. Uncheck any files you don't want to commit at the moment and click OK.

Your files are now under version control. You can revert to any version, perform diffs, see what files are changed and perform all other sorts of good things.

Version controlled files are marked to indicate their status. A full list is given here. The main ones are
  • Committed: Check mark
  • Added: +
  • Changed: !
  • Deleted: x



To come
I will do followup posts explaining
  • How to work with files on an ogoing basis
  • Various delphi integration options

Links
Subversion http://subversion.tigris.org/
Subversion book http://svnbook.red-bean.com/
Tortoise http://tortoisesvn.tigris.org/

Saturday, June 21, 2008

ti Object persistance framework updated

What's up?

v2.50 of tiOPF is now available at http://tiopf.sourceforge.net/

So what's tiOPF?

tiOPF is a Object Persistence Framework. That is, it is a framework based around saving your objects to, and loading them from, databases and/or flat files. See the overview for more details.

In a nutshell it lets you do things like:

var
user: TMyuser;
userList: TUserList;
...

user:= Tuser.CreateNew;
user.FirstName:= 'Sean';
user.LastName:= 'cross';

user.Save;

...
userList:= TUserList.Create;
userList.Load;

for user in userList do
...


tiOPF handles the saving and loading of objects to databases and flat files. You can swap between databases by initialising a new persistence layer.


Why should I care?

  • tiOPF lets you code in objects rather than datasets (you can still use data aware controls though). This gives you more object orientated code
  • tiOPF provides database independance
  • Better code reuse. Because the persistance is separated out, you can use the same code across different databases and structures
  • Easier unit testing (in my experience anyway). I find it much easier to setup objects and test them that to setup databases and test.

Links

Home page: http://tiopf.sourceforge.net/
Overview: http://tiopf.sourceforge.net/Doc/overview/index.shtml
Newsgroups: http://tiopf.sourceforge.net/Support.shtml