Web Log di Adrian Florea

"You know you've achieved perfection in design, not when you have nothing more to add, but when you have nothing more to take away." Antoine de Saint-Exupery
posts - 440, comments - 2715, trackbacks - 3944

My Links

Archives

Post Categories

Image Galleries

.RO Blogs

.RO People

.RO Sites

Blogs

Furls

Links

vinCitori

L for cLarity

"The 'l' suffix is easily confused with the digit '1' -- use 'L' for clarity". Grazie a questo warning "premuroso" del compilatore C#, il seguente quiz in Java preso dalla stessa Session TS-2575 di 2004 JavaOne Conference non ha tanto senso in C#:

6. "It's Elementary"

public class Elementary
{
  public static void main(String[] args)
  {
    System.out.println(54321 + 5432l);
  }
}

What Does It Print?

  • A. -22430
  • B. 59753
  • C. 10864
  • D. 108642
Program doesn’t say what you think it does!

Another Look

public class Elementary
{
  public static void main(String[] args)
  {
    System.out.println(54321 + 5432l);
  }
}

  • 1 - the numeral one
  • l - the lowercase letter el

How Do You Fix It?

We won’t insult your intelligence

The Moral

  • Always use uppercase el (L) for long literals
    • Lowercase el makes the code unreadable
    • 5432L is clearly a long, 5432l is misleading
  • Never use lowercase el as a variable name
    • Not this: List l = new ArrayList();
    • But this: List list = new ArrayList();

Lo so che non è rocket science :-) però per l'ennesima volta C# mostra di avere un "second mover advantage".

Print | posted on martedì 3 agosto 2004 14:10 | Filed Under [ Quiz Sharp ]

Powered by:
Powered By Subtext Powered By ASP.NET