4D command returning a value request

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

4D command returning a value request

Aaron
Question:
Will There be a 4D release soon to increase the usage of returned values on 4D command, so that I can reduce the reliance on system global process variables, like “OK"?
    a good 4D command canidate is Receive Packet.
I consider "OK" global variable because it never looses scope, which is what a global variable is.

If this is not the Right forum for this question, then the answer to this question might be where do I make that request.





Why returned values are a benefit: (optional reading)-------------------------------------------------------------

I don’t want to get into a discussion why global variables should not be used. There are very legitimate reasons for wanting enhancements of 4D commands to return a values

Back to Receive Packet. and why its specifically is a benefit
  Receive Packet($docref;$data;$EOL) for example sets the OK system global process variable to 1, unless it reads no data ,then it is sets it to 0
It should be expanded, to return 1 or 0, and for backward compatibility the OK could be maintained as is.

Therefor I could write less code lines similar to c#, java, javascript, c++, etc. (pseudo example below)
 while(  (line = file.readline()) ==1)
  //do stuff
End while


Currently, because Receive Packet does not return a value, I instead need to write code like this in 4D.

Receive Packet($docref;$data;$EOL)  //read the first line
if (ok=1)
repeat
  //do stuff
  Receive Packet($docref;$data;$EOL)
until (ok=0)

(OR)

repeat
Receive Packet($docref;$data;$EOL)  //read, this example not as good because if in do stuff changes OK and I don’t program around it, the until will break
if (ok=1)
  //do stuff
end if
until (ok=0)

I realize I could write my own read line method(which I have), but I just thought it would be handy if Receive Packet itself could return 1 or 0, in a future code release.
It would also be nice if the read line supported CR, CRLF, LF types… I got around this by writing my own open file routine, which gets the EOL (this code is not shown)

Example of Readline:
While (Readline ($docref;->$read;$EOL)=1)  //Parse the text file referenced , returns 1 if not end of File, 0 at end; read is the contents of line; EOL must be provided
   //do stuff
End while

  // Method: readline
C_LONGINT($0)  //returns 1 or 0
C_TIME($1)  //doc reference
C_POINTER($2)  //data can be updated and returned to user
C_TEXT($3)  //EOL
  //variables
C_TEXT($READ)
  //read to EOL character
RECEIVE PACKET($1;$READ;$3)
$2->:=$read
If (Length($read)>0)
$0:=1  //sometimes the last line does not have a EOL, so we still need to return 1
Else
$0:=ok
End if



thanks,
Aaron
--



**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: 4D command returning a value request

Charles Miller
This is not the right forum you will need to make a feature request for that

Also while nicely stated 4d has not typically made this type of enhancement changing a procedure to a function call there are function calls like print form where data is returned

Regards
Chuck

Sent from my iPhone

> On Aug 29, 2016, at 6:04 PM, Aaron <[hidden email]> wrote:
>
> If this is not the Right forum for this question, then the answer to this question might be where do I make that request.
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

RE: 4D command returning a value request

Timothy Penner
> > If this is not the Right forum for this question, then the answer to this question might be where do I make that request.
> This is not the right forum you will need to make a feature request for that

Here is some more info that should help you get your request to the right location:

Tech Tip: How to submit a feature request
http://kb.4d.com/assetid=76725
========================================================================
Feature requests are handled on the 4D Forums: http://forums.4d.fr/Forum/FR/1075213/0/0 

Having the feature requests handled through the forums is quite valuable to the community because of the following:

1. 4D Engineering participates on the 4D Forums, so you have the opportunity to discuss the feature request in a more immediate fashion.

2. Other users can participate in the feature request discussion and help refine the feature request so that it is appealing to more users. Also, the more users who participate in the discussion, the more visibility that particular feature request will have.
========================================================================

See also: Tech Tip: How to vote for a feature request
http://kb.4d.com/assetid=76726

Kind Regards,

Tim PENNER
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: 4D command returning a value request

KirkBrooks
In reply to this post by Aaron
Aaron,
Without speaking to your illustration of Receive Packet in particular but
to speak more generally you can accomplish much of this sort of
functionality using an IP c-obj.

Since v15 I've started initializing a var called <>appObject on startup.
You can call it anything, of course. Once it's there you can write pretty
much any sort of setters and getters you need to keep track of whatever.
More specific to your example would be a process scope var. I call that one
prosObject and it works exactly the same way.

For example, let's say I want to replace the system OK with my own which
will be boolean. Since this is a process level var I'll use prosObject:

// isOK -> boolean
$0:=ob get(prosObject;"OK";Is boolean)


I suppose that should be 'Get_OK' but I like the shorter version. The
setter would be:

// SET_OK (bool)
ob set(<>appObject;"OK";$1)


Let's say I want to monitor a printing job. Process level again.

// PRINT_SET_printableWidth (longint)
// PRINT_SET_printableHeight (longint)
// PRINT_SET_printedHeight(longint)
and so on with the complimentary getters. For something like this I'd use
Canon Smith's excellent component to allow me to group these things into a
single JSON object most likely called 'printjob' so a setter would look
like:

// PRINT_SET_printableWidth (longint)

Obj_set_long(prosObject;"printjob.printableWidth";$1)

​and the getter:​

// PRINT_GET_printableWidth

