digitalmars.D - Small feature request
- "Koroskin Denis" <2korden gmail.com> Mar 29 2008
- Kevin Bealer <kevinbealer gmail.com> Mar 29 2008
- "Koroskin Denis" <2korden gmail.com> Mar 29 2008
- Jason House <jason.james.house gmail.com> Mar 29 2008
- "Janice Caron" <caron800 googlemail.com> Mar 29 2008
- Matti Niemenmaa <see_signature for.real.address> Mar 29 2008
- "Koroskin Denis" <2korden gmail.com> Mar 29 2008
Look at this class.
class Buffer
{
private int bufferSize =3D 4096;
private void[bufferSize.init] buffer =3D void;
}
What's the capacity of buffer upon object construction?
I expect that buffer.length =3D=3D 4096, since bufferSize =3D=3D 4096, b=
ut get =
buffer.length =3D=3D 0, since bufferSize.init =3D=3D int.init.
It works not as expected and confuses a little. Do I have any chanse thi=
s =
will be fixed anytime, or is it intended?
Mar 29 2008
Koroskin Denis Wrote:Look at this class. class Buffer { private int bufferSize = 4096; private void[bufferSize.init] buffer = void; } What's the capacity of buffer upon object construction? I expect that buffer.length == 4096, since bufferSize == 4096, but get buffer.length == 0, since bufferSize.init == int.init. It works not as expected and confuses a little. Do I have any chanse this will be fixed anytime, or is it intended?
I think this is intended, but you can do this: class Buffer { typedef int BufSize_t = 4096; BufSize_t bufsize; char[BufSize_t.init] buffer; }; The code in both cases seems confusing, since you could just use: class Buffer { char[4096] buffer; } It's a static buffer so the size can't change in any case. Kevin
Mar 29 2008
On Sat, 29 Mar 2008 21:17:40 +0300, Kevin Bealer <kevinbealer gmail.com>= = wrote:Koroskin Denis Wrote: The code in both cases seems confusing, since you could just use: class Buffer { char[4096] buffer; } It's a static buffer so the size can't change in any case. Kevin
Yes, but now it looks like a magic number to me. Moreover, I prefer usin= g = constant variables instead of buffer.length every time I need its capaci= ty. Anyway, my point is that if I initialize my variable like this: T someVariable =3D someConstantExpression; then someVariable.init should evaluate to someConstantExpression hereaft= er. It does't break current rules, since T someOtherVariable; is identical to: T someOtherVariable =3D T.init; and therefore someOtherVariable.init =3D=3D T.init.
Mar 29 2008
Koroskin Denis wrote:Look at this class. class Buffer { private int bufferSize = 4096; private void[bufferSize.init] buffer = void; } What's the capacity of buffer upon object construction? I expect that buffer.length == 4096, since bufferSize == 4096, but get buffer.length == 0, since bufferSize.init == int.init. It works not as expected and confuses a little. Do I have any chanse this will be fixed anytime, or is it intended?
.init used to do what you want but was changed along the way...
Mar 29 2008
On 29/03/2008, Koroskin Denis <2korden gmail.com> wrote:Look at this class. class Buffer { private int bufferSize = 4096; private void[bufferSize.init] buffer = void; }
In the current (D2.012) regime, that should be class Buffer { private enum bufferSize = 4096; private void[bufferSize] buffer = void; }
Mar 29 2008
Koroskin Denis wrote:Look at this class. class Buffer { private int bufferSize = 4096; private void[bufferSize.init] buffer = void; } What's the capacity of buffer upon object construction? I expect that buffer.length == 4096, since bufferSize == 4096, but get buffer.length == 0, since bufferSize.init == int.init. It works not as expected and confuses a little. Do I have any chanse this will be fixed anytime, or is it intended?
This is one of the few post-1.0 changes that broke existing code. I really wish it were changed back, but I doubt it will be. -- E-mail address: matti.niemenmaa+news, domain is iki (DOT) fi
Mar 29 2008
On Sat, 29 Mar 2008 23:01:26 +0300, Janice Caron <caron800 googlemail.co= m> = wrote:On 29/03/2008, Koroskin Denis <2korden gmail.com> wrote:Look at this class. class Buffer { private int bufferSize =3D 4096; private void[bufferSize.init] buffer =3D void; }
In the current (D2.012) regime, that should be class Buffer { private enum bufferSize =3D 4096; private void[bufferSize] buffer =3D void; }
I would declare it as "static const int" if I needed a constant value. An example is probably bad but I needed a /mutable/ variable by design.
Mar 29 2008









"Koroskin Denis" <2korden gmail.com> 