Posts categorized “Software Development”.

When and why you should be using Threads

When and why you should be using Threads:

Quite often I see people making programming mistakes that will cost them dearly in the long run. They’ll do things like use App.DoEvents to keep UI updating properly, or they’ll make their program inaccessible by leaving tight loops run with no way to cancel them. These situations are perfect examples of when you should be using a thread.

Aaron Ballman has written a couple of posts about using threads in RealBasic, wish he’d written them a couple of days sooner as I’ve just recently made a couple of changes to CaseDetective using threads to help make the interface more responsive while grabbing data from the database.

My changes have turned out pretty good, working well, and a lot simpler in the end than I thought it might be. But I’ve still learnt a couple of things from Aarons post, in particular I’ll be changing my code to use a “MessageReceiver” to do the progress bar updates. That was a great idea Aaron, thanks!

He mentioned he might talk about resource management between threads and how to properly use the locking mechanisms REALbasic provides, which would be useful. I had to work out how to use semaphores myself because I was getting conflicts whereby the interface was in the process of updating from new data but another thread changed the data it was trying to use. Bang! OutOfBoundsExceptions all over the place! One App.DatabaseAccesssSemaphore signaled as soon as a thread started to run, and released when finished and all was back in control. And I didn’t really lose any responsiveness in the GUI.

Me likee threads!

Update (2005-09-02): Aaron has now written a nice article on Locking Mechanisms In REALBasic.

(Via Ramblings.)

CaseDetective Beta2 is out!

Finally, I’ve managed to work around all the connection problems users of CaseDetective Beta1 were having, and added a few other little fixes and cosmetic updates too.

It’s a little late at night (actually early in the morning) for me to launch into a review of what I’ve been up to over the last few weeks, but I will do so in the next day or so.

Time for bed me thinks, need some energy just in case anything is amiss with Beta2. Catch yer later.

Brain Muscle

I’ve been on a mad coding frenzy the last few days, trying to get CaseDetective finished, so every night I’ve been putting in between 4 and 5 hours of solid development time. It’s been great, really getting along nicely, although I’ve had to drop a few features that are just too tricky to implement well in the time I’ve got before I want to ship, I’ll see if they’re asked for before adding them to the schedule for a future release.

Why’s this post titled “Brain Muscle” you ask?

Because, as I’ve been putting in some serious time into development with RealBasic every night at home, when I sit down at work each morning (yes, I still have a day job) and start coding in Informix 4GL or SPL I start off trying to write in a RealBasic style!

I keep tripping over myself by trying to hit tab to auto-complete variable and function names while coding Informix 4GL in vi! Also, I’m forever forgetting to use the 4GL “LET” statement when assigning values to variables as RB doesn’t need such an archaic statement (and nor should 4GL, it’s predecessors didn’t, so why does 4GL?). There are many other little brain muscle things that I have to shake off each morning.

I wish I had all the trappings of a modern and well executed editor for coding in Informix 4GL as I do with RealBasic. I do use vim rather than straight vi, so I do at least get syntax highlighting which is nice, and I’ve got my .vimrc file setup to auto capitalize the Informix reserved words (you can do this with a .exrc for normal vi too). But my time spent using the RealBasic IDE (and I’m only using v5.5.5, haven’t even moved on to the spiffy new RB2005 yet) has made me realize just how much more efficient I could be if I had the right tools.

I wonder what coding EGL in Eclipse for WebSpehere is like, I’ll probably never find out though as the trial download is over 2.5Gb in size! Besides, I see myself using RealBasic more and more in the future, it’s just plain fun to use!

Tiger Tiger Tiger Tiger Tiger

So, I’ve ordered my copies of Mac OS X Tiger for desktop and server, have you yet?

However, I’m in a quandary, when should I actually install it on my main development desktop, and when should I implement the server?

The geek in me wants to install both as soon as I get them (hopefully before or on the 29th April), but the more sensible side of me says that would be a bad idea, and that I should wait for a couple of things to happen:

First “point” release out and tested.

It’s already known that there are a couple of fixes that didn’t make it into the “gold master” release of Mac OS X Tiger, and that they will be implemented in the first point release, how many other fixes might there be once this very large update is out in the wild?
As far as I’m concerned Apple always releases quality software and hardware, I’ve only ever stumbled across a couple of very minor problems with their products. But this is a huge release, there’s bound to be some creases to be ironed out. Can I afford to lose any of my data or time to such issues? Panther gave me no troubles, but will Tiger?