Obj_get_long(prosObject;"printjob.printableWidth:)


by doing that I can clean up at the end with

// PRINT_CLEAR

ob remove(prosObject;"printjob")


An aspect of this I like a lot is that I don't have to dedicate specific
variables to those things I need. I also like that I can easily see
everything I have declared in the process by looking at a single variable:
prosObject. Much easier than having to look through the entire database
variable table with I'm trying to troubleshoot something.

And it's easy to extend this idea without a lot of refactoring. Let's say I
want both a process level and an app level OK var. Not sure why but this is
just an example. I could write two different setters and getters or:

// SET_OK (bool;pointer)

// $1 is the value

// $2 is pointer to the obj

ob set($2->;"OK";$1)


Now SET_OK can be used to "OK" in any c-obj. I'm really liking the
flexibility this provides.


On Mon, Aug 29, 2016 at 3:04 PM, Aaron <[hidden email]> wrote:

> Question:
> Will There be a 4D release soon to increase the usage of returned values
> on 4D command, so that I can reduce the reliance on system global process
> variables, like “OK"?
>     a good 4D command canidate is Receive Packet.
> I consider "OK" global variable because it never looses scope, which is
> what a global variable is.
>

--
Kirk Brooks
San Francisco, CA
=======================
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: 4D command returning a value request

Keisuke Miyako
the language is evolving, so some rules can feel a bit arbitrary if not retrospective.

my understanding is that the OK variable is used to interact with the user.

sure, a command may fail because of the system, network, etc.
but for me, as far as OK is concerned, the focus is on the user.

some old commands are designed to present a dialog when a parameter is omitted,
so the boundary becomes blurry.

new commands such as JSON Parse or DOCUMENT TO TEXT do not update OK,
even though they do throw an error.

what is interesting with these commands is that they never interact with the user.

but this is just my own way of reasoning, not divine wisdom (I did not consult Engineering).


宮古 啓介
セールス・エンジニア

株式会社フォーディー・ジャパン
〒150-0043
東京都渋谷区道玄坂1-10-2 渋谷THビル6F
Tel: 03-6427-8441
Fax: 03-6427-8449

[hidden email]
www.4D.com/JP

**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: 4D command returning a value request

Bill Weale
ummmmmmm….

divine wisdom = Engineering?

or, Engineering:=divine wisdom?



www

> On Aug 30, 2016, at 12:47 AM, Keisuke Miyako <[hidden email]> wrote:
>
> but this is just my own way of reasoning, not divine wisdom (I did not consult Engineering).

**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: 4D command returning a value request

Chip Scheide
In reply to this post by Aaron
actual this is not a correct interpretation of the variable 'OK'.

'OK' is a PROCESS variable. so in every process 'OK' can have a
different value.

I do agree though that a number of 4D commands could/should be
functions (returns a value) rather then procedures (sets a single
[process] variable).

Chip
On Mon, 29 Aug 2016 17:04:21 -0500, Aaron wrote:
> I consider "OK" global variable because it never looses scope, which
> is what a global variable is.
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: 4D command returning a value request

Alan Chan
In reply to this post by Aaron
Hi Aaron,

You're requresting 4D to change all 4D command to become 4D function. It
might not be too practical especially 4D has been very busy on v16 which
is a very major upgrade - preemptive threading on 4D language. Not to
mention fine tuning the new 4D network on MacOS 64bit server.

We have doing the following to cater the OK issue you mentioned

Trans_error:=0
$ok:=0
On Err Call("CatchError")
Repeat
Receive Packet($docref;$data;$EOL)
$ok:=OK
if($ok=1)
   //do your stuff (this might change OK variable or generate other error
captured to Trans_error variable)
end if
until (($ok=0)|(Trans_error#0))
On Err Call("")

Alan Chan

4D iNug Technical <[hidden email]> writes:
>repeat
>Receive Packet($docref;$data;$EOL)  //read, this example not as good
>because if in do stuff changes OK and I don’t program around it, the
>until will break
>if (ok=1)
>  //do stuff
>end if
>until (ok=0)

**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: 4D command returning a value request

Aaron
In reply to this post by Aaron
Thank everyone for their recommendation to use the forum for the request, I have begun that process of request

I did see some messages on Global Variables.
4D doesn’t use the term "global variable", though the name of what its called in any programming language is irrelevant.

4D acknowledge that process and interprocess variables are global variables on the 4D knowledgebase
http://kb.4d.com/assetid=77156 <http://kb.4d.com/assetid=77156>

A interprocess variable can be very convenient in 4D , it doesn’t exist in other languages,
   but in other languages a solution would be to implement a database table storing settings for each userid.

thanks,
Aaron
--
Aaron Blazer - Database Analyst
North American Marketing Solutions, Inc. | 3245 N 126th St | Brookfield, WI 53005-3187
Phone: (262)289-9200 x119 | Fax: (262)289-9208
North American Marketing Solutions, Inc. - http://www.nams-inc.com/ <http://www.nams-inc.com/>
Home of 360 Direct - http://www.360direct.com/ <http://www.360direct.com/>
CONFIDENTIALITY NOTE: This email and any attachments are confidential and may be protected by legal privilege. If you are not the intended recipient, be aware that any disclosure, copying, distribution or use of this email or any attachments is prohibited under applicable law. If you have received this email in error, please notify us immediately by returning it to the sender and delete this message in its entirety from your computer.






**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************