Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.clipper.visual-objects > #13220 > unrolled thread

Function or Object

Started by"Grzegorz R." <ramotny64@gmail.com>
First post2021-01-17 03:30 -0800
Last post2021-01-20 13:09 +0100
Articles 6 — 2 participants

Back to article view | Back to comp.lang.clipper.visual-objects


Contents

  Function or Object "Grzegorz R." <ramotny64@gmail.com> - 2021-01-17 03:30 -0800
    Re: Function or Object "Wolfgang Riedmann" <wriedmann@gmail.com> - 2021-01-18 13:59 +0100
      Re: Function or Object "Grzegorz R." <ramotny64@gmail.com> - 2021-01-18 08:50 -0800
        Re: Function or Object "Wolfgang Riedmann" <wriedmann@gmail.com> - 2021-01-19 07:43 +0100
          Re: Function or Object "Grzegorz R." <ramotny64@gmail.com> - 2021-01-20 03:32 -0800
            Re: Function or Object "Wolfgang Riedmann" <wriedmann@gmail.com> - 2021-01-20 13:09 +0100

#13220 — Function or Object

From"Grzegorz R." <ramotny64@gmail.com>
Date2021-01-17 03:30 -0800
SubjectFunction or Object
Message-ID<7e5c102c-6008-4dd3-85c9-21589e5b0c51n@googlegroups.com>
Hello 
what is better (code, speed, clarity, ...) to use:
1) function
Data := FUN(x)
- where
Function FUN(argument)
  // do calculation
  output := xx
Return Output

or
2) object
Data := FUN{x}:Output
- where
Class FUN
Protect xx as ...
Access Output class FUN
RETURN xx
Init (Argument) Class FUN
  // do calculation
Return SELF

If We need only one output function is more natural but if an output should be more complex data (ex: string + number + logic) then object is easier to use.

Generally what is "better" or when is better to use FUN vs OBJ (Class)?

Rgds
Gregory

[toc] | [next] | [standalone]


#13221

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2021-01-18 13:59 +0100
Message-ID<i6lf0mFd6g9U1@mid.individual.net>
In reply to#13220
Hi Gregory,

the fastest code is using strong typed functions.

Using a class has other advantages, but speed is not one of them. And
since you are passing the parameter in the Init() method, strong typing
is not possible.

If you have more parameter, it could be an option to use a class,
assign the parameter values to strong types variables (assign) and then
call a strong typed method.

Wolfgang

Grzegorz R. wrote:

> Hello 
> what is better (code, speed, clarity, ...) to use:
> 1) function
> Data := FUN(x)
> - where
> Function FUN(argument)
>   // do calculation
>   output := xx
> Return Output
> 
> or
> 2) object
> Data := FUN{x}:Output
> - where
> Class FUN
> Protect xx as ...
> Access Output class FUN
> RETURN xx
> Init (Argument) Class FUN
>   // do calculation
> Return SELF
> 
> If We need only one output function is more natural but if an output
> should be more complex data (ex: string + number + logic) then object
> is easier to use.
> 
> Generally what is "better" or when is better to use FUN vs OBJ
> (Class)?
> 
> Rgds
> Gregory



-- 

[toc] | [prev] | [next] | [standalone]


#13222

From"Grzegorz R." <ramotny64@gmail.com>
Date2021-01-18 08:50 -0800
Message-ID<e9a78d82-81b9-49a7-9453-a56c0f8c62b0n@googlegroups.com>
In reply to#13221
Thank You Wolfgang

You mean something like:

CLASS ItemPrice
  PROTECT nItemPrice
  PROTECT nItemDscnt
  PROTECT nItemTax

ACCESS Price() CLASS ItemPrice
RETURN SELF:nItemPrice

ACCESS Dscnt() CLASS ItemPrice
RETURN SELF:nItemDscnt

ACCESS Tax() CLASS ItemPrice
RETURN SELF:nItemTax

METHOD Init() CLASS ItemPrice
// do nothing or default values
RETURN SELF

METHOD Calc(cCustID as STRING, cItemID as STRING, dDate AS DATE) CLASS ItemPrice
// do calculations & operations with In-Args
  lFound := SEEK(....)
  // get/calc data and store in class vars
  IF lFound
    nItemPrice := ...
    nItemDscnt := ...
    nItemTax := ...
  ENDIF
RETURN lFound

// ====

// main routine
// intermediate data storage
MyItemData := ItemPrice{}
lFoundFlag := ItemPrice:Calc(CustID, ItemID, TODAY())

IF lFoundFlag
  // data use
  ... := MyItemData:Price
  ... := MyItemData:Dscnt
  ... := MyItemData:Tax

//------------------------------

Do I think correct?

Gregory

