Go Back   Access World Forums > Access World > The Watercooler

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 11-07-2019, 08:37 AM   #1
vba_php
Software Engineer
 
vba_php's Avatar
 
Join Date: Oct 2019
Location: Iowa City, IA, USA
Posts: 644
Thanks: 79
Thanked 75 Times in 75 Posts
vba_php is on a distinguished road
Is OOP actually useful?

Since I just posted something about this, I want to ask other people here:

Does OOP actually need to exist? I have not yet read the wiki article on OOP but I will at some point. I personally don't see a need for it, and I kind of suspect it gained popularity because the creators marketed it as an "easier" way to program via separating different parts of code based on purpose. Perhaps programmers also think it is easy to debug and document?

I have no idea.

vba_php is offline   Reply With Quote
Old 11-07-2019, 09:31 AM   #2
Ranman256
Newly Registered User
 
Join Date: Apr 2015
Location: KY,USA
Posts: 3,378
Thanks: 0
Thanked 747 Times in 732 Posts
Ranman256 will become famous soon enough Ranman256 will become famous soon enough
Re: Is OOP actually useful?

people want to point & click.
nobody wants the old days of typing out command lines.
Ranman256 is offline   Reply With Quote
Old 11-07-2019, 10:46 AM   #3
vba_php
Software Engineer
 
vba_php's Avatar
 
Join Date: Oct 2019
Location: Iowa City, IA, USA
Posts: 644
Thanks: 79
Thanked 75 Times in 75 Posts
vba_php is on a distinguished road
Re: Is OOP actually useful?

Quote:
Originally Posted by Ranman256 View Post
people want to point & click.
nobody wants the old days of typing out command lines.
Is the "point and click" concept even related to OOP? Aren't there plenty of old languages that offer "point and click" user interfaces that are not technically OOP languages?

vba_php is offline   Reply With Quote
Old 11-07-2019, 04:06 PM   #4
The_Doc_Man
Happy Retired Curmudgeon
 
Join Date: Feb 2001
Location: Suburban New Orleans, LA, USA
Posts: 14,746
Thanks: 93
Thanked 1,724 Times in 1,595 Posts
The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold
Re: Is OOP actually useful?

OOP is a different way of looking at things. Let's see if I can give you a perspective. And since my first programming was done in FORTRAN II-D on an old IBM 1620 mod II in the 1960s, I can talk about OOP from that time.

Programming started out by making humongous arrays. The typical approach was a set of parallel arrays. By that I mean that each thing we would call a property was the name of an array. So the first object's name was in the OName(1) slot. Its color was in the OColor(1) slot. This meant you had as many arrays as the properties you were tracking. Not really that difficult to wrap your head around.

But there was this new thing called "structures" where instead of parallel arrays of properties, you created a single array of a complex structure. So that meant that Object(1) had elements of name, color, weight, etc. To the computer it made no difference because the compilers could keep track of that stuff for you either way you looked at it.

As procedural languages evolved, though, people started thinking about how long it took to write the code to set up these arrays of objects or these parallel arrays, either way you cut it. As it became clearer conceptually that computers were the ultimate model-makers, the idea of making an object out of a structure started to develop. And the issue is that if you had an object, you could do things with it. Including build code called "constructors" and "destructors" to create or destroy objects, to initialize and close them down, whatever they were doing. And that started the idea of having CODE be built into the object.

Think for a moment about Windows. You can still do this today. Pick an icon on the screen. That icon is there because the object underneath it identifies that icon. (You can click "Properties" and get to something that would let you change the icon.) If you right-click on the object, you get a list of things you can do with that object. You can open it (assuming it is openable). You can rename it, delete it, copy it, cut it, paste it, change its properties such as security, ownership, etc.

If you consider the old way of doing things, what we do now is define CLASSES of objects for which certain actions are possible for ALL MEMBERS of that class. We don't have to individually program the list of actions for each object. It is enough that it is a member of a class such as files in order to know a lot of things that can happen.

But the next step is sub-classes. In Windows, this is what is called an association. All files have basic file manipulation. But some files have more things that they can do based on the programs that work with those particular files. So files of type .DOC, .DOCX, and a few others can be opened by WORD. Files of type .XLS, .XLSX, .CSV, and a few others can be opened by EXCEL. And so on. And you don't have to do anything but get the file type correct in order for the correct sub-class options to be added to that list of things you can do with a file.

That is because a file, being a member of a particular class of objects, has a predetermined set of things you can do with it (in Access, called "methods.") This is what OOP gets you.

At the device-driver level, though, OOP is still playing around, even though sometimes you are below the level of files. For instance, a serial port can do input and output. You can open a serial port as though it were a file. Same for parallel ports. Same for networking ports. The drivers for the devices will take any request but sometimes the result is a no-op (null operation). For instance, you can open a serial port but a directory operation will only return the device name. You can close a serial port but no file actually gets stored because of that. The point, though, is that except for certain specialized scientific devices, ALL device drivers treat ALL devices like objects that can do I/O.

This is getting far afield, but I have one more point to make: The mindset of OOP is that you are modeling something. What you put inside the model might make it a black box to the world that uses it, but the object's programmer-creator is simply defining what you can do with it (and equally, what you can't.)

We could get really deep into the weeds by discussing inheritance, because sub-classes inherit properties and methods from their base class, but perhaps you might need to do some reading or thinking first before deciding that OOP is not needed.
__________________
I'm a certified grandpa (3 times now) and proud of it.
Retired over one year and survived being home all day with the wife. She must really love me.
If I have helped you, please either click the thanks or click the scales.
The_Doc_Man is offline   Reply With Quote
The Following 3 Users Say Thank You to The_Doc_Man For This Useful Post:
MickJav (11-13-2019), Steve R. (11-07-2019), vba_php (11-07-2019)
Old 11-07-2019, 05:35 PM   #5
vba_php
Software Engineer
 
vba_php's Avatar
 
Join Date: Oct 2019
Location: Iowa City, IA, USA
Posts: 644
Thanks: 79
Thanked 75 Times in 75 Posts
vba_php is on a distinguished road
Re: Is OOP actually useful?

That was very descriptive my friend! Im going to send ur post on to a recruiter that once asked me to explain object oriented programming to him. I didnt say as much as i could have but i did explain the "properties" concept to him. I didnt get into inheritence but the idea of "parents" and "children" in programming im sure can be easily understood by non technical people. What do u have to say on the subject of inheritence? I would be interested in ur take on that.
vba_php is offline   Reply With Quote
Old 11-07-2019, 06:48 PM   #6
The_Doc_Man
Happy Retired Curmudgeon
 
Join Date: Feb 2001
Location: Suburban New Orleans, LA, USA
Posts: 14,746
Thanks: 93
Thanked 1,724 Times in 1,595 Posts
The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold
Re: Is OOP actually useful?

Inheritance is the next logical step if you take the "building blocks" viewpoint of program design. Rather than make every scaffold anew every time for every structure, build on what you have, sort of like having "extra tools in the toolkit."

Back to the FILE class for discussion and examples: An every day, run-of-the-mill file can be launched if it is an executable, or its associated utility image can be launched against it if it is a document, picture, music track, or movie. But let's look at that more closely. Let's see what happens if we have an association. Remember that I said it was similar to declaring a sub-class of file that is subject to the named association of utility to file type.

Go find a NOTEPAD file (or make one.) Right-click on it and see what that list of possible actions looks like. Now find a directory file. Again, right-click and look at the actions. Find a picture file, do the same thing.

What you will see in each case are things that you can do to or with the file. Some of those things come from the utilities that can open it. Some come from the simple fact that it is a file. One can argue that the sub-class is a totally new class because of the new things you can do with it. Probably not wrong. But the things that can be done in common among the text file, picture file, and directory file are INHERITED from the general "file" class. Things like cut/paste, copy/paste, delete, change protection, change ownership, rename, ... these are abilities of the base class FILE. Things like name, size, date of creation, date of last modification, ... these are properties of the base class as well.

However, if you look at the details of the picture file, you might find the dimensions of the image (in pixels). You might find info about the color map. These are new properties unique to the sub-class, properties that were NOT inherited but rather were added when you defined the new sub-class.

If you look at executable images (.EXE) you would find that they have "Run As..." options and "compatibility-mode" options. If you look at file folders (.DIR), you would find compression and indexing options. Again, these represent actions or properties of the sub-class associated with that file type.

As it happens, you can do this to a limited degree in Access VBA. You can create a type of control that is a sub-class of another control. It will do all of the things that its base class control can do, but it can be made to do more. The problem is, of course, making sure that you don't botch/interfere with the "normal" properties and methods of the base class object. But you have the world of imagination at your fingertips if you are willing to devote yourself to a project that requires meticulous attention to detail for at least a brief time.

