Re: The D Programming Language
Gabriel Dos Reis wrote:
Walter Bright <walter@digitalmars-nospamm.com> writes:
[...]
| > I am very happy when I can implement, or extend, some feature without
| > specific compiler support.
|
| There's no way you're going to get std::string, std::vector or
| std::complex to work as well as core support for such with existing C++
| core features.
So, the question is: Can there be better library implementations, or
can the core language be extended to allow better library
implementation? (e.g. allow for literal of user-defined types),
or do you think that there are *intrinsinc* reasons why they must be
core languages? If yes, could you elaborate on those logical,
intrinsinc, reasons?
He already has. (Dynamic) Strings and (Dynamic) Arrays are just as
common and important in the vast majority of programs as Integers.
Integers are an intrinsic part of the language, yet they don't need to.
I see no indication that a language couldn't get away with a single type
-- bit -- and everything else left to the library. Thus, the same
argument applies to strings and arrays.
To be fair, std::string and std::vector are fairly impressive bits of
work, considering how they are constrained. But their deficiencies show
up everywhere.
Can you imagine having to do:
#include <integer>
// Binary for 32, because remember, you don't have int literals.
typedef std::integer<0, 0, 1, 0, 0, 0, 0, 0> int32;
void displayAnswer(const int32& answer) {
cout << "The answer to the life is: " << answer << endl;
}
const int32 main() {
try {
cout << "2 + 2 = " << int32(1, 0) + int32(1, 0);
cout << endl;
displayAnswer(int32(1, 0, 1, 0, 1, 0));
} catch (...) {
return int32(1);
}
return int32(0);
}
For even trivial programs? It'd get real messy in a hurry. Similar
hassle is incurred currently because of the lack of native dynamic
arrays and strings. I think better support for these is very important.
Here's one radical suggestion for the next C++ standard:
string literals could be of type std::string (instead of const char*).
string literals prefixed with L could be of type std::wstring (vs. const
wchar_t*).
array literals could be of type std::vector (instead of T*).
These are already part of the language, so why not rely on them?
Just food for thought.
Cheers,
-Al.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]