Page 7 of 11

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. :oops:
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 ??????? :twisted:
Think it's already been done, real-y basic :lol:

[stoking the fire] :twisted:

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? :idea:
Already done :) Ok, it's not PooBasic, but Pob-Basic

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/

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.

Re: Classes in PureBasic, ignorance from warped minds.

Posted: Mon Nov 10, 2014 5:34 pm
by Tenaja
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.
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, 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

Posted: Mon Nov 10, 2014 7:42 pm
by heartbone
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.
And 1+1 still equals 2.
Heartbone, you are making the wild assumption that adding features alters existing syntax. The module is the perfect example to disprove that assumption.
Wrong and wrong.
Just because you hate a feature does not mean you should be against it.
Wrong.
I am not likely to use oop myself,
How else can you use something?
but I would like to have the feature because I think it will open PB up to a wider audience.
IMO, from a programming perspective that's an illogical justification for such a major change of methodology.

Re: Classes in PureBasic

Posted: Mon Nov 10, 2014 9:06 pm
by Samuel
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.

Re: Classes in PureBasic

Posted: Tue Nov 11, 2014 11:51 am
by User_Russian
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.
PureBasic has been created for the beginner and expert alike.
Replace this
PureBasic has been created for the beginner only.
And this text
Experienced coders will have no problem
Replace this.
Experienced programmers would have trouble in program design.

Re: Classes in PureBasic

Posted: Tue Nov 11, 2014 12:07 pm
by Danilo
@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.

Re: Classes in PureBasic

Posted: Tue Nov 11, 2014 12:35 pm
by User_Russian
Danilo wrote:Why can't you just use D, C#, or Ruby?
Dependency on .NET or interpreter.
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!