Delphi Handbooks Collection


Delphi XE Handbook


Delphi 2010 Handbook


January 17, 2009

A Goto, After so Many Years

I've found a "goto" in a program, after so many years.

Today I was helping to finish converting a massive application (500,000+ lines of code, without counting custom components) from a multi-tier COM based architecture to a single-tier packaged based one, and found a couple of interesting tidbits:

  • One was that among the 1,000+ warnings I was randomly looking at I found a couple of real bugs caused by uninitialized local variables. I don't get developers who let warnings pile up and never look at them.
  • Another think was a classic use of a goto statement. When I noticed the label declaration after the var block of a function my eyes and brain translated it in a variable called label... but after a fraction of a second I was amused to realized this was a real goto in a real program. Pretty save, I have to say, as it was a "goto endofcode" that could have been easily coded using Exit.

Overall, though, I was impressed to be able to make the conversion and help remove the 150KB type library that was cuasing errors on some computers and was comprising hunddreds of interfaces implemented by a huge numebr of remote data modules... and convert this into runtime packages changing a minimal amount of code (as we kept GUID to identify servers, fake internal registrations, and more more).

As I'm spending some time converting applications from COM architectures, this might be worth a white paper, but that's another story.

PS. I badly want to comment on the new Delphi compiler plans, hope to have time next week, as the last 10 days have been quite hectic.





 

10 Comments

A Goto, After so Many Years 

Delphi is a huge and very mature tool that does it 
all, even goto statements. I look forward to "pure 
functions" and similar constructs in the future, which 
will make Delphi 2007 source code look very old 
fashioned, very quickly. Delphi 2009's Unicode and 
Generics already did that.
Comment by Lars D [http://compaspascal.blogspot.com/] on January 17, 01:18

Uninitialized local variables 

Good you brought that topic up. D2009 seem to have
(IMO quite serious) bug about functions that return
strings. In old Delphi, as much I remember, function
result was empty string by default and you did not
need to initialize the result each time as Result :=
'' but when calling such function from loop in D2009
you get unexpected result when you are not
initializing result by yourself. And of course
compiler does not warn about uninitialized result
variable of string type.

For example see my QC post at
http://qc.codegear.com/wc/qcmain.aspx?d=68249 but
seems CodeGear is not that much interested.

Just a warning to these who migrate old code to D2009.
Comment by Ahto T. on January 17, 12:25

A Goto, After so Many Years 

I use goto's in Delphi code once every blue moon... 

Last time was in a highly optimized routine where I
needed to jump out of two while loops at once and it
did give me an extra 2% of performance. Given the need
for optimization there, a goto was the way to go.

I am glad that in Delphi you can use a goto when needed!
Comment by Ritsaert Hornstra [] on January 17, 13:25

A Goto, After so Many Years 

a new delphi compiler plans...

- 64-bit?
- smart device?
- CROSS PLATFORM SOURCE CODE???
Comment by ahmoy on January 17, 16:58

A Goto, After so Many Years 

It's sad that remoting was never implemented well in 
Delphi, often never upgraded since Windows 95 days, 
making "old" C/S attractive.
I am working right now on an application where the 
multitier model fits very well due to its requisites, 
but building it with Delphi is becoming overly 
difficult, because many DataSnap bugs and limits are 
surfacing too often.
And while MS rolled out WCF, all Codegear could do is 
to build a stored procedure-like way of calling 
remote functions.
IMHO the "enterprise" features of Delphi are rapidly 
weaking, some database drivers, a very limited 
Datasnap, and a non-connection limited Intraweb no 
longer justify the "enterprise" name, when tehre 
desktop verion of high-end databases, and 
apache+PHP/Python/Ruby gives you all the Internet 
power one needs.
Comment by Luigi D. Sandon on January 17, 17:46

A Goto, After so Many Years 

Ahto - as you yourself note in the QC report you give,
the behaviour described is found in D7 too!  So, it's
hardly a bug (if indeed it is a 'bug') specific to D2009.
Comment by CR on January 18, 00:31

Sorry 

Yes, I forgot that the problem was in 7 as well. But
IMO it is a bug anyway, no matter if it is old. :)
Comment by Ahto T. on January 18, 01:52

Converting from COM to packages 

I would be very interested in reading about converting
from COM to runtime packages.
Comment by Mark [] on January 21, 20:54

N-Tier to Single tier? 

I didn't get it. Back in 1995 everything was single
tiered. Then we went to 2, 3, N-tiers. Now we are
going back?? Could you please tell me more about the
reasons, the benefits?
Of course, as you have mentioned, there were some
obvious bugs in the code causing problems. I guess
that the bad behavior of the application was not
caused by COM or the number of tiers itself, was it?

Best regards
Comment by Alexandre Machado on January 22, 01:11

A Goto, After so Many Years 

I never used goto in Pascal code, but there are many
goto's in the VCL sources. Eg. open
Generic.Defaults.pas to find the implementation of
something like C-switch operator without breaks using
goto's.
Comment by Serg on January 22, 09:16


Post Your Comment

Click here for posting your feedback to this blog.

There are currently 0 pending (unapproved) messages.