OOP vs non OOP

closed account (N8MNAqkS)
I apologize for all of the probably pointless questions I have been posting lately. I am sure I could just Google the answers but I feel like I get a more complete understanding of things when I ask them here. so here is another question that I should probably already know the answer to.

Apart from classes, what is the major difference between OOP and non OOP languages. what else (in c++ more specifically) is considered an "object".
The difference is in how you think about the problems. OOP languages lend themselves more easily to writing programs in which you model self-contained lumps of data and function; an "OOP language" will contain a number of features that make the creation and use of self-contained lumps of data and function easy.
closed account (N8MNAqkS)
.
Last edited on
Sometimes it is the mechanics as well. I have seen 'object oriented c' where function pointers in a struct offered methods and has-a offered enough inheritance to make it all work.

Procedural programming is very powerful for some types of coding; I used to do a lot of math and sometimes, you just need something like a cross product of 2 <vectors> without having to attach that to an object or anything. Attaching it to an object just adds baggage and limits reuse (ironically, right?) for something like that. C++ is still a hybrid language -- you can write procedural code where it makes sense to do so. Its sometimes very nice to have procedural code that operates on your objects (think, 2 unrelated objects that you want to tie together very briefly, eg writing a simple log file or save-everything) as well.

all that to say, to me, Repeater's first sentence nails it. Its how you think about the problem more than anything else. The mechanics don't matter as much as one might think at first -- object oriented code is boiled down to assembly just like anything else, so you could, therefore, write OOP code in assembly or C or any other full power but not directly OOP language. Its a ton of work to do it, because you have to reinvent the tools as you need them, but its doable. Its just bytes and pointers, at the end of the day... you can make a union of everything, make a pointer->array of those, and bam ... array[0] is an integer, array[1] is a double, array[3] is a function pointer... its a crude class surrogate... an enum names the array locations and things begin to look interesting indeed... all that with effectively just a byte pointer :P No one would do any more of this than necessary, though (its rare but occasionally one is forced into a particular language). OOP assembly is going to be hard to write and slower than it needs to be, giving up the one major advantage of assembly and wallowing in its drawback. Same for C... OOP C beyond the 'advanced structs' level is a lot of work. If you need OOP, you should use OOP language instead of trying to craft it; my point wasnt that you should do it, but that you can, if the problem design is better solved in OOP and you are stuck in a non OOP language you can make it happen...
Last edited on
closed account (N8MNAqkS)
ok. thank you for your answer.

but as a side question, would you recommend learning an OOP as a first language.
Personally, No. OOP is a complex thing in and of itself and from what I have seen in others (I learned procedural first) trying to pick up logic/loops/syntax/basics on top of objects leads to a lot of 'memorize this and mimic it without understanding' rather than deep understanding of the basics.
This is a broad generalization of course, but its what I have seen from folks coming out of college in the last 20 years or so -- many of them can craft a big chained inheritance object structure in their sleep and fumble basic logic and loops and algorithms stuff like a high-school kid.
So does this make OOP languages more powerful and/or more useful.

No, not more useful, it's like French and Chinese, in both languages you may do love poem or vitriolic sermon.

would you recommend learning an OOP as a first language.

Yes. Otherwise you may experience a clash of cultures as I did -- I am a mainframe dinosaur. Up to now I did only two (and a half) oo-programs, a simulation of a pen plotter and another of a printer in ooREXX -- http://www.hp41.org/LibView.cfm?Command=Author&AuthorID=3202
The half program I did yesterday, work in progress, but C++, see here: http://www.cplusplus.com/forum/general/252307/#msg1110816
The object there is a "shoe of cards" with two card decks to deal for a Blackkjack game. Currently this object only displays the dealt cards and returns the value. I have to add the possibility to query the face (?) of the last card, to determine exactly if if Blackjack! or not.

A deterring example of oo-programming. Nothing what would not be possible without oo.

