Classes in PureBasic
Re: Classes in PureBasic
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.
quidquid Latine dictum sit altum videtur
-
- Addict
- Posts: 1518
- Joined: Wed Nov 12, 2008 5:01 pm
- Location: Russia
Re: Classes in PureBasic
Because it is not in PB!Fred wrote:Not everybody wants 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
Think it's already been done, real-y basicFred wrote:PooBasic, really ???????

[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()
Windows 11, Manjaro, Raspberry Pi OS


Re: Classes in PureBasic
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.
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.
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
Re: Classes in PureBasic
Already doneskywalk wrote:Fred, would you consider another language spinoff like PooBasic?

http://uploads.pob-tech.com/files/docs/ ... tax_en.pdf
Extract from doc :
The Basic syntax of the POB-Basic And all of documentations come from PureBasic:
http://www.purebasic.com/
Please correct my english
http://purebasic.developpez.com/
http://purebasic.developpez.com/
Re: Classes in PureBasic
+1 before the thread get closed
Re: Classes in PureBasic
-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.
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.
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.
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.
Keep it BASIC.
Re: Classes in PureBasic, ignorance from warped minds.
It's quite distant from classic Basic already, luckily. Pointers in BASIC ? AH!heartbone wrote: 1) the language would no longer be BASIC
You could simply not use classes.heartbone wrote: 2) it would take me many times longer, perhaps over a decimal order of magnitude, to get anything accomplished.
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.
"Have you tried turning it off and on again ?"
A little PureBasic review
A little PureBasic review
Re: Classes in PureBasic, ignorance from warped minds.
With modules, we are nearly there, syntactically. And how about that...code that does not use modules has not changed because of the feature.heartbone wrote:As it is PB is a really useful tool, and if the OOP proponents were to be accomodated, then it would become CRAP.
Heartbone, you are making the wild assumption that adding features alters existing syntax. The module is the perfect example to disprove that assumption.
Just because you hate a feature does not mean you should be against it. I am not likely to use oop myself, but I would like to have the feature because I think it will open PB up to a wider audience.
Re: Classes in PureBasic
And 1+1 still equals 2.Tenaja wrote:With modules, we are nearly there, syntactically. And how about that...code that does not use modules has not changed because of the feature.
Wrong and wrong.Heartbone, you are making the wild assumption that adding features alters existing syntax. The module is the perfect example to disprove that assumption.
Wrong.Just because you hate a feature does not mean you should be against it.
How else can you use something?I am not likely to use oop myself,
IMO, from a programming perspective that's an illogical justification for such a major change of methodology.but I would like to have the feature because I think it will open PB up to a wider audience.
Keep it BASIC.
Re: Classes in PureBasic
Here's my two cents on the subject.
I'm relatively new to C++, but I've been learning a little by little over the last year. So, I'm not as knowledgeable as others, but I'd like to think I have a little understanding of classes.
From what I've learned so far I'll say that any competent programer can learn how to use a class system with little effort.
It isn't rocket science after all. Just by using them a little bit one will learn how easy they are to use.
Now will classes ever be added to Purebasic. I doubt it, but I won't be against it if the team decides to implement them into Purebasic.
Adding new features will only help Purebasic in the long run. It's just if the features are worth the effort to implement.
I'm relatively new to C++, but I've been learning a little by little over the last year. So, I'm not as knowledgeable as others, but I'd like to think I have a little understanding of classes.
From what I've learned so far I'll say that any competent programer can learn how to use a class system with little effort.
It isn't rocket science after all. Just by using them a little bit one will learn how easy they are to use.
Now will classes ever be added to Purebasic. I doubt it, but I won't be against it if the team decides to implement them into Purebasic.
Adding new features will only help Purebasic in the long run. It's just if the features are worth the effort to implement.
-
- Addict
- Posts: 1518
- Joined: Wed Nov 12, 2008 5:01 pm
- Location: Russia
Re: Classes in PureBasic
All who oppose classes probably nothing not know about them! Nobody is forcing you to use OOP, but its implementation should be in PB!
For some task types, they are ideal, and their absence is very difficult to develop and modernize code. Using interfaces and DataSection (To store addresses procedures) greatly complicates the code reduces its readability, and greatly complicates the inheritance. In addition in interface may not be variable, only the function.
Why Fred against OOP? He believes that this language is only for beginners? Then PB should be free and be taught in schools.
In this case, on the main page of the site you need this text.
For some task types, they are ideal, and their absence is very difficult to develop and modernize code. Using interfaces and DataSection (To store addresses procedures) greatly complicates the code reduces its readability, and greatly complicates the inheritance. In addition in interface may not be variable, only the function.
Why Fred against OOP? He believes that this language is only for beginners? Then PB should be free and be taught in schools.
In this case, on the main page of the site you need this text.
Replace thisPureBasic has been created for the beginner and expert alike.
And this textPureBasic has been created for the beginner only.
Replace this.Experienced coders will have no problem
Experienced programmers would have trouble in program design.
Re: Classes in PureBasic
@User_Russian:
Are you unable to learn any of the plenty OOP languages out there? Why can't you just use D, C#, or Ruby? It's easy.
Are you unable to learn any of the plenty OOP languages out there? Why can't you just use D, C#, or Ruby? It's easy.
-
- Addict
- Posts: 1518
- Joined: Wed Nov 12, 2008 5:01 pm
- Location: Russia
Re: Classes in PureBasic
Dependency on .NET or interpreter.Danilo wrote:Why can't you just use D, C#, or Ruby?
I need a system language and PB in most of the suitable. But there are some drawbacks, including a lack of OOP.
If switch to another language, then at C++, but then on the main page, lie, claiming that PB is suitable for experienced programmers.
If need to switch to another programming language, the PB, only for beginners!