Forum > Beginners

overloading original FPC functions

<< < (3/3)

Joanna:
Swap is a name that doesn’t really give much information apart from a general idea of swapping. I once read a book that suggested how to name procedures. If I was swapping things I would use a name like swap_specifics

alpine:

--- Quote from: Weiss on May 21, 2024, 05:38:07 am ---
--- 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.

--- End quote ---
That changes the discussion a bit. :) Swap is a name so vague...

But I'll have to agree with Joanna this time, I'd never name a procedure in such an uninformative way. Unless is a nested one and it really doesn't matter.

PascalDragon:

--- 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.
--- End quote ---

This is not about reserved words or keywords. For those one needs to prefix them with & to be able to use them (e.g. &type or &while). Anything contained in the System unit however is not a keyword. They are just symbols and for these the normal visibility rules apply. Not to mention that FPC itself uses this functionality: Integer is declared as 16-bit signed type in the System unit, but as a 32-bit signed type in the ObjPas unit which is automatically used if mode ObjFPC or Delphi is used, thus using Integer will in fact access ObjPas.Integer unless you manually specify System.Integer. This is simply how Pascal works.


--- Quote from: Joanna on May 20, 2024, 01:41:57 am ---I once used Dec as a key for resource strings and the dec() function was no longer accessible
--- End quote ---

You could have just used System.Dec as is the case for any symbol hidden in this way.

Navigation

[0] Message Index

[*] Previous page

Go to full version