Page 6 of 11
Re: Classes in PureBasic
Posted: Thu Oct 23, 2014 3:00 pm
by Fred
So we have to listen to you ? Not everybody wants OOP, and PB won't have a OOP built-in, it's a design choice and I have made it clear a lot of time on this forum. If you don't like it, do as Shield did, find a tool which fits your needs better.
Re: Classes in PureBasic
Posted: Thu Oct 23, 2014 3:12 pm
by skywalk
Fred, would you consider another language spinoff like PooBasic?

Re: Classes in PureBasic
Posted: Thu Oct 23, 2014 3:13 pm
by Fred
PooBasic, really ???????

Re: Classes in PureBasic
Posted: Thu Oct 23, 2014 3:15 pm
by skywalk
I was half kidding.
The other half was serious. I want to import C++ libs without extern C wrappers.

Re: Classes in PureBasic
Posted: Thu Oct 23, 2014 3:25 pm
by Fred
It should may be possible trough special interfaces, so it doesn't requiers built-in OOP.
Re: Classes in PureBasic
Posted: Thu Oct 23, 2014 4:11 pm
by skywalk
Ah, that would be awesome.
The list of C++ libs are growing and not always support extern C.
Forgive my ignorance of features that are OOP limited.
Is the lack of operator and procedure overloading OOP related also?
It is a nuisance to write multiple copies of Procedures just to handle different datatypes.
Re: Classes in PureBasic
Posted: Thu Oct 23, 2014 6:20 pm
by freak
Importing C libs is unlikely in my opinion. The reason is that the C++ standard does not formalize the implementation details of the language so different compilers do important things very differently (name mangling, calling conventions etc.). Trying to handle all that correctly (even if we would support just one C++ compiler per platform) would be much more work than it is worth in my opinion.
Re: Classes in PureBasic
Posted: Thu Oct 23, 2014 7:57 pm
by User_Russian
Fred wrote:Not everybody wants OOP
Because it is not in PB!

In this forum, a lot of requests add OOP.
Really there is not much of tasks for which OOP, most optimal choice. But such tasks have to solve them and the easiest way using OOP.
For example, there are two classes that have the same interface, but the functionality is different. In the procedure of passing a pointer to an object and call methods of the object. Not known in advance what the object class and it does not matter, because the interface is the same. Without OOP do quite complicated (in Example 2 class, but can be greater than 1000).
I can not understand the reason why you refuse to add OOP in PB. Perhaps there is some difficulty in adding (have to rewrite the compiler)?
Re: Classes in PureBasic
Posted: Fri Oct 24, 2014 7:07 am
by idle
Fred wrote:PooBasic, really ???????

Think it's already been done, real-y basic
[stoking the fire]
but concerning classes the only thing that'd really make it easier would be if the compiler could set vtable entries.
I always feel like I'm repeating myself setting them.
for UserRussian, maybe this will help
Code: Select all
Macro DefineClass(name)
Structure name
*vt
EndMacro
Macro ClassInterface(name)
EndStructure
Interface i#name
free()
EndMacro
Macro SetMethod(address)
PokeI(*this\vt+MethodOffset,address)
MethodOffset+SizeOf(Integer)
EndMacro
Macro New(Class,Interfaces)
Procedure New_#Class#()
Protected MethodOffset, *this.class
*this = AllocateMemory(SizeOf(class))
*this\vt = AllocateMemory(SizeOf(Interfaces))
InitializeStructure(*this,class)
EndMacro
Macro EndClassInterface(name)
EndInterface
EndMacro
Macro Methods(name)
Procedure name#_Free(*this.name)
If *this
FreeMemory(*this\vt)
ClearStructure(*this,name)
FreeMemory(*this)
EndIf
EndProcedure
new(name,i#name)
SetMethod(@name#_Free())
EndMacro
Macro EndDefineClass(name)
ProcedureReturn *this
EndProcedure
EndMacro
;-Test the class macros
;1) DefineClass(ClassName)
;2) Add Structure fields eg a.i, list alist.i()
;3) ClassInterface(ClassName)
;4) Define the interface methods
;5) EndClassInterface(ClassName)
;6) Define the class procedures
;7) Methods(ClassName)
;8) SetMethod(@Of_Each_Method_In_The_Same_Order_As_The_Interface())
;9) EndDefineClass(ClassName)
DefineClass(Test)
x.i ;structure fields
ClassInterface(Test)
Plus(*that.Test) ;interface member
Minus(*that.Test)
Set(x.i)
Get()
EndClassInterface(Test)
Procedure Test_Set(*this.Test,x.i) ;do the procedures
*this\x = x
EndProcedure
Procedure Test_Get(*this.Test)
ProcedureReturn *this\x
EndProcedure
Procedure Test_Plus(*this.test,*that.test)
*this\x + *that\x
EndProcedure
Procedure Test_Minus(*this.test,*that.test)
*this\x - *that\x
EndProcedure
Methods(Test) ;define the methods
SetMethod(@Test_Plus()) ;set the function pointers in the vtable
SetMethod(@Test_Minus())
SetMethod(@Test_Set())
SetMethod(@Test_Get())
EndDefineClass(Test) ;end the class
*a.iTest = New_Test()
*b.iTest = New_Test()
*a\Set(2)
*b\set(2)
*a\plus(*b)
Debug *a\get()
*a\minus(*b)
Debug *a\get()
*a\free()
*b\free()
Re: Classes in PureBasic
Posted: Fri Oct 24, 2014 8:01 am
by Shield
There are OOP pre-compilers available that probably do a better job than macros could,
so these might be an option for User_Russian.
Another approach would be using modules, structures and prototypes,
but that has an equally bad typing overhead, though it doesn't require extensive use of macros
or even a pre-compiler.
Re: Classes in PureBasic
Posted: Fri Oct 24, 2014 8:38 pm
by Comtois
skywalk wrote:Fred, would you consider another language spinoff like PooBasic?

