LB Booster
« Object Oriented Liberty BASIC? »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 04:08am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1 2 3  Notify Send Topic Print
 veryhotthread  Author  Topic: Object Oriented Liberty BASIC?  (Read 3288 times)
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Object Oriented Liberty BASIC?
« Thread started on: Jun 8th, 2014, 09:39am »

It's been suggested that it could be useful to add some simple OO (Object Oriented) features to LBB. That's certainly something I would be prepared to consider, but I'm not sure what the take-up would be. The impression I get is that a lot of LB programmers are quite 'old school' - too often I see programs that still use GOSUB! - and might find OO programming rather 'alien'.

If I were to go down that route I would expect to add the following keywords initially: CLASS, METHOD, NEW (or NEWOBJECT), DISCARD, INHERIT. They would support the fundamental operations necessary to create and manipulate objects. Note that it almost certainly wouldn't be practical to implement automatic object destruction when dropping out of 'scope'.

I would appreciate some feedback on this. Would you actually use such a feature if it was added?

Richard.
User IP Logged

lancegary
New Member
Image


member is offline

Avatar




PM


Posts: 9
xx Re: Object Oriented Liberty BASIC?
« Reply #1 on: Jun 8th, 2014, 10:17pm »

Sounds a great idea though I would have to learn how to use them.

Thanks for the recent update as well.

Lance
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Object Oriented Liberty BASIC?
« Reply #2 on: Jun 15th, 2014, 8:30pm »

The conventional syntax for accessing an object method or field (member variable) would be to use a dot, such as object.method() or object.field, but the fact that a dot is a valid character in an LB identifier complicates things.

LB resolves the ambiguity in respect of structure members by adding the .struct suffix, and in principle it would be possible to adopt a similar syntax such as .object, but personally I think this is ugly.

So I am currently thinking that an OOP extension for LB could instead use the scope resolution operator ::, for example object::method() or object::field. In languages which use both the dot and :: notations there is a subtle difference in their meaning, but I am hoping that would only worry purists!

What do people think?

Richard.
User IP Logged

lancegary
New Member
Image


member is offline

Avatar




PM


Posts: 9
xx Re: Object Oriented Liberty BASIC?
« Reply #3 on: Jun 17th, 2014, 2:12pm »

on Jun 15th, 2014, 8:30pm, Richard Russell wrote:
The conventional syntax for accessing an object method or field (member variable) would be to use a dot, such as object.method() or object.field, but the fact that a dot is a valid character in an LB identifier complicates things.

LB resolves the ambiguity in respect of structure members by adding the .struct suffix, and in principle it would be possible to adopt a similar syntax such as .object, but personally I think this is ugly.

So I am currently thinking that an OOP extension for LB could instead use the scope resolution operator ::, for example object::method() or object::field. In languages which use both the dot and :: notations there is a subtle difference in their meaning, but I am hoping that would only worry purists!

What do people think?

Richard.


I don't know enough to comment intelligently. The double colon is used in Fortran, I think. The subtle difference escapes me, however. They say beautiful aircraft fly well and mathematicians believe that all good maths is elegant or beautiful. So if the notation system seems elegant to you I'm sure it will be a pleasure for us to use.

Lance
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Object Oriented Liberty BASIC?
« Reply #4 on: Jun 22nd, 2014, 7:38pm »

The lack of feedback possibly indicates that people can't see the benefit in Object Oriented extensions to LBB. Here's an illustration (adapted from a Visual BASIC example) of how OOP features can be used simply to provide data structures which are otherwise not available in LB; in this case there are no 'methods' (subs or functions) in the classes:

Code:
    Dim person(10) As Person
    person(9)::Name$(1) = "John"
    person(9)::Name$(2) = "Smith"
    person(9)::address1::Street$(1) = "10"
    person(9)::address1::Street$(2) = "Royal Avenue"
    person(9)::address1::City$ = "Beverly Hills"
    person(9)::address1::Zip$  = "90210"

    Print person(9)::Name$(1); " ";
    Print person(9)::Name$(2)
    Print person(9)::address1::Street$(1); " ";
    Print person(9)::address1::Street$(2)
    Print person(9)::address1::Zip$
    Discard person()
    End

Class Person
    Dim Name$(2), address1 As Address
End Class

Class Address
    Dim Street$(3), City$, Zip$
End Class 

Richard.
User IP Logged

Sean
New Member
Image


member is offline

Avatar




PM


Posts: 6
xx Re: Object Oriented Liberty BASIC?
« Reply #5 on: Jun 23rd, 2014, 10:39am »

