"R" suffix for reals

Jonathan M Davis jmdavisProg at gmx.com
Sun May 6 18:46:04 PDT 2012


On Monday, May 07, 2012 03:02:28 bearophile wrote:
> Jonathan M Davis:
> > And what is so onerous about having to do 1.0L instead of 1R?
> 
> It's not onerous, the purpose of "R" is not to save typing ".0".
> 
> > (it would have to be either double or real, and
> > apparently it's real).
> 
> 1.0L is always a real in D.
> 
> > We _could_ add R, but I don't really see what it buys us.
> 
> Octal literals are deprecated in D because programmers sometimes
> forget about them, or make mistakes adding a leading zero,
> thinking it does nothing as in math, and defining a number
> different from the desired one.
> 
> If you write "auto x = 1L;" thinking about defining a real, as
> you define a float with "auto x = 1F;" you are introducing a
> small bug.
> 
> Or maybe you initially have written:
> auto r = 1.1L;
> And later you want to change the number to 1.0 and you fix it
> like this:
> auto r = 1L;
> Now you have a little bug.
> 
> The "R" is more symmetric with "f", it works as "f" for real.
> This makes learning D a bit simpler.
> 
> Very often it's better to have literals as much specific as
> possible, otherwise you get situations like the following one,
> what's the problem here (Issue 4703)?
> 
> import std.stdio: writeln;
> void main() {
>      int[] associative_array = [1:2, 3:4, 5:6];
>      writeln(associative_array);
> }

I'm sorry, but I think that you're making an issue out of nothing. 1L is 
clearly a long, not a real, and you're going to get compilation errors very 
quickly if you really meant to have a real. Yes, there _are_ cases where you 
could have a silent, logic error, but I really don't think that it's often 
enough to merit changing the language. I do not believe that I have _every_ 
seen this problem in real code. And by introducing R, you would create one 
more thing that D programmers would have to learn and know. I don't think that 
the suggested change comes even close to justifying itself.

- Jonathan M Davis


More information about the Digitalmars-d mailing list