All tools/software verified as working on Tiger.

It could take a very long time before all the software I use is either verified as working fine on the released version of Mac OS X Tiger or a new release built and verified for it.
My biggest concern is of course RealBasic, and in particular RealBasic 2005 which is due out in the next couple of months. RealBasic is what I’m using to build my own software, so I really do need to know that it works well with Tiger, whether I need to wait until v2005 is out before running on Tiger, will v5.5.x work OK on Tiger? Will the software I build with RealBasic on Tiger work on Mac OS X Panther, all the normal versions of Windows and Linux (if I decide to support it), or should I stick with Panther for a while? Will the software I build on Panther be OK on Tiger? Will the first release of this huge update to RealBasic that is v2005 be stable from the get-go too? There’s a lot of uncertainty there for me.

For the first time I’m going to start running my desktop Mac as a full blown server, I just can’t resist having Mac OS X Tiger as my main server in the office, dumping my trusty (but old) mini-itx based Debian Linux server. I’m really looking forward to the account management aspects and Portable Home Directories which I had real problems with on Linux, but hope that Tiger can do simply. Hopefully then my PowerBook and PowerMac will be in sync every time I re-connect, and it looks like this will include all my music, pictures and everything else in my home directory, which is way cool (gonna take some lengthy syncing at first though).
This is obviously going to be quite a shift, I’m really looking forward to all the tools OS X Server brings to the table to make configuration a breeze. I also have a lot more disk space in my PowerMac than in my current Linux server, four 120Gb disks compared to the single 120Gb drive in my mini-itx box, and I’m thinking it might be good to configure them as a couple of mirrors for safety, hopefully I can do that during install, but I don’t know for sure.

So it seems I have a lot of questions, and these may take some time to be answered, let’s hope I get some reassurances before the 29th, because I’m just not sure whether my sensible side will be able to hold my technology lusting geek side back!

The joy of desktop apps

Having linked to DrunkenBlog’s interview with Brent and Sheila Simmons last night, I’ve just downloaded MarsEdit and given it a whirl. Wow, I love desktop applications, what a difference it makes to be able to post to my blog without going to my website.

This is why I think CaseDetective for FogBugz will be useful for a number of people, desktop apps just have so much of a nicer feel to them, you can do so much more, and quicker too. For example, I’ve got spell checking as I write this, no more copying to Word (yes I use MS Word on my Mac, so what of it?) just to check my atrocious spelling.

So, what’s CaseDetecive I hear you ask? CaseDetective for FogBugz is the application I’m working on, a desktop companion to FogBugz by Fog Creek.

My intentions are that CaseDetecive allow me (and anyone else who may be interested) to extract data from FogBugz and generally dig a little deeper than you can with the current release (4.0). I want to be able to extract to Excel or similar apps various fields that meet various criteria (filters), and I think there are quite a few others who would like to be able to do the same too.

I’ve got a lot of ideas for what I want CaseDetective to allow me to do beyond just extracting data, but I’ll talk about that a little further down the line. If anyone reading this is a FogBugz user, and has any ideas on what they would like to be able to do from a desktop companion app, please add a comment to this post. All suggestions are very welcome!

Lost Focus, Now Regained

I’ve been suffering from a spell of lost focus recently, just haven’t managed to get going on developing my app, and have been having some (continuing) problems in deciding on the app’s initial feature set.

This is probably one of the most common reasons in delaying and possibly even killing a new product, because if you don’t know what the product is trying to achieve, and for whom, you lose focus and start developing features that may be irrelevant and really have no product as you have not properly identified the market.

With Christmas and a faulty video card on my development box introducing some time away from development for the best part of the last month, I’ve had some time to re-think my product’s focus, who I am making the product for and what features they are going to want. However, what I’ve really come to believe over this little hiatus is that I’m wasting way too much time thinking about extended features, when in reality until people start using my software and giving me feedback I don’t really know what the customer wants, I can only think I know, even if I am a customer myself. I’ve said all this before, but this time I’m being ruthless in applying these principles.

