I'm sorry, what was your point again? I thought you were saying OOP is useless.
C could be nice, but looking at my project it would be a nightmare without OOP. Any optimization I could pull out using C would be obliterated due to messy code.
I'm sorry, what was your point again? I thought you were saying OOP is useless.
C could be nice, but looking at my project it would be a nightmare without OOP. Any optimization I could pull out using C would be obliterated due to messy code.
You claim that OOP is useless, yet you use it:
Are you saying this isn't OOP or what?
Object Orientation is a mode of thought.
Whether it is applied as a naming metaphors or language mechanics is irrelevant.
Any grouping of data that represents a concept (and hence any method that operates on that object) is an application of object orientation.
Having the mechanics built into the language is definitely useful, and makes a lot of sense.
Only small minded people would disagree
If you're worried about that your typing speed is too low, there are many IDE addons that will generate these get/setters faster than I could ever write them by hand.
This nails it. Your posts in this thread are really good.
And then you decide you're working on a slower but higher precision engine and you decide to use doubles, or big integers, or a data class, or a tuple, or a function that returns an integer for some brutally fucked up reason.... Your entire game doesn't compile for days.
This doesn't get better in C.
A second at best, in the biggest and shittiest code base ever written. What you fail to realize is that most of the function calls will only add a sub millisecond overhead to compilation time since they're returning something or setting it, something the compiler can optimize. What the compiler cannot do for you though is rewrite your code when the implementation details of your program change.
I very much disagree with this. If you're incapable of writing clean, maintainable, fast and safe C code, you're simply a bad C programmer. OOP is NOT necessary to have maintainable code.
It seems you're starting to realize the benefits, so that's good. Hopefully you do not make the mistake of not using accessors for poor reasons, although they say making big mistakes is the best way to learn. In due time you will realize why you're writing this extra code. I'm not a big fan of Java/C++ partly because it doesn't make it as easy as C# to implement get/sets to be honest. C# is really well made in that if you start by making your variables properties, you can change them later to include some code without breaking your interface (something you cannot do if you use regular variables). It's really neat and it looks just like if you were writing C.
I never said it was necessary, however it is arguably easier to work with classes and objects, especially if you're working on projects where multiple instances of a particular bit of code with unique identity just makes sense, if you like. Sure, the same thing is possible in C, it just requires a different way of thinking/tacking the problem, and ultimately would use more code (though not always)
Guess we'll have to disagree. I really think this is a matter of being good with the language. OOP is definitely not a model that applies to every situation. Right now I'm only bringing up procedural as an example, but there's metaprogramming, functional programming, etc. Plenty of ways to program can make sense without any OOP whatsoever.
Hello I'm a lone programmer who has never worked in a team and my methods are better than yours because best practice is my practice.
#define private public
#define protected public
Oh no I agree, it doesn't make sense to make use of OOP in all situations. I program many PHP scripts without making use of the OOP capability
As I mentioned, OOP enables another way of thinking. Some people prefer it, others don't. For me, it depends on the problem at hand
I'm pretty sure that no matter how you think you are coding, you will always wind up designing using object orientation.
Take some Maurice-style code:
local names = {"Bob", "John", "Edward"} local age = {55, 18, 24} local page = {1, 22, 3}
Those tables all refer to the same 'object' (in a conceptual sense): a person.
Despite not utilising any naming metaphors (person_names) or any form of direct grouping (persons = {{name='',age=...}}), it is still object oriented.
When you deal with this code, you will not think "I need to get the nth entry in age, because that's what this row # is."; you will think "I need to get the nth entry in age, because that's the age of the person that this row is about."
Post any of your apparent OOP-free PHP and I will (probably) show you how it is, actually, object oriented.
I have a standard bit of code which grabs blog posts from a database, then iterates through all the blog posts generating HTML to sit the posts in. Now I can see where you're coming from, the blog posts are all objects (they have associated titles, dates, usernames, content etc. all stored in one row) however to actually make use of the OOP tools would be silly in my case, when you can do it directly:
(NB the following code is invalid (missing variables and other problems) but it just happens to be what I'm working on right now, but should suffice for the purpose of illustrating my point)
Code:<?php for($i = 0; $i < $numRows; $i++) { $ID = mysql_result($blogData, $i, 'ID');//used for linking $image = mysql_result($blogData, $i, 'image'); $user = mysql_result($blogData, $i, 'user'); $timestamp = mysql_result($blogData, $i, 'timestamp'); $title = mysql_result($blogData, $i, 'title'); $covertext = mysql_result($blogData, $i, 'covertext'); $content = mysql_result($blogData, $i, 'content'); ?> <div class="post"> <h2 class="title"><a href="viewpost.php?post=<?php echo $ID?>"><?php echo $title?></a></h2> <p class="meta">Posted by <a href="about.php"><?php echo $user ?></a> on <?php echo date("F j, Y, g:i a", $timestamp)?>. Posted under: <?php echo $categories ?> • <a href="viewpost.php?post=<?php echo $ID?>" class="comments">Comments (<?php echo $numComments ?>)</a> • <a href="viewpost.php?post=<?php echo $ID?>" class="permalink">Full article</a></p> <div class="entry"> <p> <?php if($image != '') {?><img src="<?php echo $image ?>" width="565" height="250" alt="" /><?php } echo nl2br($covertext) ?></p> </div> </div> <?php } ?>
Just because you can relate to objects in real life from some code doesn't mean that person is doing object oriented programming. OOP came out as a way to make those objects be meaningful and have programming constructs of their own (inheritance, data members, encapsulation, etc.) Writing a C function that can act on a particular struct isn't really object oriented programming even if you're dealing with a data 'object' in the context of programming.