If no OOP, how about object-based coding style in PB?

Everything else that doesn't fall into one of the other PB categories.
milliHelp
User
User
Posts: 18
Joined: Sun Jun 29, 2003 10:14 pm

If no OOP, how about object-based coding style in PB?

Post by milliHelp »

Hi!

Whereas the PB government clearly states there are no plans to add an OOP-flavour to the language, it's possible to use an object-based syntax for coding.
It can be easily implemented using macros. Obviously, this complicates debugging, but nevertheless.

What do you think about writing this:

Code: Select all

_(window, w0, open(20,20,50,50,"My First Win"))
with w0
  \size(300,200) :\color(RGB(255,230,230)) __
  
_(window, w1)
with w1
  \open(400,10,400,100,"w1") :\color( w0\color()+100 ) :\timer(0,50) :\title("My Second Win")
  s$= "!!!" :\title( s$ ) __
  
_(menu, m) 
with m
  \make(w0)
  \title("Fruits") :\item(0,"Apples") :\bar() :\item(1,"Bananas") __
with m
  \title("Props")
  \sub("&Colors") :\item(10,"Red") :\item(11,"Green") :\item(12,"Blue") :\sub_()
  \bar() :\item(13,"&More...") __

repeat 
  e = w1\waitEv()
  If e=#PB_Event_Timer: w1\x( w1\x_()+1 ): w0\y( w0\y_()+1 ): EndIf
  
until e = cEv(CloseWindow) 
end
instead of this? :

Code: Select all

