OOP Support (it is time)
-
- User
- Posts: 52
- Joined: Wed Feb 04, 2009 8:11 am
- Location: Armenia
OOP Support (it is time)
PureBasic I`r really great language. I love it a lot.
But i think it is really time to add unless partial OOP support in it.
Basically Object is a set of functions connected to a structure.
Bu creating clever this() function and adding keywords such as "Class EndClass" this can be done.
I think this will put PB to next level. And he might become serious competition to languages such as C# or AS3.
But i think it is really time to add unless partial OOP support in it.
Basically Object is a set of functions connected to a structure.
Bu creating clever this() function and adding keywords such as "Class EndClass" this can be done.
I think this will put PB to next level. And he might become serious competition to languages such as C# or AS3.
Re: OOP Support (it is time)
...and again...
DaylightDreamer, please do a quick search to find at least one of those two thousand threads where this has been discussed...
DaylightDreamer, please do a quick search to find at least one of those two thousand threads where this has been discussed...
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
-
- User
- Posts: 52
- Joined: Wed Feb 04, 2009 8:11 am
- Location: Armenia
Re: OOP Support (it is time)
I did. Actually.
I'm not speaking about pre compilers or some attempts to emulate it or judging winch method is better procedural or OOP.
I have started with the 1st version of PB
I have recommended PB to a lot of people, programmers,during this time but they don't want to even look at it when they find out that PB is not OOP.
I'm not speaking about pre compilers or some attempts to emulate it or judging winch method is better procedural or OOP.
I have started with the 1st version of PB
I have recommended PB to a lot of people, programmers,during this time but they don't want to even look at it when they find out that PB is not OOP.
Re: OOP Support (it is time)
Yes, but those discussions were not all about pre-compilers.
It's just a (sad) fact that we won't see OOP natively implemented in PureBasic any time soon.
Pre-compilers are the only way we can get some kind of OOP into the language,
but that's not really a great solution.
It's just a (sad) fact that we won't see OOP natively implemented in PureBasic any time soon.
Pre-compilers are the only way we can get some kind of OOP into the language,
but that's not really a great solution.
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: OOP Support (it is time)
OOP is the greatest technology improvement in the last years. But PB (the PB-API) have to be developed from scratch to support OOP. And so it would be no longer PB as we know and love it.
I'm software developer in my job and my free time. Small projects I do develop in PB, larger ones in Java, C# or C++. And PB has great advantages compared to OOP languages as long as you don't want to program an enterprise application...
(sorry, bad english
)
I'm software developer in my job and my free time. Small projects I do develop in PB, larger ones in Java, C# or C++. And PB has great advantages compared to OOP languages as long as you don't want to program an enterprise application...
(sorry, bad english

ThinkPad T61 | PureBasic 4.51 | Windows 7 (32) | Kubuntu 11.10 (64) | Syllable (32)
Re: OOP Support (it is time)
I think PB is a wrapper for FASM, rather than a true machine code compiler,so maybe PB is hard to support OOP ?
However,there're some unofficial solutions to support some basic OOP in PB,such as pure object.
However,there're some unofficial solutions to support some basic OOP in PB,such as pure object.
poor English...
PureBasic & Delphi & VBA
PureBasic & Delphi & VBA
Re: OOP Support (it is time)
PB is not a "wrapper" for FASM...it's a compiler that outputs assembler.leonhardt wrote:I think PB is a wrapper for FASM, rather than a true machine code compiler,so maybe PB is hard to support OOP?
Many compilers do that because assembler basically is machine code since it can be translated almost 1:1
based on the features of specific assemblers.

So it also isn't harder to implement (if not easier even).
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
-
- User
- Posts: 52
- Joined: Wed Feb 04, 2009 8:11 am
- Location: Armenia
Re: OOP Support (it is time)
And i think there is a simple solution.
If you can manage to pass a structure values into a function you can put them into a function named this()
I managed to do that using hash arrays the problem with hash array that you cannot assign different types to different slots.
But if you pas a structure value i think this will be sufficient.
I`m not seeking a full OOP support. It is OK to have something from PHP4 for example.
If you can manage to pass a structure values into a function you can put them into a function named this()
I managed to do that using hash arrays the problem with hash array that you cannot assign different types to different slots.
But if you pas a structure value i think this will be sufficient.
I`m not seeking a full OOP support. It is OK to have something from PHP4 for example.
-
- User
- Posts: 52
- Joined: Wed Feb 04, 2009 8:11 am
- Location: Armenia
Re: OOP Support (it is time)
Exactly. That`s the same thing i had to do.shadow wrote:Small projects I do develop in PB, larger ones in Java, C# or C++.
Re: OOP Support (it is time)
While I can't say I ever been a fan of the whole OOP concept, probably due to the ridiculous academic examples of its benefits relating to animals and my observation that it makes code appear bloated, I have spent some time trying to understand it.
From these recent attempts to understand it (I do understand the useful concept of encapsulation...not sure about inheritance - seems like another academic benefit and I doubt it makes life easier/better in the real world...anyway) by looking at C++, C#, D, Java and trying to learn ObjC, I have come to the conclusion that the biggest problem (for people like me) is the syntax.
So, the concepts can be understood if you're interested enough to want to learn, it's the hideous syntax that puts me off. People go on (again, usually academics, language developers, etc) about the beauty of SmallTalk and hence, Objective C, but I think it's absolutely hideous.
I remember, back in the 80s the talk about the future of high-level languages and I always thought that the ideal (and future) for a high-level language was something that did a lot in a smallish amount of code but was very easy to understand, i.e. like BASIC!
But what have we got in the mainstream nowadays, C derivatives that are made even more obscure (imho) by adding OOP. I mean, I can read plain C but you add the OOP stuff, esp, that NSxxxx stuff in Objective C and I'm lost. How can this be easier?
Additionally, the idea of adding huge libraries and frameworks to lowish level languages (like C) makes things even worse. If I was going to improve C, I'd want to give it more commands in the style of the old commands but did more. Not add on a completely different way to do many of the same things but with an even more obscure syntax.
Anyway, 'What's you point', I hear you say
Well, if PB ever had OOP, please, please, please can it implement it with a syntax in keeping with PB's existing style, i.e. simple, English-like (sorry to those who would prefer a different language, bloody English, eh, LOL) commands with few parameters, few brackets (definately no square brackets!), etc.
I'm sure OOP could be of use to more people, even if we forget about inheritance and polymorphism and just agree that encapsulation is the prime benefit (btw - many of the designers of major languages seem to agree with this point) provided it was straightforward to program.
Again going back to the concept of high-level languages, surely the ultimate objective is for them to 'get out of the way' leaving us more time to think about solving the problem in front of us, not puzzling over the syntax or worrying about which design pattern to use. That's power. And if the code can be easy to read by less experienced programmers, all the better, after all, that was an objective of COBOL, which, say what you like, is still running in major institutions on mainframes today.
Haha, sorry for the rant, I've been wanting to get this off my chest for sometime now
Cheers
Hysteria
From these recent attempts to understand it (I do understand the useful concept of encapsulation...not sure about inheritance - seems like another academic benefit and I doubt it makes life easier/better in the real world...anyway) by looking at C++, C#, D, Java and trying to learn ObjC, I have come to the conclusion that the biggest problem (for people like me) is the syntax.
So, the concepts can be understood if you're interested enough to want to learn, it's the hideous syntax that puts me off. People go on (again, usually academics, language developers, etc) about the beauty of SmallTalk and hence, Objective C, but I think it's absolutely hideous.
I remember, back in the 80s the talk about the future of high-level languages and I always thought that the ideal (and future) for a high-level language was something that did a lot in a smallish amount of code but was very easy to understand, i.e. like BASIC!
But what have we got in the mainstream nowadays, C derivatives that are made even more obscure (imho) by adding OOP. I mean, I can read plain C but you add the OOP stuff, esp, that NSxxxx stuff in Objective C and I'm lost. How can this be easier?
Additionally, the idea of adding huge libraries and frameworks to lowish level languages (like C) makes things even worse. If I was going to improve C, I'd want to give it more commands in the style of the old commands but did more. Not add on a completely different way to do many of the same things but with an even more obscure syntax.
Anyway, 'What's you point', I hear you say

