why do some writers declare and define variables separately

Discussion in 'C Programming' started by yoodavid, Sep 18, 2013.

  1. yoodavid

    Öö Tiib Guest

    That is _the_ problem that destructors solve. Objects have birth and death.
    Name one real life object that does not have it? If destructors are missing
    then developer can still manually turn object into some custom-made "dead"
    state ready for disposal by garbage collector. That is inconvenient if user
    does not want to deal with aspect of killing object ("what means i have to
    close the configuration?") and also the encapsulation now leaks
    information ("you must close the configuration because there is underlying
    file open").
    Benefit is not automatic management of precious resources. OOP does not
    need it. OOP involves restricting unneeded access to underlying precious
    resources of abstraction and bundling those with needed (for user) operations
    that involve the resources. That is called "encapsulation". It can not be done
    perfectly if outside user of abstraction _must_ deal with lifetime (to kill,
    close, free, join) underlying precious resources of abstraction. Such
    manipulations _can_ still be among operations with abstraction but usage
    of those _is not_ among mandatory responsibilities of user of abstraction
    anymore thanks to destructors.
    I did nowhere say that destructors (or RAII) can be /only/ used for OOP. Use how
    you want. I said that destructor and RAII idiom are very beneficial featurefor
    OOP features like information hiding, encapsulation and separation of concerns.
    Yes. Similarly a pine may be in garden, in park or in forest. Pine is not forest,
    pine is tree and there may be forest without pine. However there can't be forest
    without trees and pine is good, straight tree in forest.
    It is like to claim that there are no logical connections between pine and
    forest? World largest forests (see "taiga") are mostly pines, spruces and larches.
    So world forests would be _lot_ poorer without those pines.
    Öö Tiib, Oct 24, 2013
    1. Advertisements

  2. The number 42. In Smalltalk, numbers are objects and respond to message
    like any other. I think you have decided that objects must correspond
    to things in "real life" (is a number such a thing? I don't know) and
    that they must have a "death" that the programmer in charge of. You
    may, in other words, be defining the term so that a destructor plays a
    central role.

    I don't see what this has to do with my point. I was on the way to
    illustrating destructors without OO to show the other half of my
    argument, and I picked resource manage as an example because it is often
    cited as a benefit of C++'s object model.
    When I say X, it does not mean that you said ~X.

    I am painting an alternative picture: one in which destructors can exist
    without OO, and in which OO can exist without destructors.
    So in this analogy destructors=pine trees, object-orientation=forest?
    That seems reasonable, up to a point. They are separate concepts, not
    intrinsically linked -- you can have one without the other, and vice-versa.
    Yes, though "logical" is obviously itself being used metaphorically.
    Alternatives are "intrinsic", "inevitable", "fundamental", and so on.
    Have you used Smalltalk? I think you are steeped in the culture of
    lexically scoped languages without function-like objects in which the
    lifetime of an object assumes greater importance.
    Ben Bacarisse, Oct 24, 2013
    1. Advertisements

  3. yoodavid

    Tim Rentsch Guest

    The adjective "object-oriented" was applied to Simula only
    after it appeared in papers talking about Smalltalk. I
    don't think there is any serious disagreement that the term
    "object-oriented programming" originated with Alan Kay more
    or less at the inception of doing Smalltalk (possibly a year
    or two earlier when he was writing his thesis on the Dynabook).
    Certainly some of the key ideas were present in earlier systems,
    notably Sketchpad which predates even Simula, but it was Kay
    who coined the term and first articulated the approach as a
    general programming paradigm. Simula was dubbed an object-
    oriented language only afterwards, because it has classes.
    The point of the quoted paragraph is not where the ideas
    were first seen but where the term originated and who first
    articulated a meaning for it.
    Tim Rentsch, Oct 24, 2013
  4. yoodavid

    Öö Tiib Guest

    If we discuss values as objects (as immutable everlasting objects) then yes,
    we never need to construct or destroy or modify integer value 42 or string
    literal "42". So while it can be amusing to consider them (and the bits they
    consist of) as objects too the purpose of OOP is not to dig into bits but to
    abstract away AFAIK.
    It clarifies mine point. The benefit is not resource management (that is good
    but everybody need to do it regardless of paradigm) but better encapsulation
    (that is OOP).
    Fair enough.
    Destructors are feature that I miss the most in OOP languages that lack them.
    Unlike generic programming that is different paradigm (and that I also miss) the
    destructors are special methods of class of object. Method is OOP term. So
    while using destructors as strange functions that are called when variable goes
    out of scope is fine (do what you want, your tools) it is not by design. Itis like
    using the templates of C++ for compile-time metaprogramming. It is possible
    since the template system of C++ is Turing-complete (and again do what you
    want) but ... hell, it looks awful and unmaintainable mess when done.
    I tried. Results did perform 10 times worse than C. I was terrified when
    people said that this is normal, by design. How can it compete? So I
    dropped it. What does Smalltalk do with objects like thread, network
    connection, file descriptor, communication port or connected USB or
    Bluetooth device? Such are precious resources and precise monitoring
    and management of life-time of such is important. In C++ OOP one
    can make it responsibility of single object and so abstract that concern
    away from rest of the code.

    C++ performs as well as C, has most of C features (some unneededly
    even IMO) and has number of additional useful features so that excuses
    the warts (some unfortunate features) for me, YMMV.
    Öö Tiib, Oct 24, 2013
  5. yoodavid

    Tim Rentsch Guest

    The question is not which system first supported or displayed
    characteristics of object-oriented programing, but from whence
    the term originated and hence was defined. For all I know the
    people who developed Simula may have been doing what is now
    termed object-oriented programming, and if so more power to
    them, but they did not originate the term.
    This is a misuse of language. By themselves programming
    langauges are neither object-oriented nor non-object-oriented.
    A programming language may provide good support for doing
    object-oriented programming, which Simula certainly does,
    but that doesn't mean Simula defines or helps define what
    constitutes "object-oriented programming"; that was done by
    Alan Kay and the other people who did Smalltalk.
    Tim Rentsch, Oct 24, 2013
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.