Recent

Author Topic: maximum number of parameters of a method  (Read 1741 times)

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: maximum number of parameters of a method
« Reply #15 on: March 22, 2023, 10:00:10 am »
Who says tha files are only added?
Files ??? You mentioned fields. Not files.

But you can also remove fields.
When a field is removed you can just do the same, increase the number and fix the code.
No need to change the number back.

440bx

  • Hero Member
  • *****
  • Posts: 3945
Re: maximum number of parameters of a method
« Reply #16 on: March 22, 2023, 10:03:30 am »
(if I use a record I need to find all cals and make sure new parameters are filled as well, for sure this won't happen).
That is true at compile time but, there is a way to ensure all the parameters have been set by each caller at runtime.

Basically, that would allow the program to detect that a particular call failed to fill one or more parameters.  It would not be able to detect missing parameters if the function isn't called (which is something the compiler could do if it accepted more than 255 parameters.)

If you're interested in how to implement a runtime solution - which admittedly falls a bit short of your original goal - make it known and I'll present how to go about it.
« Last Edit: March 22, 2023, 10:05:19 am by 440bx »
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Чебурашка

  • Hero Member
  • *****
  • Posts: 568
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: maximum number of parameters of a method
« Reply #17 on: March 22, 2023, 10:06:11 am »
Files ??? You mentioned fields. Not files.

I did a typo.

But you can also remove fields.
When a field is removed you can just do the same, increase the number and fix the code.
No need to change the number back.

Basically this is svn inside source code.

I won't follow this approach, but somebody could like it.
« Last Edit: March 22, 2023, 02:06:11 pm by tt »
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

rvk

  • Hero Member
  • *****
  • Posts: 6111
Re: maximum number of parameters of a method
« Reply #18 on: March 22, 2023, 10:08:19 am »
I won't follow this approach, but somebody could like it.
Ok.

Please let us know the chosen solution in the end.

Чебурашка

  • Hero Member
  • *****
  • Posts: 568
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: maximum number of parameters of a method
« Reply #19 on: March 22, 2023, 10:12:48 am »
(if I use a record I need to find all cals and make sure new parameters are filled as well, for sure this won't happen).
That is true at compile time but, there is a way to ensure all the parameters have been set by each caller at runtime.

Basically, that would allow the program to detect that a particular call failed to fill one or more parameters.  It would not be able to detect missing parameters if the function isn't called (which is something the compiler could do if it accepted more than 255 parameters.)

If you're interested in how to implement a runtime solution - which admittedly falls a bit short of your original goal - make it known and I'll present how to go about it.

Thanks 440bx, I was looking for something that, once function is modified to add a new parameter, the program that uses it was forced to fillup the new parameter in all places where it is called. I develop a library+wrapper in fpc. Library is later made as a .so, while wrapper is embedded in a kylix software (wrapper is made to compile both in fcp and kylix). Fixing things in kylyx is not as confortable as making in modern delphi xe IDEs or Lazarus. This is why the function with parameters was very "safe" to me.
« Last Edit: March 22, 2023, 11:12:33 am by tt »
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

Чебурашка

  • Hero Member
  • *****
  • Posts: 568
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: maximum number of parameters of a method
« Reply #20 on: March 22, 2023, 10:17:07 am »
I won't follow this approach, but somebody could like it.
Ok.

Please let us know the chosen solution in the end.

Just to say something fun, there was a italian comedian (Corrado Guzzanti), saying:

"La risposta è dentro di te... epperò è sbagliata!" :D

I already implemented the modification using the record+record pointer. Now it compiles of course.
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

440bx

  • Hero Member
  • *****
  • Posts: 3945
Re: maximum number of parameters of a method
« Reply #21 on: March 22, 2023, 10:19:12 am »
This is why the function with parameters was very "safe" to me.
I understand that but, if the ideal solution isn't available then it seems reasonable to settle for something that is, at least, somewhat close.

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Чебурашка

  • Hero Member
  • *****
  • Posts: 568
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: maximum number of parameters of a method
« Reply #22 on: March 22, 2023, 11:04:51 am »
This is why the function with parameters was very "safe" to me.
I understand that but, if the ideal solution isn't available then it seems reasonable to settle for something that is, at least, somewhat close.

Ok, please explain.
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

Чебурашка

  • Hero Member
  • *****
  • Posts: 568
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: maximum number of parameters of a method
« Reply #23 on: March 22, 2023, 02:25:53 pm »
Please let us know the chosen solution in the end.
I already implemented the modification using the record+record pointer. Now it compiles of course.

But after a while I went back to my original idea, based on explicit parameters.

Instead of assigning them all in one single method call, I just split into a sequence of them, to be called in a row. Taken all together they end up assigning all parameters. When a new parameters must be added will be added to the last (and if necessary I will add more setting methods). This goes back to the "safe" compile time explicit check of assignment. Yes it does break the assumption that receiver of the message receives it in an atomic way, but this is the best compile time solution I can figure out to overcome the parameter count hard limit.
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

 

TinyPortal © 2005-2018