Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coding conventions for number literal suffix? [closed]

I did some googleling, but was unable to find a solution to my question.

Are there generally accepted java coding conventions according to double and float declaration?

What syntax is recommended by those guidelines?

      Double d = 1d;
      Double d = 1D;
      Double d = 1.;
      Double d = 1.0;
      Double d = 1.0d;
      Double d = 1.0D;

Same goes for Float and Long and also their primitives.

      Long l = 1l;
      Long l = 1L;

All compile the same, but there are difference in clearness when reading these lines of code. The one with the upper case d seems to be more likely to be read wrong --> "D" could be read as "0" or so.

like image 343
L.Butz Avatar asked May 09 '14 06:05

L.Butz


1 Answers

It's really just personal preference and I believe lowercase is more common. It's like indentation, pick something and stick with it.

The Java language spec mentions that captial L is preferred for long values because it's easier to read but it doesn't say anything about f/F or d/D.

like image 118
takteek Avatar answered Oct 16 '22 22:10

takteek