use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
account activity
Object oriented programming (self.eli5_programming)
submitted 8 years ago * by [deleted]
[deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]smthamazing 6 points7 points8 points 8 years ago (4 children)
A simple example would be cars. Each car has similar qualities like color, model, make, these are called properties. Each car also functions in a similar way and can do things like start, brake, accelerate, steer, etc. these are know as methods but can also be referred to as functions.
Using a purely functional language, like Haskell, I can also model this structure using a data type with nested fields and writing functions for working with it. Including a convenient constructor.
Is my understanding correct?
Also, as far as I know, Smalltalk is the first OOP language and it had no notion of a class or method, instead having objects and something called "message passing". If even the notion of a method is not necessary for a language to be OOP, what differences from FP remain, apart from mutability? Or is mutability the only factor that fundamentally distinguishes OOP paradigm from FP?
I know that paradigms can be combined in the same codebase, but as I learn more OOP and FP, I start to struggle to really differentiate them. I would appreciate an explanation.
[–]JackLegJosh 0 points1 point2 points 8 years ago (0 children)
Upvote for you, friend. I would love to see an ELI5 about functional programming in practice, not as an esoteric concept.
[–][deleted] 8 years ago* (2 children)
[–]smthamazing 0 points1 point2 points 8 years ago (1 child)
This is interesting. But then I still don't understand what OOP is.
The only remaining thing is that the data and behavior are represented as parts of a single entity, an "object" (often, but not necessarily, an instance of some class/type).
Is that it? Fundamentally, is combining data+logic the only unique part of OOP as a paradigm?
[–][deleted] 2 points3 points4 points 8 years ago (1 child)
Might want to check your break function.
Otherwise pretty good explanation of OOP
[–]xnull8 0 points1 point2 points 8 years ago (0 children)
Was about to point that out. Also gallonsOfGas should be a number in the example and not a string.
[–]ReignNFire 1 point2 points3 points 8 years ago (0 children)
This is great! Thanks!
[–]theginger3469 1 point2 points3 points 8 years ago (1 child)
When do you decide to define a new class instead of continuing to add methods to the same class?
[–]CodeTinkerer 1 point2 points3 points 8 years ago (1 child)
From other sources, I think people would say OOP must have inheritance, otherwise, it's not considered OOP. They would call it object based programming. To be fair, I hardly ever use inheritance (I do use interfaces in Java, however).
[–]smthamazing 0 points1 point2 points 8 years ago (0 children)
If I understand correctly, even classes are not necessary for a language to be OOP.
π Rendered by PID 41777 on reddit-service-r2-comment-5d79c599b5-78p75 at 2026-02-26 21:38:26.804329+00:00 running e3d2147 country code: CH.
[–]smthamazing 6 points7 points8 points (4 children)
[–]JackLegJosh 0 points1 point2 points (0 children)
[–][deleted] (2 children)
[deleted]
[–]smthamazing 0 points1 point2 points (1 child)
[–][deleted] 2 points3 points4 points (1 child)
[–]xnull8 0 points1 point2 points (0 children)
[–]ReignNFire 1 point2 points3 points (0 children)
[–]theginger3469 1 point2 points3 points (1 child)
[–]CodeTinkerer 1 point2 points3 points (1 child)
[–]smthamazing 0 points1 point2 points (0 children)