The joys of old code

I’ve been playing around with Delphi ever since high school.  I took a Pascal programming class and thought it was a really cool language.  Shame you couldn’t do visual programming with it, though.  (I was really into VB at the time.)  Then a buddy of mine introduced me to version 1 of “this new Visual Pascal program” and it was love at first byte.  But I didn’t get real serious about Delphi until about three years ago, when I decided to dust off an old pet project of mine from the D7 days, a tool I created for the purpose of making team collaboration easier for RPG Maker 2000 projects.

Continue reading ‘The joys of old code’ »

Delphi memory management made simple

Most of my posts on here have been about technical subjects, geared towards moderate-to-advanced Delphi coders.  This one’s to help out the beginners who are still learning the ropes.  I’d like it to be something that people can send new users to from StackOverflow or other sites if they’re having trouble figuring out how to clean up their memory properly.

I’ve never really understood why people find memory management difficult.  Maybe I just “get it” for some reason, but it’s never seemed all that arcane or complex to me.  In all my time working with Delphi, I’ve only run into one truly difficult memory management scenario, and it’s something that most people won’t ever have to deal with: sharing global interface references across package boundaries.  If you do that wrong, you’re likely to run into some very strange errors at program shutdown that are hard to debug.

But people keep asking questions about the basics of what to free and how to free it on StackOverflow, and from answering them and analyzing the questions and the answers, it seems to me that the entirety of memory management can be boiled down to one single principle.

Continue reading ‘Delphi memory management made simple’ »

Closing the documentation gap

This morning on StackOverflow, someone asked a question about invoking constructors through extended RTTI. It happened that I’d had to work out a way to do that a couple weeks ago, and it took me about 5 minutes to find the code, strip out a few specific details and type up a solution.  I got an accepted response, a few upvotes, and a very interesting comment from the author:

Continue reading ‘Closing the documentation gap’ »

TValue is very slow!

Delphi 2010’s help describes TValue, used by the RTTI unit to store values of arbitrary types, as “a lightweight version of the Variant type.” I saw that and it made me wonder, how lightweight is it? How fast is using TValue?

Thankfully, among D2010’s lesser-known new features is the Diagnostics unit, which gives us TStopwatch, a simple record for timing operations. That makes it very easy to write a simple speed test.
Continue reading ‘TValue is very slow!’ »

The Tragedy of Steel

Sorry if this is a bit long and off-topic, but it’s incredibly important to anyone who makes computer use a significant part of their lifestyle. Please, read this and pass it on. Link people to this post, or copy it and repost it yourself.*  Translate it into other languages if you have to. Everyone on the Internet needs to read and understand this.
Continue reading ‘The Tragedy of Steel’ »

How to break the D2010 compiler

I really loved when Delphi 2009 came out, how it fixed so many ugly problems in the Delphi IDE.  The stability issues and memory leaks that plagued D2006 and D2007 were greatly reduced.  And it just got better in D2010.

The tradeoff, though, seems to have been compiler stability.  Trying to do anything with Generics in D2009 before Update 3 came out was a nightmare, and even after, (and even in D2010,) there were still plenty of dark corners where you can end up with an Internal Compiler Error or linker error on something that, syntactically speaking at least, is perfectly cromulent Object Pascal.

Continue reading ‘How to break the D2010 compiler’ »

Random musing: TStringList

A while back, Jim McKeeth told me (jokingly, of course) that with a TStringList and a TDataset, you can solve any programming problem.  He also likes to compare TStringList to a Swiss Army Knife, because it can do so many things.  And it sort of made me wonder.  Continue reading ‘Random musing: TStringList’ »

Learning Delphi: A true story

It’s pretty common where I work to go out to lunch together with other coworkers. We’re located downtown, right across the street from a major shopping mall and with plenty of restaurants within walking distance. A few months ago I was out with a few of the other coders, and one of the guys, David, told the story of how he got into programming. It made quite an impression on me. You’ll see why. Unfortunately he’s no longer with the company, so I can’t get the exact story from him to retell here, but I’ll give the idea of it here.

Disclaimer: Even when I give the story from his perspective, they aren’t exact quotes by any means. My memory’s real good, but not that good! But this is the basic idea of what he said, with no ficionalizing.