w0 = OpenWindow(#PB_Any, 20, 20, 50, 50, "My First Win", 0)
ResizeWindow(w0, #PB_Ignore, #PB_Ignore, 300, 200)
SetWindowColor(w0, RGB(255, 230, 230))

w1 = OpenWindow(#PB_Any, 400, 10, 400, 100, "w1", 0)
SetWindowColor(w1, GetWindowColor(w0)+100 )
AddWindowTimer(w1, 0, 50)
SetWindowTitle(w1, "MySecond Win")
s$="!!!"
SetWindowTitle(w1, GetWindowTitle(w1)+s$)

m = CreateMenu(#PB_Any, WindowID(w0))
MenuTitle("Fruits")
MenuItem(0, "Apples")
MenuBar()
MenuItem(1, "Bananas")

MenuTitle("Properties")
OpenSubMenu("&Colors")
MenuItem(10, "Red")
MenuItem(11, "Green")
MenuItem(12, "Blue")
CloseSubMenu()
MenuBar()
MenuItem(13, "&More...")

Repeat 
  e = WaitWindowEvent()
  If e=#PB_Event_Timer 
    ResizeWindow(w1, WindowX(w1)+1, #PB_Ignore, #PB_Ignore,#PB_Ignore)
    ResizeWindow(w0, #PB_Ignore, WindowY(w0)+1, #PB_Ignore,#PB_Ignore) 
  EndIf
  
Until e = #PB_Event_CloseWindow 
End
Last edited by milliHelp on Mon Jan 18, 2016 3:48 pm, edited 1 time in total.
User avatar
TI-994A
Addict
Addict
Posts: 2700
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: If no OOP, how about object-based coding style in PB?

Post by TI-994A »

milliHelp wrote:What do you think about writing this:

Code: Select all

_(window, w0, open(20,20,50,50,"My First Win"))
with w0
  \size(300,200) :\color(RGB(255,230,230)) __
  
_(window, w1)
with w1
  \open(400,10,400,100,"w1") :\color( w0\color()+100 ) :\timer(0,50) :\title("My Second Win")
  s$= "!!!" :\title( s$ ) __
  
_(menu, m) 
with m
  \make(w0)
  \title("Fruits") :\item(0,"Apples") :\bar() :\item(1,"Bananas") __
with m
  \title("Props")
  \sub("&Colors") :\item(10,"Red") :\item(11,"Green") :\item(12,"Blue") :\sub_()
  \bar() :\item(13,"&More...") __

repeat 
  e = w1\waitEv()
  If e=#PB_Event_Timer: w1\x( w1\x_()+1 ): w0\y( w0\y_()+1 ): EndIf
  
until e = cEv(CloseWindow) 
end
Well, I think it's gibberish. :lol:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
HanPBF
Enthusiast
Enthusiast
Posts: 570
Joined: Fri Feb 19, 2010 3:42 am

Re: If no OOP, how about object-based coding style in PB?

Post by HanPBF »

There are various OOP like solutions available:
- using interface
- using select-case
- using precompiler (please search forum)

PreCompiler lacks autocompletion feature/intellisense, select-case makes hand-crafted multiple dispatch possible, interface gives good OOP.

If PureBasic got anonymous procedures, that would be a quantum leap...

Code: Select all

; non working code just as example for a way a closure might be called
procedure test()
  aTestCall(closure
    debug "in closure"
  endClosure)
endProcedure
Even with interface and events You need to write verbose, artificial procedure names...
Must not be a true closure holding the outer scope; don't like that either.


Btw, shouldn't we have a
Board index » PureBasic » OOP
forum? :wink:
User avatar
heartbone
Addict
Addict
Posts: 1058
Joined: Fri Apr 12, 2013 1:55 pm
Location: just outside of Ferguson

Re: If no OOP, how about object-based coding style in PB?

Post by heartbone »

HanPBF wrote:Btw, shouldn't we have a
Board index » PureBasic » OOP
forum? :wink:
No. :wink:
This forum is here to support PureBASIC.

(Although understandable as misery loves company,)
the desire for OOP constructs to be made available within a BASIC language is a very STUPID concept which arises from abused minds.

However, if you really need it, there is nothing stopping you from making another wacky off topic thread, dedicated on extolling the virtues of OOP to indie BASIC programmers.
Keep it BASIC.
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: If no OOP, how about object-based coding style in PB?

Post by Lunasole »

heartbone wrote: (Although understandable as misery loves company,)
the desire for OOP constructs to be made available within a BASIC language is a very STUPID concept which arises from abused minds.

However, if you really need it, there is nothing stopping you from making another wacky off topic thread, dedicated on extolling the virtues of OOP to indie BASIC programmers.
I don't see anything stupid or opposing to procedural programming if you using "class modules" (the term from VB6, simplified form of OOP). They just like already existing modules in PB, but allowing you not to morph your code to a bloated piece of shit if you need to use few instances of some code doing different things, also wrapping any complex subsystem into them keeps code clear and makes it more transparent and reliable, makes program architecture better.
So stupid is "baby duck syndrome", not allowing to see something like this to be implemented in BASIC-like language 'cause there was no OOP on Amiga in 80th', lol.

Also it is not correct to call Purebasic as BASIC-language, it is so far from original BASICs (except 3.5 similar keywords) so you should better compare it to C (or Objective C, cause there are interfaces and other high-level stuff that C misses).
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
User avatar
heartbone
Addict
Addict
Posts: 1058
Joined: Fri Apr 12, 2013 1:55 pm
Location: just outside of Ferguson

Re: If no OOP, how about object-based coding style in PB?

Post by heartbone »

Lunasole wrote:
heartbone wrote: (Although understandable as misery loves company,)
the desire for OOP constructs to be made available within a BASIC language is a very STUPID concept which arises from abused minds.
However, if you really need it, there is nothing stopping you from making another wacky off topic thread, dedicated on extolling the virtues of OOP to indie BASIC programmers.
I don't see anything stupid or opposing to procedural programming if you using "class modules" (the term from VB6, simplified form of OOP). They just like already existing modules in PB, but allowing you not to morph your code to a bloated piece of shit if you need to use few instances of some code doing different things, also wrapping any complex subsystem into them keeps code clear and makes it more transparent and reliable, makes program architecture better.
:?: :?: :?:
So stupid is "baby duck syndrome", not allowing to see something like this to be implemented in BASIC-like language 'cause there was no OOP on Amiga in 80th', lol.
About the lack of OOP in the 80's, thank heavens! :lol: Otherwise, I think much less progress would have been made.
Also it is not correct to call Purebasic as BASIC-language, it is so far from original BASICs (except 3.5 similar keywords) so you should better compare it to C (or Objective C, cause there are interfaces and other high-level stuff that C misses).
I disagree with you there, but you'd better take that up with Fantaisie Software. I will tell you that I was looking for a new software development environment when I discovered PureBasic, and if BASIC was not part of the name, then I likely would not have investigated it. Obviously it was what I had been searching for.

I consider most of the high level languages that I've selected for indie programming to be more Fortran 77 like, than an original line numbered BASIC.
The sole exception, ATARI BASIC, truly was a classic BASIC, a format too limited for substantial projects.

Using PureBasic to develop software, after many years of using other earlier similar toolsets, is a joy.
I truly appreciate the wisdom and vision of Fred in resisting clutter, bloat, and perversion of a fine tool.
A tool that is truly out of sync with the prevailing "wisdom".

I suspect anyone who gets computer programming taught to them at school will be using a Scratch like language, or an object oriented language.
It's really too bad that the schools and universities are not more concerned with creating effective programmers.
Otherwise PB would have an essential place in the classrooms across the globe.
Unfortunately, at this time there is little to no place for PureBasic when training future corporate software developers.
Keep it BASIC.
milliHelp
User
User
Posts: 18
Joined: Sun Jun 29, 2003 10:14 pm

Re: If no OOP, how about object-based coding style in PB?

Post by milliHelp »

In fact, the idea is not about OOP itself, in its deepest depth, purity and completeness. It's already shown many times that we can implement OOP infrastructure in PB manually, but the solutions appear to be too heavyweight.

The thought is just about having one more coding style, which in some cases may be appropriate and handy. It seems we already have a couple of generations of programmers who started their careers with OBJECT.METHOD()-like syntax. And in deed it's rather flexible, terse and aesthecially pleasant - VB/VBA scripts or jquery-based code (with its chaining coding techniques) can be examples.

Even without user-defined objects, having only a set of predefined objects wrapping in their methods calls to library commands, may be a nice addition.
Such a wrapper library, if implemented via macros, may resemble c++ headers, included in the program.

So is the metaphysics.
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: If no OOP, how about object-based coding style in PB?

Post by Lunasole »

heartbone wrote:About the lack of OOP in the 80's, thank heavens! :lol: Otherwise, I think much less progress would have been made.
But the progress came to OOP anyway. Even those who still writing in C using custom OOP emulation based on structures and pointers to functions, cause it is almost impossible to write something more or less complex without such tricks (you will got extremely bloated and trashed code which will be hard to improve and debug further, if no OOP usage even in such form). So what's the smartest, if you writing such stuff by yourself and wasting time for it on every project, or if language gives some basic OOP abilities and you don't waste your time for implementing such routines everytime?
I truly appreciate the wisdom and vision of Fred in resisting clutter, bloat, and perversion of a fine tool.
You talking about his "wisdom and vision", but if you read his interviews you will see that he doesn't use PB for his serious projects. He used java, C++, and such crap, fully object-based. Even the PB itself is written far from procedural-only. It doesn't logically merging with "anti-OOP vision" :) So maybe there are other reasons.
It's really too bad that the schools and universities are not more concerned with creating effective programmers.
Otherwise PB would have an essential place in the classrooms across the globe.
Unfortunately, at this time there is little to no place for PureBasic when training future corporate software developers.
It is sad, but from corporate sector nobody needs that. In 2016 computers are so powerful and have so much memory that even some poorly written java-crap can work without visible problems and average user found it fine. So we got the same programs as in 2000x, doing the same stuff but eating x50 more resources. Even drivers often are such a piece of monkey-product, for example my AMD video driver service is written on .NET and eats resources almost as middle modern game, also working very poorly "having 3 button-interface and 4 settings", so I just turned that useless monster off. Jokes about "mouse driver takes 50mb" are now real, but that is not OOP problems itself (good programs are good in classes too), it's because all the things now are much more commercialized and companies want to make things faster and produce them more often, it's a global degradation trend for anything what becomes popular enough and there is nothing to do with that, the OOP is a tool, not a reason of that all.

Anyway, me personally dislike OOP too and almost never used it even writing at languages supporting it. I just want to tell it has to be supported to allow not doing the same stupid routine shit (which also looks ugly and bloated in code) everytime when you need some part of code to work in several instances separately. That's why i like the concept of very limited OOP to be present in language ("class modules"), not the OOP as language paradigm. And surely such class modules don't lead to performance or other issues, they just wrapping C-style OOP emulation to handy and usable form.
The other OOP-usage I found justified, is it's usage to bind some external libs exporting classes. If you have ever dealing with such C++ object dlls/libs you should know how complicated it is if you trying to use such lib from PB while it has no special support for this.
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: If no OOP, how about object-based coding style in PB?

Post by Keya »

millihelp, with all due respect it looks like youre saying "rather than Purebasic syntax why dont we change it to use CSS/HTML-style instead?" (any chance you're a web developer?), and I can't see a single advantage - it doesn't read any more easily (quite worse actually i think), it's not any faster to produce (and your demo uses multiple lines for the PB source when in the OOP version you've bundled them all into one, giving unfair and false impression of decreased size), and it would require a lot of work - both from Fred and from the minds of existing PB developers who've taken the time to get used to the existing syntax :D If you want to design in CSS-style (or whatever that is) i'd suggest using a language that at least is already nearly in that style, rather than taking something so far away as a procedural desktop language and trying alchemy-style to turn it upside down on its head :)
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: If no OOP, how about object-based coding style in PB?

Post by Dude »

milliHelp wrote:What do you think about writing this
I think it looks like crap. Sorry, but you asked. :)
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: If no OOP, how about object-based coding style in PB?

Post by Dude »

HanPBF wrote:Btw, shouldn't we have a
Board index » PureBasic » OOP
forum? :wink:
Nope. Those who want OOP can find an OOP language and frequent that forum.
HanPBF
Enthusiast
Enthusiast
Posts: 570
Joined: Fri Feb 19, 2010 3:42 am

Re: If no OOP, how about object-based coding style in PB?

Post by HanPBF »

Hello Dude and Heartbone,

I wanted another forum to collect the OOP-wishes appearing every 1 to 2 months to have there own place...
It's a little repetitive annoyance here (but it's o.k.).

My still existing wish is to forbid using "OOP" as a word in this forum; but maybe some won't like this neither...

The problem is, if You extend the compiler to typing and dispatch You must extend also the tool.
I really appreciate the auto completion we have with PureBasic and would want it to have with dispatched procedures, too.

What I would first like to see is more acceptance by those who wish "OOP" that the implementation is a really, really, really big step!

Why do we have so many OOP-proposals; may they be precompiled or by interface or macros but no one says: "and here is the editor for this conecpt". To have an idea about a new syntax or type system or "OOP" is easy; but the way to implementation is hard.

The only way is: build a precompiler and an IDE with auto completion and prove it works; then PB may be influenced by that somewhen.

And please accept that there is not one "OOP"! There are many.

In my work programming solves 5% of the problems. There are other things making more headache...

I think generating code the way You want is o.k.. For that task, take PB: it's done fast and runs fast..
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: If no OOP, how about object-based coding style in PB?

Post by IdeasVacuum »

You are marching into Rome and saying you don't want to talk in Italian - can they change their language to Greek? If you really need OOP, use an OOP language, leave this Procedural language alone!
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
heartbone
Addict
Addict
Posts: 1058
Joined: Fri Apr 12, 2013 1:55 pm
Location: just outside of Ferguson

Re: If no OOP, how about object-based coding style in PB?

Post by heartbone »

Lunasole wrote:
heartbone wrote:I truly appreciate the wisdom and vision of Fred in resisting clutter, bloat, and perversion of a fine tool.
You talking about his "wisdom and vision", but if you read his interviews you will see that he doesn't use PB for his serious projects. He used java, C++, and such crap, fully object-based. Even the PB itself is written far from procedural-only.
The only serious projects of Fred that I am familiar with, are PureBasic and SpiderBasic.

Of course PureBasic could not be written in itself.
I am under the impression that SpiderBasic was written using PureBasic.
Lunasole, what projects are you referring to?
IdeasVacuum wrote:You are marching into Rome and saying you don't want to talk in Italian - can they change their language to Greek? If you really need OOP, use an OOP language, leave this Procedural language alone!
Exactly, except in my analogy it was in Quebec trying to change French to Spanish.
Keep it BASIC.
HanPBF
Enthusiast
Enthusiast
Posts: 570
Joined: Fri Feb 19, 2010 3:42 am

Re: If no OOP, how about object-based coding style in PB?

Post by HanPBF »

I didn't get it:
Of course PureBasic could not be written in itself.
Why???? Or did I miss the context?
Post Reply