poniedziałek, 18 stycznia 2021 o 13:59:05 UTC+1 Wolfgang Riedmann napisał(a):
> Hi Gregory, 
> 
> the fastest code is using strong typed functions. 
> 
> Using a class has other advantages, but speed is not one of them. And 
> since you are passing the parameter in the Init() method, strong typing 
> is not possible. 
> 
> If you have more parameter, it could be an option to use a class, 
> assign the parameter values to strong types variables (assign) and then 
> call a strong typed method. 
> 
> Wolfgang
> Grzegorz R. wrote: 
> 
> > Hello 
> > what is better (code, speed, clarity, ...) to use: 
> > 1) function 
> > Data := FUN(x) 
> > - where 
> > Function FUN(argument) 
> > // do calculation 
> > output := xx 
> > Return Output 
> > 
> > or 
> > 2) object 
> > Data := FUN{x}:Output 
> > - where 
> > Class FUN 
> > Protect xx as ... 
> > Access Output class FUN 
> > RETURN xx 
> > Init (Argument) Class FUN 
> > // do calculation 
> > Return SELF 
> > 
> > If We need only one output function is more natural but if an output 
> > should be more complex data (ex: string + number + logic) then object 
> > is easier to use. 
> > 
> > Generally what is "better" or when is better to use FUN vs OBJ 
> > (Class)? 
> > 
> > Rgds 
> > Gregory
> --

[toc] | [prev] | [next] | [standalone]


#13223

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2021-01-19 07:43 +0100
Message-ID<i6ndd9FonpvU1@mid.individual.net>
In reply to#13222
Hi Gregory,

yes, this is what I meant. But I would strong type the entire code:

ACCESS Price() as float pascal CLASS ItemPrice
 RETURN SELF:nItemPrice

METHOD Calc(cCustID as STRING, cItemID as STRING, dDate AS DATE) ;
as logic pascal CLASS ItemPrice
// do calculations & operations with In-Args

Many classes in the .NET Framework work this manner.
Such code is not only fast and imposes correct parameter types, but is
also clear and easy to read even after years.

Wolfgang

Grzegorz R. wrote:

> Thank You Wolfgang
> 
> You mean something like:
> 
> CLASS ItemPrice
>   PROTECT nItemPrice
>   PROTECT nItemDscnt
>   PROTECT nItemTax
> 
> ACCESS Price() CLASS ItemPrice
> RETURN SELF:nItemPrice
> 
> ACCESS Dscnt() CLASS ItemPrice
> RETURN SELF:nItemDscnt
> 
> ACCESS Tax() CLASS ItemPrice
> RETURN SELF:nItemTax
> 
> METHOD Init() CLASS ItemPrice
> // do nothing or default values
> RETURN SELF
> 
> METHOD Calc(cCustID as STRING, cItemID as STRING, dDate AS DATE)
> CLASS ItemPrice // do calculations & operations with In-Args
>   lFound := SEEK(....)
>   // get/calc data and store in class vars
>   IF lFound
>     nItemPrice := ...
>     nItemDscnt := ...
>     nItemTax := ...
>   ENDIF
> RETURN lFound
> 
> // ====
> 
> // main routine
> // intermediate data storage
> MyItemData := ItemPrice{}
> lFoundFlag := ItemPrice:Calc(CustID, ItemID, TODAY())
> 
> IF lFoundFlag
>   // data use
>   ... := MyItemData:Price
>   ... := MyItemData:Dscnt
>   ... := MyItemData:Tax
> 
> //------------------------------
> 
> Do I think correct?
> 
> Gregory
> 
> poniedziałek, 18 stycznia 2021 o 13:59:05 UTC+1 Wolfgang Riedmann
> napisał(a):
> > Hi Gregory, 
> > 
> > the fastest code is using strong typed functions. 
> > 
> > Using a class has other advantages, but speed is not one of them.
> > And since you are passing the parameter in the Init() method,
> > strong typing is not possible. 
> > 
> > If you have more parameter, it could be an option to use a class, 
> > assign the parameter values to strong types variables (assign) and
> > then call a strong typed method. 
> > 
> > Wolfgang
> > Grzegorz R. wrote: 
> > 
> > > Hello 
> > > what is better (code, speed, clarity, ...) to use: 
> > > 1) function 
> > > Data := FUN(x) 
> > > - where 
> > > Function FUN(argument) 
> > > // do calculation 
> > > output := xx 
> > > Return Output 
> > > 
> > > or 
> > > 2) object 
> > > Data := FUN{x}:Output 
> > > - where 
> > > Class FUN 
> > > Protect xx as ... 
> > > Access Output class FUN 
> > > RETURN xx 
> > > Init (Argument) Class FUN 
> > > // do calculation 
> > > Return SELF 
> > > 
> > > If We need only one output function is more natural but if an
> > > output should be more complex data (ex: string + number + logic)
> > > then object is easier to use. 
> > > 
> > > Generally what is "better" or when is better to use FUN vs OBJ 
> > > (Class)? 
> > > 
> > > Rgds 
> > > Gregory
> > --



-- 

[toc] | [prev] | [next] | [standalone]


#13224

