Pros and Cons of OOP

Discuss other programming languages besides AutoHotkey
Miguel7
Posts: 186
Joined: 08 Sep 2014, 07:06

Pros and Cons of OOP

11 Sep 2014, 09:21

Hey guys,

This is a question I've had in the back of my mind for awhile now, not specific about any one language but just in general. I've programmed in languages that are object-oriented to the extreme, like Java and C#, and also languages like JavaScript, Python, VBA, and (as I found out yesterday) AutoHotkey; this second group of languages supports OOP but doesn't necessarily require it. And for most of them, a beginner doesn't even know there are any "objects" involved - I wrote VBA macros for two years before I ever heard of OOP. So I guess in this post I'm talking not so much about whether a language is technically OO but more the style or process of writing the code.

As an example, let me use AHK (since that's what everyone here is likely to know :lol:). You can write a script like this:

Code: Select all

^n::
Run Notepad
MsgBox Time to get your code on!
ExitApp
There may be several objects at work here behind the scenes (listening for the hotkey, running Notepad, and the object(s) associated with Notepad itself), but to the guy writing the script it looks more procedural ("If this hotkey is pressed, (1) Run notepad, (2) put up a message box, and (3) stop the script"). Same goes for JavaScript

Code: Select all

function go(){
    var txt = document.getElementById("someInputField").value;
    alert(txt);
}
Same deal: technically, the script is accessing a DOM object (another subject I didn't know Jack about until I'd been using JavaScript for years :lol:), but in practice it looks like a list of tasks ("when the user presses a button, (1) get the text for to be displayed, and (2) display it in a message/alert box"). Both languages support OO and are actually using it, but this is less apparent than in Java or C#. You get the idea. :)

So whether we're writing in AHK, JavaScript or whatever, what do you think are the advantages and disadvantages of using OOP vs. another approach? I have my opinions about it, but I thought I'd get other programmers' perspective on the subject.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Pros and Cons of OOP

11 Sep 2014, 12:42

To me the main disadvantage of OOP or Prototype Oriented Programming is that it is more difficult to produce such code right away.When you have a new problem you might need to do some tests before coming up with an idea on how to do a class based design. I do not see any other disadvantages. (I read something about higher memory accession in comparison to normal code in the case of C++, but cannot find the source)

The main advantages are code maintainability (Bug Finding) and the consistency of your code. Also I can understand OOP quite easily in comparison to normal code.
Recommends AHK Studio
guest3456
Posts: 3463
Joined: 09 Oct 2013, 10:31

Re: Pros and Cons of OOP

11 Sep 2014, 12:53

those examples are horrible

Miguel7
Posts: 186
Joined: 08 Sep 2014, 07:06

Re: Pros and Cons of OOP

11 Sep 2014, 17:00

nnnik wrote:To me the main disadvantage of OOP or Prototype Oriented Programming is that it is more difficult to produce such code right away.When you have a new problem you might need to do some tests before coming up with an idea on how to do a class based design. I do not see any other disadvantages. (I read something about higher memory accession in comparison to normal code in the case of C++, but cannot find the source)

The main advantages are code maintainability (Bug Finding) and the consistency of your code. Also I can understand OOP quite easily in comparison to normal code.
My thoughts exactly. Funny thing is this describes my week at work. :lol: Over the weekend I came up with an idea that I thought would be a huge help in one of my projects, so on Monday I immediately dove in and started scripting, just to see if it could be done. I found out it could, but my code was a mess (despite my best efforts to keep it organized and readable) and would have been a bear to maintain. So today, I spent some serious time transitioning my old "normal" code to OOP. I found that not only did my code still work, but it was easier to read, debug, and add features. This also looks like it's going to be easier to integrate into my main script; I can tell already it'll prevent some conflicting variable names, and my hotkeys will be a lot less complicated (just calling an object's methods rather than implementing the same functionality at that level).
User avatar
joedf
Posts: 8959
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Pros and Cons of OOP

12 Sep 2014, 04:16

Varies on the user and the programmer.
With absolute zero OOP, programmer 'hates' it.
With 100% abuse of OOP, user hates it.

Modern technolgies are starting to solve these problems for both the user and the programmer. I guess by the year 2100, this question becomes irrelevant. It will then only be a question of programming styles. And opinion based questions are never "truly" answered.

My suggestion: take your pick ;)
Regards
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
User avatar
RobertL
Posts: 546
Joined: 18 Jan 2014, 01:14
Location: China

My simple point on OOP & PP

12 Sep 2014, 21:50

  • Object is an abstract concept, represent the independence nature/essence like class/instance or something.
    Object.Property, Object.Method, Object.Event (passive Callback method).
  • Procedur is a collapse form from objects relation and action.
    Usually the external representation of OO, which we learn/study outside in.
  • I think OOP is a distribute-like programming thinking than PP(procedural programming).
    They can change/convert to each other with certain balance.
我为人人,人人为己?

Return to “Other Programming Languages”

Who is online

Users browsing this forum: No registered users and 45 guests