Thread: So, "object-oriented" programming...

  1. #16
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    I think there's amazing benefit in being inspired by Haskell and studying category theory, I really do.

    However, I think those lessons should be taken with a grain of salt and our code should be "inspired by" and not "a direct expression of". I think Haskell makes the mistake of attempting a direct expression of category theory in programming and it's honestly pretty terrible.

    Writing C++ that's inspired by CT is entirely different. CT gets you to think of programming as a pure type transformations in a pipeline and this is surprisingly powerful. C++ just has the advantage that it allows you to write efficient functionally-inspired code.

    Haskell's type system is pretty top-notch though, I must admit. But ultimately, it's readily expressible using C++'s current class system. Granted, I've never really written any OO C++.

  2. #17
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    Quote Originally Posted by MutantJohn View Post
    C++ just has the advantage that it allows you to write efficient functionally-inspired code.
    Yes, I think this is good, especially with C++11 (or 12?), lambda expressions and move-semantics. I love C++ for that fact that it gives the programmer complete control over the efficiency of this programs, and not depending on some "optimizing" compiler. In many cases, the programmer, given that he or she knows the complexity of his or her constructs. can develop an "optimized" solution.. whether that be time, or space.

    Programmers should not delegate "optimization" to their compilers. That's what I hate about Haskell, and love about C++. C++ at least forces one to consider their logic, and not punting it off to the compiler. The compiler is just another program, written by Humans (TM), it is not infallible. Also, in many cases, I am of the belief that "optimizing" compilers are a fad.. and that we programmers should write our programs to a very specific semantic.

    We don't rely on some "God" who optimizes our code for us... I'm sorry, but full-program analyzing compilers are a myth. Are you smarter than your compiler? Yeah, then let it don't do anything weird under your nose! We need complete control. But we also need abstraction (controlled).

    Back to the main topic, I don't believe OO solves any of real human software development problems, at least no more than a functional or non-class procedural approach would.
    Last edited by MacNilly; 02-13-2017 at 06:02 PM. Reason: Format

  3. #18
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    Quote Originally Posted by MacNilly View Post
    Programmers should not delegate "optimization" to their compilers. That's what I hate about Haskell, and love about C++.
    Really? Do you turn off optimizations when you build the final binaries of your program? For moderate sized programs it can make quite a difference in size or speed. Optimizing yourself would require knowing which machine instructions to use, allocate registers yourself, reorder instructions to get the most out of your clock cycles, etc. Even if you have the know-how, do you really want to do such optimization work by hand for the entire program?

  4. #19
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    Quote Originally Posted by c99tutorial View Post
    Really? Do you turn off optimizations when you build the final binaries of your program?cget the most out of your clock cycles, etc. Even if you have the know-how, do you really want to do such optimization work by hand for the entire program?
    I don't give a ........ about compiler optimizations... most of the ones I've studied can be had by "not being an idiot", and paying attention to the language semantics: The more simple these are, with given efficiency contracts, the more better I can develop my program, given those constraints.

    Any idiot that depends on their "compiler optimizations" is just that...

    The aforementioned things like
    get the most out of your clock cycles, etc.
    .. a waste of time
    Last edited by MacNilly; 02-13-2017 at 07:28 PM.

  5. #20
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    Quote Originally Posted by c99tutorial View Post
    Really? Do you turn off optimizations when you build the final binaries of your program? For moderate sized programs it can make quite a difference in size or speed. Optimizing yourself would require knowing which machine instructions to use, allocate registers yourself, reorder instructions to get the most out of your clock cycles, etc. Even if you have the know-how, do you really want to do such optimization work by hand for the entire program?
    Exactly. DO you think a stupid compiler can figure that out.. no, I didn't think so.

    EDiT: Hey, maybe you can write a super-efficient compiler than just does "THe Best ........ing Thing" (TM). UNtil then, STFU
    Last edited by MacNilly; 02-13-2017 at 07:32 PM.

  6. #21
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Holy crap, the posts seemed to deteriorate, almost as if Mac is drinking O_o

    I think I saw a video of a talk by Sean Parent. Or was it Herb Sutter? Which one works at Adobe? Because it's that one.

    Anyway, one of the super cool things in their talk was about compilers and what we type in a program. To me, optimizations are part of this super awesome disconnect between what we type and what's actually executed.

    By this I mean, you write up a C program that adds up two numbers and prints the result. The compiler doesn't really have to care about how you told it to do something if it knows the end goal you're trying to reach. What's more, processors themselves are free to execute instructions however they want. There's so many levels of indirection that you can't actually have true control over what's executed. When you write a program, you're not telling the computer to do something, you're asking it, man.

  7. #22
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by MacNilly View Post
    Exactly. DO you think a stupid compiler can figure that out.. no, I didn't think so.
    Actually, compilers are written by people who are intimately familiar with processor architectures, and yes, they can figure that out. Build a program with GCC, using only your "don't be an idiot" optimization method, with no compiler optimizations enabled. Compare its performance to the same program built with -O3. You will see that you are objectively wrong.

    Quote Originally Posted by MacNilly View Post
    EDiT: Hey, maybe you can write a super-efficient compiler than just does "THe Best ........ing Thing" (TM). UNtil then, STFU
    I doubt any of us in this thread can, but the people who write compilers are much smarter than you or I, and they know what they're doing.

    Telling someone to "STFU" when you disagree with them is not constructive, and destroys any credibility you might have had (and I'm being generous here, suggesting that you had any to begin with). It's pretty clear that you don't actually understand object oriented design and programming, or maybe even programming in general, given your attitude toward optimizing compilers. It's also clear that you're not interested in what anyone else thinks about it, as evidenced by your suggestion that people who disagree should simply "STFU." Either learn some humility, or don't ask loaded questions in places where you won't like the answers.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

  8. #23
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    You're right... I apologize. To Elkvis and c99tutorial. I hope you will accept it.

    Maybe somebody should close the thread, I seemed to have botched it.
    Last edited by MacNilly; 02-14-2017 at 03:06 PM.

  9. #24
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Nah, we all good, homie.

  10. #25
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Lot of comments, my thoughts:

    I like OOP where appropriate simply because I like the idea of functions being part of a class instead of defined separately, i.e. I like doing this:
    Code:
    aFart.Release();
    //vs.
    ReleaseFart(aFart);
    Compiler optimization: a good mix of using the compiler flags and your own knowledge is the true way to go, you can't do well with just one. For example, I've seen the Intel compiler produce insanely fast executables under normal flags that Clang or GCC can't touch, and conversely, some compilers are too dumb to recognize simple things like dividing by the same number several times and replace that op with multiplication of the reciprocal (way faster).

  11. #26
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Also, related to a comment made earlier, I know one guy who does -O0 for release binaries. He claims optimization causes problems...think he had a bad experience with a very old version of gcc.

  12. #27
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by Epy View Post
    Also, related to a comment made earlier, I know one guy who does -O0 for release binaries. He claims optimization causes problems...think he had a bad experience with a very old version of gcc.
    On Windows, it is NOT rare to have issues with -O3; so, I tend to only use -O2.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  13. #28
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Really? What does cl.exe do at -O3? My bad, /Ox

  14. #29
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Quote Originally Posted by stahta01 View Post
    On Windows, it is NOT rare to have issues with -O3; so, I tend to only use -O2.

    Tim S.
    I don't doubt that his claim was legitimate at the time. I also use -O2 instead of -O3 in my makefiles.

  15. #30
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Quote Originally Posted by Epy View Post
    I like OOP where appropriate simply because I like the idea of functions being part of a class instead of defined separately, i.e. I like doing this:
    Code:
    aFart.Release();
    //vs.
    ReleaseFart(aFart);
    Thats not OO, it's just an SVO-style dispatch notation. You can have one without the other.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 12-08-2014, 08:12 PM
  2. Replies: 9
    Last Post: 09-19-2011, 03:12 AM
  3. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 08:25 AM
  4. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 07:59 AM
  5. "Object reference not set to an instance of an object"
    By Manitoadlet in forum C++ Programming
    Replies: 6
    Last Post: 09-10-2002, 06:09 PM

Tags for this Thread