Oxygen Basic

Programming => Problems & Solutions => Topic started by: José Roca on October 20, 2018, 08:30:06 PM

Title: About Properties
Post by: José Roca on October 20, 2018, 08:30:06 PM
I know that properties are methods in disguise, but Visual Basic and the visual designers have done so much harm that now everybody expects support for them in the classes.
Title: Re: About Properties
Post by: JRS on October 20, 2018, 09:24:23 PM
How do you have a R/O method? Properties suggest a static value be returned even though under the covers it may be an expression. I don't think you will make much headway eliminating properties from the OOP paradigm.
Title: Re: About Properties
Post by: on October 20, 2018, 11:03:24 PM
You don't get irony, do you? Charles is British and will understand me.

Translation for Americans: O2 classes don't support properties and I'm suggesting to add this feature because, although they aren't really needed, since they are methods in disguise, people expects them.
Title: Re: About Properties
Post by: Charles Pegge on October 21, 2018, 12:08:27 AM
Virtual objects are the only exportable form of object, common to all compilers, and virtual objects have virtual variables. Hence the need for properties.

In o2 you can 'set properties' by pseudo-assignment (like the mid statement)

c.vf()=x

Code: [Select]
class cc
========
  int vp
  function vf(int va) {vp=va} 'SET
  function vf() as int {return vp} 'GET
end class

dim as cc c
c.vf()=42
print c.vf()

my non-ironic response :)
Title: Re: About Properties
Post by: José Roca on October 21, 2018, 01:31:10 AM
But properties have at least an index parameter.
Title: Re: About Properties
Post by: Charles Pegge on October 21, 2018, 02:15:41 AM
Can you give us an example of property indexes, José
Title: Re: About Properties
Post by: José Roca on October 21, 2018, 06:47:59 PM
All the COM collections have an Item property with an index parameter. There was also one, whose name can't remember, that had rwo parameters.
Title: Re: About Properties
Post by: Charles Pegge on October 22, 2018, 04:36:38 AM
There's no problem providing indexes to access members of a collection/array object

This a test piece using a direct object (new and del not required) with automatic destruction. This will work with the next o2.

ia.item(15)=42
print ia.item(15)


Code: [Select]
'2018-10-22

uses RTLobjects

class IntArray
==============
  '
  %= si sizeof(int)
  '
  int lbound 'lower limit
  int ubound 'upper limit
  sys buf    'data buffer
  int bytes  'sizeof buffer
  '
  method Create(int l=0, u=0) as IntArray
  =======================================
  return.constructor(l,u)
  end method

  method constructor(int l=0, u=0)
  ================================
  'l lbound
  'u ubound
  lbound=l
  ubound=u
  bytes=si*(ubound-lbound+1)
  buf=getmemory bytes
  end method
  '
  method destructor()
  ===================
  freememory buf
  end method
  '
  method item(int i,int v) 'INPUT
  ===============================
  'SET
  'i index
  'v value
  int a at buf+(i-lbound)*si
  a=v
  end method
  '
  method item(int i) as int 'OUTPUT
  =================================
  'GET
  'i index
  int a at buf+(i-lbound)*si
  return a
  end method
  '
  method ptr(int i) as sys 'RETURN POINTER
  ========================================
  'GET POINTER
  'i index
  return buf+(i-lbound)*si
  end method
  '
  method resize(int n) 'RESIZE ARRAY
  ==================================
  'n number of elements
  sys bo=buf
  int lo=bytes
  n*=si
  bytes=n
  buf=getmemory n
  if bytes then
    if n<lo then lo=n
    copy buf,bo,lo
  end if
  freememory bo
  end method
  '
end class
'
'TESTS
======
let ia=Intarray.create(10,20) 'lbound, ubound
'#recordof ia
ia.item(15)=42
ia.resize(100)
print ia.item(15)
Title: Re: About Properties
Post by: José Roca on October 22, 2018, 05:27:08 AM
I personally don't care if I have to use xx.item(15) instead of xx.item = 15, but the ex-VBer's are always bugging with properties and "for each".

Title: Re: About Properties
Post by: JRS on October 22, 2018, 09:10:32 AM
I don't think O2 needs to emulate VB, only talk to it.
Title: Re: About Properties
Post by: José Roca on October 22, 2018, 09:54:13 AM
To talk with a dead corpse? Who cares?
Title: Re: About Properties
Post by: JRS on October 22, 2018, 10:03:37 AM
If VB stopped working on Windows, it would be a major crisis. VB isn't going away. C# is doing it's best to try and replace it.

VB was designed in a way that keeping it alive after Microsoft tried to abandon it is how it is able to stay relevant. It's not in the same boat as PowerBASIC.
Title: Re: About Properties
Post by: José Roca on October 22, 2018, 08:31:08 PM
It is an endangered specie only useful to maintain legacy applications. I never have liked it.
Title: Re: About Properties
Post by: JRS on October 22, 2018, 09:01:33 PM
You're an API guy. Drag & Drop isn't your style. There is no bad or better, just tools to match ones skill level.
Title: Re: About Properties
Post by: José Roca on October 22, 2018, 09:29:00 PM
If it not was for the API guys, the Drag & Drop guys won't have tools.

Many years ago, a C++ programmer ironically thanked Microsoft for the creation of Visual Basic because it gave C++ programmers the opportunity to make money writing OCX's for it.

Title: Re: About Properties
Post by: JRS on October 23, 2018, 07:45:43 AM
Microsoft's RETRY is C# and the Azure App Store.