1. Post #81
    Naelstrom's Avatar
    June 2010
    1,957 Posts
    Yes, but it's written in C and assembly.
    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.
    Reply With Quote Edit / Delete Reply Linux United States Show Events Agree Agree x 2 (list)

  2. Post #82
    dajoh's Avatar
    March 2011
    563 Posts
    Yes, but it's written in C and assembly.
    You claim that OOP is useless, yet you use it:

    Code:
    typedef struct Thing_Tag {
        int foo1;
        long long foo2;
        int add;
    } Thing;
    
    /* What an useless function. I'd write
    
    Thing something;
    something.foo1 = number1;
    something.foo2 = number2;
    
    instead of
    
    Thing something;
    Thing_New(&something, number1, number2); */
    void Thing_New(Thing *this, int foo1, long long foo2)
    {
        this->foo1 = foo1;
        this->foo2 = foo2;
    }
    
    int Thing_DoStuff(Thing *this)
    {
        if (this->add || (this->foo1 <= 4))
            return this->foo1 + (int)(this->foo2);
        return this->foo1 * (int)(this->foo2);
    }
    /* This is how I like to format stuff */
    Are you saying this isn't OOP or what?
    Reply With Quote Edit / Delete Reply Windows 8 Sweden Show Events Winner Winner x 2Agree Agree x 2 (list)

  3. Post #83
    Gold Member
    Deco Da Man's Avatar
    July 2007
    1,005 Posts
    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.
    Reply With Quote Edit / Delete Reply Windows 7 Australia Show Events Agree Agree x 2 (list)

  4. Post #84
    Gold Member
    Zeh Matt's Avatar
    May 2011
    545 Posts
    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
    Reply With Quote Edit / Delete Reply Windows 7 Germany Show Events Dumb Dumb x 1Agree Agree x 1 (list)

  5. Post #85
    Gold Member
    gparent's Avatar
    January 2005
    3,928 Posts
    But right now I'm on my own project right now and all I'm worried about is speed. Adding useless accessor methods or picking whatever attributes I feel other classes shouldn't be able to access is just a big waste of time in this case.
    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.
    Here's my brief explanation:
    When you design a method, the first thing you think about is not how it will work but what it will do: given input A, produce B.
    The way the method goes about this is insignificant to the scope of the whole project; this is the basis of abstraction
    This nails it. Your posts in this thread are really good.
    e.g. a camera class with nine different floats corresponding to x,y,z,upx,upy,upz,targetx,targety,targetz.
    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.
    How about I just go back to using C
    This doesn't get better in C.
    But in some big code executions I'd imagine that you could shave a few seconds off of a 10sec long execution with optimization.
    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.
    Preferably you'd want the code to execute and do the things you want it to do...OOP allows you to manage your code better and therefore keep it running correctly! C is nice for small things, however imagine writing a huge project in it! OOP is a wonderful tool
    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.

  6. Post #86
    Gold Member
    Trumple's Avatar
    September 2009
    5,367 Posts
    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.
    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)

  7. Post #87
    Gold Member
    gparent's Avatar
    January 2005
    3,928 Posts
    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.
    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.
    Reply With Quote Edit / Delete Reply Windows 7 Show Events Agree Agree x 1 (list)

  8. Post #88
    AtomiCasd's Avatar
    June 2011
    588 Posts
    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.
    Reply With Quote Edit / Delete Reply Windows 7 Norway Show Events Funny Funny x 4 (list)

  9. Post #89
    #define private public
    #define protected public
    Reply With Quote Edit / Delete Reply Windows 8 Russian Federation Show Events Funny Funny x 3Informative Informative x 1 (list)

  10. Post #90
    Gold Member
    Trumple's Avatar
    September 2009
    5,367 Posts
    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.
    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
    Reply With Quote Edit / Delete Reply Windows 7 United Kingdom Show Events Agree Agree x 2 (list)

  11. Post #91
    Gold Member
    Deco Da Man's Avatar
    July 2007
    1,005 Posts
    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.
    Reply With Quote Edit / Delete Reply Windows 7 Australia Show Events Agree Agree x 1 (list)

  12. Post #92
    Gold Member
    Trumple's Avatar
    September 2009
    5,367 Posts
    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 ?>
    			&nbsp;&bull;&nbsp; <a href="viewpost.php?post=<?php echo $ID?>" class="comments">Comments (<?php echo $numComments ?>)</a> &nbsp;&bull;&nbsp; <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
    }
    ?>

  13. Post #93
    Gold Member
    gparent's Avatar
    January 2005
    3,928 Posts
    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.
    Reply With Quote Edit / Delete Reply Windows XP Show Events Disagree Disagree x 3Agree Agree x 3Dumb Dumb x 1 (list)