So, I’m chucking a lot of my ideas for the future out the window, and am going to concentrate on the few features that I want now, and think others also want now (deduced from posts to forums etc). At the moment I’m the only customer I can talk to, so I’m going to satisfy my needs first, and wait for feedback before spending time on any further features.

As part of this re-focus I’ve designed a much better user interface, having some time away from the project and in particular using a few apps that I really enjoy using has made me realise that I was going down the wrong route, I was complicating the interface when I could really do a lot better with only a handful of controls. I was going to be using tabs to separate different views of the data (remember, this is primarily a reporting/data view tool), but this was a bit clunky and meant the user would need to use at least two clicks to change their view of the data, with a lot of eye movement in hunting down items to select in a newly visible tab. There are better ways to do this, there might be a slight increase in clutter in a particular control but subtle use of colour and visual separators can help the user quickly find the area they are looking for.

Anyway, tonight I’ll be back on the development box and ripping the app apart, I think I have a fair bit of work to do now, but less than I would have if I hadn’t re-focused my view of the apps future, I’ve got my confidence back and am seriously excited about getting down and dirty with the code again.

Been Doing A Bit Of Housekeeping

How do! It’s been a couple of weeks since my last post, in that post I said I was going to take a week to re-consider my application’s internal architecture, which I did. I’m now ready to proceed with a pretty heavy clean out of the app, moving some of the code out from gui objects into some sub-classed classes that can be re-used as and when.

Before getting stuck into my “re-design” I had a quick re-read of some of the RealBasic User Guide, which turned out to be an extremely useful thing to do. I had read a couple of posts on the NUG that discussed Interfaces that piqued my interest. Interfaces are an area of Object Orientation that had totally confused me before; I just didn’t understand what their use was. It seemed to me that they were just an inconvenience, why would you make more work for yourself by creating interface classes that didn’t actually do anything, and then have to code those interface methods in any object that “implemented” that interface? Well, it turns out that this concept of interfaces is very useful indeed (yeah, I know, why would it exist otherwise :-) ).

By creating some specific interface classes, and setting some objects to implement them, you can automate a lot of the relationships between objects, because of the fabbie IsA operand (in RealBasic). For example, say you have a gui object, a button say, and when pushed you want your program to go to the database and grab the latest data, and then all the other gui objects on that window should refresh to show that latest data. In normal programming you could end up writing a lot of code in that button’s action method or some other object’s method that specifically references those ListBoxes and other gui controls that need to be refreshed. Whereas if you use the concept of interfaces you can pretty much automate this refresh without any specific references to objects, which is great when you want to change the controls on your window etc. If those ListBoxes etc were actually a sub-class of ListBox, and also “implemented” a “DataConsumer” interface for example, and that interface had a function called DataAvailable, then an object that provides the new data could loop through all objects that are of type “DataConsumer” (e.g. IsA DataConsumerInterface) and call their DataAvailable methods so that they can refresh themselves. And, because the objects that implement the DataAvailable method of the DataConsumerInterface could be of pretty much any type of object, they could have very different ways of using the available data, but your DataProvider doesn’t care, it just tells the objects to do what they like with the data. This chaining of interface methods could go quite deep, here’s a noddy little example method calling chain:

Button.Action –> DataProviderInterface.GetData –> DatabaseInterface.GetData –> DataProviderInterface.DataAvailable –> DataConsumerInterface.DataAvailable

There could be many of the objects at the end of a “–>”, each getting called in turn to do whatever is required purely because they are of the right type (i.e. implement a specific Interface). This means your application gets quite loosely coupled internally, objects start providing services to others in a fairly loose knit way.

So, I’m really starting to see the benefits of Interfaces, it’s kind of a way of implementing your own Events scheme. That was week one.

Week two, I didn’t actually get around to coding any of these changes. Because I realised I needed to pull a lot of my code out into new classes, I also thought it might be prudent to change Source Control Manager (SCM) software, as CVS just wasn’t going to cut it. Why? Because I’ll no doubt be creating a number of external objects while refactoring my code, and that may including renaming them occasionally, and CVS is rubbish at that, history isn’t going to be maintained, and I would like to keep that.

So, I went on a World Wide Wander in a search of a better SCM than CVS. The obvious upgrade would of course be Subversion, and I looked long and hard at it, and didn’t like what I could see. It doesn’t matter what some people say, there are dependencies that I can’t deal with, and I’m just not quite comfortable with it’s maturity just yet, and I guess I don’t like the idea of using a database to store the code. I just have some funny feelings about SVN, so I’m staying clear for the moment.

