Forum > Beginners

overloading original FPC functions

<< < (2/3) > >>

Weiss:

--- Quote from: Joanna on May 20, 2024, 01:41:57 am ---I think fpc should be more strict to prevent reusing things that should be reserved words. I once used Dec as a key for resource strings and the dec() function was no longer accessible

--- End quote ---

in my case it wouldn't be a problem, this is genuine overloading of function with different parameters. My function exists in an implementation part, not in an interface. I understand danger here is only a confusion by someone who knows what other obscure function in system unit does.

alpine:

--- Quote --- Please share your thoughts.
--- End quote ---
The only justification to obscure a system function would be for debugging purposes or to make it work better while doing the same thing. The other is just aiming at your own leg.

Rename it, or put a specific suffix, or enclose it in a dedicated scope (eg. static class function) and use it qualified. https://www.freepascal.org/docs-html/ref/refsu30.html

Joanna:
@weiss what was the name of the function you reused?
I think it’s a bad idea to reuse names. I’d much rather make a new name with underscores or something.

Weiss:

--- Quote from: Joanna on May 20, 2024, 03:45:34 pm ---@weiss what was the name of the function you reused?
I think it’s a bad idea to reuse names. I’d much rather make a new name with underscores or something.

--- End quote ---

swap(). I did not have to overload, like Thaddy suggested, it works without appending " : overload". I can't remember how did I come to conclusion that I have to overload, perhaps when I typed, IDE suggested different parameters and a path to it.

Like I said in my original post, I tried renaming. It just doesn't work, when what you do is actually swapping a and b. A becomes B and B becomes A. Swap(a,b). Scalars or arrays. I eventually overloaded my swap because I needed to swap many other things. I will probably be swapping bitmaps and who knows what else. And then, there is a little obscure original "swap" which does not really swap but "flip". Hard decision. Folks, I even went to all the trouble disturbing busy people on this forum. And if all there is a bit of confusion, then I am re-using the name. There are not that many words in my vocabulary.

Thaddy:
 :) Swap is indeed a good candidate.. The use case for the swap in system is not as strong as almost any other swap you can think of. And there is an alternative by using rotation.
(not to mention that it happily swaps the sign bit away, rendering it useless for signed types, you must use something like sar + xor to do that correctly)

In mode Objfpc the overload is not necessary, but it is in mode Delphi!

In general I think you just provided counter-proof against the advice to rename.
System.swap is horrible, re-use the name by all means  :D :D 8) ::)

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version