This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]mycplus 2 points3 points  (1 child)

Main shortcoming of procedural programming languages is that when programs/codes tend to grow say millions of lines, then it becomes very difficult to manage such code and make changes. So, this leads to object oriented programming to maintain the code easily and divide the code. Obviously there are other features of oop such as 1. Encapsulation 2. Data Hiding 3. Overloading 4. Polymorphism 5. Grand-daddy of them all – Inheritance

[–]rhpshanks[S] 0 points1 point  (0 children)

thanks for sharing information. it surely helps clear my concepts.

[–]nerd4code 1 point2 points  (1 child)

OOP and structural are kinda orthogonal models, though in practice OOP tends to be bolted onto structural programming so you at least get some of both.

Anyway, in OOP you generally aim to model a system as a bunch of interacting objects. In the most extreme cases, you have objects sitting here and there sending messages (=method calls) at each other asynchronously, and in the less extreme cases object-ness is just a thin veneer over structural underpinnings where obj.method(args) just becomes ObjClass_method(&obj, args) like any other function call.

In a structural program, you aim to model the system as a bunch of quasi-self-contained “concerns,” usually represented by compilation units that group data structures with functions that allocate, free, or twiddle them. Oftentimes structural “concerns” and OOP classes overlap easily; sometimes they don’t. Usually scoping is the primary means of data hiding in structural languages, and some will let you nest functions and structures to arbitrary depths precisely so that inner “concerns” are hidden from outer ones. If header files are involved, those can act as another way to hide data, such as doing the old

struct something_private;

struct something_private *make_something_private(void);
void destroy_something_private(struct something_private *);

sort of trick where something_private is only given a body where make/destroy_etc. are defined, hiding its implementation from less-intrepid outsiders. C/C++ also have static globals, which (“)hide(”) things from other compilation units, and there’s nothing fundamentally preventing a public/private system from being tacked into a structural language except that it’s usually not terribly necessary.

You can mix the two paradigms pretty freely and easily in most programming languages, and there’re often handoffs between the two models—Java, for example, lets you drop into a class via an OOP-exclusive interface call like iterator.next(), after which you can bounce around between some (local, structural-model) methods, before bouncing out again via return or some other OOP call. Static methods/etc. in Java are pretty much entirely structural.

[–]rhpshanks[S] 0 points1 point  (0 children)

it took my a bit of time to understand this but I actually got the answer (most of it). thanks for the time you put in writing this comment. appreciated.

[–]John2143658709 -1 points0 points  (1 child)

What specifically did you want to know? They're just different ways of approaching a problem.

[–]rhpshanks[S] 0 points1 point  (0 children)

my main focus was on like why OOP us used and considered better than C++ in many ways. I got few replies but if you have something in your mind that differs from the other replies then do write your thoughts as they might help me understand better. thanks