Delphi Prism new language features
Andreano Lanusse wrote about the new Delphi Prism language features compared to Delphi Win32.
Some of them I really would like to see in Delphi Win32 and some I don’t like and disallowed it in our internal code creation rules. The most important I dislike is
“Variable everywhere and create a instance at the same time you declare.”
var path : String := System.IO.Path.GetFullPath(tbDatabase.Text); db : DataContext := new DataContext(path); begin var i : Integer := 0; var contacts := from contact in db.GetTable<Contact>() select contact; end.
Looks awkful to me (like VB). This is the code written by our long term code creation rules:
var Path: String; Db: DataContext; I: Integer := 0; begin Path := System.IO.Path.GetFullPath(tbDatabase.Text); Db := new DataContext(Path); Contacts := from contact in db.GetTable<Contact>() select contact; end;
I like the separation from var declaration and code.
4 Comments to Delphi Prism new language features
Yes, variable everywhere and create an instance at the same time you declare is really something I dislike too.
It mess up the code in a awfully way.
I disagree in some degree 😉
Of course it’s very clean to have everytging you work on declared in front.
But if you need some variables for loops (like the allmighty ‘for i := 0 to…’), or only in scope of a loop, then it’s a lot cleaner to not declare it oustide of that scope.
Being able to access a variable that was valid in a loop and might or might not be available for access later is generally a bad idea. Declaring a variable that is used only in a loop directly in that loop makes the code cleaner and more maintainable.
November 24, 2008
If you need variables for loops, maybe try to avoid them using the “for each” construct…
The Prism feature with the for loop variables:
var x := -1;
var list := new List
for x in list do
Console.Writeline(x)
Console.Writeline(x);
Output:
1
2
3
-1
At the end, x will still be -1, because it is a different variable than the x inside the loop.
”
(Taken from the prism wiki)
Is this good readable code? I don’t think so. You’ll use the “x” variable but inside the “for” loop it’s a different “x” – same name, different behavior/content? The only thing I see is to use special variables only intended for use within for loops (like I,J,K,L) – which we do anyway.
Or why not using special prefixes (like in PHP, Perl, etc.) for those cases?
for $x in list do
Console.Writeline(x)
?
November 24, 2008
btw, what about nested for loops? Does this work with prism?
for i: Integer := 0 to 10 do
for i: Integer := 0 to 20 do
Console.Writeline(i)
Leave a comment
About Dennis D. Spreen
Search
Recent Posts
- How to compile Lua 5.4.0 for Android as a dynamic library using Android Studio 4
- Please make inline vars usable for production – fix RSP-28892
- How to compile Lua 5.4.0 as a Mac OS X dynamic library
- How to compile Lua 5.4.0 for Linux as a shared library
- How to compile Lua 5.4.0 for Windows
- Daily Wage – a Spigot/Bukkit plugin that pays out a daily wage
- How to compile Lua 5.3.5 for Windows
- Better Collada exporter for Blender with custom properties
- MOS6502-delphi – a MOS 6502 CPU emulator for Delphi
- Pass a multidimensional array as a parameter (with a hidden caveat)
Categories
Tags
Archives
- May 2020
- March 2020
- June 2019
- March 2017
- August 2016
- July 2016
- June 2016
- January 2016
- September 2015
- February 2015
- January 2015
- October 2014
- September 2014
- August 2014
- May 2014
- March 2014
- February 2014
- November 2011
- June 2011
- February 2011
- March 2010
- September 2009
- August 2009
- July 2009
- May 2009
- March 2009
- February 2009
- January 2009
- November 2008
- October 2008
- February 2008
- June 2007
Delphi Feeds
- EKON30, the 30th edition of the Die Entwickler Konferenz für Delphi, is coming soon in Düsseldorf, Germany. 23 – 27 November, 2026 October 23, 2026
- TeeChart for R and Python October 23, 2026
- The PHP Apocalypse October 23, 2026
- SAP SQL Anywhere: End of Support, Pricing, and Migration Alternatives in 2026 October 22, 2026
- My Custom CRM October 22, 2026
- ISOlDE Gameengine: What an Experienced Developer Can Achieve in Three Days With AI October 22, 2026
- Join Me Online at CodeCraft: Visual Robot Programming with Visuino - October 29, 2026 October 21, 2026
- Post-Quantum Readiness: Start with Your Software Estate Inventory October 21, 2026
- Minitab: Turning Statistical Analysis into Clear, Actionable Insights with TeeChart October 21, 2026
- Subscription option for selected TMS products October 21, 2026


November 24, 2008