PDA

View Full Version : Doc: old style code in example



wila
12-Sep-2018, 04:23 PM
Hi,

DF19.1 (and all earlier versions) has this example code under YesNo_Box



Use Windows.pkg

Procedure Example
Integer eResponse

Move (YesNo_Box("Delete this file?", "", MB_DEFBUTTON2)) to eResponse

If (eResponse = MBR_YES) Begin
Send DeleteFile
End
End_Procedure // Example


In my opinion we should not promote the use of move for functions, not even global functions.

So my suggestion would be to rewrite that to:


Use Windows.pkg

Procedure Example
Integer eResponse

Get YesNo_Box "Delete this file?" "" MB_DEFBUTTON2 to eResponse

If (eResponse = MBR_YES) Begin
Send DeleteFile
End
End_Procedure // Example


Same thing for the YesNoCancel_Box

PS: Curious why vBulletin makes the function name bold? I sure didn't do that.
--
Wil

Samuel Pizarro
12-Sep-2018, 05:22 PM
In my opinion we should not promote the use of move for functions, not even global functions.

Any real reason for that? Or it's just your preference ?

Really, why not use move (global_function(...)) to var ?

wila
12-Sep-2018, 06:26 PM
Samuel,

Because it isn't simplifying the language.

It has been reported several times here that you always should use "Get" for calling functions that are non global. Following on that there are claims on bugs that are being reported for when somebody uses the move syntax for functions that you should use "Get" instead.
Those BTW are statements made by DAW employees (sorry no direct link, but you can find it in this forum)

In that case you shouldn't educate people on using move for global functions as they will end up using them for non global functions as well.

Yes, move works for global functions, but it doesn't help in making your code more readable (and thus maintainable).

Not saying that the move syntax makes no sense for some global functions, like the mathematical ones, but these are operating system specific ones, not language functions.

--
Wil

Samuel Pizarro
12-Sep-2018, 06:30 PM
got your point...

thanks!

Vincent Oorsprong
13-Sep-2018, 02:04 AM
Wil,

YesNo_Box is a global routine and global routines are addressed via an expression.

Mike Peat
13-Sep-2018, 02:14 AM
Or you could even do:



Use Windows.pkg

Procedure Example
If (YesNo_Box("Delete this file?", "", MB_DEFBUTTON2) = MBR_YES) ;
Send DeleteFile
End_Procedure


Mike :)

wila
13-Sep-2018, 05:37 AM
Vincent,

Yes I am well aware that it is a global function and that you can use it in an expression.
It is also you who replied here in the forum that we should not use move for non global functions after bumping into a IMO runtime expression bug when using move.
That's a confusing statement for new users.

Some functions are to be consumed by move and some other functions you use get.
You cannot mix and match and expect to have it work correctly.
They are both functions.

--
Wil

Vincent Oorsprong
13-Sep-2018, 06:21 AM
Wil,

I feel we have been very clear (since v7) that:

Global functions and built-in functions are to be called via an expression

You cannot do a MID or a DLL function via GET so the global and built-in function call explanation is very simple (to me)


Class (object) function members to be called with GET

Exception was made for Entry_Item (MyFunction (Self)) but this is with the CodeJock grid introduction now via an OnSetCalculatedValue event



I whish it was more enforced by the compiler since the change of allowing to have multiple functions with the same name in one program back in 1999
I whish we enforced it in sample code and packages to give a better example

wila
13-Sep-2018, 06:30 AM
Vincent,

For global functions you can use both get and move (via an expression). A limited number of built-in functions are only available via the expression syntax.

For class/object functions you can use get and move, but the move not always works as expected if the function was already declared differently elsewhere.

If DAW would recognize the second case as a bug and address that then I guess my suggestion is moot.

Although personally I'd use get where possible, because it -in my opinion- generates easier to read code.
--
Wil

Michael Mullan
13-Sep-2018, 07:51 AM
that's a pain to debug, because what is it if it's NOT MBR_YES

Mike Peat
13-Sep-2018, 07:59 AM
Fair point. :)

Frank Cheng
13-Sep-2018, 08:10 AM
You guys really don't have to wish. You have total control over the source code/pkg/sample code for DF and the compiler, and the source material for the html help.
It's just that you guys don't think of it as a big enough deal to spend time to work on it.

On the other hand, as a non DAW DF developer, the only thing we could do is "wish".

Frank Cheng