From"Grzegorz R." <ramotny64@gmail.com>
Date2021-01-20 03:32 -0800
Message-ID<846e4f06-1ea8-41e8-a64f-9620af88b7abn@googlegroups.com>
In reply to#13223
wtorek, 19 stycznia 2021 o 07:43:56 UTC+1 Wolfgang Riedmann napisał(a):
> Hi Gregory, 
> 
> yes, this is what I meant. But I would strong type the entire code: 
> 
> ACCESS Price() as float pascal CLASS ItemPrice 
> RETURN SELF:nItemPrice 
> 
> METHOD Calc(cCustID as STRING, cItemID as STRING, dDate AS DATE) ; 
> as logic pascal CLASS ItemPrice
> // do calculations & operations with In-Args
> Many classes in the .NET Framework work this manner. 
> Such code is not only fast and imposes correct parameter types, but is 
> also clear and easy to read even after years. 
> 
> Wolfgang
> Grzegorz R. wrote: 
> 
> > Thank You Wolfgang 
> > 
> > You mean something like: 
> > 
> > CLASS ItemPrice 
> > PROTECT nItemPrice 
> > PROTECT nItemDscnt 
> > PROTECT nItemTax 
> > 
> > ACCESS Price() CLASS ItemPrice 
> > RETURN SELF:nItemPrice 
> > 
> > ACCESS Dscnt() CLASS ItemPrice 
> > RETURN SELF:nItemDscnt 
> > 
> > ACCESS Tax() CLASS ItemPrice 
> > RETURN SELF:nItemTax 
> > 
> > METHOD Init() CLASS ItemPrice 
> > // do nothing or default values 
> > RETURN SELF 
> > 
> > METHOD Calc(cCustID as STRING, cItemID as STRING, dDate AS DATE) 
> > CLASS ItemPrice // do calculations & operations with In-Args 
> > lFound := SEEK(....) 
> > // get/calc data and store in class vars 
> > IF lFound 
> > nItemPrice := ... 
> > nItemDscnt := ... 
> > nItemTax := ... 
> > ENDIF 
> > RETURN lFound 
> > 
> > // ==== 
> > 
> > // main routine 
> > // intermediate data storage 
> > MyItemData := ItemPrice{} 
> > lFoundFlag := ItemPrice:Calc(CustID, ItemID, TODAY()) 
> > 
> > IF lFoundFlag 
> > // data use 
> > ... := MyItemData:Price 
> > ... := MyItemData:Dscnt 
> > ... := MyItemData:Tax 
> > 
> > //------------------------------ 
> > 
> > Do I think correct? 
> > 
> > Gregory 
> > 
> > poniedziałek, 18 stycznia 2021 o 13:59:05 UTC+1 Wolfgang Riedmann 
> > napisał(a): 
> > > Hi Gregory, 
> > > 
> > > the fastest code is using strong typed functions. 
> > > 
> > > Using a class has other advantages, but speed is not one of them. 
> > > And since you are passing the parameter in the Init() method, 
> > > strong typing is not possible. 
> > > 
> > > If you have more parameter, it could be an option to use a class, 
> > > assign the parameter values to strong types variables (assign) and 
> > > then call a strong typed method. 
> > > 
> > > Wolfgang 
> > > Grzegorz R. wrote: 
> > > 
> > > > Hello 
> > > > what is better (code, speed, clarity, ...) to use: 
> > > > 1) function 
> > > > Data := FUN(x) 
> > > > - where 
> > > > Function FUN(argument) 
> > > > // do calculation 
> > > > output := xx 
> > > > Return Output 
> > > > 
> > > > or 
> > > > 2) object 
> > > > Data := FUN{x}:Output 
> > > > - where 
> > > > Class FUN 
> > > > Protect xx as ... 
> > > > Access Output class FUN 
> > > > RETURN xx 
> > > > Init (Argument) Class FUN 
> > > > // do calculation 
> > > > Return SELF 
> > > > 
> > > > If We need only one output function is more natural but if an 
> > > > output should be more complex data (ex: string + number + logic) 
> > > > then object is easier to use. 
> > > > 
> > > > Generally what is "better" or when is better to use FUN vs OBJ 
> > > > (Class)? 
> > > > 
> > > > Rgds 
> > > > Gregory 
> > > --
> --
Thank You,
I'm working on my code that is nearly 20 years old when I was much less advanced in object programming and there is a lot of mess to clean-up. :(
Last question concerning above example:
If Init() does nothing and my class is not inherited (ie no any SUPER:Init() ) must it exist or may be omitted?

Regards
Gregory

[toc] | [prev] | [next] | [standalone]


#13225

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2021-01-20 13:09 +0100
Message-ID<i6qksfFdiueU1@mid.individual.net>
In reply to#13224
Hi Gregory,

> I'm working on my code that is nearly 20 years old when I was much
> less advanced in object programming and there is a lot of mess to
> clean-up. :( Last question concerning above example:  If Init() does
> nothing and my class is not inherited (ie no any SUPER:Init() ) must
> it exist or may be omitted?

in VO you don't need an Init method, and I have many cases where I do
not added it intentionally.

But you should be aware that .NET needs a constructor (the Init method
in the .NET world), so you should add it for the case you like to
migrate your code later to X# (both the XPorter and the compiler have
an option to generate missing constructors).
Therefore I have started to add these methods to my VO code whenever I
touch a place where it is missing.

Wolfgang


-- 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.clipper.visual-objects


csiph-web