OOP

I understand the theory and code examples you see in books and tutorials but I just don't know when and why I should use this OOP shit

Please enlighten me oh you super senior^9001 software developer engineers

Attached: nan.jpg (2128x1416, 655K)

Other urls found in this thread:

yegor256.com/tag/oop.html
zvrba.net/downloads/EOReview.pdf
harmful.cat-v.org/software/c /I_did_it_for_you_all
cs.rit.edu/~ats/books/ooc.pdf
youtu.be/QM1iUe6IofM
twitter.com/NSFWRedditGif

>when and why I should use this OOP shit
always or never, but don't mix

it's a design principle that works best for solving problems which you can model as a bunch of items with some kind of state and some kind of behavior

always, and mix (e.g. with functional paradigms), but quickly forget about all the inheritance crap

(cont.)
>inheritance crap
Not that there aren't exceptions. It's a powerful and convenient tool. But newfags always think that's what makes things oop, which is just dead wrong. [spoiler]and considered harmful[/spoiler] I think spoilers don't work on Jow Forums, eh? Faggots.

Are you designing a system where there are many items that share a common set of characteristics? This is one of the simplest and most useful applications of OOP. An example being:
>a set of beans that are based off of tables in a database
>all of the tables have some meta columns like create_date, create_user, last_change_date, last_change_user
>you can make all of your beans extend a class that has those getters and setters that way they one, reduce duplicate code, and two, let you apply global filters to all things being written to the database

t. newfag, and a q.e.d. to newfags thinking inheritance is what makes oop

The closest I've done is a simple db management program in Visual Studio. Inserting users with different properties into a sql database

I guess i just don't get it because i haven't done any big projects? That or because I'm retarded

Same, except I'm a university graduate and 3 year professional software developer and have never felt the need to utilize oop

>That or because I'm retarded
Maybe. Tell me more about oop paradigms, user. Just the important stuff.

Read this guy he is pure oop evangelist yegor256.com/tag/oop.html

>professional software developer
>never felt the need to utilize oop
holy shit, do you even know what oop entails?

This Bugayenko fellow seems very popular on here, but I think he's much hype and little substance. zvrba.net/downloads/EOReview.pdf

op.getGun().shootHead();

OOP is a scam. Let's start with the fact that no one knows what OOP is, they're as many definitions as there are "OOP gurus". Nobody knows what "good OOP" is, nobody can show you an example of "correct" OOP.
It's basically a religion at this point, like God. If you've used OOP and it works, that's because OOP works. If you've used OOP and it doesn't work, that's because you haven't been using enough OOP, or that's not "good" OOP. If you didn't use OOP at all and it still works... well shit, OOP works in misterious ways.
Just read all those stupid books and write the stupid code to please the corporate drones, get your paycheck and don't ever believe this crap unironically.
Follow guys like Muratori, Eskil Steenberg, Jon Blow et al for emotional relief. Don't reveal your power level to your "code ninja" coworkers.
Good luck and have fun.

Oh and the people who preach OOP usually never wrote more than 1 page of code in their lifes. It's like those business trainers whose business *is* doing business training. At least anti-OOP guys actually practice what they preach and write actual software on a daily basis.

based. we can close this thread now.

/thread

Object Oriented Programming Sucks.
AKA
OOPS
No really though just use C.

>nobody can show you an example of "correct" OOP.
this is the thing that pisses me off the most
there's so many ways to write this fucking garbage

OOP is a layer of complication and bloat that applications (whatever the type) don't need.
>Stick to structures, pointers and functions and you won't go wrong, ever.

>why I should use this OOP shit
Because you can't FP everything, can you?

Well, then you use OOP to make code reusable and keep it from influencing shit all over the program with global variables, global functions and so on.

>global variables bad
>singletons good
>:^|

harmful.cat-v.org/software/c /I_did_it_for_you_all

based

Attached: canvas.jpg (1920x1080, 299K)

(cont'd)
PS: If you can FP something well, you should prefer doing so. It's obviously more reusable and more safe.

Yes, singletons with their limited scope are better than global variables.

Simply don't use global variables, they're not functional.

A better example: I had to write a bunch of programs for my data structures class. All of which had to read a CSV file that consisted of all the states in the U.S. and their various attributes such as name, capitol, population ect.

Once read, I would have to sort that information in various ways with different data structures like Linked lists and trees and shit by state. OOP is well suited for this problem, I just created a state object class that stored all of the fields that each state would have according to the CSV and generated 50 objects from that class from the data read. I code oke class, get 50 objects by using some logic, store those objects in data structures, and then I'm free to manipulate them as I like. I can throw them all in a state object array, for example.

Nobody says nothing about global constants, and they're basically global read-only variables.
It's *writing* to global variables that's bad, because when you read that variable and it has some bogus value you have no fucking clue where that came from and how to debug it. That's the real problem with them. So basically what you want is having a way to debug who writes to a global variable, that's what singleton solves, and that's what you can solve without any OOP at all by simply creating an intermediary function that would allow you to trap who writes what.

int ebil_global_var;

void set_ebil_global_var(int new_val) {
ebil_global_var = new_val

// and you debug it like this:
// if ( new_val === BULLSHIT )
}


There, solved your poblem without having to create 10000 classes and minimal abstraction penalty.

oop is the most natural way to code because the point is its the same model as how human view the world. things as similar/ dissimilar object, with states and behaviors.

that said it tends to make a pretty shit multithreaded code

This poster is correct is smart, I indeed think about the real world in terms of visitors, factories and interceptors.
For example, I could not comprehend what a chair and an armchair was until someone explained to me what an abstract proto chair is.

> they're basically global read-only variables
Global constants are values, not variables. Yes, read-only is a HUGE difference.

> It's *writing* to global variables that's bad
No. Having them is bad. You need to know you can't write in any legal fashion within the scope of your programming language to be sure the program is functional.

> There, solved your poblem without having to create 10000 classes and minimal abstraction penalty.
Nope. It's
val global_val
Nothing else will do. It needs to be safe for parallelism including partial executions with splits between machines, safe for copy&paste, safe for everything.

Issue with discussing OOP is that there's several differing opinions on what OOP even is. Python for example has classes but no data hiding. To some that means it isn't "truly OOP"
In it's broadest definition, OOP is the usage of composite data types with functions attached to them. Applied wisely that can simplify systems and save having to write magnitudes of codr, or you can fuck yourself with fragile code structures.

based

You fool, OOP is a design language used to model problems. Just because you learned words doesn't mean that you can speak well.
That's the common fallacy if you learned some oop language you are automagically mastered software design. No you don't.

Yes, just like hegelian dialects, bash your head against the wall repeatedly until you've brainwashed yourself enough into believing it.
Notice how OOP is unfalsifiable. You can't prove OOP does not work, or doesn't work in certain situtations, or even that some problems are better approached with something else than OOP, that can't happen, OOP is always the right tool for the job, if you think it isn't, you simply haven't been reading enough word diarrhea from the gurus.

OOP never made sense to me until I actually had to use it, then everything kinda clicked

>I just don't know when and why I should use this OOP shit
That's because OOP is total shit. Completely niggerlicious. There is NOTHING that should be done with it.

t. Haskell shill

>implying

Attached: 1554246554537.png (376x341, 102K)

It's great for gamedev.

I second this. I never felt a need for it until working in gamedev

Why do programmers have such a hard time understanding there's the right tool for the job and something is rarely universally bad or universally good

how the fuck would any 20+ person software project get done are you guys fucking high?

if it's not immediately obvious to you then you should leave programming immediately pajeet and go back to working at seven eleven.

Can you do oop in C?

i am really surprised that no-one made a "OOP is a fag"

Sure.

>I just don't know when and why I should use this OOP shit
Good, this means you've been using your brain. OOP is mostly used in business so companies can hire swaths of cheap, easily replaced idiots instead of having to spend money on skilled engineers that can make work demands. Otherwise it's just a convoluted and opaque way of doing things that other paradigms can do in simpler, easier to understand ways, since learning how computers actually work ended up being a lot less effort than memorizing and working with vague blobs.
The only exception is in game development, and even then you should try to keep it to a minimum and keep your blobs separate from the rest of the code.

cs.rit.edu/~ats/books/ooc.pdf

Attached: 1516145721396.jpg (640x633, 161K)

The number one rule of programming:
>Do not repeat yourself
The number two rule of programming:
>Do not share state
Everything else comes from these.

Try writing something bigger and you will see that it will start to get useful to sort all the shit.

But then you will have awful ideas of what to do with it and this is the time to stop.

>beans
Fuck off poojeet. Java is shit.

>The number two rule of programming:
>>Do not share state
you just made that rule up

off by 1

No I didn't.
There's a reason global vars and state are a bad thing.
For example: when attempting to debug a multi-threaded program.

There's a reason global vars exist

Sure. And you should break the rules... When you know exactly what you're doing and why and what the trade-offs are.

Just like you should use different programming paradigms when you know exactly what you're doing and why and what the trade-offs are.

The true path to enlightenment is to realize that there is no one path to perfect code.

Literally they only correct way to do GUIs. Eg. each button is instance of button class, holds this variable as it's label and performs this method when clicked. Label variable can be dynamically updated from other parts of the program. You store all button instances in some data structure, a list, dictionary or whatever for easy access. Same with pretty much all other GUI widgets.

you should never really break DRY unless you don't have a choice
there's plenty of reasons to use global variables

This thread makes a cry a little. Holy shit, I hope most of you retards are just meming.

Work on or manage large codebase with more than 5 engineers and see why procedural or functional paradigms are shit and highly coupled. Design patterns exist because they work and are usually most elegant and reusable solution to a given problem.

>there's plenty of reasons to use global variables
And those reasons are...?

Kinda funny that one of the most famous C codebases, Linux, has to ape OOP features present in C just to get work done.

t. the dude who thinks oop = design pattern

for things that need to be accessed globally

Like what?

Have fun implementing common patterns without OOP

Most of this thread is just posers parroting contrarian opinions they heard on Jow Forums to make themselves feel smart and LARP as Linux systems programmers though

>The true path to enlightenment is to realize that there is no one path to perfect code.
Which is why OOP is shit, the whole 90s OOP craze was driven by the notion that it was a silver bullet for problem solving because most people didn't know how shit it almost always is in practice. Sometimes it's better to reuse your code now and then instead of jumping through hoops to make it as reusable as possible, you're just replacing your old boilerplate with new, worse boilerplate.

like anything
have you ever programmed a computer before? do you think you need to wrap everything in an instanced object for it to be safe?

all the time

>The true path to enlightenment is to realize that there is no one path to perfect code.
This kind of attitude is how we get unreadable unmaintable garbage like perl.

Engineering standards and best practices exist for a reason. Miss me with that "tHeRe iS nO oNe pAtH tO pErFeCt cOdE" shit you special snowflake faggot.

I've been writing software for about a decade and a half in everything from C, C++, Java, C#, Python, PHP, Ruby, and Lua to Rust, Lisp, x86 and MIPS assembly.
I've worked on projects from school assignments to server-side tools to native desktop apps to web dev to embedded to game dev.
I've worked on my own, with class mates, with co workers.
I've worked with awesome borderline geniuses and with literal autistics.

I asked you to explain your argument and what do you respond with?
>hurr, if you don't already agree with me then you must be nub git gud
Yeah. So you're wrong. You have no argument. You're full of shit.
Here it is playing by your own rules: if you had experience of your own you'd be able to give a straight answer to a straight question.

>Miss me with that
What is this? Are you a fine upstanding inner city youth? Or are you just a pipsqueak up past his bed time?

>Have fun implementing common patterns without OOP
Sure. But design patterns are just a language so we can talk with each other and refer to the same concept. It is as much not OOP as inheritance is not OOP. Both have their place though, sure.
>Most of this thread is just posers parroting contrarian opinions they heard on Jow Forums to make themselves feel smart and LARP as Linux systems programmers though
yeah, it's really bad. You'd think there'd be at least one or the other clever joke or something, but no, is just utter stupidity and bullshit all the way down. I wonder is Jow Forums full of fat fucks? Is it the same on all boards?

>getting triggered by slang on an informal anime imageboard

Everything that doesn't need to be instanced can be a global
You sound like a student making things up

this is a better argument for traits, typeclasses, or hell even interfaces.

this is factually incorrect, humans tend to think in a relational model.

Relational models such as ECS or 'behaviours' type systems have taken over since the 2000s, as hierarchical models were/are too rigid.

OOP != modularity. encapsulated modules can be written in any language of any paradigm

>Do not share state
the world is shared state, user
exposing proper APIs to maintain invariants and providing means to safely read/modify that state is the key

>Have fun implementing common patterns
"patterns" are a language fault.

>Relational models such as ECS or 'behaviours' type systems have taken over since the 2000s, as hierarchical models were/are too rigid.
this is so laughably wrong on like three different levels
stop talking shit about things you don't know anything about

I bet you think C++ is the dominant language of the games industry, too.

It is
what fantasy land do you come from

It is, though

>when to use OOP?
in games and web crap

> implying it is not true
This is why Jow Forums gets made fun of.

OOP is just grouping variables and parts of global state.
FP is like modelling complete state transitions- no good when you only need to change part of the state.
Classic imperative languages are better in this regard, but aren't as great when certain values need to be managed in tandem.
In a sense, OOP is just an extension of the addition of types to imperative programming, where now even functions may be attached to a type/struct, more than just some bits of data.
Put another way, the move from mathematical type to a type comprised of a struct could be considered the basis of OOP

youtu.be/QM1iUe6IofM
watch this whole video and the other ones in his channel
Then stop thinking in terms of OOP. Minimize it when you have to use it.

Phoenix uses Elixir, which is functional. In my experience it's so much more pleasant. Even in "web crap", OOP is not the way.

You see a lot more C# now a days.

No you don't, that's only Unity, used by small companies or solo developers, everything else is written in C++ with some scripting languages thrown on top

>people still think one programming paradigm is superior to others and they don't all have advantages and disadvantages

write something non trivial for once

>I use the best tool for the job

Attached: 1518071157963.gif (380x400, 197K)

Global != shared state.
Nice straw man. Student.

OO is good for cookie cutter development. A small group of senior engineers can layout a few interfaces in an afternoon of meetings and then delegate the implementation of methods and sub classes to the juniors.

>I bet you think C++ is the dominant language of the games industry, too.
What's UE3 and 4 built with?
What's Unity written in?
CryEngine? Frostbite?
Everything by id after Quake 3?
Infernal Engine? (now defunct)
Godot?

Maya, Blender, Max, zbrush, Photoshop, Krita... They're not game engines, sure, but they're heavily involved in the making-of.

Don't mouth off about shit you don't know.
It makes you seem foolish.

I guess you've never written a complex OO code. Cuz if you did you would have stfu.

>there's plenty of reasons to use global variables
If you want to be specific, there's plenty of reasons to share state too, using finite resources being the primary case

UE3's editor had a lot of C# in it.
But UE4 is almost entirely C++ (I worked with it for years)
Unity is actually written in C++. You write game logic in C# because the Unity devs don't want anyone to be able to actually get into their engine without paying and also to dumb down the API so mediocre and lazy people can use it.
Sure, there's probably tools for other engines written in C#. But actual engines use C++. C# will absolutely NEVER run a real game engine. Why? Because garbage collection. Because boxing. Because portability (C# is fine on Windows or even XBox... but what about Playstation? Nintendo? Mac? iOS? Android? Not to mention Linux).

Ah yes, the man who spends a decade to create something you can shit out on Unity3D/UE in a week. A great example of anti-OOP evangelists.

he's also never made a game

you mean that the superclass is the world of forms and its subclasses inherits all the qualities but are imperfect because of the added instances?

>but I just don't know when and why I should use this OOP
Never because it's shit. It's a failed design principle that people still cling on to because of sunk cost fallacy

Attached: OOPD.png (1940x970, 100K)