Inheritance, done properly, is a much faster way to "spiffy up" a project. Done poorly, it will make you prematurely have to join the Hair Club for Men after you have yanked out the hair you thought you had.
__________________
I'm a certified grandpa (3 times now) and proud of it.
Retired over one year and survived being home all day with the wife. She must really love me.
If I have helped you, please either click the thanks or click the scales.
The_Doc_Man is offline   Reply With Quote
The Following User Says Thank You to The_Doc_Man For This Useful Post:
vba_php (11-07-2019)
Old 11-07-2019, 07:08 PM   #7
vba_php
Software Engineer
 
vba_php's Avatar
 
Join Date: Oct 2019
Location: Iowa City, IA, USA
Posts: 644
Thanks: 79
Thanked 75 Times in 75 Posts
vba_php is on a distinguished road
Re: Is OOP actually useful?

Doc Man,

Do you have any experience with current OOP languages like Java, C#, Python or C++? Sometimes I think the "levels" that are used with OOP are a great way to organize a code project and avoid the "pulling your own hair out" scenario. For instance, the namespace, the class, the method, etc...

vba_php is offline   Reply With Quote
Old 11-08-2019, 06:43 AM   #8
The_Doc_Man
Happy Retired Curmudgeon
 
Join Date: Feb 2001
Location: Suburban New Orleans, LA, USA
Posts: 14,746
Thanks: 93
Thanked 1,724 Times in 1,595 Posts
The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold The_Doc_Man is a splendid one to behold
Re: Is OOP actually useful?

To be honest, my knowledge is mostly theoretical.

When I went through college, OOP was just becoming a possible thing. I remember having a discussion with a friend who was asking the same questions (more or less) as you have.

There is absolutely no doubt that you can program a project without OOP and for my dissertation research, the little program I built couldn't use OOP. It was all assembly language and in a space-limited environment.

If there is any problem with OOP, the encapsulation makes it hard to fit when you are already shoe-horning code to make things fit. And my main problem was that because of the limited memory, every line of code was one less data point I could take.

I had no disk on that lab computer. Back then, it was all based on paper-tape and something called a RIM loader. There was no swapping or paging. There was no saving to disk.

Therefore, my problem was loading things to memory as tightly as possible. Subroutines weren't a problem. Encapsulation was, because I couldn't afford any code that I wouldn't be using in that environment.

When I graduated, my first job didn't involve OOP that much. We eventually developed something that used some aspects of OOP by abstracting common elements of the oil and gas pipeline industry for our basic control system. Then we allowed "inheritance" of a sort for any custom sensors that didn't map directly to one of the types of sensors we already supported. But as most of that was written in assembly, OOP wasn't really as much of an issue.

By the time I reached my government contractor position, I was in as an O/S manager and systems analyst. The opportunity wasn't there for too many OOP situations. So while I have tried to keep up my reading, I have not dealt with OOP that much. Now that I am retired, it would be a purely academic exercise and I have other fish to fry.
__________________
I'm a certified grandpa (3 times now) and proud of it.
Retired over one year and survived being home all day with the wife. She must really love me.
If I have helped you, please either click the thanks or click the scales.
The_Doc_Man is offline   Reply With Quote
Old 11-08-2019, 08:53 AM   #9
vba_php
Software Engineer
 
vba_php's Avatar
 
Join Date: Oct 2019
Location: Iowa City, IA, USA
Posts: 644
Thanks: 79
Thanked 75 Times in 75 Posts
vba_php is on a distinguished road
Re: Is OOP actually useful?

well regardless of weather you have experience or not, your insights are certainly helpful to us I'm sure! I know I enjoyed reading them.
vba_php is offline   Reply With Quote
Old 11-12-2019, 07:55 AM   #10
kevlray
Newly Registered User
 
Join Date: Apr 2010
Location: Central California
Posts: 684
Thanks: 9
Thanked 56 Times in 54 Posts
kevlray will become famous soon enough
Re: Is OOP actually useful?

I used an employer created OOP language many years ago (gaming software). It not very fancy, but it was very helpful in creating multiple instances of an object (you could not not create new objects, every thing was a instance of a particular type of object). Thus you could control each instance of an object independently with very little code.
kevlray is online now   Reply With Quote
Old 11-12-2019, 08:48 AM   #11
MajP
Newly Registered User
 
