IT SOLUTIONS
Your TECHNOLOGY partner! 
 
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post:

Enter your name and security key.

Your Name:
Today's security key = P213A
Enter key:
Write a Comment...

Comments

1 Comments.
Share a thought or comment...

mtiede
Comment 1 of 2

I personally don't like these inline declarations.  Why have them?  They just goof up the readability of the routine.  Now, if I look at the declaration of local variables, I don't know how many more might be defined later.  So I don't have a good idea of the variable "context" before starting to read the logic (the code).

I've used languages that allowed such things LONG ago when I used PL/I.  And they didn't bother me then.  After many years of Pascal, I now understand the benefits of declaration separate from code.

I assume the main reason that someone would want the inline declaration is because it is too much of a bother to scroll back up to the declaration section to define it and then have to scroll back.

Maybe it would be better if the editor just had a command that pushed the declarations back up to the top.

On the other hand, again from PL/I, if the inline declaration has a different scope, that is something else again.  So if a new, nested begin end block contained an inline variable declaration, I suppose I could understand its use.  But I would rather see the editor pull such bits of code up to a local procedure.  Again for readability.

And if the inline variable and local block scope were being used to get some sort of performance advantage by not having to make a local call, I would rather see the optimizing compiler figure that out.

Readability is what makes me stay with Pascal.

Posted 48 months ago


Mike Prestwood
Comment 2 of 2

I agree! I think it was added because other languages allow it. In particular C#. Kind of a catch up mentality. However, I agree with you, I think code is cleaner when variables are not inline.

Posted 48 months ago

Commenting on...

[View/Review Post]
Title: Delphi Prism Code Blocks (begin..end)
By: Mike Prestwood

Languages Focus: Code Blocks

The rules for code blocks within a language dictate where you can declare variables, how you "bracket" code, etc.

Delphi Prism Code Blocks

Same as in Delphi for Win32 but Prism also supports inline variable declaration.

function DoSomething : integer;
var
 a, b : integer;
begin
 a := 1;
 b := 2;
 var c : integer; //Prism allows inline (local) variables.
 c := a + b;
  
 result := c;
end;

Delphi for .Net Code Blocks Example

The following is a Delphi for .Net example using VCL.Net.

Add SysUtils to your uses clause.

uses
  Borland.Vcl.SysUtils;

Here is the code for the function and click event:

function Add(a, b : Integer) : integer;
begin
  result := a + b;
end;
 
procedure TWinForm.Button1_Click(sender: System.Object; e: System.EventArgs);
begin
 MessageBox.Show(IntToStr(Add(3, 4)));
end;

Notice the function has to come before it's first usage. Alternatively, you can move the function below it's first usage if you prototype the function in the interface section:

interface
  function Add(a, b : Integer) : integer;
-
  Load Time=less than 1 second.
 
Print This

KB Post Options:
-
 
Have a question? Need our services? Contact us now.
--Mike Prestwood

Call: 916-726-5675

email: info@prestwood.com


©1995-2013 Prestwood IT Solutions.   [Security & Privacy]   Made in the U.S.A..   No H1-B.   No offshoring.