don't do this! how not to write java™ technology-based ... · >mentor, trainer,...
TRANSCRIPT
![Page 1: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/1.jpg)
Don't Do This! How Not To Write Java™ Technology-Based SoftwareDean WamplerObject Mentor, [email protected] @deanwampler
Speaker logo centered below photo
Tuesday, June 2, 2009
![Page 2: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/2.jpg)
> Mentor, Trainer, Consultant at Object Mentor, Inc.objectmentor.compolyglotprogramming.com
2
Tuesday, June 2, 2009
![Page 3: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/3.jpg)
> September 2009oreilly.com/catalog/9780596157746/
> Read it now:programmingscala.com
3
Tuesday, June 2, 2009
![Page 4: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/4.jpg)
4
Lessons fromthe trenches...
http://everystockphoto.com/photo.php?imageId=4027778http://everystockphoto.com/photo.php?imageId=4027778Tuesday, June 2, 2009
![Page 5: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/5.jpg)
5
10 mistakes
http://everystockphoto.com/photo.php?imageId=4027778http://everystockphoto.com/photo.php?imageId=4027778
and how to avoid them.
Tuesday, June 2, 2009
![Page 6: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/6.jpg)
Mistake #1: Comment everything!
6© Dean WamplerTuesday, June 2, 2009
![Page 7: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/7.jpg)
7
public class Account { … /** * Withdraw money from account. * @param amount to withdraw (double) * @return new balance (double). */ public double withdraw(double amount) { balance -= amount; return balance; }}
Version 1
Tuesday, June 2, 2009
![Page 8: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/8.jpg)
8
public class Account { … /** * Withdraw money from account. * @param amount to withdraw (double) * @return new balance (double). */ public double withdraw(double amount) { balance -= amount; return balance; }}
Version 1
Command-queryseparation?
Tuesday, June 2, 2009
![Page 9: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/9.jpg)
9
public class Account { … /** * Withdraw money from account. * @param amount to withdraw (double) * @return new balance (double). */ public void withdraw(double amount) { balance -= amount; }}
Version 2
Tuesday, June 2, 2009
![Page 10: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/10.jpg)
10
public class Account { … /** * Withdraw money from account. * @param amount to withdraw (double) * @return new balance (double). */ public void withdraw(double amount) { balance -= amount; }}
Version 2
What about overdrafts?
Tuesday, June 2, 2009
![Page 11: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/11.jpg)
11
public class Account { … /** * Withdraw money from account. * @param amount to withdraw (double) * @return new balance (double). */ public void withdraw(double amount) throws OverdraftException { if (balance < amount) throw new OverdraftException( balance, amount); balance -= amount; }}
Version 3
Tuesday, June 2, 2009
![Page 12: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/12.jpg)
12
public class Account { … /** * Withdraw money from account. * @param amount to withdraw (double) * @return new balance (double). */ public void withdraw(double amount) throws OverdraftException { if (balance < amount) throw new OverdraftException( balance, amount); balance -= amount; }}
Version 3
Tuesday, June 2, 2009
![Page 13: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/13.jpg)
13
public class Account { … /** * Withdraw money from account. * @param amount to withdraw (double) * @return new balance (double). */ public void withdraw(double amount) throws OverdraftException { if (balance < amount) throw new OverdraftException( balance, amount); balance -= amount; }}
Version 3Doubles???
Tuesday, June 2, 2009
![Page 14: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/14.jpg)
14
public class Account { … /** * Withdraw money from account. * @param amount to withdraw (double) * @return new balance (double). */ public void withdraw(Currency amount) throws OverdraftException { if (balance.lessThan(amount)) throw new OverdraftException( balance, amount); balance = balance.minus(amount); }}
Version 4
Tuesday, June 2, 2009
![Page 15: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/15.jpg)
15
public class Account { … /** * Withdraw money from account. * @param amount to withdraw (double) * @return new balance (double). */ public void withdraw(Currency amount) throws OverdraftException { if (balance.lessThan(amount)) throw new OverdraftException( balance, amount); balance = balance.minus(amount); }}
Version 4
Tuesday, June 2, 2009
![Page 16: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/16.jpg)
16
public class Account { … /** * Withdraw money from account. * @param amount to withdraw (double) * @return new balance (double). */ public void withdraw(Currency amount) throws OverdraftException { if (balance.lessThan(amount)) throw new OverdraftException( balance, amount); balance = balance.minus(amount); }}
Version 4
Still Accurate??
Tuesday, June 2, 2009
![Page 17: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/17.jpg)
17
How do you test-drive
comments?
Tuesday, June 2, 2009
![Page 18: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/18.jpg)
18
Why comments?
To communicate.
Tuesday, June 2, 2009
![Page 19: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/19.jpg)
19
Communicatewith literate
code and tests.
Tuesday, June 2, 2009
![Page 20: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/20.jpg)
20
class AccountTest { … @Test(expected=OverdraftException.class) public void overdraftThrowsException() { Currency c1 = new Currency(1000.00,…); Currency c2 = new Currency(1000.01,…); Account account = new Account(c1); account.withdraw(c2); }} Tests as
documentation
Tuesday, June 2, 2009
![Page 21: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/21.jpg)
#2: Here, have an exception!
21http://www.damnit.org/2008-02/29osqid.jpg/viewTuesday, June 2, 2009
![Page 22: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/22.jpg)
#2: Here, have an exception!
22http://www.damnit.org/2008-02/29osqid.jpg/view
“Use checked exceptions.”
Tuesday, June 2, 2009
![Page 23: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/23.jpg)
23
import java.io.*public class FileFilter {
public static interface Filter { String filterLine(String line); } …
Tuesday, June 2, 2009
![Page 24: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/24.jpg)
24
… public void filter(File src, File dest, Filter filter) { String lineSeparator = …; BufferedReader in = new BufferedReader( new FileReader(src)); BufferedWriter out= new BufferedWriter( new FileWriter(dest)); …
Tuesday, June 2, 2009
![Page 25: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/25.jpg)
25
… public void filter(File src, File dest, Filter filter) { String lineSeparator = “…”; BufferedReader in = new BufferedReader( new FileReader(source)); BufferedWriter out= new BufferedWriter( new FileWriter(destination)); …
FileFilter.java:10: unreported exception java.io.FileNotFoundException; must be caught ... BufferedReader in = new BufferedReader(new …
Tuesday, June 2, 2009
![Page 26: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/26.jpg)
26
… public void filter(File src, File dest, Filter filter) throws FileNotFoundException, IOException { String lineSeparator = “…”; BufferedReader in = new BufferedReader( new FileReader(source)); BufferedWriter out= new BufferedWriter( new FileWriter(destination)); …
Tuesday, June 2, 2009
![Page 27: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/27.jpg)
27
How are the exceptionshandled?
Tuesday, June 2, 2009
![Page 28: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/28.jpg)
28
… main(String[] args) { … workFlowProcess(…) { … stuffInTheMiddle(…) { … manipulateFiles(…) { FileFilter fileFilter = new …; fileFilter.filter(…); …
Who handles the FileNotFoundException
and IOException?
Tuesday, June 2, 2009
![Page 29: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/29.jpg)
29
Could add throwsat every levelof the stack...
Namespace pollution
Tuesday, June 2, 2009
![Page 30: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/30.jpg)
30
Could eatthe exception immediately...
Do you really know how to recover??
Tuesday, June 2, 2009
![Page 31: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/31.jpg)
#2: Here, have an exception!
31http://www.damnit.org/2008-02/29osqid.jpg/view
“Handle every exception as soon
as you can.”
Tuesday, June 2, 2009
![Page 32: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/32.jpg)
32
… main(String[] args) { … workFlowProcess(…) { … stuffInTheMiddle(…) { … manipulateFiles(…) { try { FileFilter fileFilter = new …; fileFilter.filter(…); } catch (Throwable th) { log(th); // Now what!! } …
Eat it…?
Tuesday, June 2, 2009
![Page 33: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/33.jpg)
33
… main(String[] args) { … workFlowProcess(…) { … stuffInTheMiddle(…) { … manipulateFiles(…) { FileFilter fileFilter = new …; fileFilter.filter(…); …
One of these methodsknows what to do.
Tuesday, June 2, 2009
![Page 34: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/34.jpg)
34
Useuncheckedexceptions.
Tuesday, June 2, 2009
![Page 35: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/35.jpg)
35
Handleexceptions
strategically.
Tuesday, June 2, 2009
![Page 36: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/36.jpg)
36
… main(String[] args) { … workFlowProcess(…) { … stuffInTheMiddle(…) { … manipulateFiles(…) { FileFilter fileFilter = new …; fileFilter.filter(…); …
Maybe you catch file IO exceptions and attempt
recovery...
Tuesday, June 2, 2009
![Page 37: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/37.jpg)
#3: Just because youʼre paranoid doesnʼt mean you shouldnʼt check for nulls...
37http://www.flickr.com/photos/brewedfreshdaily89/2909152638/in/photostream/
Tuesday, June 2, 2009
![Page 38: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/38.jpg)
38
… public void filter(File src, File dest, Filter filter) throws FileNotFoundException, IOException { if (src == null || dest == null || filter == null) panic(“…”); …
Tuesday, June 2, 2009
![Page 39: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/39.jpg)
39
… public void filter(File src, File dest, Filter filter) throws FileNotFoundException, IOException { if (src == null || dest == null || filter == null) panic(“…”); …
Tuesday, June 2, 2009
![Page 40: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/40.jpg)
40
Null checksobscurecode.
Tuesday, June 2, 2009
![Page 41: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/41.jpg)
41
Null checkshave to betest driven.
Tuesday, June 2, 2009
![Page 42: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/42.jpg)
42
But, isnʼtdefensive
programminggood?
Tuesday, June 2, 2009
![Page 43: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/43.jpg)
43
Use strategicdata validation.
Tuesday, June 2, 2009
![Page 44: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/44.jpg)
44
Check at module
boundaries.
Tuesday, June 2, 2009
![Page 45: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/45.jpg)
45
Weed out nulls with
automated tests.
Tuesday, June 2, 2009
![Page 46: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/46.jpg)
#4: We can build a better X in house.
46
http://picturethis.channel4.com/photo/9075
Tuesday, June 2, 2009
![Page 47: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/47.jpg)
47
NIHsyndrome.
Tuesday, June 2, 2009
![Page 48: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/48.jpg)
48
Examples:message queues.
Tuesday, June 2, 2009
![Page 49: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/49.jpg)
49
Examples:rules engines.
Tuesday, June 2, 2009
![Page 50: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/50.jpg)
50
Examples:web template
engines.
Tuesday, June 2, 2009
![Page 51: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/51.jpg)
51
Whatʼs the cost of development?
Tuesday, June 2, 2009
![Page 52: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/52.jpg)
52
Whatʼs the cost of long-term
maintenance?
Tuesday, June 2, 2009
![Page 53: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/53.jpg)
53
In-house tools become a
maintenance burden.
Tuesday, June 2, 2009
![Page 54: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/54.jpg)
54
Porting to a 3rd-party tool is
painful.
Tuesday, June 2, 2009
![Page 55: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/55.jpg)
#5: Iʼll grab my own JDBC connection, thank you very much!
55© Dean WamplerTuesday, June 2, 2009
![Page 56: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/56.jpg)
56
public void transfer( Account src, Account dest, Currency amount) { try { src.withdraw(amount); dest.deposit(amount); Class.forName("sun.jdbc..."); Connection con = DriverManager.getConnection(…); Statement stmt = con.createStatement(); …
Tuesday, June 2, 2009
![Page 57: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/57.jpg)
57
public void transfer( Account src, Account dest, Currency amount) { try { src.withdraw(amount); dest.deposit(amount); Class.forName("sun.jdbc..."); Connection con = DriverManager.getConnection(…); Statement stmt = con.createStatement(); …
… or any other “hard” dependency.
Tuesday, June 2, 2009
![Page 58: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/58.jpg)
58
How do you unit test transfer?
Tuesday, June 2, 2009
![Page 59: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/59.jpg)
59
Hide dependencies
behind abstractions.
Tuesday, June 2, 2009
![Page 60: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/60.jpg)
60
Inject dependencies:
inversion of control.
Tuesday, June 2, 2009
![Page 61: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/61.jpg)
61
public void transfer( Account src, Account dest, Currency amount) { try { src.withdraw(amount); dest.deposit(amount); accountPersister.persist(src); accountPersister.persist(dest); …
Tuesday, June 2, 2009
![Page 62: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/62.jpg)
62
public void transfer( Account src, Account dest, Currency amount) { try { src.withdraw(amount); dest.deposit(amount); accountPersister.persist(src); accountPersister.persist(dest); …
accountPersister set through constructor or setter.
Tuesday, June 2, 2009
![Page 63: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/63.jpg)
63
For testing, set accountPersister to a test double.
Tuesday, June 2, 2009
![Page 64: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/64.jpg)
64
For production, set accountPersister
using Spring.
Tuesday, June 2, 2009
![Page 65: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/65.jpg)
65
You can remove the persistence
code completely...E.g., using Aspects.
Tuesday, June 2, 2009
![Page 66: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/66.jpg)
#6: Why retest when you can copy and paste?
66© Dean WamplerTuesday, June 2, 2009
![Page 67: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/67.jpg)
67
“Manual testing hurts.
Tuesday, June 2, 2009
![Page 68: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/68.jpg)
68
So donʼt edit, retest and
redeploy code.
Tuesday, June 2, 2009
![Page 69: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/69.jpg)
69
Copy, paste, and tweak it instead!”
Tuesday, June 2, 2009
![Page 70: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/70.jpg)
70
⇒ Massive duplication!
Tuesday, June 2, 2009
![Page 71: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/71.jpg)
71
Automated testing eliminates
the pain.
Tuesday, June 2, 2009
![Page 72: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/72.jpg)
#7: This code doesnʼt need to be thread safe.
72http://www.flickr.com/photos/billward/359774589/Tuesday, June 2, 2009
![Page 73: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/73.jpg)
73
Folk definition of insanity:Do the same thing over and over again and expect the
results to be different.
“The Problem with Threads”, IEEE Computer, May 2006Tuesday, June 2, 2009
![Page 74: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/74.jpg)
74
Thatʼs multithreaded programming in a nutshell.
Tuesday, June 2, 2009
![Page 75: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/75.jpg)
75
Code should tell its story.
Tuesday, June 2, 2009
![Page 76: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/76.jpg)
76
public class Account { … public void withdraw(Currency amount) throws OverdraftException { if (balance.lessThan(amount)) throw new OverdraftException( balance, amount); balance = balance.minus(amount); }}
Tuesday, June 2, 2009
![Page 77: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/77.jpg)
77
public class Account { … public void withdraw(Currency amount) throws OverdraftException { if (balance.lessThan(amount)) throw new OverdraftException( balance, amount); balance = balance.minus(amount); }} With threads, this code isnʼt
telling me the whole story.Tuesday, June 2, 2009
![Page 78: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/78.jpg)
78
public class Account { … public void withdraw(Currency amount) throws OverdraftException { if (balance.lessThan(amount)) throw new OverdraftException( balance, amount); balance = balance.minus(amount); }} These two operations
must be atomic!Tuesday, June 2, 2009
![Page 79: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/79.jpg)
79
2 ways to fix this code:
Tuesday, June 2, 2009
![Page 80: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/80.jpg)
80
#1: Use thread synchronization
primitives.
Tuesday, June 2, 2009
![Page 81: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/81.jpg)
81
Tuesday, June 2, 2009
![Page 82: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/82.jpg)
82
#2: Write concurrent code without threads.
Tuesday, June 2, 2009
![Page 83: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/83.jpg)
83
Use Actors.Go to Jonas Bonérʼs talk
tomorrow for other options...
Tuesday, June 2, 2009
![Page 84: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/84.jpg)
84
ActorsMessage passing
between autonomous Actors.
Tuesday, June 2, 2009
![Page 85: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/85.jpg)
85
ActorsNo shared, mutable state.
Tuesday, June 2, 2009
![Page 86: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/86.jpg)
86
ActorsMade famous by Erlang.Also supported in Scala.
Google: Java actors
Tuesday, June 2, 2009
![Page 87: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/87.jpg)
#8: Sophisticated code needs sophisticated APIʼs.
87http://www.flickr.com/photos/randomurl/440190706/Tuesday, June 2, 2009
![Page 88: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/88.jpg)
88
“Enterprise appsrequire EJBs.”
Tuesday, June 2, 2009
![Page 89: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/89.jpg)
89
Accidental vs.
essential complexity.
Tuesday, June 2, 2009
![Page 90: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/90.jpg)
90
“Do the simplest thing
that could possibly work!”
Tuesday, June 2, 2009
![Page 91: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/91.jpg)
91
2 ways to stay focused:
Tuesday, June 2, 2009
![Page 92: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/92.jpg)
92
#1: Use Test-Driven
Development (TDD).
Tuesday, June 2, 2009
![Page 93: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/93.jpg)
93
#2: Use Domain-Specific
Languages (DSLs).
Tuesday, June 2, 2009
![Page 94: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/94.jpg)
94
Vacation vacation = vacation() .starting("10/09/2007") .ending("10/17/2007") .city("Paris") .hotel("Hilton") .airline("United") .flight("UA-6886");
http://www.infoq.com/articles/internal-dsls-javaTuesday, June 2, 2009
![Page 95: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/95.jpg)
95
Vacation vacation = vacation() .starting("10/09/2007") .ending("10/17/2007") .city("Paris") .hotel("Hilton") .airline("United") .flight("UA-6886");
Expresses business logic.
http://www.infoq.com/articles/internal-dsls-javaTuesday, June 2, 2009
![Page 96: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/96.jpg)
96
Vacation vacation = vacation() .starting("10/09/2007") .ending("10/17/2007") .city("Paris") .hotel("Hilton") .airline("United") .flight("UA-6886");
Hides implementation.
http://www.infoq.com/articles/internal-dsls-javaTuesday, June 2, 2009
![Page 97: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/97.jpg)
97
What are the appropriate details
at this level of abstraction?
Tuesday, June 2, 2009
![Page 98: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/98.jpg)
#9: Everything is an object.
98© Dean WamplerTuesday, June 2, 2009
![Page 99: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/99.jpg)
99
Most appsare CRUD.
Tuesday, June 2, 2009
![Page 100: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/100.jpg)
100
Do you really needORM and OO middleware?
Tuesday, June 2, 2009
![Page 101: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/101.jpg)
101
Business rules:objects
or functions?
Tuesday, June 2, 2009
![Page 102: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/102.jpg)
102
Why are map/reduce and key-value DBs
so hot?Tuesday, June 2, 2009
![Page 103: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/103.jpg)
103
Embrace otherparadigms:
functional, aspects, logic, ...
Tuesday, June 2, 2009
![Page 104: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/104.jpg)
#10: Java and XML are all we really need.
104http://www.flickr.com/photos/randomurl/440190706/Tuesday, June 2, 2009
![Page 105: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/105.jpg)
105
Why did we enterXML Hell?
Tuesday, June 2, 2009
![Page 106: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/106.jpg)
106
XML is for data,not scripting.
Tuesday, June 2, 2009
![Page 107: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/107.jpg)
107
Application
Kernel of Components
Built-in Scripts User Scripts
(Java Components) + (Groovy/JRuby/Jython/... Scripts)
= Applications!Tuesday, June 2, 2009
![Page 108: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/108.jpg)
108
Application
Kernel of Components
Built-in Scripts User Scripts
Components + Scripts = Applications
Tuesday, June 2, 2009
![Page 109: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/109.jpg)
109
Why is Emacsstill relevant?
C + ELisp = Emacs
Tuesday, June 2, 2009
![Page 110: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/110.jpg)
A Way Forward...
110© Dean WamplerTuesday, June 2, 2009
![Page 111: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/111.jpg)
111
Communicate thrucode and tests.
#1: Comments
Tuesday, June 2, 2009
![Page 112: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/112.jpg)
112
Handle themstrategically.
#2: Exceptions
Tuesday, June 2, 2009
![Page 113: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/113.jpg)
113
Validate data at boundaries.
#3: Paranoid?
Tuesday, June 2, 2009
![Page 114: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/114.jpg)
114
Use inversion of control.
#4: Dependencies
Tuesday, June 2, 2009
![Page 115: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/115.jpg)
115
What is central to your business?
#5: NIH Syndrome
Tuesday, June 2, 2009
![Page 116: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/116.jpg)
116
Avoid duplication.Automate testing.
#6: Copy & Paste
Tuesday, June 2, 2009
![Page 117: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/117.jpg)
117
Avoid shared, mutable state.
#7: Thread Safety
Tuesday, June 2, 2009
![Page 118: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/118.jpg)
118
Focus using TDD. Use DSLs.
#8: Complexity
Tuesday, June 2, 2009
![Page 119: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/119.jpg)
119
Use FP, AOP, Relational, Logic...
#9: Objects Only?
Tuesday, June 2, 2009
![Page 120: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/120.jpg)
120
Components + Scripts = Apps
#10: Java Only?
Tuesday, June 2, 2009
![Page 121: Don't Do This! How Not To Write Java™ Technology-Based ... · >Mentor, Trainer, Consultant at Object Mentor, Inc. objectmentor.com polyglotprogramming.com 2 Tuesday, June 2, 2009](https://reader033.vdocuments.us/reader033/viewer/2022042303/5ece27faf6bb9c0f49301a04/html5/thumbnails/121.jpg)
Dean WamplerObject Mentor, Inc.
[email protected]@deanwamplerblog.objectmentor.compolyglotprogramming.com/papersprogrammingscala.com
Tuesday, June 2, 2009