I would love to have OOPS, but we (the lb'ers) were kept waiting and are still waiting rolleyes I think we have moved on. Does BBC basic support OOPS? I have moved on to AutoIt and Lazarus myself.
« Last Edit: Jun 23rd, 2014, 10:40am by Sean » User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Object Oriented Liberty BASIC?
« Reply #6 on: Jun 24th, 2014, 1:38pm »

on Jun 23rd, 2014, 10:39am, Sean wrote:
I would love to have OOPS, but we (the lb'ers) were kept waiting and are still waiting rolleyes I think we have moved on. Does BBC basic support OOPS? I have moved on to AutoIt and Lazarus myself.

I see. If you feel like that, why did you join this forum?

Richard.
User IP Logged

Sean
New Member
Image


member is offline

Avatar




PM


Posts: 6
xx Re: Object Oriented Liberty BASIC?
« Reply #7 on: Jun 24th, 2014, 2:34pm »

To praise your work. LBB definitely is going into my toolkit.
User IP Logged

bluatigro
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 111
xx Re: Object Oriented Liberty BASIC?
« Reply #8 on: Jan 20th, 2015, 09:06am »


i wood like it when
objects can be stored sepredly
in a *.bas

and can be added whit a 'import'
or 'include' comand

and i like to have operator overloading
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Object Oriented Liberty BASIC?
« Reply #9 on: Jan 20th, 2015, 09:17am »

on Jan 20th, 2015, 09:06am, bluatigro wrote:
and can be added whit a 'import' or 'include' command

LBB has an 'include command. It works in a similar fashion to LB Workshop's include command, except that in LBW the included code is appended to the program, whereas in LBB it is inserted where the include statement is:

http://www.lbbooster.com/lbb.html#directives

The command is only recognised if it starts in the first column; preceding whitespace is not accepted. Also, for compatibility with LBW, 'include is ignored if it is at the very start of the program:

Code:
'ensure include is not the first line
'include mylib.bas 

Edit:
Quote:
and i like to have operator overloading

Isn't 'operator overloading' useful only if the language has user-defined data types? Liberty BASIC doesn't (it has just numbers and strings).

Effectively there is already operator overloading to the extent that the + operator means different things for numbers and strings. Also, in LBB, some operators work on complete arrays:

Code:
    a() = b() + c() 

Richard.
« Last Edit: Jan 20th, 2015, 1:06pm by Richard Russell » User IP Logged

bluatigro
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 111
xx Re: Object Oriented Liberty BASIC?
« Reply #10 on: Jan 20th, 2015, 11:11am »

'include error ?
or wat else do i wrong ?
_math.bas Code:
''bluatigro 20 jan 2015 :
''_math.bas
global pi , golden.ratio
pi = atn( 1 ) * 4
golden.ratio = ( sqr( 5 ) - 1 ) / 2
global true , false
true = not( false )
end
function rad( deg )
  rad = deg * pi / 180
end function
 

_color.bas Code:
'include _math.bas
''bluatigro 20 jan 2015 : 
''_color.bas
global black$ , red$ , green$ , yellow$
global blue$ , magenta$ , cyan$ , white$
global gray$ , pink$ , purple$ , orange$
black$   = rgb$( 000 , 000 , 000 )
red$     = rgb$( 255 , 000 , 000 ) 
green$   = rgb$( 000 , 255 , 000 ) 
yellow$  = rgb$( 255 , 255 , 000 ) 
blue$    = rgb$( 000 , 000 , 255 ) 
magenta$ = rgb$( 255 , 000 , 255 ) 
cyan$    = rgb$( 000 , 255 , 255 ) 
white$   = rgb$( 255 , 255 , 255 ) 
gray$    = rgb$( 127 , 127 , 127 ) 
pink$    = rgb$( 255 , 127 , 127 ) 
purple$  = rgb$( 127 , 000 , 127 ) 
orange$  = rgb$( 255 , 127 , 000 ) 
end
function rgb$( r , g , b )
  r = r and 255
  g = g and 255
  b = b and 255
  rgb$ = str$( r ); " " ; g * 256 ; " " ; b * 256 ^ 2
end function
function red( clr$ )
  red = val( word$( clr$ , 1 ) ) 
end function
function green( clr )
  green = val( word$( clr$ , 2 ) )
end function
function blue( clr$ )
  blue = val( word$( clr$ , 3 ) ) 
end function
function klmix$( kl1$ , f , kl2$ )
  r1 = red( kl1$ )
  g1 = green( kl1$ )  
  b1 = blue( kl1$ )  
  r2 = red( kl2$ )
  g2 = green( kl2$ )
  b2 = blue( kl2$ )
  r = r1 + f * ( r2 - r1 )
  g = g1 + f * ( g2 - g1 )
  b = b1 + f * ( b2 - b1 )  
  klmix$ = rgb$( r , g , b )
end function
function rainbow$( deg )
  rainbow$ = rgb$( sin( rad( deg ) ) * 127 + 128 _
                 , sin( rad( deg + 120 ) ) * 127 + 128 _
                 , sin( rad( deg - 120 ) ) * 127 + 128 )
end function  
 

_sphere.bas Code:
'include _color.bas
''bluatigro 20 jan 1015
''_sphere.bas
WindowWidth = DisplayWitdh
WindowHeight = DisplayHeight
global winx , winy
winx = WindowWidth
winy = WindowHeight
global height
sub sphere h$ , x , y , z , d , clr$
  if abs( height - y ) < d then
    dd = sqr( d ^ 2 - ( height - y ) ^ 2 + .001 ) * 2
    kl$ = mix$( clr$ , .5 - ( height - y ) / d / 2 , black$ )
    #h$ "goto " ; x + winx / 2 ;" "; winy / 2 - height - z / 4 
    #h$ "backcolor " ; kl$
    #h$ "color" ; kl$
    #h$ "down"
    #h$ "ellipsefilled "; dd ;" "; dd / 4 
    #h$ "up"
  end if
end sub                               
 

main Code:
'include "_sphere.bas"
nomainwin
open "sphere-test" for graphics as #m
  #m "trapclose [quit]"
  for height = 0-winy/2 to winy/2
    call sphere #m , 0 , 0 , 0 , 50 , red$
  next height
wait
[quit]
  close #m
end
 
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Object Oriented Liberty BASIC?
« Reply #11 on: Jan 20th, 2015, 11:24am »

on Jan 20th, 2015, 11:11am, bluatigro wrote:
or wat else do i wrong ?

Nothing "wrong" exactly, but you are hoping that 'include can be 'nested', i.e. that one included file can include another file, etc. Unfortunately it doesn't work like that in LBB, you can only use 'include in your 'main program':

Code:
nomainwin
open "sphere-test" for graphics as #m
  #m "trapclose [quit]"
  for height = 0-winy/2 to winy/2
    call sphere #m , 0 , 0 , 0 , 50 , red$
  next height
wait
[quit]
  close #m
end
'include _sphere.bas
'include _math.bas
'include _color.bas 

As far as I'm aware LB Workshop's include has the same limitation.

Richard
« Last Edit: Jan 20th, 2015, 1:01pm by Richard Russell » User IP Logged

bluatigro
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 111
xx Re: Object Oriented Liberty BASIC?
« Reply #12 on: Jan 20th, 2015, 2:06pm »

i tryed this Code:
nomainwin
open "" for graphics as #m
  #m "trapclose [quit]"
  #m "fill black"
  for height = 0-winy/2 to winy/2
    call sphere 0 , 0 , 0 , 50 , red$
  next height
wait
[quit]
  close #m
end
'include _math.bas
'include _color.bas
'include _sphere.bas
 

Code:
''bluatigro 20 jan 1015
''_sphere.bas

  WindowWidth = DisplayWitdh
  WindowHeight = DisplayHeight
  global winx , winy
  winx = WindowWidth
  winy = WindowHeight
  global height

sub sphere x , y , z , d , clr$
  if abs( height - y ) < d then
    dd = sqr( d ^ 2 - ( height - y ) ^ 2 + .001 ) * 2
    kl$ = mix$( clr$ , .5 - ( height - y ) / d / 2 , black$ )
    #m "goto " ; x + winx / 2 ;" "; winy / 2 - height - z / 4 
    #m "backcolor " ; kl$
    #m "color" ; kl$
    #m "down"
    #m "ellipsefilled "; dd ;" "; dd / 4 
    #m "up"
  end if
end sub                               
 

_math.bas and _color.bas are not changed

error :
- where is my red sphere
- the window isnt fulscreen
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: Object Oriented Liberty BASIC?
« Reply #13 on: Jan 20th, 2015, 4:42pm »

on Jan 20th, 2015, 2:06pm, bluatigro wrote:
- where is my red sphere
- the window isnt fulscreen

I think your problem is that the code is now in the wrong sequence. Your 'included' file _sphere.bas contains both initialisation code which must come before the 'open for graphics' (e.g. setting WindowWidth and WindowHeight) and code which must come after the open statement (e.g. sub sphere). That can't work!

You either need to transfer the initialisation code into the 'main program', or you need to split your included file into two parts (e.g. _sphereinit.bas and _spheresub.bas) so you can include them in different places:

Code:
nomainwin
'include _sphereinit.bas
open "" for graphics as #m
  #m "trapclose [quit]"
  #m "fill black"
  for height = 0-winy/2 to winy/2
    call sphere 0 , 0 , 0 , 50 , red$
  next height
wait
[quit]
  close #m
end
'include _spheresub.bas 

There's nothing 'magic' about 'include: the resulting 'merged' program must follow all the usual rules governing the order in which things are declared.

Richard.
User IP Logged

bluatigro
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 111
xx Re: Object Oriented Liberty BASIC?
« Reply #14 on: Jan 23rd, 2015, 11:30am »


update :
- all global's are now in *_init.bas

error :
- same errors

Code:
'include _fullscreen_init.bas
'include _math_init.bas
'include _color_init.bas
'include _sphere_init.bas
nomainwin
open "" for graphics as #m
  #m "trapclose [quit]"
  #m "fill black"
  for height = 0-winy/2 to winy/2
    call sphere 0 , 0 , 0 , 50 , red$
  next height
wait
[quit]
  close #m
end
'include _math.bas
'include _color.bas
'include _sphere.bas
 
User IP Logged

Pages: 1 2 3  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls