Hypothetical: All code in classes but main()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bjarne Stroustrup

    #46
    Re: Hypothetical: All code in classes but main()

    "Mark A. Gibbs" <x_gibbsmark@ro gers.com_x>
    [color=blue]
    > So, given that we are actually discussing C++ in comp.lang.c++, I see no
    > rational interpretation of that point that does not support free functions.
    >
    > Besides, given:
    >
    > class A {};
    > class B {};
    >
    > void helper(A, B);
    >
    > Where does helper() go?
    >[/color]

    Two comments:

    (1) I have never been seriously tempted to put all functions into
    classes. Doing so would simply lead to the kind of workarounds/hacks
    that you find in Java (e.g. the standard math functions). Lots of
    functions really don't have state and shouldn't pretend to by being
    part of a class. Versions of the brief argument above is present in my
    writings on C++ from the earliest days. A slightly stronger version is
    that in the absence of ordinary ("free-standing") functions, a binary
    operator, say +, would have to have two separate definitions (one in
    each argument class) to be symmetric.

    (2) In this discussion, there have been some conjectures made about my
    "real opinions". I tend to dislike such conjectures in general, and I
    find them rather odd when juxtaposed with statements to the effect
    that the person making them hasn't read "The Design and Evolution of
    C++". D&E isn't perfect, of course, but it is a clearer statement of
    my intent vis-avis C++ than you can find for most languages.

    - Bjarne Stroustrup; http://www.research.att.com/~bs

    Comment

    Working...