comp.lang.ada
 help / color / mirror / Atom feed
From: Maciej Sobczak <see.my.homepage@gmail.com>
Subject: Re: Factory Pattern
Date: Fri, 27 Jul 2007 05:47:34 -0700
Date: 2007-07-27T05:47:34-07:00	[thread overview]
Message-ID: <1185540454.137500.28610@b79g2000hse.googlegroups.com> (raw)
In-Reply-To: <VBjqi.41910$Fc.25058@attbi_s21>

On 27 Lip, 12:16, "Jeffrey R. Carter"
<spam.jrcarter....@acm.nospam.org> wrote:

> > No. C and C++ have enumerations.
>
> Which are just names for integer values, last time I looked.

No. There are implicit conversions to int, but enums are separate
types.

> The type of
> a function parameter would be int.

No. Each enum is a separate type:

#include <iostream>

enum E1 {a, b, c};
enum E2 {x, y, z};

void foo(E1 e) { std::cout << ": foo(E1)\n"; }
void foo(E2 e) { std::cout << ": foo(E2)\n"; }
void foo(int e) { std::cout << ": foo(int)\n"; }

int main()
{
    std::cout << static_cast<int>(a);
    foo(a);
    std::cout << static_cast<int>(x);
    foo(x);

    int i = 0;
    std::cout << i;
    foo(i);
}

This program prints:

0: foo(E1)
0: foo(E2)
0: foo(int)

which means that even though a and x have the same value when
converted to int, they are distinct from int and between each other
and can be properly picked by separately overloaded functions.

> And even if that's not the case,
> experienced users are accustomed to doing it this way from the days
> before it had them.

I consider myself to be an experienced user of C++ and I don't seem to
remember it working the way you describe. I'm not a dinosaur though,
so I might have missed a thing or two as well...

> And even newer users are accustomed to seeing it
> done this way in the code they've been exposed to.

>From what you write it appears that you have been looking at C++ quite
a while ago - in which case I wonder where you get the knowledge of
what newer users are exposed to.

> And even if that's
> not the case, C/++, emphasizing ease of writing over ease of reading,
> induces a mindset in the user of "why bother typing this enumeration
> definition and using it when I can just say int?"

I agree with this. C++ allows the programmer to be explicit about many
things, but does not require it. Many programmers, especially those
that have been exposed to poorly written C (this is unfortunately
unavoidable) or some scripting languages of the Perl league are
tempted to reduce the dictionary of their designs and end up with
numbers everywhere. In most cases not even named.

> All of these are
> symptoms of "C/++ thinking".

These are symptoms of hacking. Note that we are discussing it not in
the context of C++, but in the context of some Ada program that was
shown few posts earlier - this shows that hacking is possible in every
language and since there are about 2500 of them, there is no reason to
distinguish any single one of them as the supposed originator. C++ is
not even old enough to be the source of such practices. It just allows
them. Like Ada (which is actually older and allowed such bad practices
earlier ;-) ).

--
Maciej Sobczak
http://www.msobczak.com/




  reply	other threads:[~2007-07-27 12:47 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-25 18:19 Factory Pattern shaunpatterson
2007-07-25 18:28 ` Martin
2007-07-25 18:51 ` Dmitry A. Kazakov
2007-07-25 21:06   ` Georg Bauhaus
2007-07-25 19:27 ` Matthew Heaney
2007-07-26  0:51 ` Jeffrey R. Carter
2007-07-26  6:44   ` Maciej Sobczak
2007-07-26  8:40     ` Georg Bauhaus
2007-07-26  9:53       ` Dmitry A. Kazakov
2007-07-26 11:01         ` Georg Bauhaus
2007-07-26 13:02           ` Maciej Sobczak
2007-07-26 13:44             ` Dmitry A. Kazakov
2007-07-26 14:58             ` Georg Bauhaus
2007-07-26 22:31             ` Randy Brukardt
2007-07-27 13:07               ` Maciej Sobczak
2007-07-27 14:23                 ` shaunpatterson
2007-07-27 22:23                 ` Randy Brukardt
2007-07-28 18:56                   ` Maciej Sobczak
2007-07-29  7:54                   ` Maciej Sobczak
2007-07-29  8:53                     ` Dmitry A. Kazakov
2007-07-29 10:53                     ` Georg Bauhaus
2007-07-26 16:58         ` Adam Beneschan
2007-07-29 11:38         ` Manuel Gomez
2007-07-27 10:16     ` Jeffrey R. Carter
2007-07-27 12:47       ` Maciej Sobczak [this message]
2007-08-26  7:18         ` David Thompson
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox