Named parameters implementation in harbour?

232 views
Skip to first unread message

Roberto Parisi

unread,
Mar 15, 2025, 2:25:45 AM3/15/25
to Harbour Developers
Hi all,
I think Harbour would make a big step forward if it adds support for named parameters.
Do you think it would be possible to implement them with Harbour's current structure?  

Regards

alkresin

unread,
Mar 21, 2025, 5:09:33 AM3/21/25
to Harbour Developers
Roberto,
  theoretically, this could be possible, but for those functions only, which are defined in the same source file, where their calls are - because Harbour compiler knows nothing about parameter names. This limitation makes the feature meaningless.

But, fortunately, we have a preprocessor). Below is  a small sample:

#xtranslate dbUseArea( [new=<nw>[,]] [file=<(db)>[,]] [exclusive=<ex>[,]] ) => dbUseArea( <nw>,,<(db)>,, <ex>,, )

dbUseArea( file=aaa.dbf )
dbUseArea( file=aaa.dbf, exclusive=.t. )
dbUseArea( exclusive=.f., new=.t. )

You can create an include file with rules for all functions you need. This doesn't allow to use positional and named parameters together, though.

Regards, Alexander.
суббота, 15 марта 2025 г. в 09:25:45 UTC+3, Roberto Parisi:

Roberto Parisi

unread,
Mar 24, 2025, 9:52:58 PM3/24/25
to Harbour Developers
Thanks, nice solution, but I was thinking about a "native" solution.
My dream is one day having harbour like python, ease of coding is almost there, we just need to leave behing some legacy stuff. 
Would be great a new harbour fork breaking old style clipper stuff and focusing on modern languages features.

Regards.

Eric Lendvai

unread,
Mar 25, 2025, 2:17:31 AM3/25/25
to Harbour Developers
I completely agree with Roberto, many mother languages have that support, for example: Python, Ruby, C#, Objective-C, Swift, Kotlin

Why Use Named Parameters?
  • Improves readability: Easier to understand function calls.

  • Avoids parameter order dependency: Useful when functions have many parameters.

  • Enhances code maintainability: Adding default values is easier.


Gerald Drouillard

unread,
Mar 25, 2025, 9:40:27 AM3/25/25
to harbou...@googlegroups.com
I use a couple different ways for programs or functions with many parameters.
  1. Pass the parameters as a hash.
  2. pass the parameters as a string eg myfunc("file=aaa.dbf", "exclusive=.t.").  Works the same as the command line when starting a program.
function myfunc( ... )
private file,exclusive
default_parameters(hb_AParams(),.t.)




--
You received this message because you are subscribed to the Google Groups "Harbour Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-deve...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/harbour-devel/fa045487-c7cc-40ff-a38f-89348f38261an%40googlegroups.com.
default_parameters.prg
Reply all
Reply to author
Forward
0 new messages