Goodbye OOP

For everything that's not in any way related to PureBasic. General chat etc...
HanPBF
Enthusiast
Enthusiast
Posts: 564
Joined: Fri Feb 19, 2010 3:42 am

Re: Goodbye OOP

Post by HanPBF »

I'd like to confirm that it's a difference if You code in a team with various knowledge or do code on Your own or inhouse in a very small team.

And I can confirm that I have mainly seen coders using intellisense with no idea what's involved behind or even what a class or a method is; of course inheritance was not known.

But when I put it down to "organizing code" then I see not very many patterns/ideas to organize procedural code so it can be maintained a long time.
(At the same time, patterns in OOP only repair the annoying things of OOP...)

Any hints for "organizing procedural programs"?
Thorium
Addict
Addict
Posts: 1271
Joined: Sat Aug 15, 2009 6:59 pm

Re: Goodbye OOP

Post by Thorium »

Brian Will did some good videos on the matter.
The title is a bit clickbaity, but the content is good. He actualy supplies real world examples that he converts from OOP and makes them smaller and easier to read.

https://www.youtube.com/playlist?list=P ... nyDSvAqNJJ
User avatar
Derren
Enthusiast
Enthusiast
Posts: 313
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

Re: Goodbye OOP

Post by Derren »

Shield wrote:

Code: Select all

animal.eat(); // Which eat should be called, the one from Rabbit or the one from Antelope?
The one that's defined in jackrabbit, as I said.
If you use my code, it gets resolved? What's the issue?
Normally, you can overwrite functions of an inherited class.
I do think that this is valid code in many languages:

Code: Select all

class parent{
  function eat(){print 'parent is eating';}
  function sleeo(print 'parent is sleeping';)
}

class child extends parent{
  function eat(print 'child is eating';)
}

obj= new child();
obj->eat(); //child is eating
obj->sleep(); //parent is sleeping
If you can do this, you can surely tell your jackrabbit how to eat.

If however, your jackrabbit inherits from animal as well as the parent animals, your code is bad and animal contains too many functions, or the rabbit and antelope do not properly overwrite them.

And I do not know why you think that this is god or even valid code:

Code: Select all

class_A obj_A = new class_A();
class_B obj_B = obj_A;
You're and obj_A which is of type/class A to obj_B which was explicitly made into an object of class B. That's like assigning a string to an integer and then asking whether or not "+" in PB should add 1 or append "1"
Welcome to Javascript
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: Goodbye OOP

Post by Lunasole »

HanPBF wrote: Any hints for "organizing procedural programs"?
There are lot of ways, but I like the most "logical separation" doing it through code folding.
There are so called 'regions' in C#, and that's the idea I've adopted for this. In PB similar can be done using ";{" and ";}" to hide whole regions of code.

For example, that's how main file of my game is looking using concept of regions:
http://rgho.st/7wNHrYSVH

The 'regions' of course can be nested too and so on + additional folding is provided by other PB keywords like "if", "for", "select", "procedure"...
Cool & simple, just unfold what you need and edit it not seeing anything else. For me the result of it is very clear and I never encountered problems with code organized such way (I'm working on that game code almost one year already and total its size is large enough, also for this time I wrote lot of other stuff organized the same).

But of course only that is not enough to not drown in long-term perspective. Important parts of the game are separated from others into "subsystems", and they are isolated classes by fact. One subsystem can store local pointer to instance of another [that pointer is received only through subsystem init procedure] and then access its properties by that pointer (there are also additional rules to how they can be accessed). To use other subsystem functions, instance pointer is not needed - I'm just declaring required functions (some internal subsystem code cannot be called such way from another subsystem).
That's all also clear enough and similar is used in large projects on C, so I call it "OOP in C style".
Same can be done using Purebasic modules, which are very close to a classes and truly isolating code (not only "logically"), but I still didn't found a valuable reason to use them - they requiring to be declared, UseModule(), etc, which is additional bureaucracy.

Also subsystems of course are placed in different source files, and all is joined to a project. But all their headers/structures I'm gathering into a single declare file (such also used in C projects, for example lib Leptonica provides only one but very large file "allheaders.h" ^^ which is generally much better that 1000 small files trashing project folders).
Within this file (and basically any other file) also regions are used to organize code the most efficiently (for example, separated region are defined for every subsystem).

In total, the base of my code organization is code folding, and some rules I'm always keeping on, when writing something larger than script-like stuff in only one source file (and also some rules about code documentation, used notations, etc).
You of course should find your own way (in meditation ^^), which will be really better for you.

After all It is fact for me, that procedural code is clearer and is less boring and time-wasting to organize it well, than to write code in OOP languages.
At least, that is fully true when working with PB and it's IDE ^^ (which however lacks several important functions, like "go to definition/declaration", but that's another talk). For C it depends on IDE mainly. I'm not writing much own things on C and have no formed strategy to organize C code, just sometimes learning how others are doing that in large stuff.
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
User avatar
Shield
Addict
Addict
Posts: 1021
Joined: Fri Jan 21, 2011 8:25 am
Location: 'stralia!
Contact:

Re: Goodbye OOP

Post by Shield »

Regarding the diamond problem, consider this:
https://en.wikipedia.org/wiki/Virtual_inheritance