He wasn’t originally a computer programmer. Hadn’t even really studied it in college. David’s degree was in accounting, and he was working as an accountant with an insurance company back in the 90s. He explained, “They had a tuition reimbursement program set up with the local college. You could take classes there, and as long as you got a B or better at the end of the semester, they’d pay you back for the courses. The tuition was several hundred dollars per course, so you had a pretty strong incentive to do well in them!

“Anyway, I was working with this insurance company, and my job was to take care of custom policies. They had this thing where they’d write out custom policies for all the small businesses in the area, which were all more or less from the same template but with a bunch of cudtomized details tailored to each one. And every month I’d get this big stack of a few hundred sheets of printer paper and have to crunch all the numbers. It was annoying, really tedious work.” We commiserated with him about how much that must have sucked, as we sat there waiting for our orders to arrive.

“After a while I got them to give me direct access to the database to read these values from, instead of giving me a printout from it, and that helped a bit, but there was still a lot of stuff I had to do by hand. I got to thinking that this was the sort of thing that could be simplified by writing a computer program, if only I knew how to. Well, they had a course at the college on database programming, and I signed up for it.”

He looked at us a bit wryly and said, “To this day I don’t know how I actually got into the class. I wasn’t paying enough attention when I registered for it. Turns out it was a graduate-level Computer Science course! I didn’t have any CS background, and after the first day in the class I was completely lost. The entire grade for the semester was based on a project. You needed to create a database program to solve a real-world problem. And it had to have a graphical user interface, it had to have reporting…” he listed off several requirements, and this was about where I saw where the story was headed. It was almost like he was reading off a lit of Delphi’s historical strong points.

“I was completely lost. I didn’t even know where to start! But I’d already paid the tuition and I couldn’t get it back without a B or better in the class. So I went to talk to a friend of mine who was a professor in the CS department. I explained the problem to him, and he listened, and when I was done he thought about it for a moment. ‘Well,’ he said, ‘you could try Visual Basic, but there’s this new thing that just came out that might work better for you. It’s called Delphi.’ He was able to get me set up with a copy, and I installed it on my computer at work.

“For the next few months, that’s pretty much what my life was about. I’d work on my job during the day, then stay after in the evening to figure out how to use Delphi and how to make it talk to a database. Needless to say, I didn’t get very much sleep! But when the end of the semester rolled around, I had a working program. And I ended up getting an A on the class.”

Ladies and gentlemen, that right there is a testament to the power of the Delphi language! From a cold start, no programming background at all, to writing an app good enough to ace a graduate-level CS course in a matter of months. Granted, David’s a very intelligent guy, and that certainly played a part in being able to pick it up so quickly, but even so, a lot of it’s the Delphi language itself. (You’d never see results like that in the C family!)

Delphi is an evolution of Pascal, which was originally created by Niklaus Wirth as a teaching language. Being easy to learn was an explicit design goal. That originally came with a few tradeoffs and drawbacks, but the Borland team managed to extend the language into a powerful general-purpose programming system while still holding to the Pascal philosophy of making the language’s syntax and semantics as intuitive and easy to understand as they could. That’s what made it possible for David to pick up so quickly, and that’s why even experienced programmers who have been coding for years love Delphi: the language just makes sense. It may not have <insert trendy feature from some other language here>, but language design makes the code, even code the dreaded “other people’s” variety, easier to read and comprehend, and that counts for a lot in modern team-based software development.

In Object Pascal, things make sense, and they tend to work right even if you don’t quite understand them. IMO this is the main reason why so many people who know Delphi actually find it enjoyable to work with, as opposed to just something they write code in because they need to get something written, and why they sometimes even go so far as to call it “the best programming language.”

Abusing extended RTTI for fun and profit

I’ll admit, I don’t like the default settings for Delphi 2010’s extended RTTI.  Making almost everything included by default ends up compiling a ton of junk into the EXE, most of which will never get used.  But every once in a while, you can find some sort of use for it.

Continue reading ‘Abusing extended RTTI for fun and profit’ »

Programming Ethics 101

A few days ago on StackOverflow, someone posted the question, How can I keep Task Manager from killing my program? The first comment asks a very good question:  “What legitimate reason do you have for doing this?”
It reminded me of the guy who wanted to know how to make a file that can’t be edited or deleted by any means. Both of these guys seemed to have honorable intentions, but just hadn’t thought the ramifications through all that well. Continue reading ‘Programming Ethics 101’ »