Recent

Author Topic: Change the reference of a record  (Read 6414 times)

dolemi

  • New Member
  • *
  • Posts: 13
Change the reference of a record
« on: January 03, 2016, 03:26:45 pm »


I suggest:

Change:
Procedure InputRec(NameInput:String; AgeInput:Integer);
Begin
    With aRec Do Begin
      Name := NameInput;
      Age  := AgeInput;
    End
End;

To:

Procedure InputRec(Name:String; Age:Integer);
Begin
    With aRec Do Begin
      .Name := Name;
      .Age  := Age;
    End
End;


lazjump

  • Jr. Member
  • **
  • Posts: 61
Re: Change the reference of a record
« Reply #1 on: January 03, 2016, 03:28:56 pm »
Why?
I thought Delphi was expensive until I learned the price of ExtJS

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Change the reference of a record
« Reply #2 on: January 03, 2016, 03:35:48 pm »
Does your extension pas the tests in http://www.freepascal.org/faq.var#extensionselect ?

If you really want to make an extension compelling its description should be complete,
E.g. WITH allows multiple expressions, and can be nested.

Personally I think that if you need this, you use WITH too much :-)

« Last Edit: January 03, 2016, 03:37:31 pm by marcov »

dolemi

  • New Member
  • *
  • Posts: 13
Re: Change the reference of a record
« Reply #3 on: January 03, 2016, 03:43:10 pm »
Big projects with millions lines of code, use WITH is faster and neatly.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Change the reference of a record
« Reply #4 on: January 03, 2016, 03:51:23 pm »
Big projects with millions lines of code, use WITH is faster and neatly.

Actually, faster rarely matters with large projects since typing is negligible compared to lowering programming error rates.

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: Change the reference of a record
« Reply #5 on: January 03, 2016, 04:46:35 pm »


I suggest:

Change:
Procedure InputRec(NameInput:String; AgeInput:Integer);
Begin
    With aRec Do Begin
      Name := NameInput;
      Age  := AgeInput;
    End
End;

To:

Procedure InputRec(Name:String; Age:Integer);
Begin
    With aRec Do Begin
      .Name := Name;
      .Age  := Age;
    End
End;


New hobby in 2016?
Please stop trolling.

http://forum.lazarus.freepascal.org/index.php/topic,30966.msg197495.html
http://forum.lazarus.freepascal.org/index.php/topic,30954.0.html

All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

BeniBela

  • Hero Member
  • *****
  • Posts: 905
    • homepage
Re: Change the reference of a record
« Reply #6 on: January 07, 2016, 09:25:59 pm »
This is looks awesome!

Although it might be hard to know which Name is which one...


AlanTheBeast

  • Sr. Member
  • ****
  • Posts: 348
  • My software never cras....
Re: Change the reference of a record
« Reply #7 on: January 07, 2016, 10:48:22 pm »


I suggest:

Change:
Procedure InputRec(NameInput:String; AgeInput:Integer);
Begin
    With aRec Do Begin
      Name := NameInput;
      Age  := AgeInput;
    End
End;

To:

Procedure InputRec(Name:String; Age:Integer);
Begin
    With aRec Do Begin
      .Name := Name;
      .Age  := Age;
    End
End;



I'm trying to like it.  It seems right but also seems unnecessary.

I'll go even further.  The absence of the . is a direct consequence of the "with".  Seeing the . makes me wonder if there's some new inference about what is being referenced.  eg: when I see ^ I know it's a pointer.  What does the . mean now? 

(As to your example it's one of my favourites about bad names for record components)

Everyone talks about the weather but nobody does anything about it.
..Samuel Clemens.

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: Change the reference of a record
« Reply #8 on: January 07, 2016, 11:48:32 pm »
I would prefer this:

Code: Pascal  [Select][+][-]
  1. With X := aRec Do Begin
  2.   X.Name := Name;
  3.   X.Age  := Age;
  4. End

With or without equal sign.

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: Change the reference of a record
« Reply #9 on: January 08, 2016, 03:51:56 am »

I suggest:
Change:

    With aRec Do Begin
      Name := NameInput;
      Age  := AgeInput;
    End
To:
    With aRec Do Begin
      .Name := Name;
      .Age  := Age;
    End
Why?
Big projects with millions lines of code, use WITH is faster and neatly.
IMHO, @dolemi want the SynEditor just popup quickly when he write "." .
In that situation, yes! writting "." can triggers to popup of list of known variable faster (popped out).
But it should not the feature of "pascal language", isn't it?


As complement, you can find the shortcut-command for showing quickly that variable-list-suggestion. Maybe Ctrl+J / Ctrl+Space ?
When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Change the reference of a record
« Reply #10 on: January 08, 2016, 12:48:58 pm »
I would prefer this:

Code: Pascal  [Select][+][-]
  1. With X := aRec Do Begin
  2.   X.Name := Name;
  3.   X.Age  := Age;
  4. End

With or without equal sign.

If it were a new language, I would go for that too. But I think currently these kinds of micro syntax optimalizations are worse than the problem (compatibility both to older versions and Delphi) and general size of the language.

 

TinyPortal © 2005-2018