Edit: and yes, diamond structures are almost always a bad idea and indicate a flaw in the design.
Derren wrote: And I do not know why you think that this is god or even valid code:

Code: Select all

class_A obj_A = new class_A();
class_B obj_B = obj_A;
As I mentioned before, https://en.wikipedia.org/wiki/Liskov_su ... _principle
This is a fundamental mechanic in OOP languages.
Image
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 avatar
tj1010
Enthusiast
Enthusiast
Posts: 624
Joined: Mon Feb 25, 2013 5:51 pm
Location: US or Estonia
Contact:

Re: Goodbye OOP

Post by tj1010 »

Rust is commonly considered a next-gen language or even the programming language to replace all programming languages because it solves so many security and optimization problems transparently and has a lot of developers. It's OOP.
The truth hurts.
Thorium
Addict
Addict
Posts: 1271
Joined: Sat Aug 15, 2009 6:59 pm

Re: Goodbye OOP

Post by Thorium »

tj1010 wrote:Rust is commonly considered a next-gen language or even the programming language to replace all programming languages because it solves so many security and optimization problems transparently and has a lot of developers. It's OOP.
From what i read, Rust is multi-paradigm, not just OOP.
However i didnt tried it out yet.
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: Goodbye OOP

Post by Lunasole »

To continue a bit with OOP - here is some real world project I've received today to "fix" it.
By description it takes video and sends it to web-service for analysis, then displays and stores results of analysis.
And as can be seen from sources, it is written in C++ using that qt, widely popular within monkeys nowadays.
Also obviously, that's not even a big project, kind of qt helloworld using prepared frameworks.

As was expected, I've refused from it, after wasting 30 min trying to understand just HOW IT WORKS. I said that man that code is just damn poor and let he throw it back to one who written it.

But a minute later I remembered this thread and it became interesting for me to post code here for fun. How much can YOU understand from that typical product from average OOP-monkey , written fully in OOP with "true expressive power"? ^^

@Shield
http://rgho.st/7Xc2F2mM6

I can surely say the code of same [bad] quality written in C (or especially in PB, which is SO MUCH easier) is about 100 times clearer, even if read it in notepad++, lol.
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Goodbye OOP

Post by TI-994A »

tj1010 wrote:Rust is commonly considered a next-gen language or even the programming language to replace all programming languages...
As have been said about many languages before it. :wink:
tj1010 wrote:It's OOP.
Probably the reason behind its massively bloated binaries. :lol:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
the.weavster
Addict
Addict
Posts: 1537
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Re: Goodbye OOP

Post by the.weavster »

Lunasole wrote:And as can be seen from sources, it is written in C++ using that qt, widely popular within monkeys nowadays.
Perhaps you could point us monkeys to a procedural equivalent to Qt.
User avatar
tj1010
Enthusiast
Enthusiast
Posts: 624
Joined: Mon Feb 25, 2013 5:51 pm
Location: US or Estonia
Contact:

Re: Goodbye OOP

Post by tj1010 »

TI-994A wrote:
tj1010 wrote:Rust is commonly considered a next-gen language or even the programming language to replace all programming languages...
As have been said about many languages before it. :wink:
tj1010 wrote:It's OOP.
Probably the reason behind its massively bloated binaries. :lol:

That was all marketing for abstract languages like Python, .NET, and PHP etc..

All those really addressed was development overhead they don't really differentiate from a poorly coded and built c++ binary performance and security wise.
The truth hurts.
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Goodbye OOP

Post by TI-994A »

tj1010 wrote:That was all marketing for abstract languages like Python, .NET, and PHP etc..

All those really addressed was development overhead...
And this language is doing the same thing. It claims zero-cost abstraction, when in reality, that cost is being exacted in the form of huge executables.

Truly low-level languages don't fall victim to that.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: Goodbye OOP

Post by Lunasole »

the.weavster wrote: Perhaps you could point us monkeys to a procedural equivalent to Qt.
I don't remember any (except myself sometimes ^^). As I said it is anyway not so hard to deal with procedural code (even if it is extremely bad, uses GOTO operators and so on [but well, massive GOTO labels are TOO MUCH, with them code is really very close to such OOP monkey-code by its logic and architecture]).

Maybe that's because writing some more or less complex project in procedural language requires much more coding experience and knowledges to not shoot off own legs or something else mentioned, so those who are begginer procedural coders, just cannot finish such projects and need more practice to success, thus rarely procedural monkey code can be seen in something "commercial-grade" nowadays.
A kind of fool protection, which differs from OOP fool protection greatly, as OOP easily lets any fool to become successful fool by automatically fixing lack of experience and skill, allowing code to be done and formally finished, until someone has to work with that code and call author codemonkey.
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Goodbye OOP

Post by TI-994A »

Lunasole wrote:...it is anyway not so hard to deal with procedural code...

...OOP easily lets any fool to become successful fool...
In all honesty, both paradigms have their strong suits.

While I am partial to the imperative/procedural architecture, there are times when a well-designed class could be a real boon. But objectivating every conceivable task is simply overkill, unproductive, and even inefficient.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: Goodbye OOP

Post by Lunasole »

@TI-994A, exactly. What you said is like an "epilogue" to all I've written before ^^
(if not talk more about codemonkeys, of course :3)
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
Post Reply