View mode: basic / threaded / horizontal-split · Log in · Help
February 14, 2012
More octal questions
OK, so I know that octals are deprecated, and the compiler will refuse
to compile code with octals unless the -deprecated flag is used.

But I find that std.datetime has literals of the form 000, 01, 02, 03,
and so on. Are these considered OK? Should my lexer accept them?


T

-- 
To err is human; to forgive is not our policy. -- Samuel Adler
February 14, 2012
Re: More octal questions
On 02/14/2012 10:24 PM, H. S. Teoh wrote:
> OK, so I know that octals are deprecated, and the compiler will refuse
> to compile code with octals unless the -deprecated flag is used.
>
> But I find that std.datetime has literals of the form 000, 01, 02, 03,
> and so on. Are these considered OK? Should my lexer accept them?
>
>
> T
>

Yes.

On 02/11/2012 05:37 PM, Timon Gehr wrote:
> Octal literals whose value is larger than 7 must be rejected. Octal literals with values up to 7 must be accepted.
February 15, 2012
Re: More octal questions
Where do you see those literals? I'm only seeing strings.
February 15, 2012
Re: More octal questions
On 02/15/2012 09:30 AM, Andrej Mitrovic wrote:
> Where do you see those literals? I'm only seeing strings.

Line 8322: _assertPred!"=="(SysTime.fromISOString("20101222T172201"), 
SysTime(DateTime(2010, 12, 22, 17, 22, 01)));
February 15, 2012
Re: More octal questions
On Wed, Feb 15, 2012 at 02:42:04PM +0100, Timon Gehr wrote:
> On 02/15/2012 09:30 AM, Andrej Mitrovic wrote:
> >Where do you see those literals? I'm only seeing strings.
> 
> Line 8322:
> _assertPred!"=="(SysTime.fromISOString("20101222T172201"),
> SysTime(DateTime(2010, 12, 22, 17, 22, 01)));

That unittest contains a lot of these literals. I'm not sure if this is
leftover from older code?


T

-- 
What's a "hot crossed bun"? An angry rabbit.
February 15, 2012
Re: More octal questions
On Wednesday, February 15, 2012 08:32:55 H. S. Teoh wrote:
> On Wed, Feb 15, 2012 at 02:42:04PM +0100, Timon Gehr wrote:
> > On 02/15/2012 09:30 AM, Andrej Mitrovic wrote:
> > >Where do you see those literals? I'm only seeing strings.
> > 
> > Line 8322:
> > _assertPred!"=="(SysTime.fromISOString("20101222T172201"),
> > SysTime(DateTime(2010, 12, 22, 17, 22, 01)));
> 
> That unittest contains a lot of these literals. I'm not sure if this is
> leftover from older code?

They're not left over at all, and they have nothing to do with octal. It's 
simply a matter of the natural thing for me to do when dealing with dates and 
times is to put the 0 in front of single digit numbers. You'll note that in 
the string representations, you _have_ to (per the ISO standard). So, I ended 
up doing it with the integer literals without thinking about it.

- Jonathan M Davis
February 15, 2012
Re: More octal questions
On Wed, Feb 15, 2012 at 08:41:33AM -0800, Jonathan M Davis wrote:
[...]
> They're not left over at all, and they have nothing to do with octal.
> It's simply a matter of the natural thing for me to do when dealing
> with dates and times is to put the 0 in front of single digit numbers.
> You'll note that in the string representations, you _have_ to (per the
> ISO standard). So, I ended up doing it with the integer literals
> without thinking about it.
[...]

Yes, I guessed as much. Which brings up a question of what exactly octal
deprecation will entail. Seems like it would make sense to allow initial
0's in decimal literals once octal literals are phased out.

Also, string escape sequences appear to allow backslash octal as well;
are these being deprecated or are they here to stay?


T

-- 
Тише едешь, дальше будешь.
February 15, 2012
Re: More octal questions
On Wednesday, 15 February 2012 at 17:48:03 UTC, H. S. Teoh wrote:
> Yes, I guessed as much. Which brings up a question of what 
> exactly octal deprecation will entail.

The goal here is to make sure things either do what they
look like, or don't compile.

010 doesn't do what it looks like to a person used to
decimal; it is a C octal literal for decimal 8.

So it is deprecated.

But, making it mean decimal 10 is also a no go, because
if you're used to C syntax, it won't do what you expect.

That's why it is an error. It is sure to confuse *somebody*.

01, 02, 03, ... 07 though work in both cases, so they
might still be allowed. (I'm not sure if they are or not).


But since there's no confusion for decimal people or for
C people, there's no problem with those small numbers.

> Also, string escape sequences appear to allow backslash octal 
> as well;
> are these being deprecated or are they here to stay?

I'm not sure.
February 15, 2012
Re: More octal questions
On Wed, Feb 15, 2012 at 06:52:09PM +0100, Adam D. Ruppe wrote:
[...]
> The goal here is to make sure things either do what they
> look like, or don't compile.
> 
> 010 doesn't do what it looks like to a person used to
> decimal; it is a C octal literal for decimal 8.
> 
> So it is deprecated.
> 
> But, making it mean decimal 10 is also a no go, because
> if you're used to C syntax, it won't do what you expect.
> 
> That's why it is an error. It is sure to confuse *somebody*.

True. Especially if a C coder tries calling chmod() with 0644 and it
silently gets interpreted as decimal.


> 01, 02, 03, ... 07 though work in both cases, so they
> might still be allowed. (I'm not sure if they are or not).
[...]

Currently the compiler accepts them (even without -deprecated).
Otherwise std.datetime wouldn't compile. :)


T

-- 
Bomb technician: If I'm running, try to keep up.
February 16, 2012
Re: More octal questions
On Wednesday, February 15, 2012 18:52:09 Adam D. Ruppe wrote:
> On Wednesday, 15 February 2012 at 17:48:03 UTC, H. S. Teoh wrote:
> > Yes, I guessed as much. Which brings up a question of what
> > exactly octal deprecation will entail.
> 
> The goal here is to make sure things either do what they
> look like, or don't compile.
> 
> 010 doesn't do what it looks like to a person used to
> decimal; it is a C octal literal for decimal 8.
> 
> So it is deprecated.
> 
> But, making it mean decimal 10 is also a no go, because
> if you're used to C syntax, it won't do what you expect.
> 
> That's why it is an error. It is sure to confuse *somebody*.
> 
> 01, 02, 03, ... 07 though work in both cases, so they
> might still be allowed. (I'm not sure if they are or not).
> 
> But since there's no confusion for decimal people or for
> C people, there's no problem with those small numbers.

Arguably more import is the fact that making 010 mean 10 would be a problem 
for porting code from C/C++. In general, C/C++ is either valid D code with the 
same semantics, or it doesn't compile (though there are a few exceptions - 
e.g. static arrays being value types). Treating 010 as 10 would violate that. 
So, I'd be very surprised if Walter agreed to do that. It'll just permanently 
stay an error like it is now.

- Jonathan M Davis
« First   ‹ Prev
1 2
Top | Discussion index | About this forum | D home