writing beautiful code - not just for aesthetic value

8
Writing beautiful code not just for aesthetic value -- Attila-Mihály Balázs

Upload: today-software-magazine

Post on 06-Mar-2016

223 views

Category:

Documents


2 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Writing beautiful code - not just for aesthetic value

Writing beautiful codenot just for aesthetic value

-- Attila-Mihály Balázs

Page 2: Writing beautiful code - not just for aesthetic value

Double d1 = (5.0d - 5.0d) * 1.0d;Double d2 = (5.0d - 5.0d) * -1.0d;System.out.println(d1.equals(d2));

double d1 = (5.0d - 5.0d) * 1.0d;double d2 = (5.0d - 5.0d) * -1.0d;System.out.println(d1 == d2);

Double Trouble

Page 3: Writing beautiful code - not just for aesthetic value

BigDecimal d1 = new BigDecimal("1.2");BigDecimal d2 = new BigDecimal("1.20");System.out.println(d1.equals(d2));

* http://hype-free.blogspot.ro/2008/12/negative-zero-what-is-it.html

Double Trouble

Page 4: Writing beautiful code - not just for aesthetic value

Double v = null;Double d = true ? v : 0.0d;System.out.println(d);

Where is my null at?

Page 5: Writing beautiful code - not just for aesthetic value

Collection<V> items;

if (items.size() == 0) { ... }

if (items.isEmpty()) { ... }

We come up empty

Page 6: Writing beautiful code - not just for aesthetic value

// WRONG! DON’T DO THIS!Vector v1;...if (!v1.contains(s)) { v1.add(s); }

Remove old cruft!

Page 8: Writing beautiful code - not just for aesthetic value

Questions?

Thank you!

Attila-Mihály Balá[email protected]

http://hype-free.blogspot.com/