05 July 2011 ~ 0 Comments

Castalia’s Inline Variable Declaration

One of the biggest complaints I hear about Delphi syntax is the need to declare variables at the top of a function before they can be used. Other languages, like C++ or java, let you declare a variable at any point in your code. I have mixed feelings about this.

On the one hand, I believe that Delphi’s approach (require all variables to be declared in a VAR section at the beginning of a function) is stronger and more readable, and that it gives you a quick at-a-glance feeling for the data being used in your function. It also contributes to Delphi’s lightning-fast compile times, for reasons that are beyond the scope of this post.

On the other hand, it can be an annoyance to have to jump back into the VAR section of the Delphi function every time you need another variable. It breaks up your mental “flow” and, in particularly large and complex functions, can cost time and effort in getting back to where you left off.

This is the reason I created Inline Variable Declaration in Castalia for Delphi.

Inline Variable Declaration gives you the best of both worlds. It lets you write a VAR declaration anywhere in your function, and then automatically moves that VAR declaration into the variable declaration section of your function without breaking your flow or losing your place.

Inline Variable Declaration isn’t a very discoverable feature the Castalia adds to Delphi – you have to know it’s there, but once you do, it can save you a little time and a lot of mental effort.

For more information on Inline Variable Declaration in Castalia for Delphi, see http://twodesk.com/castalia/codingassistance.html#inlinevars

Leave a Reply