Well, if PB ever had OOP, please, please, please can it implement it with a syntax in keeping with PB's existing style, i.e. simple, English-like (sorry to those who would prefer a different language, bloody English, eh, LOL) commands with few parameters, few brackets (definately no square brackets!), etc.
I'm sure OOP could be of use to more people, even if we forget about inheritance and polymorphism and just agree that encapsulation is the prime benefit (btw - many of the designers of major languages seem to agree with this point) provided it was straightforward to program.
Again going back to the concept of high-level languages, surely the ultimate objective is for them to 'get out of the way' leaving us more time to think about solving the problem in front of us, not puzzling over the syntax or worrying about which design pattern to use. That's power. And if the code can be easy to read by less experienced programmers, all the better, after all, that was an objective of COBOL, which, say what you like, is still running in major institutions on mainframes today.
Haha, sorry for the rant, I've been wanting to get this off my chest for sometime now

Cheers
Hysteria
Re: OOP Support (it is time)
Hi
OOP by itself does not mean we have to have bloated code or huge frameworks. I came from an OOP background and I like Purebasic very much but I also think as I have mentioned here before that some OOP concepts would be very helpful in PB. The ability to simply define a class with some properties and methods and then create an object (instance) of the class would be very helpful. I would not want PB to become an OOP language I prefer a hybrid approach of using both procedural and OOP code in the same application. That is exactly what you can do using the now discontinued MS Visual FoxPro and it was very handy to be able to mix and match as needed.
Simon
OOP by itself does not mean we have to have bloated code or huge frameworks. I came from an OOP background and I like Purebasic very much but I also think as I have mentioned here before that some OOP concepts would be very helpful in PB. The ability to simply define a class with some properties and methods and then create an object (instance) of the class would be very helpful. I would not want PB to become an OOP language I prefer a hybrid approach of using both procedural and OOP code in the same application. That is exactly what you can do using the now discontinued MS Visual FoxPro and it was very handy to be able to mix and match as needed.
Simon
Simon White
dCipher Computing
dCipher Computing
Re: OOP Support (it is time)
Slightly modified from another thread:
Code: Select all
Interface IPerson
Shout(Msg.s)
Whisper(Msg.s)
EndInterface
Structure SObject
*vTable
EndStructure
Structure SPerson Extends SObject
; vTable:
*Shout
*Whisper
; Data fields
Name.s
EndStructure
Procedure MyClass_Shout(*Self.SPerson, Msg.s)
MessageRequester("Shout!", *Self\Name + ": " + UCase(Msg))
EndProcedure
Procedure MyClass_Whisper(*Self.SPerson, Msg.s)
MessageRequester("Whisper!", *Self\Name + ": (shhh!) " + Msg)
EndProcedure
Procedure MyClass(Name.s)
Protected *Self.SPerson = AllocateMemory(SizeOf(SPerson))
InitializeStructure(*Self, SPerson)
*Self\vTable = @*Self\vTable + SizeOf(*Self\vTable)
*Self\Shout = @MyClass_Shout()
*Self\Whisper = @MyClass_Whisper()
*Self\Name = Name
ProcedureReturn *Self
EndProcedure
Bill.IPerson = MyClass("Bill")
Bob.IPerson = MyClass("Bob")
Bill\Shout("Hello world!")
Bob\Whisper("Goodbye, world!")
Re: OOP Support (it is time)
Well I think it would be fine (as a hybrid approach - I wouldn't want to lose the existing procedural alternative) if it could be implemented in an elegant manner avoiding where possible '\', use of pointers or pointer-like objects, etc. I think it would be a good opportunity for PB to define a new standard in OOP syntax. Unfortunately, I don't have sufficient-enough grasp of OOP syntax in any language to illustrate this with an example of my own...but I'd know it if I saw it ;o)swhite wrote:Hi
OOP by itself does not mean we have to have bloated code or huge frameworks. I came from an OOP background and I like Purebasic very much but I also think as I have mentioned here before that some OOP concepts would be very helpful in PB. The ability to simply define a class with some properties and methods and then create an object (instance) of the class would be very helpful. I would not want PB to become an OOP language I prefer a hybrid approach of using both procedural and OOP code in the same application. That is exactly what you can do using the now discontinued MS Visual FoxPro and it was very handy to be able to mix and match as needed.
Simon
Re: OOP Support (it is time)
I'd like to bring the Procedures inside Structures thread
to the surface again.
IMHO, that would be a nice feasible OO extension for PB.
And I did not read anything about it being rejected (yet).
Maybe someone could post something like "I'd like that too"
there to bring it on top from time to time.

to the surface again.

IMHO, that would be a nice feasible OO extension for PB.
And I did not read anything about it being rejected (yet).

Maybe someone could post something like "I'd like that too"
there to bring it on top from time to time.


If liberty means anything at all, it means the right to tell people what they do not want to hear.
- George Orwell
- George Orwell
Re: OOP Support (it is time)
@swhite, that Visual FoxPro syntax looks pretty nice from the snippets I've just found (wikipedia example below)
We could lose the && for comments though (who thought of that!!)
loMine = CREATEOBJECT("MyClass")
? loMine.cProp1 && This will work. (Double-ampersand marks an end-of-line comment)
? loMine.cProp2 && Program Error: Property CPROP2 is not found.
? loMine.MyMethod1() && This will work.
? loMine.MyMethod2() && Program Error: Property MYMETHOD2 is not found.
DEFINE CLASS MyClass AS Custom
cProp1 = "My Property" && This is a public property
HIDDEN cProp2 && This is a private (hidden) property
PROCEDURE Init() && Class constructor
This.cProp2 = "This is a hidden property."
ENDPROC
PROCEDURE MyMethod1()
* This is a public method, calling a hidden method that returns
* the value of a hidden property.
RETURN This.MyMethod2()
ENDPROC
HIDDEN PROCEDURE MyMethod2() && This is a private (hidden) method
RETURN This.cProp2
ENDPROC
ENDDEFINE
We could lose the && for comments though (who thought of that!!)

loMine = CREATEOBJECT("MyClass")
? loMine.cProp1 && This will work. (Double-ampersand marks an end-of-line comment)
? loMine.cProp2 && Program Error: Property CPROP2 is not found.
? loMine.MyMethod1() && This will work.
? loMine.MyMethod2() && Program Error: Property MYMETHOD2 is not found.
DEFINE CLASS MyClass AS Custom
cProp1 = "My Property" && This is a public property
HIDDEN cProp2 && This is a private (hidden) property
PROCEDURE Init() && Class constructor
This.cProp2 = "This is a hidden property."
ENDPROC
PROCEDURE MyMethod1()
* This is a public method, calling a hidden method that returns
* the value of a hidden property.
RETURN This.MyMethod2()
ENDPROC
HIDDEN PROCEDURE MyMethod2() && This is a private (hidden) method
RETURN This.cProp2
ENDPROC
ENDDEFINE