From: Peter Dimov on
Andrei Alexandrescu (See Website For Email) wrote:
> David Abrahams wrote:
> > "Andrei Alexandrescu (See Website For Email)"

[...]

> >>So my answer to "Purify can't tell you..." is "Because you don't
> >>need Purify".
> >
> >
> > Of course not. That's a cute comeback but misses the point entirely.
> > In a GC'd system Purify is the wrong tool because there are no invalid
> > pointers. Instead you need a tool that tells you that something has
> > been kept alive too long, and nobody's figured out a tool to do that
> > because it's effectively impossible for a tool to tell what "too long"
> > is.
>
> Ehm. I thought we were talking about arbitrary memory overwrites. Maybe
> I did miss the point entirely.

Dave's point, to which I also subscribe, is that when nothing in a
programming language is illegal, you have no "legal standing" to
declare a program incorrect. So you can't have a tool like Purify that
automatically identifies that a program has performed an illegal
operation, because there are no illegal operations whatsoever.

It is certainly true that illegal operations that manifest themselves
as changing valid object memory at a random location are an incredible
pain to debug. On a practical level, this cannot be denied. On a
theoretical level, there is nothing in the C++ specification that
mandates that undefined behavior must be left undetected; in principle,
this allows a C++ implementation to be safer than Java. (In practice,
this never happens, because there is (was?) no market demand for it.
Hardware architectures that dutifully crashed your program on every
invalid pointer operation are now extinct.)


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Jeffrey Yasskin on
On Dec 4, 7:30 am, Walter Bright <wal...(a)digitalmars-nospamm.com>
wrote:
> In C++, core arrays have one subset of needed array features, and
> std::vector has the other subset of needed array features. The problemhttp://groups-beta.google.com/group/comp.lang.c++.moderated/browse_thread/thread/a048420165ad4719/7fa216cbf715a79e
> is the two don't combine with each other to create full featured arrays.
>
> BTW, the array example in D would be:
>
> int[] a = [1, 2, 3, 42, 66];
> writefln(a.length);

The array example in C++0x will be:
vector<int> a = {1, 2, 3, 42, 66};
std::cout << a.size();
See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2100.pdf
(initializer lists). Yes, it took longer to come up with a language
extension that enabled a library solution. But doing so meant that
_any_ library type could take advantage of it, rather than needing a
patch to the compiler for every type you want a good syntax for.

Jeffrey


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Mathias Gaunard on
Walter Bright wrote:

> I think there is huge
> opportunity in the programming language area for a language as
> performance oriented as C++ but with the productivity capabilities of
> Python/Ruby.

The ML family of programming languages probably already fills that spot.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Mathias Gaunard on
Peter Dimov wrote:

> There is one something in C++ that makes it difficult to write
> libraries, and it's the lack of an ownership convention. In Java you
> just return a reference to the object and that's it. Most C++ libraries
> have to start by defining their own convention. Or had to, before
> shared_ptr.

It's not like you have many choices.
Return the object by value if you can, or if you need pointers be it for
reference semantics of polymorphism use a wrapper (auto_ptr, shared_ptr,
clone_ptr or eventually variant).

Other possibilities result in exception unsafe code.


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Kevin Hall on
Walter Bright wrote:
> In C++, core arrays have one subset of needed array features, and
> std::vector has the other subset of needed array features. The problem
> is the two don't combine with each other to create full featured arrays.
>
> BTW, the array example in D would be:
>
> int[] a = [1, 2, 3, 42, 66];
> writefln(a.length);
>

This is a place where a library component could come to the rescue.
For example:

template <typename T>
class array_wrapper
{
T* data_;
size_t size_;

public:
template<size_t N>
array_wrapper(T (&a) [N])
: data_(a)
, size_(N)
{}

size_t size() const {return size_;}

T& operator[](size_t index) {return data_[index];}
const T& operator[](size_t index) const {return data_[index];}

// Other member functions, operators, even iterators...
};

Is it ugly that a library component must be used? Sure... OK.
Is it the worst thing in the world? By no means!


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]