www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Why do not have `0o` prefix for octal numbers?

reply "Hauleth" <lukasz niemier.pl> writes:
Some time ago I've asked on SO why most languages have `0` prefix 
for octal numbers. My opinion is the same as D designers that it 
cause a lot of bugs, but why octal numbers are avaible only by 
using `std.conv.octal`?
Sep 19 2012
next sibling parent "David Nadlinger" <see klickverbot.at> writes:
On Wednesday, 19 September 2012 at 16:02:41 UTC, Hauleth wrote:
 Some time ago I've asked on SO why most languages have `0` 
 prefix for octal numbers. My opinion is the same as D designers 
 that it cause a lot of bugs, but why octal numbers are avaible 
 only by using `std.conv.octal`?
How often do you use octal numbers? The reason is simply to avoid language feature creep where a library solution is perfectly acceptable. David
Sep 19 2012
prev sibling parent reply "monarch_dodra" <monarchdodra gmail.com> writes:
On Wednesday, 19 September 2012 at 16:02:41 UTC, Hauleth wrote:
 Some time ago I've asked on SO why most languages have `0` 
 prefix for octal numbers. My opinion is the same as D designers 
 that it cause a lot of bugs, but why octal numbers are avaible 
 only by using `std.conv.octal`?
AFAIK: It is experimental. "The $(D octal) facility is intended as an experimental facility to replace _octal literals starting with $(D '0'), which many find confusing." The reason for deprecating "0" prefix was indeed because of bugs. Then it was noticed that a library solution was available, and as a rule of thumb, if the library can do it, it is moved from the language to the library. You'll see a lot of threads talking about "scope", which went the same way (which is now a library feature, not a language feature). IMO, deprecating "0765" was a good move. Personally, I'd rather have had "0o765" instead of "octal!765" (if only for highlighting). But I don't think it is a big deal.
Sep 19 2012
parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Wed, 19 Sep 2012 12:15:19 -0400, monarch_dodra <monarchdodra gmail.com>  
wrote:

 On Wednesday, 19 September 2012 at 16:02:41 UTC, Hauleth wrote:
 Some time ago I've asked on SO why most languages have `0` prefix for  
 octal numbers. My opinion is the same as D designers that it cause a  
 lot of bugs, but why octal numbers are avaible only by using  
 `std.conv.octal`?
AFAIK: It is experimental. "The $(D octal) facility is intended as an experimental facility to replace _octal literals starting with $(D '0'), which many find confusing."
That comment is very old. It is no longer experimental. If you want an explanation, see here: http://www.drdobbs.com/tools/user-defined-literals-in-the-d-programmi/229401068 -Steve
Sep 20 2012
parent "monarch_dodra" <monarchdodra gmail.com> writes:
On Thursday, 20 September 2012 at 18:12:50 UTC, Steven 
Schveighoffer wrote:
 On Wed, 19 Sep 2012 12:15:19 -0400, monarch_dodra 
 <monarchdodra gmail.com> wrote:

 On Wednesday, 19 September 2012 at 16:02:41 UTC, Hauleth wrote:
 Some time ago I've asked on SO why most languages have `0` 
 prefix for octal numbers. My opinion is the same as D 
 designers that it cause a lot of bugs, but why octal numbers 
 are avaible only by using `std.conv.octal`?
AFAIK: It is experimental. "The $(D octal) facility is intended as an experimental facility to replace _octal literals starting with $(D '0'), which many find confusing."
That comment is very old. It is no longer experimental. If you want an explanation, see here: http://www.drdobbs.com/tools/user-defined-literals-in-the-d-programmi/229401068 -Steve
Very interesting read. TY.
Sep 20 2012