Removing TStringList where possible...

I have just done a little exercise where I created a typed list of Tshoved_timber objects, using Generics.

uses
System.Generics;

Tshoved_timber_list = class( TObjectList<Tshoved_timber> )
end;


Using the TObjectList provides 2 main benefits:
  1. The list is typed - no typecasting required to access the items in the list.
  2. The list owns the contents - no need to free individual list items, just the list itself.
I did have to add a new string field to the Tshoved_timber class to hold the name.

I then went through a refactoring exercise, which was mostly quite mechanical, changing all the references appropriately. The main thing I will say is I deleted quite a lot of duplicated code and generally simplified things significantly.

Once we have a repository, I would hope we could have a good discussion regarding overall design and look at what changes we can/should make to improve the overall design.

Regards,
Alistair Ward.
 
_______________
message ref: 452

Martin Wynne

Admin
Location
West of the Severn UK
Info
Please do not send requests for help direct to me via email.

Post your questions on the forum where everyone can see them and add helpful replies.
Hi Alistair,

As you may have noticed, TStringList is my go-to component for almost everything.

I started Delphi with Delphi2 which didn't support TObjectList, it was introduced in Delphi5. There was a TList in Delphi2, but it didn't then support the OwnsObjects property, which defaults to True in the TObjectList descendant.

When I switched to Delphi5, I could have changed to using TObjectList more often (and several other new things, such as dynamic arrays). But my approach has always been "if it ain't broke don't fix it", and that would be my instinct now with Tshoved_timber_list too. I always ask myself whether time spent has actually advanced the functionality of Templot an inch. If making code more elegant was important, I would be gone from now until Christmas. :)

My switch to Delphi5 was essentially for one reason only -- Delphi2 didn't support the mouse wheel. Just writing that now makes me realise how ancient everything is.

p.s. to use TObjectList in Delphi5 and other old versions of Delphi it needs to be

Code:
uses
  Contnrs;

Are you using Lazarus, or a modern version of Delphi?

cheers,

Martin.
 
_______________
message ref: 472
Hi Martin,

I have been using Lazarus, as I don't have access to a company-provided license for Delphi any more. It's been about 10 years since I used Delphi as the my main development language. These days I use mostly C++ at work, and have grudgingly come to appreciate it. On the other hand, I would be completely lost if I was asked to write a Windows GUI app in C++ :-(

I think the crux of the problem with Templot is in these 2 comments:
But my approach has always been "if it ain't broke don't fix it"
and (from the Version Control topic)
Templot developed over 40 years, originally for my own use only, by bolting bits on as and when I needed them, and then unbolting them, or bits of them, and bolting them on somewhere else, or something else in their place. Some bits were tied on with string. It's the original Meccano tea trolley which morphed into a combine harvester, with bits of hovercraft attached, and it's all still exactly the same.

In software development we talk quite a lot about "Technical Debt", which basically refers to code that (maybe) works, but is not elegant or well designed. We regularly go through our code looking for instances of this and working on improving it. Does it add functionality for our users? No. What it does do is keep our code tidy(ish), and gives us a reasonable chance of adding new features without breaking too much else in the process... In the long run, that is a win for our customers.

So that is why I am keen to work through the code tidying things up. It doesn't add any functionality, but it makes the code easier to understand and therefore easier to make changes without breaking things.

One of my favorite sayings (which I pass on to all the junior staff I work with) is "The primary purpose of source code is to explain to the next developer that looks at it (which could be you in 6 months time!) what you intended to do. Creating an executable program is just a useful side-effect"

Cheers,
Alistair

ps. I got your email re Sketchboard - I'll think on that one a bit before jumping in to anything.
 
_______________
message ref: 475

Martin Wynne

Admin
Location
West of the Severn UK
Info
Please do not send requests for help direct to me via email.

Post your questions on the forum where everyone can see them and add helpful replies.
the next developer that looks at it (which could be you in 6 months time!)

Hi Alistair,

Only 6 months! I'm still looking at code I wrote 40 years ago. :)

If I changed it now I would be lost.

For example this function name and 2-character parameter names come from an 8-bit version of Basic from 1979, and have never been changed:

function f28000(aq:integer; xs,ys:extended):integer;

(28000 was the line number)

What's interesting is that the code embedded in the ROM chip for that version of Basic includes the line:

(c) W. H. Gates

cheers,

Martin.
 
_______________
message ref: 479
My first computer was about that vintage as well... but I don't remember if it had that copyright notice. In my case it was a Dick Smith System 80 (clone of the TRS-80, possibly sold as Video Genie in the UK?)

Cheers,
Alistair.
 
_______________
message ref: 492
Top