Edit: addendum -- "It's never too late to learn XXX" (and/or C++). Much better than "Life is too short to learn German" (who said that?) ;)
Last edited on
closed account (N8MNAqkS)
but I am I high school kid learning oop as a first language :(


u have burned me.
closed account (N8MNAqkS)
so I have some conflicting answers.

"would you recommend oop as a first language".

mike says yes.

jonnin says no.

hmmmmm.

well what language would you recommend I learn first if not an OOP language.
closed account (z05DSL3A)
HueMungus wrote:
but I am I high school kid learning oop as a first language :(
OOP is a programming paradigm...a style, or “way,” of programming and NOT a language.
https://en.wikipedia.org/wiki/Programming_paradigm
OOP is not fallen from the sky, there was an epoch before that, and people wrote their programs without OOP. But sometimes they felt that some problems would be hard to solve, where OOP helped them a lot.

So you could try to program without OOP. But at a distinct point of your language knowledge, you may feel that some things will be hard to implement without OOP.

If you want an easy to learning language, you could give a try to Python, which provides basic OOP facilities. A good playground for beginners is
http://www.codeskulptor.org
Its online-interpreter serves with facilities to GUI programming and has very good API documentation.
closed account (N8MNAqkS)
sry grey wolf I meant I am learning Object oriented programing.
You say that you are learning object oriented programming paradigm, a style or “way” to think.

That is good. Thinking is good. The OOP way of thinking provides "intuitive" solutions for some problems.

Thinking has very little to do with programming languages. Languages are mere translation tool to convey the thoughts into CPU instructions.
what language would you recommend I learn first if not an OOP language

A non-ooP? I depends your goal, what do you like to do? Is it just to train your brain or something you could use in future?
If it's for brain-training only, get an emulator of an out-of-date calculator, RPN if possible, what lets you look at formulas 'the other way' (without brackets, without =-key). Some decades ago those slide rule replacements had been awesome, for me they still are today. For example, just recently, to solve orthogonal regression and XY-regression I did on an HP-33C a routine with just 30 bytes for both. (YX-regression is what most calculators have built-in.) What is it? See the diagram here: https://fr.wikipedia.org/wiki/Corr%C3%A9lation_(statistiques)#Relation_de_cause_%C3%A0_effet
Links:
http://www.hp41.org/LibView.cfm?Command=Author&AuthorID=3201
https://hp.giesselink.com (missing ROMs? "See" here: https://hp.giesselink.com/ImageArt/ImageArt.htm )
https://www.hpcalc.org/torrents/hpemulators.torrent
http://teenix.org

If you like to do a bit more, procedures on your PC to read files, to write files, some housekeeping and in addition have the chance to do some procedures, for example Pi to 20'000 digits or more, or find some well known primes with well known procedures, then REXX is what you need.
Link:
https://sourceforge.net/projects/oorexx Yes, I know, you asked for non-oo -- it incorporates the original REXX too, you are not forced to use the oo-ability.
https://github.com/vlachoudis/brexx

In contrast, if you like to do something with dialogs, showing graphics, shiny surface like this one:
www.stehlin.net/hpclub/Aristo/4-banger.zip
then Delphy could do what you want. There is a free version of it.
Link:
https://www.embarcadero.com/products/delphi/starter

One day, when you made some experience in programming, I suggest to have a look at this one: https://en.wikipedia.org/wiki/Brainfuck
you don't have any 'answers'. you have 2 OPINIONs. Both are valid.

People have been successful doing it both ways. People have had a hard struggle doing it both ways. Knowing procedural for decades and then moving to OOP was a hard move for many. Jumping right into OOP is overwhelming for many. It depends on many variables ... the student, the way things are taught, the pace of the learning, the exercises asked to be solved, all that tie into which may work better for you.

You will do more OOP than not if you code professionally one day. OOP is better for large projects for most efforts and most real programs are substantial (all the easy stuff was done long ago). A very small number of things (like my math example) are better suited to use a hybrid or procedural design, but its rare. Small programs are often easier to write with procedural, doubly so if you know that approach well. Crafting a class to do 10 lines worth of coding is often silly.

One more way to look at it: OOP programing contains procedural programming. The methods you write for any class / object ARE procedural programming designed and implemented for the most part. So learning OOP (specifically in C++) is going to teach you both. Which is the drawback... you are learning two things at once. Learning procedural first reduces the amount of material you need to absorb all at once by a decent bit if you are coming into it knowing little. Again, thats just my opinion, based off my life experiences and encounters with many fresh out of school programmers.
Last edited on
Thinking has very little to do with programming languages.

If this holds true either the term "Pipethink” (see p.2 in http://vm.marist.edu/~pipeline/plunge.pdf ) is a fallacy -- or building PIPELINES is not programming. And following is not a program:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* SNFHPILD EXEC: Delta-sniffer for virtual HPIL. MF 25.3.2013        */
/* needs DCF REXX to decode frames                                    */
 
exIP = 172.18.23.33                   /* out IP                       */
p.in = 60002; p.ex = 60002            /* 1st in and out port          */
q.in = 60003; q.ex = 60003            /* 2nd in and out port          */
 
h = 'To quit enter PIPMOD STOP.'      /* just a hint                  */
if arg() > 0 then do                  /* any argument shows settings  */
   say 'In1:' p.in || ', out1:' exip || ',' p.ex || '.'
   say 'In2:' q.in || ', out2:' exip || ',' q.ex || '.' h
end
else say h                            /* display hint in any case     */
 
'PIPE(sep | end ?)',
 '|a:tcplisten' p.in,                 /* get client connected         */
 '| take',                            /* one only                     */
 '|b:tcpdata linger 1200',            /* read in from the loop        */
 '| fblock 2',                        /* make single frames           */
 '|c:fanout',                         /* get a copy                   */
 '|d:tcpclient' exIP p.ex,            /* send it out on the loop      */
 '?a:',                               /* errors from TCPLISTEN        */
 '|e:faninany',                       /* collect more errors          */
 '| pipestop',                        /* in case of error give up     */
 '| sort uniq',                       /* if others tell the same      */
 '|f:chop after blank',               /* get leading return code ...  */
 '| aggrc',                           /* ... and set RC of this PIPE  */
 '?b:|e:',                            /* errors from TCPDATA          */
 '?c:',                               /* frames from the loop         */
 '| dcf',                             /* decode frame                 */
 '|g:fanout',                         /* to COMBINE                   */
 '|h:spec *-* 1.19 /:/ nw',           /* frame from first station...  */
   'select 1 *-* nw',                 /* ... and from second station  */
 '| term',                            /* present to user              */
 '?d:|e:',                            /* errors from TCPCLIENT        */
 '?f:',                               /* from CHOP                    */
 '| term',                            /* send to CRT                  */
 '?g:',                               /* from FANOUT                  */
 '|i:combine x',                      /* spot the difference          */
 '| xlate *-* 01-ff 2 00 0',          /* colorize delta               */
 '| insert /vsc writ cms 0 24 0 (color /',            /* combine CMDs */
 '| insert /;PSC REF/ after',         /* show it immediately          */
 '| split ;',                         /* one CMD one line             */
 '| cms',                             /* execute the CMDs             */
 '?j:tcplisten' q.in,                 /* get client connected         */
 '| take',                            /* one only                     */
 '|k:tcpdata linger 1200',            /* read in from the loop        */
 '| fblock 2',                        /* make single frames           */
 '|l:fanout',                         /* get a copy                   */
 '|m:tcpclient' exIP q.ex,            /* send it out on the loop      */
 '?j:|e:?k:|e:?m:|e:',                /* errors to PIPESTOP           */
 '?l:',                               /* frames from the loop         */
 '| dcf',                             /* decode frame                 */
 '|n:fanout',                         /* to COMBINE                   */
 '|h:',                               /* to SPEC                      */
 '?n:|i:'                             /* short through                */
 
exit rc                               /* that's it                    */

Just in the append before I mentioned RPN which offers a different way to "attack" equation. This has nothing to do with thinking?
Thinking has very little to do with programming languages.

Ken Iverson claimed the opposite:
http://www.eecg.toronto.edu/~jzhu/csc326/readings/iverson.pdf

On the other hand, your programming language rarely forces you into a particular way of thinking about a program. For instance, object-oriented C is quite common, and some kind of pipe abstraction will be introduced to C++20 through the standard library. Neither of these approaches are "encouraged" by the language.

There are artifacts, though - the C++'s implementation of pipelining arrives through meta-programming, and so they won't be as nice syntactically as might be achieved in other languages.
Last edited on
HueMungus wrote:
what else (in c++ more specifically) is considered an "object".

nobody picked up on this part of the original question yet. In C++, an "object" is, simply put, a region of memory with a type, a value, and a lifetime.
An integer is an object. A pointer is an object. A string is an object.
See here for details: https://en.cppreference.com/w/cpp/language/object

The concept typically described as "object" in OOP theory is supported by C++ via what C++ calls "polymorphic object", see https://en.cppreference.com/w/cpp/language/object#Polymorphic_objects , but since C++ is not an OOP language (see https://isocpp.org/blog/2014/12/myths-1 ), this is just an opt-in feature.

Last edited on
nobody picked up on this part of the original question yet

At least I linked to an example in here http://www.cplusplus.com/forum/beginner/252376/#msg1110890 , the phrase starting with "The half..."
Topic archived. No new replies allowed.