I used c2.com and Version Control System Comparison to get a head start, whittling it down to a few candidates, including (but not restricted to) GnuArch, Monotone and Perforce.

I’ve used GnuArch before, and really liked it, but it’s a bit fiddly, and the tools are a pretty basic, I was looking for something a little more mature and with a few nice gui interfaces.

I’ve not used Monotone, and was tempted, but I’d have to build it (I’m using Mac OS X which doesn’t have a binary available), and frankly I don’t have a lot of time to go learning what seems to me to be a fairly complex application. And again, I couldn’t see any nice gui programs for it.

So, I’ve gone for Perforce, and so far, I’m totally over the moon with it. It was an absolute delight to set up, just dropped a couple of binaries in my path (/usr/local/bin) and started up the server with a couple of environment variables set to tell it where I wanted to store the data. And that was it really, the Command Line Interface (CLI) is a doddle, very straight forward to use, but also very powerful, and there is a pretty good gui app too. And to round it all off, it’s got one of the best web interfaces I’ve seen. I like the fact that the meta-data is kept separate from the actual source control, and I particularly like that the source is held in RCS files, makes it really simple to extract from if I should want to change SCM, I trust RCS. It may be a little out of my budget to buy (even though it is pretty cheap), but thankfully it’s free for two users, and there’s only one person in my company, so I’m covered!

So, this week I are be mostly getting my code into shape, honest!

Brent Simmons gave me a sleepless night.

I had a really sleepless night last night, and it’s all down to Brent Simmons’ Black Box Parsing post on his weblog.

Why am I blaming him? Because it finally brought to the fore that I really need to clean up my code and make it far more object orientated (OO), something that has been nagging me for quite some time.

I’m afraid I’m a bit of a perfectionist, and this is probably one of my biggest sources of procrastination, something I realised just recently when listening to The Procrastinator’s Handbook: Mastering the Art of Doing It Now. Wanting to do something perfectly, is most definitely the reason I procrastinate the most, the idea of not getting something done to a high standard creates a lot of fear in me, and can stop me in my tracks.

However, I’ve already developed some of my application in a way which is congruous with OO development, and each time I add a new feature or need to modify a bit of code, I improve it a little and usually move it towards better using the OO features of RealBasic, probably because I’m learning so much more each time I sit down and start developing. I’m now at a point though that I really need to clean up a core part of my project, there are some new features I want to implement and can not do cleanly and efficiently with the current layout and communication between the data model, gui objects and controlling functions (see what I did there, Model-View-Controller :-) ).

What’s really bad is that I’ve been fully aware of the benefits of the Model-View-Controller (MVC) pattern for a year or two, since I first started looking at development on my Mac. Objective-C is a great OO development platform, and I’ve played with it and run through a number of tutorials and created a few play apps using the great free IDE called XCode on OS X, usually using the MVC pattern. So, why is it I didn’t use MVC properly from the outset when I started doing some serious development? Who knows, maybe I’m just lazy, or maybe I’m not lazy enough to use the productivity gains when OO is used to its full potential. Or maybe, I just got carried away and fell into the trap of whipping up a quick prototype, but not enforcing the fact that it really was a prototype and that it should be thrown away and developed afresh correctly with longevity in mind. Mind you, there are some people that believe a prototype should never be thrown away, that it should simply be improved upon and brought up to scratch rather than writing off the investment in it. I think I may go down the hybrid route; I can easily save elements of my project as classes, and even enforce this in my mind by making them external classes that can be picked up by other projects if I wish. This will help me get started in shifting the code around to get rid of some of the dependencies I built in between the model and view, and allow me to work on parts individually and swap in improved objects as necessary. That’s where the Black Box approach really comes in handy.

So, I’ve decided that next week will be an architecture design week, I will sit down and design the architecture of my app properly, making sure to keep the model, view and controllers separate, and to ensure that I allow the application to use different models without changing anything in the view, and only adding one hook in one of the controllers. I want to make my app able to switch between different database schemas with so much ease that I can quickly and easily add new models as new databases come to market in the area I’m targeting.

Should be fun, and once I’m happy with my design I may start sleeping properly again, until the next big idea hits that is!