Presentation is loading. Please wait.

Presentation is loading. Please wait.

Becoming a Better Developer. Things I have learned...

Similar presentations


Presentation on theme: "Becoming a Better Developer. Things I have learned..."— Presentation transcript:

1 Becoming a Better Developer

2 Things I have learned...

3 ... that has made me to a better developer...

4 ... than I was before I learned them

5 Johannes Brodwall

6 Lead Software Architect, BBS

7 Organizer, Oslo XP Meetup

8 Board-member, Oslo Agile UG

9 Committee member, ROOTS conference

10 Slides:

11 Experience Report

12 Things I have learned...

13 ... that has made me to a better developer...

14 ... than I was before I learned them

15 (2)

16 Be brief

17 "I would have written a shorter letter but I didn't have the time.“ - Mark Twain

18 (1)

19 Accept failure

20 (But only settle for perfection)

21 Developer or coder?

22 Coder: A good coder writes good code

23 Programmer: A good programmer is a good coder who thinks well

24 Developer: A good developer is a good programmer who communicates well

25 The Word: Versatility

26 Define: Versatility ”having a wide variety of skills”

27 Know a lot about something And something about a lot

28 (3)

29 In-depth knowledge

30 Code:

31 public void testFoo() { try { int result = bar.doBar(); assertEquals("should be 0", 0, result); } catch (BarException e) { fail("illegal exception caught"); }

32 public void testFoo() throws BarException { int result = bar.doBar(); assertEquals("result", 0, result); }

33 Socket s = null; try { s = new Socket(”server”, 12345); } catch (IOException e) { log.error(”An exception occurred”, e); } InputStream in = s.getInputStream();

34 Exception Handling

35 Socket s = null; try { s = new Socket("server", 12345); } catch (IOException e) { log.error("An exception occurred", e); throw new CustomException(e); } InputStream in = s.getInputStream();

36 try { Socket s = new Socket("server", 12345); InputStream in = s.getInputStream(); } catch (IOException e) { throw new CustomException(e); }

37 Catch block? Probably bug

38 Johannes’ first rule of exceptions

39 ”There is usually nothing you can do”

40 Source control Unit testing Continuous Integration

41 What is a task?

42 What is a good task?

43 ”How will I know when it is done?”

44 (How about: The tests passes)

45 public void testProcessFile() throws IOException { processor.process(file); assertEquals(StatusCode.PROCESSED, file.getCurrentStatusCode()); assertEquals("transmissions", 1, file.getTransmissions().size()); Transmission transmission = file.getTransmissions().iterator().next(); assertEquals(3, transmission.getTransactions().size()); assertEquals("transactionSum", new Money(7000, Currency.getInstance("NOK")), transmission.getTransactionSum());

46 Code perfection From:

47 Category category = dao.get(1); Category parent = dao.get(category.getParentId()); List children = new ArrayList(); for (Long childId : parent.getSubcategoryIds()) { children.add(dao.get(childId)); } System.out.println(children);

48 Category category = dao.get(1); System.out.println( category.getParent().getSubcategories());

49 Exploit Defaults

50

51 No: You are not special

52

53 No: You are not special

54 This gives tablename: bookcategory But we wanted: book_category

55 No: You are not special (except when you are)

56

57 No: You are not special Sun/Apache/Rod Johnson/DHH/Gavin King is probably smarter than you

58 (4)

59 Don’t overspecialize

60 Specialization is for insects!

61 Learn a different programming language Javascript example:

62 function sum(array){ return reduce(array, 0, function(a, b){ return a + b; }); }

63 function sum(array){ return reduce(array, 0, function(a, b){ return a + b; }); } sum([1, 2, 3, 4, 5]); => 15

64 function sum(array){ return reduce(array, 0, function(a, b){ return a + b; }); }

65 function reduce(array, initial_value, fn) { var result = init; for (i = 0; i < array.length; i++) result = fn( result, array[i] ); return result; } function sum(array){ return reduce(array, 0, function(a, b){ return a + b; }); }

66 Object sum(Collection collection) { return reduce(collection, 0, new BinaryFunction() { public Object doIt(Object a, Object b) { return (Integer) a + (Integer) b; } }); }

67 Practical use in Java Lazy Loading Example: easy.htmlhttp://today.java.net/pub/a/today/2006/07/13/lazy-loading-is- easy.html

68 Parent getById(final long parentId) { ResultSet rs =....; Parent parent = transformFromRs(rs); parent.setKids( (Collection)lazyLoad(new LazyLoader() { public Object loadObject() { return kidsByParentId(parentId) } }); return parent; }

69 function getById(parentId) { var rs =....; var parent = transformFromRs(rs); parent.kids = lazyLoad( function() { return kidsByParent(parentId); }); return parent; }

70 JavaScript Scheme Ruby

71 Developer or coder?

72 Coder: A good coder writes good code

73 Programmer: A good programmer is a good coder who thinks

74 (5)

75 See the bigger box

76 ”There is no use in trying,” said Alice. ”One cannot believe impossible things”

77 ”I daresay you haven’t had much practice,” said the queen.

78 ”When I was you age, I always did it for half an hour a day. Why, sometimes, I believed as many as six impossible things before breakfast” Lewis Carroll: Through the looking glass

79 How many Petals Around the Rose

80 Disclaimer: Riddle-solving doesn’t measure intelligence

81 (My wife solved this one faster than me)

82 How many Petals Around the Rose

83 Answer: 10 petals around the rose

84 How many Petals Around the Rose

85 Answer: 6 petals around the rose

86 How many Petals Around the Rose

87 How many Petals Around the Rose Answer: 0 petals around the rose

88 “The most profound discoveries never begin with EUREKA! Usually they start with the words "now that's odd..."

89 How many Petals Around the Rose

90 How many Petals Around the Rose Answer: 6 petals around the rose

91 How many Petals Around the Rose

92 How many Petals Around the Rose Answer: 2 petals around the rose

93 Solve it yourself (Or my blog) –http://www.brodwall.com/johannes/blog/2006/07/22/thinking- outside-the-box/http://www.brodwall.com/johannes/blog/2006/07/22/thinking- outside-the-box/

94 Ask ”why”

95 Why are we doing this?

96 Why are you writing ”pay for order” functionality? –Because it is needed for the user to pay for the ticket order service Why are we writing the ticket order service? –Because it is our project mandate to deliver an online ticket system Why is an online ticket system our mandate? –Because we believe that with our expertice in interactive web solutions, we can offer a really good service

97 ”Why am I writing this”

98 From: Johannes To: Bjørn Subject: Build server is down Hi, Bjørn The build server is down. ~Johannes

99 What do you expect the recipient to do?

100 From: Johannes To: Bjørn Subject: FYI: Build server is down Hi, Bjørn For your info: The build server is down. I am currently investigating and will let you know as soon as I know more. ~Johannes

101 From: Johannes To: Bjørn Subject: Please get the build server up again Hi, Bjørn The build server is down. Can you get it fixed? ~Johannes

102 Communications is

103 Communications is not explaining

104 Communication is creating a shared understanding

105 (6)

106 Coupling

107 Secret to good design: Avoid bad coupling Exploit good coupling

108 ”Two things are coupled if change to one requires change to the other”

109 Avoiding bad coupling

110 Programming by intention

111 public void testCategoryIsStoredCorrectly() { Category category = new Category("category name", 1999); category.addSubcategory(new Category("foo")); category.addSubcategory(new Category("bar")); Object id = dao.save(category); dao.flushCache(); Category copy = dao.get(id); assertNotSame(copy, category); assertAllFieldsEquals(copy, category); }

112 (Hiding details)

113 public void testSearchForNameAndCreationYear() { Collection expected = new HashSet(); storeMatching(new Category("magic 1",1999), expected, dao); storeNonMatching(new Category(”non-magic 2",2000), dao); CategorySpecification specification =...; Collection actual = dao.find(specification); assertCollectionHasSameElements(”find " + specification, expected, actual); }

114 Avoiding repetition

115 Comments repeating code Code duplication Duplicated decisions

116

117 Tell, Don’t Ask

118 Depend on abstractions (interfaces)

119 (7)

120 Haste != Productivity

121 Johannes’ only rule for crisis management

122 Don’t just do something Stand there!

123 Productivity = Getting Things Done

124 What is a good task?

125 ”How will I know when it is done?”

126 ”How will someone else know when it is done?”

127 Tip: Offload your task list from your brain

128 Yellow notes Outlook: Flags and Tasks Gmail: Inbox

129 Tip: Do it now, Do it soon, Defer it, Delegate it, or Drop it

130 The Art of the Two-Minute

131 Follow up on what you defer and delegate

132 (8)

133 Myopia (nearsightedness): the inability to see distant objects as clearly as near objects.

134 Myopia is good for your health

135 Implement for today

136 Not for tomorrow

137 ”We have to write this as a web service in case someone someday want to integrate with us”

138 Enterprisey!

139 Not for yesterday

140 From

141 ” This class was written by some earlier (Alex?) to manage the indexing of something (maybe). It is probably important. Don't delete. I don't think it's used anywhere - at least not in the new MacroINdexer module which may actually replace what it was used for.” Credit: AntiPatterns

142 (9)

143 Leave proud

144 /** TODO: Write a better comment. foo */ public boolean checkIt(String foo) { StringBuffer buffer = new StringBuffer(); buffer.append(foo); if (getStuff().startsWith(buffer.toString())) { return true; } else if (!getStuff().startsWith(buffer.toString())) { return false; } else { return false; } }

145 /** TODO: Write a better comment. foo */ public boolean checkIt(String foo) { StringBuffer buffer = new StringBuffer(); buffer.append(foo); if (getStuff().startsWith(buffer.toString())) { return true; } else if (!getStuff().startsWith(buffer.toString())) { return false; } else { return false; } } TODO comments Skeleton javadoc Premature (and unneeded) optimization Very common verbositis Common unthinking

146 public boolean isUsernameEqual( String username) { return get Address(). startsWith(username + }

147 (2)

148 Be brief

149 ”Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.” (Antoine de Saint-Exupery)

150 (1)

151 Accept failure

152 "Knowing the path is not the same as walking the path” - Tao te Ching

153 Summary 1.Accept failure 2.Be brief 3.In-depth knowledge 4.Don’t overspecialize 5.See the bigger box 6.Eliminate bad coupling 7.Don’t just do something, stand there 8.Work for today 9.Leave proud


Download ppt "Becoming a Better Developer. Things I have learned..."

Similar presentations


Ads by Google