Join Date: May 2018
Location: USA baby
Posts: 1,892
Thanks: 38
Thanked 574 Times in 539 Posts
MajP has a spectacular aura about MajP has a spectacular aura about
Re: Is OOP actually useful?

Quote:
Does OOP actually need to exist?
Being this is an Access forum, I think that question is self answering. 99 percent of everything you do in access is OOP. How would you envision working with forms, reports, controls, recordsets, etc if not OOP. VBA is not a pure OOP language since no inheritance or polymorphism, but it is definitely OOP.
MajP is offline   Reply With Quote
Old 11-12-2019, 08:57 AM   #12
vba_php
Software Engineer
 
vba_php's Avatar
 
Join Date: Oct 2019
Location: Iowa City, IA, USA
Posts: 644
Thanks: 79
Thanked 75 Times in 75 Posts
vba_php is on a distinguished road
Re: Is OOP actually useful?

Quote:
Originally Posted by MajP View Post
VBA is not a pure OOP language since no inheritance or polymorphism, but it is definitely OOP.
well i've never considered visual basic legacy versions or any variations of it to be OOP. In VBA there are classes and types and stuff and that might get close, but what i'm referring to specifically is what you have mentioned, such as inheritance, plymorphism and the whole idea of creating the coding objects out of properties. In access, I definitely don't consider vba coding that refers to access GUI objects as OOP programming.

Languages that I'm specifically referring to regarding this OOP thing:

Java
Python
C++
C#
VB.NET
PHP
vba_php is offline   Reply With Quote
Old 11-13-2019, 12:43 AM   #13
MajP
Newly Registered User
 
Join Date: May 2018
Location: USA baby
Posts: 1,892
Thanks: 38
Thanked 574 Times in 539 Posts
MajP has a spectacular aura about MajP has a spectacular aura about
Re: Is OOP actually useful?

VBA provides the two main tenets of OOP: encapsulation and abstraction. It does not provide the lesser two of inheritence and polymorphism. To me the first two overshadow the other two.

So let me get this straight. If I build a custom class with public accessors, custom events, and protected class variables in VBA it would not be OOP, but if I build the exact identical class in VB.net then it is OOP?

Maybe look at my code in this thread
https://www.access-programmers.co.uk...d.php?t=306791
And see if you think that looks like OOP. If I wrote it in JAVA, c#, .net (I know those) it would sure look the same. Could I write this not OOP? I guess but it would be really hard and really clunky.
MajP is offline   Reply With Quote
Old 11-13-2019, 04:02 AM   #14
vba_php
Software Engineer
 
vba_php's Avatar
 
Join Date: Oct 2019
Location: Iowa City, IA, USA
Posts: 644
Thanks: 79
Thanked 75 Times in 75 Posts
vba_php is on a distinguished road
Re: Is OOP actually useful?

Quote:
Originally Posted by MajP View Post
If I build a custom class with public accessors, custom events, and protected class variables in VBA it would not be OOP, but if I build the exact identical class in VB.net then it is OOP?
well prolly not, that's why I said that classes and types in VBA are close to OOP. Maybe I should have said building them is technically classified as OOP. I think that would be a better thing to say.

regarding your attachments in that other thread, the public properties in the class modules you wrote I would say is OOP usage.
vba_php is offline   Reply With Quote
Old 11-13-2019, 04:35 AM   #15
MajP
Newly Registered User
 
Join Date: May 2018
Location: USA baby
Posts: 1,892
Thanks: 38
Thanked 574 Times in 539 Posts
MajP has a spectacular aura about MajP has a spectacular aura about
Re: Is OOP actually useful?

Quote:
classes and types in VBA are close to OOP. Maybe I should have said building them is technically classified as OOP.
I got to completely disagree. At the route the difference between OOP and functional/procedural programming is the concepts of objects. Build your own objects or using already built objects makes no difference. If you are working with objects in VBA you are doing OOP. It is a limited language as pointed out (not overloading, no parameterized contructors, no polymorphism, no inheritance), but still is OOP. On the other hand procedural programming is structured top down and has not concept of objects.

Code:
Dim RS as dao.recorset
set RS = currentdb.openrecordset ("someQuery")
I just instantiated an instance of an object. Common Access vba task. Not sure how that is not OOP. In procedural programming there is not even a concept of instantiation.

MajP is offline   Reply With Quote
The Following User Says Thank You to MajP For This Useful Post:
NauticalGent (11-13-2019)
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump




All times are GMT -8. The time now is 01:15 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World