In classic procedural style programming you had a data structure and then a set of functions that operated on that data structure
Something like
structure point
double x
double y
end structure
structure rectangle
double top
double left
double width
double height
double angle
end structure
rotate( r as rectangle, bangle as double) as rectangle
// code to rotate a rect
end rotate
contains(r as rectangle, p as point) as boolean
end contains
This was as close to a “class” as you could get
The code to implement the things that rectangles could do wasnt part of the structure itself
It was separate
And you had to remember to pass in the instance you wanted to manipulate
In an OOP way the class and code are one
More like
class point
double x
double y
end structure
class rectangle
double top
double left
double width
double height
double angle
rotate( byangle as double) as rectangle
// code to rotate a rect by the given angle
end rotate
contains( p as point) as boolean
end contains
The code is part of the definition of the class and you dont have to pass in the instance to manipulate
Thats implied
Languages like C++ originally were just preprocessors for the code that then got rewritten as plain C and then compiled
So its not that you cant make OO-like code in a non-OO language
You just have more work to do
And an example PureBasic Module demonstrating a few functions for a Rectangle:
; declare the module's public API ...
DeclareModule Rectangle
Structure Rectangle
top.d
left.d
width.d
height.d
angle.d
EndStructure
Declare Free(*r.Rectangle)
Declare.d GetAngle(*r.Rectangle)
Declare.i New(top.d, left.d, width.d, height.d, angle.d=0)
Declare SetAngle(*r.Rectangle, new_angle.d)
EndDeclareModule
; implementation of the module ...
Module Rectangle
Procedure.d GetAngle(*r.Rectangle)
ProcedureReturn *r\angle
EndProcedure
Procedure SetAngle(*r.Rectangle, new_angle.d)
*r\angle = new_angle
EndProcedure
Procedure Free(*r.Rectangle)
FreeStructure(*r)
EndProcedure
; constructor
Procedure.i New(top.d, left.d, width.d, height.d, angle.d=0)
Protected *r.Rectangle = AllocateStructure(Rectangle)
*r\top = top
*r\left = left
*r\width = width
*r\height = height
*r\angle = angle
ProcedureReturn *r
EndProcedure
EndModule
; and example of usage ...
CompilerIf #PB_Compiler_IsMainFile
Define.Rectangle::Rectangle *r
*r = Rectangle::New(10, 10, 500, 300)
Rectangle::SetAngle(*r, 30)
Debug Rectangle::GetAngle(*r)
Rectangle::Free(*r)
CompilerEndIf
I’ve experimented with PureBasic and, besides some slightly odd syntax, it’s pretty straight forward, binaries are small and fast. My main concern is that the built-in controls are pretty limited in customizability – it seems you have to rely on community-provided code/extensions beyond the basics, so to speak. And, there it seems like the community is fairly small and sometimes the developers of these things just disappear. Another big issue for me is limited support for the webview component. On Windows, it is still IE11, which I believe is now officially deprecated. On Mac and Linux, the webgadget API was never fully realized, so it’s barely functional. Both issues are, again, addressed by some community-provided extensions, but the lack of attention to this in the core product and the fragility of depending on community-sourced code for key components gives me pause.