On 02/15/2011 02:28 AM, Jonathan M Davis wrote:
On Monday, February 14, 2011 17:06:43 spir wrote:
On 02/15/2011 01:56 AM, Jonathan M Davis wrote:
On Monday, February 14, 2011 16:30:09 Andrej Mitrovic wrote:
Here's something I've noticed (x86 code):
void main()
{
ulong size = 2;
int[] arr = new int[](size);
}
This will error with:
sizetTest.d(8): Error: cannot implicitly convert expression (size) of
type ulong to uint
size_t is aliased to uint since I'm running 32bit.
I'm really not experienced at all with 64bit, so I don't know if it's
good to use uint explicitly (my hunch is that it's not good). uint as
the array size wouldn't even compile in 64bit, right?
If I'm correct, wouldn't it be better if the error showed that it
expects size_t which might be aliased to whatever type for a
particular machine?
Use size_t. It's the type which is used. It's aliased to whichever type
is appropriate for the architecture. On 32 bits, that would be a 32 bit
integer, so it's uint. On 64 bits, that would be a 64 bit integer, so
it's ulong.
Rename size-t, or rather introduce a meaningful standard alias? (would vote
for Natural)
Why? size_t is what's used in C++. It's well known and what lots of programmers
would expect What would you gain by renaming it?
Then state on D's front page:
"D is a language for C++ programmers..."
"size"_t is wrong, wrong, wrong:
* Nothing says it's a type alias (should be "Size").
* The name's "morphology" is weird.
* It does not even tell about semantics & usage: a majority of use cases is
probably as indices! (ordinal, not cardinal as suggested by the name).
("sizediff_t" also exists, but seems unused in D)
"Natural" would be good according to all those points: the name tells it's
unsigned, a natural number is either an ordinal or a cardinal, and it fits D
style guidelines. Better proposals welcome :-)
Aliasing does /not/ mean removing size_t, just proposing a correct, sensible,
and meaningful alternative. If people like it, and if using the correct name is
encouraged, then after a few years the legacy garbage can endly be recycled ;-)
In any case, this alternative must be *standard*, for the whole community to
know it. I have used Ordinal & Cardinal for a while, but stopped because of
that: people reading my code had to guess a bit (not that hard, but still), or
jump to declarations.
Again: size_t is /wrong/. The fact that for you it means what it means, due to
your experience as C++ programmer, does not change a iota (lol!) to its
wrongness. If we never improve languages just because of mindless conservatism,
then in 3 generations programmers will still be stuck with junk from the 1970's.
Denis
--
_________________
vita es estrany
spir.wikidot.com