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.”
1 2 3 4 5 6 7 8 9 |
<strong>var</strong> path : String := System.IO.Path.GetFullPath(tbDatabase.Text); db : DataContext := new DataContext(path); <strong>begin</strong> var i : Integer := 0; var contacts := from contact in db.GetTable<Contact>() select contact; <strong>end.</strong> |
Looks awkful to me (like VB). This is the code written by our long term code creation rules:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<strong>var</strong> Path: String; Db: DataContext; I: Integer := 0; <strong>begin</strong> Path := System.IO.Path.GetFullPath(tbDatabase.Text); Db := new DataContext(Path); Contacts := from contact in db.GetTable<Contact>() select contact; <strong>end; </strong> |
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.
November 24, 2008
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
- Habari STOMP Client libraries release 2024.12 December 7, 2024
- Delphi and AI December 7, 2024
- Uses Clause Manager topic added to the GExperts help December 6, 2024
- Upgrading C++Builder 12.2: Tip #4 1/2: Check out compiler safety options December 6, 2024
- Upgrading C++Builder 12.2: Tip #4, Take Advantage of Security and Correctness December 5, 2024
- .NET MAUI: Complete Guide December 4, 2024
- Upgrading C++Builder 12.2: Tip #3, Massive Files with iostreams December 4, 2024
- Log exceptions in your Delphi app in the cloud with StellarDS.io December 4, 2024
- Introducing Signotaur - Remote Code Signing Server December 4, 2024
- Upgrading C++Builder 12.2: Tip #2, Handling Old RTL December 3, 2024
November 24, 2008