Already done

Ok, it's not PooBasic, but Pob-Basic
http://uploads.pob-tech.com/files/docs/ ... tax_en.pdf
Extract from doc :
Re: Classes in PureBasic
Posted: Mon Nov 10, 2014 12:41 pm
by Justin
+1 before the thread get closed
Re: Classes in PureBasic
Posted: Mon Nov 10, 2014 12:57 pm
by bbanelli
-1 ('cause I don't really like them)
Although this types of threads were quite frequent while I was skimming through forum, there are more pressing matters and bug fixes that can make PureBasic even better than it currently is and it does not include OOP.
Classes in PureBasic, ignorance from warped minds.
Posted: Mon Nov 10, 2014 4:37 pm
by heartbone
I won't call the advocates of OOP any vile names, I'll just make the observation that they are victims of an evil plot.
If that crap, excuse me, classes were to be made part of the language then...
1) the language would no longer be BASIC
2) it would take me many times longer, perhaps over a decimal order of magnitude, to get anything accomplished.
As it is PB is a really useful tool, and if the OOP proponents were to be accomodated, then it would become
CRAP.
For example, I recently decided to make a game that I did not even know much about until less than a month ago.
I started the interface layout and creating the graphics on Sunday, October 26, 2014.
My goal is for the game to be easy to play using only the arrow keys.
There will be no fancy eye candy, no awesome sound effects, nor music in this bare bones version.
I am aiming for the game's logic to be stripped down to the bare essentials,
with any extra steps unrelated to the deductive logic elements removed from game play.
Today I'm working on
ALPHA.19 and I'll have a playable BETA in an estimated fifteen to twenty hours of additional work.
If I were using C++, then I'd still be designing the classes.
Dammit Jim, I'm a programmer, not a computer science professor.
Re: Classes in PureBasic, ignorance from warped minds.
Posted: Mon Nov 10, 2014 5:20 pm
by luis
heartbone wrote:
1) the language would no longer be BASIC
It's quite distant from classic Basic already, luckily. Pointers in BASIC ? AH!
heartbone wrote:
2) it would take me many times longer, perhaps over a decimal order of magnitude, to get anything accomplished.
You could simply not use classes.
The problem is the code posted in the forum would certainly change a lot, and probably around 50% of PB user would have an hard time to follow it. Also since PB cannot become object oriented at its core, it would be a procedural Basic with Classes, similarly to C++ that is C with classes.
You would found in the forum good OOP code, good procedural code, crappy OOP code, crappy procedural code, horrible mixed code, sensible mixed code, etc. and only 10% of the forum members would be able to navigate it and adapt it when needed as needed.
Now you just have good and crappy procedural code with some mixed nuance introduced by the modules which are still procedural code inside a box with a very low entry barrier.
Anyone can participate and tinker with what posted, and that's what Fred seems to want according to what he said in the past.