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
Recent Posts
- Eclipse on Mac OS X – Workspace error on NFS mounts
- Lua 5.1 for Delphi 2010
- WordPress Plugin – QR Code Tag v1.0
- Favourite Android applications
- Hint: Blank Typo3 installation screen
- How to create an ESXi v4 Whitebox ISO with Windows Tools
- Ext: tt_news – no translation for name of months
- check_apachestatus_auto.pl v1.2 released
- Ext: indexed_search – Disable indexing of meta tags
- nagios_mdaemon_check.exe v1.0 released
Search
Categories
Tags
Archives
Blogroll
Delphi Feeds
- Virtual method interception
- Brian Lindahl on VS2010 Integration
- Open Letter to Digital Metaphors
- Goodies and Bugs in Delphi XE
- Flying with MEF in Delphi Prism
- Use Custom Check Box Images for a ListView - Delphi 's TListView Checkboxes are Ugly
- DWScript status update
- Reminder: Dwarfland Photos now also on iPhone
- Ingenious!
- New pool about Delphi VCL
I'm an avid programmer working on a variety of platforms in a variety of languages with a wide technical interest.

November 24, 2008