Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Struggling understanding what OOP is about

  1. Dec 24, 2015 #1
    Hello Forum,

    I understand that Java is an example of a computer language based on object oriented programming. I have read about objects, classes, etc. and I think I get those ideas. The other type of programming, opposite to OOP, is procedural programming: the computer simply receives a logical list of commands.

    I have used Matlab in the past. To me, it seems like everything needs to be specified in the matlab code but it is also possible to write m-files and call them from other matlab programs. For example, I could write a m-file to draw a house and call that file from my main program. That said, I don't think Matlab is considered OOP. Is that correct? I am trying to compare Matlab to Java to see if I can better understand what OOP is about and what it is not...

    thanks,
    fog37
     
  2. jcsd
  3. Dec 24, 2015 #2
    There is no definition of OOP that everyone agrees upon, there is only broad agreement on the set of key characteristics. I don't know a better brief treatment of them than http://www.stroustrup.com/whatis.pdf.
     
  4. Dec 24, 2015 #3

    Student100

    User Avatar
    Education Advisor
    Gold Member

  5. Dec 24, 2015 #4
    Thank you. I will read what is on the links.

    For instance, Let's say I want the matlab program I am writing to draw a sphere. I previously wrote a general and short m-file, a function called sphere.m, for drawing spheres of all sorts. I could call that m-file into the the matlab program I am writing. Am I doing OOP in that case?
     
  6. Dec 24, 2015 #5

    phinds

    User Avatar
    Gold Member
    2016 Award

    Well, not quite. For most (all?) C++ compilers you are not required to use OOP, but JAVA is inherently OOP and you don't have a choice about it. You CAN write procedural code within a class but technically it's still OOP.

    This message was brought to you by the nitpicker in chief :smile:
     
    Last edited: Dec 24, 2015
  7. Dec 24, 2015 #6

    jtbell

    User Avatar

    Staff: Mentor

    And you can do some aspects of object-oriented programming in C by using function pointers in structs to implement member functions of objects. However, all struct members are "public"; IFAIK there's nothing like C++'s private member data and functions in classes. And there's no inheritance between structs in C.
     
  8. Dec 24, 2015 #7

    ChrisVer

    User Avatar
    Gold Member

    Is Matlab really considered a language? I thought it was more like an environment like mathematica etc.
     
  9. Dec 24, 2015 #8

    FactChecker

    User Avatar
    Science Advisor
    Gold Member

    MATLAB is a fairly sophisticated language. There is also a large environment that it works within. The environment includes an editor, tools for auto-generating C/C++ code, interfaces with Simulink, modeling standards checking, etc.
     
  10. Dec 24, 2015 #9

    Mark44

    Staff: Mentor

    Yes, it is a language.
     
  11. Dec 24, 2015 #10

    phinds

    User Avatar
    Gold Member
    2016 Award

    All major programming languages have been evolving for decades and becoming not "just" languages but huge development environments. That is, the languages themselves have evolved only some (although some have become, really, new languages, such as VB6 -> VB.NET) but the development environments have evolved enormously to where today, unless you are really using a stripped down compiler environment to write a console app, if you had nothing but the language itself, you would have damned near nothing of any use.

    For example, many decades ago I wrote some programs in BASIC. The entire "development environment" was an interpreter. Almost 25 years ago Microsoft released Visual Basic which was a significant evolution from BASIC and the last incarnation of which was VB6. By the time it got to VB6 the development environment had swamped the language itself in terms of overall capabilities. Today I write in the successor language VB.NET, which is a significant evolution from VB6, not just an extenision, and the development environment is far more complex than VB6.

    If I had nothing but VB.NET as a language, and just a syntax compiler, I could not do squat without spending MANY hours doing each of the things that are just a mouse-click or two in the development environment that is the totality of VB.NET

    And so it goes ...

    My point being that trying to distinguish between a "language" and a "development environment" in today's world is a waste of time.
     
  12. Dec 25, 2015 #11

    meBigGuy

    User Avatar
    Gold Member

    I may be wrong, but from what I remember your sphere.m will probably create a sphere object (lets call it sphere1) and you can access sphere1.volume, or pass it to other objects that will inherit its methods and data. That is pretty much OOP. (maybe your sphere.m doesn't do that?)

    If it were procedural, you would define a sphere with some data in variable (say, sphere1_diam), and operate on it with math procedures to determine the volume. You could stick them and some function pointers in a generic sphere array, and that would start to resemble an object.

    In matlab, the sphere and its methods (functions) and data are encapsulated in a sphere object.
     
  13. Dec 25, 2015 #12
    You could consider your sphere.m file to be a module. One of the goals of object oriented programming is modularity. But what defines object oriented programming, while it may vary, is generally following the adherence to a set of programming principles. In contrast, an object oriented language is a language that has built in features to support this style of programming, and in some cases such as Java, the exclusion of features that support other paradigms.

    This would be procedural programming using an object oriented language. Again, there is a difference between the style of programming and the language.

    Maybe a few languages have become tied to an environment. Most are independent of the development environment. And you certainly don't need an IDE to make graphical programs. In most major programming languages, not using an IDE dosn't impose any limitations on what you can produce, although an IDE might offer some convenience for beginners, or include some nice integrated debugging or profiling tool.
     
    Last edited: Dec 25, 2015
  14. Dec 25, 2015 #13

    phinds

    User Avatar
    Gold Member
    2016 Award

    Yeah, I think my thinking has somewhat been warped by VB.NET where you ARE tied to the environment and the basic language syntax is just a small part of the overall development process. I've done lots of programming other languages and I agree w/ you but all of the basic languages like C, C++, C##, Java and so forth are very dependent on system calls and each language's function libraries to do a lot of the heavy lifting. If you only know the syntax of the language and don't have a good knowledge of that other stuff, you aren't going to get much done outside of straight number crunching.

    I still do, on occasion, write console apps (using VB.NET) but they're pretty primitive compare to windows apps.
     
  15. Dec 25, 2015 #14
    I guess I was thinking about IDE's. I suppose more of what you said is true, and less of what I've said is true, if we're talking about libraries, run-time environments, and interpreters.
     
  16. Dec 25, 2015 #15

    phinds

    User Avatar
    Gold Member
    2016 Award

    Right. Compilers and an interpreters are fundamental to developing code in a language and the syntactical aspects of the language ARE the language. Everything else is support and that's what I'm talking about. Without the support structure, you really don't get much beyond writing simple console apps and number crunching programs, especially compared with what you can do WITH all the support stuff. I can pop out a windows app today in a few hours that would have taken me weeks in the early days of windows when I was using C and bringing in the windows system libraries. Today I just drag and drop stuff from a toolbox onto a form and there's my GUI that used to take a ton of painstaking work.
     
  17. Dec 25, 2015 #16

    jtbell

    User Avatar

    Staff: Mentor

    For most general-purpose languages, IDEs and the libraries for programming for a specific OS are separate issues, in principle at least. You can write a call to a function for opening a window, using a plain old text editor, and compile/link using command-line tools. It just becomes a chore working out the correct parameters for e.g. window size and location, and remembering which libraries to link. The latter is where makefiles come into play on Unix-like systems.
     
  18. Dec 25, 2015 #17

    phinds

    User Avatar
    Gold Member
    2016 Award

    So, @fog37, have we all just been talking to ourselves our are you getting anything out of this? :smile:
     
  19. Dec 26, 2015 #18
    Its rare to see so much chatter on a thread on PF (much of it interesting) without seeing a strait-forward answer to the OP's question. So I will throw mine in.

    OOP is a way to organize code in objects, which are collections of declared variables (sometimes called members or attributes of the object) and functions (called methods of the object). It can be contrasted with functional programming languages where the top level entities are functions, rather than objects, and the program executes by passing structured data into functions. In OOP, the structured data is grouped in an object, along with a collection of method functions which are part of that object and act upon the data of that object when called.

    I don't know your programming history, but if you have a structured collections of data (struct) which includes functions that can act upon it in the same class/object, that's OOP. If you have structs which are passed to independent functions which act upon them, its not.

    Simply, an OOP language will give you a person object, with a method sayName(), that will draw upon information (members/attributes) of the person, like what their name is. So you will write bob.sayName() to get "bob" output. In other paradigms, you will pass the Bob struct, which includes Bob's name, to the sayName() function to get the same result. Its a different way of structuring things to achieve the same results all languages achieve.
     
  20. Dec 26, 2015 #19
    You guys are great. Thank you.
    Still digesting all all these valuable infos. I know matlab to a superficial level (m-files, arrays, functions). I have never seen anything written as sphere1.volume. What type of object is that?

    Could any of you provide a trivial example and explain how I would write it in matlab and in java? Maybe it would make things less abstract. To me programming is simply a set of instructions and calling of functions (which are also programs stored somewhere else) to manipulate data. Arrays, structures, variables are efficient ways to organize the data. Functions, instead, act on the data to produce new output data, visualize the data, etc.

    I think I understand modular programming, i.e. creating small programs all linked together to achieve a specific task....
     
  21. Dec 26, 2015 #20

    anorlunda

    Staff: Mentor

    You will have to think a lot more about programming and different ways to approach programming problems before you'll be answer your own question "What is it all about." Learning how to do it in different languages won't answer that question. If you're not interested enough to study it, then you should drop the question. There are no trivial answers.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Struggling understanding what OOP is about
  1. C# oop static instance (Replies: 2)

  2. Question about OOP (Replies: 2)

Loading...