Recent

Author Topic: Optimising as you programme  (Read 1047 times)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8491
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Optimising as you programme
« Reply #15 on: September 23, 2022, 06:17:05 am »
* How many times would you need to call a property before its better to cache it locally ?  That would, IMHO, depend on the type too, the cost of declaring an integer and copying data to it would be less than, say a string (that is generally a managed ANSIString for most of us).
Me: Everytime. First, always locally cache property calls will save you from guesswork whether that property is mapped to a method or mere field. Second, usually a property call is a long chain (e.g.: AListBox.Items.Count), save some typing as you may not know eventually how many times it will be called.

Arioch

  • Sr. Member
  • ****
  • Posts: 414
Re: Optimising as you programme
« Reply #16 on: September 23, 2022, 06:07:39 pm »
Second, usually a property call is a long chain (e.g.: AListBox.Items.Count), save some typing as you may not know eventually how many times it will be called.

Third, if you eventually decide you needed some other property/control - you only have change one place, not dozen :-)

and that is where i miss one-addignment variables, like in functional languages or val vs var in Scala. I think newer Delphi tackled it with letitng consts be declared in every begin-end like in C, or maybe not. Can i have procedure .... begin ... begin const SL = Self.Memo1.Lines; SL.Clear; ... in Delphi 10.x ? Don't know.
« Last Edit: September 23, 2022, 06:10:21 pm by Arioch »

 

TinyPortal © 2005-2018