Lately I've evaluated JavaFX for a project and I saw a code like:
/**
* Title of the progress popup.
*/
var progressTitle: Text = Text {
content: "Opening {taskName}"
font: bind getFont(fontName, fontSize)
wrappingWidth: bind popupWidth - 30
translateY: 20
translateX: 10
fill: Color.BLACK
};
that has reminded me xharbour/contrib/xwt2 syntax that Giancarlo
Niccolai started many years ago.
So I started to think that it would be useful to have this kind of
OPTIONAL way to pass parameters to functions.
To explain the idea imagine calls like: myclass():new( 10, 20, "text
to print", .T. ), myclass():move( 5, 5 )
class myclass
method new
...
method move
endclass
method new( top, left, text, enable )
::top := top
::left := left
::text := text
::enable := enable
...
return nil
method move( x, y )
::top += x
::left += y
...
return nil
code could become myclass():new( "top: 10; left: 20; text:text to
print; enable:.T." ), myclass():move( "x:5; y:5" )
method new( .=>. )
// .=>. will create an hash like QProp made of { "top"=>10,
"left"=>20, "text"=>"text to print", "enable"=>.T.}
...
return
method move( .=>. )
QProp( "top" ) += QProp( "x" )
QProp( "left" ) += QProp( "y" )
// creating a shortcut it could become sth like:
// :::top += :::x
// :::left += :::y
...
return
I see many advantages:
- is completely optional and is compatible with existing code and syntax
- self documenting parameters and position independence
- easy to check optional and required parameters
- usable in procedures and functions also
- avoid the "copy of parameters" in VARs
- less need of commands to make code readable
- remove the "skip of commas" for optional parameters
I'd like to know the opinion of core developers about it.
best regards,
Lorenzo
I've extracted some lines of code from xharbour/contrib/xwt2 to test it:
try with sth like ./test1 "Left:1; Right:4; Text:enter text here;
Fake: 123a; Fake:a123; Enable: .T."
#xcommand ? <data,...> => OutStd( <data>, HB_OSNewLine() )
procedure main( cRequest )
LOCAL cRegexStyle := HB_RegexComp('\s*([^:]+):\s*(("?)(.*?)\3)\s*(;|$)')
LOCAL aMatch, nValue
LOCAL hProps := {=>}
cRequest := AllTrim( cRequest )
DO WHILE Len( cRequest ) > 0
aMatch := HB_Regex( cRegexStyle, cRequest )
IF aMatch == NIL
? "MALFORMED: Signal error"
RETURN
ELSE
nValue := Val( aMatch[5] )
IF ( nValue != 0 .or. aMatch[5] == "0" ) .and. Len( AllTrim(
Str( nValue ) ) ) == Len( aMatch[5] )
hProps[ aMatch[2] ] := nValue
ELSEIF aMatch[5] == ".T."
hProps[ aMatch[2] ] := .T.
ELSEIF aMatch[5] == ".F."
hProps[ aMatch[2] ] := .F.
ELSE
hProps[ aMatch[2] ] := aMatch[5]
ENDIF
cRequest := Substr( cRequest, Len( aMatch[1] ) + 1 )
ENDIF
ENDDO
IF Len( hProps ) > 0
? HB_VALTOEXP( hProps )
ENDIF
RETURN
_______________________________________________
Harbour mailing list (attachment size limit: 40KB)
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour