[ home / board list / faq / random / create / bans / search / manage / irc ] [ ]

/prog/ - Programming

Programming board

Catalog

8chan Bitcoin address: 1NpQaXqmCBji6gfX8UgaQEmEstvVY7U32C
The next generation of Infinity is here (discussion) (contribute)
A message from @CodeMonkeyZ, 2ch lead developer: "How Hiroyuki Nishimura will sell 4chan data"
Name
Email
Subject
Comment *
File
* = required field[▶ Show post options & limits]
Confused? See the FAQ.
Embed
(replaces files and can be used instead)
Options
Password (For file and post deletion.)

Allowed file types:jpg, jpeg, gif, png, webm, mp4, pdf
Max filesize is 8 MB.
Max image dimensions are 10000 x 10000.
You may upload 1 per post.


File: 1427981975656.jpg (16.5 KB, 589x362, 589:362, object-oriented-programmin….jpg)

23a99d No.1911

Hello /prog/, I need some advices about object oriented programming, why is it better than procedural? I code for the web so I always faced php, JavaScript and such, and lately I'm seeing OOP everywhere, bunch of frameworks that are messy, I get so confused, I understood the basics, but I can't let go the idea that procedural is more understandable, what can I do about it? Have you got some useful links? I really don't wanna quit coding just cause objects fuck with my head

cf12e7 No.1912

>>1911
>Hello /prog/, I need some advices about object oriented programming, why is it better than procedural?
>better

Different tools, different jobs, etc, etc, etc.


The basic principle of OOP is to make code more "modular" by coupling data structures with code to operate on them (so-called "objects").

What makes this special is that you don't have to understand the internals of an object in order to work with it - only the methods it exposes.

This gives you two advantages:
1.) You can arbitrarily change one part of the program without worrying about breaking anything else (often, you won't even have to recompile the rest of your code)

2.) You can write very generic code that works with lots of different kinds of objects


Of course, this is only true for well-designed OO code; if your design is shit, then you'll still have all of the problems that OOP is supposed to solve.



>but I can't let go the idea that procedural is more understandable, what can I do about it?

I find that drawing diagrams helps.

But the main thing is: keep practising.

b5bf0b No.1913

>>1912
Pretty much this.

I'm still not fond of repackaging old shit to use again, but I had a prof that made us work with shitty classes to learn OOP. I'm a lot better with it now.

c738aa No.1919

>>1911
>OOP is a fag?
No, you got that wrong, it spells "OP", not "OOP".

ae1fd3 No.1922

File: 1428079638863.jpg (14.63 KB, 234x200, 117:100, 1412862838910.jpg)

>>1919
Oh my god, you enlighten me, I totally didn't know that

006876 No.1933

>>1919
Excellent example of what OO programmers call "Polymorphic Dispatch."

ae1fd3 No.1939

File: 1428143391830.jpg (31.66 KB, 576x470, 288:235, 1423770530760.jpg)

>>1923
>>1933

194fed No.1946

On the subject of OOP, could anyone recommend a fun project to work on that would be well suited to an OOP approach?

0bb13d No.1947

>>1946
A dungeon crawler or an RPG of some sort. To be fair, OOP gets a lot of shit but video games on their current form would be impossible to program without it.

Can you imagine something like Minecraft written in a imperative language?

cf12e7 No.1948

>>1947
>would be impossible to program without it
Not even close. Literally any language of any paradigm can be used to write a video game.

I suspect the only reason OOP is so prominent in the gaming industry is because of C++.


>Can you imagine something like Minecraft written in a imperative language?

Minecraft is written in an imperative language.

See:
https://en.wikipedia.org/wiki/Java_%28programming_language%29
https://en.wikipedia.org/wiki/Imperative_programming

f60dfa No.1964

>>1911
As >>1912 said, OOP is good for designing interfaces which hide the details of implementation through encapsulation. The tight coupling between data and code makes each class self managing, in theory. Although OOP certainly has a place in software engineering, it is often misused and its ideology of "generic programming" taken to the extreme. Writing needlessly complex inheritance relationships only to "generalize" builds cruft around the core solution of the program. Instead of making your solution more general, make it more specific! Being able to assume how and why your code is used makes each instruction have a clear purpose, thereby giving way for optimization opportunities. By contrast, having to juggle between remembering what state each monolithic object was in is a big strain on the developer who is looking to decrease complexity, not add to it.
Take a look at Data Oriented Design: http://dataorienteddesign.com/dodmain/

f60dfa No.1965

>>1964
To quote http://pivotallabs.com/all-evidence-points-to-oop-being-bullshit/
>State is not your friend, state is your enemy. Changes to state make programs harder to reason about, harder to test and harder to debug. Stateful programs are harder to parallelize, and this is important in a world moving towards more units, more cores and more work. OOP languages encourage mutability, non determinism and complexity.

77a8b9 No.1966

>>1965
>le state is evil maymay
Even the developers of Scala admit every program needs state to some extent to be useful. Without state you will only end up making an overcomplicated slow mess.

f60dfa No.1976

>>1966
Of course state is needed, but sometimes it can be represented in a more deterministic way. For example, consider this simulation code which updates dynamic objects:

for(each object) {
if(object has the "need update" flag set) {
obj.simulate(deltaTime);
}
}

Obviously this is a trivial example, but if you had tens of thousands of these objects and many state flags, the cost of loading the cache with _potentially_useless_ information is extremely bad for performance. One potential solution could be to organise the objects which need an update at the end of the array, and simply loop over that range. This way, the state of the data ("need update" flag) is _assumed,_ and is not continually checked:

for(each "need update" object) {
obj.simulate(deltaTime);
}

You get the point, of course

f1dacc No.1993

>>1976
True, but you still need sort your objects according to its "flag",Which is fine if only done occasionally but it is a lot worse if it needs to be done every update.


It is stupid to say "x is bad" since it depends on what you're trying to achieve. Even experienced programmers say this shit.

bb09e8 No.2015

much OOP code is just useless bloaty layers of abstraction but if you use it properly or if you use well-written frameworks you'll see the beauty of it.

9646d3 No.2020

>>2015
Pretty much this.

It can be used well, but very few people actually do it. 90% of code I've seen is sadly bloaty shit - almost as if they don't know what they're doing. As such, I've just come to hate it.



[Return][Go to top][Catalog][Post a Reply]
Delete Post [ ]
[]
[ home / board list / faq / random / create / bans / search / manage / irc ] [ ]