Smell your Code! @ IET-KFUPM PATW

96
Smell your Code! Yaser Sulaiman 1

description

This is the presentation I gave at the IET-KFUPM Present Around The World competition (http://iet.ikfupm.com/patw2011/), for which I was the second runner-up. It is based on an earlier presentation I gave at Free Dimension, the company I work for part-time.

Transcript of Smell your Code! @ IET-KFUPM PATW

Page 1: Smell your Code! @ IET-KFUPM PATW

Smell your Code!

Yaser Sulaiman

1

Page 3: Smell your Code! @ IET-KFUPM PATW

Our road map

3

Page 4: Smell your Code! @ IET-KFUPM PATW

Who? What? Why? How?

4

Page 5: Smell your Code! @ IET-KFUPM PATW

If you can take away only 1 lesson…

5

Page 6: Smell your Code! @ IET-KFUPM PATW

Don’t Repeat Yourself!

6

Page 7: Smell your Code! @ IET-KFUPM PATW

This rule is so important…

7

Page 8: Smell your Code! @ IET-KFUPM PATW

I must break it!

8

Page 9: Smell your Code! @ IET-KFUPM PATW

Don’t Repeat Yourself!

9

Page 10: Smell your Code! @ IET-KFUPM PATW

Who? What? Why? How?

10

Page 11: Smell your Code! @ IET-KFUPM PATW

“Who are you?”

11

Page 12: Smell your Code! @ IET-KFUPM PATW

A scientist, not an engineer

(I probably should be doing this @ ACM, not IET)

12

Page 13: Smell your Code! @ IET-KFUPM PATW

13

Page 14: Smell your Code! @ IET-KFUPM PATW

14

Page 15: Smell your Code! @ IET-KFUPM PATW

15

Page 17: Smell your Code! @ IET-KFUPM PATW

17

Page 19: Smell your Code! @ IET-KFUPM PATW

19

Page 22: Smell your Code! @ IET-KFUPM PATW

22 logo by Yukihiro Matsumoto

Page 23: Smell your Code! @ IET-KFUPM PATW

“You talkin’ to me?”

23

Page 24: Smell your Code! @ IET-KFUPM PATW

Are you a software developer?

24

Page 25: Smell your Code! @ IET-KFUPM PATW

If not, do you write code?

25

Page 26: Smell your Code! @ IET-KFUPM PATW

If not, would you be remotely interested in writing cleaner code

and making your life easier?

26

Page 27: Smell your Code! @ IET-KFUPM PATW

If not, you’re free to zone out

27

Page 28: Smell your Code! @ IET-KFUPM PATW

“Why should I listen to you?”

28

Page 29: Smell your Code! @ IET-KFUPM PATW

I won’t give you the “I’m a passionate software developer” BS

29

Page 30: Smell your Code! @ IET-KFUPM PATW

I’ve a terminal illness

30

Page 31: Smell your Code! @ IET-KFUPM PATW

Make that 2 terminal illnesses

31

Page 32: Smell your Code! @ IET-KFUPM PATW

Perfectionism &

OCD

32

Page 34: Smell your Code! @ IET-KFUPM PATW

Who? What? Why? How?

34

Page 35: Smell your Code! @ IET-KFUPM PATW

“Code smells?! Can I smell my code?!”

35

Page 37: Smell your Code! @ IET-KFUPM PATW

Yes you can, but not with your nose

37

Page 38: Smell your Code! @ IET-KFUPM PATW

Code smells are warning signs

38

Page 40: Smell your Code! @ IET-KFUPM PATW

They’re surface indications of deeper problems

40

Page 41: Smell your Code! @ IET-KFUPM PATW

41 photo by BenChenowethWork

Page 42: Smell your Code! @ IET-KFUPM PATW

They’re surface indications of deeper problems

42

Page 43: Smell your Code! @ IET-KFUPM PATW

A code smell ⇏ a problem

43

Page 44: Smell your Code! @ IET-KFUPM PATW

Who? What? Why? How?

44

Page 45: Smell your Code! @ IET-KFUPM PATW

The bigger picture

45

Page 46: Smell your Code! @ IET-KFUPM PATW

Software Quality

Code Quality

Code Smells

46 not to scale

Page 47: Smell your Code! @ IET-KFUPM PATW

Writing HQ code should be the priority

47

Page 48: Smell your Code! @ IET-KFUPM PATW

HQ code = easy toread

understandchange

48

Page 49: Smell your Code! @ IET-KFUPM PATW

In the short term, HQ code may cost more

49

Page 51: Smell your Code! @ IET-KFUPM PATW

Easier to change ≈ less costly

51

Page 52: Smell your Code! @ IET-KFUPM PATW

In the long run, HQ code costs less

52

Page 53: Smell your Code! @ IET-KFUPM PATW

One path to cleaner code goes through code smells

53

Page 54: Smell your Code! @ IET-KFUPM PATW

Who? What? Why? How?

54

Page 55: Smell your Code! @ IET-KFUPM PATW

There’re many code smells

55

Page 56: Smell your Code! @ IET-KFUPM PATW

The following smells are just a small subset

56

Page 57: Smell your Code! @ IET-KFUPM PATW

They’re the ones that drives me crazy the most

57

Page 58: Smell your Code! @ IET-KFUPM PATW

Code Smell #1

58

Page 59: Smell your Code! @ IET-KFUPM PATW

DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code

59

Page 60: Smell your Code! @ IET-KFUPM PATW

The nastiest code smell

60

Page 61: Smell your Code! @ IET-KFUPM PATW

DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code DupIicated code

61

Page 62: Smell your Code! @ IET-KFUPM PATW

Code Smell #2

62

Page 63: Smell your Code! @ IET-KFUPM PATW

functions.With(just, way, too, many, parameters, and,

then, even, some, more)

63

Page 64: Smell your Code! @ IET-KFUPM PATW

How many is too many?

64

Page 65: Smell your Code! @ IET-KFUPM PATW

Steve McConnell: > 7 ± 2

65

Page 66: Smell your Code! @ IET-KFUPM PATW

Robert C. “Uncle Bob” Martin: > 3

66

Page 67: Smell your Code! @ IET-KFUPM PATW

Code Smell #3

67

Page 68: Smell your Code! @ IET-KFUPM PATW

Not following a coding convention/standard/style

consistently

68

Page 69: Smell your Code! @ IET-KFUPM PATW

69 stolen from EmacsWiki

Page 70: Smell your Code! @ IET-KFUPM PATW

Not following a coding convention/standard/style

consistently

70

Page 71: Smell your Code! @ IET-KFUPM PATW

The specifics doesn’t really matter; what matters most is consistency

71

Page 72: Smell your Code! @ IET-KFUPM PATW

Code Smell #4

72

Page 73: Smell your Code! @ IET-KFUPM PATW

// code.CommentOut();

73

Page 74: Smell your Code! @ IET-KFUPM PATW

Don’t get me wrong

74

Page 75: Smell your Code! @ IET-KFUPM PATW

When you’re experimenting, comment code to your heart's

content

75

Page 76: Smell your Code! @ IET-KFUPM PATW

Just remember to clean up after yourself

76

Page 77: Smell your Code! @ IET-KFUPM PATW

And don’t commit commented-out

code

77

Page 78: Smell your Code! @ IET-KFUPM PATW

“Commented-out code is an abomination.”—Uncle Bob

78 photo used with permission of Uncle Bob

Page 79: Smell your Code! @ IET-KFUPM PATW

Commented-out code makes Uncle Bob angry

79

Page 80: Smell your Code! @ IET-KFUPM PATW

It makes me angry

80

Page 82: Smell your Code! @ IET-KFUPM PATW

Code Smell #5

82

Page 83: Smell your Code! @ IET-KFUPM PATW

// This is a comment

83

redundant

Page 84: Smell your Code! @ IET-KFUPM PATW

Who? What? Why? How?

84

Comments should focus on

Page 85: Smell your Code! @ IET-KFUPM PATW

Who? What? Why? How?

85

Page 86: Smell your Code! @ IET-KFUPM PATW

I may have come off as an a$$

86

Page 87: Smell your Code! @ IET-KFUPM PATW

My code smells as bad as everyone else’s.. sometimes even worse

87

Page 88: Smell your Code! @ IET-KFUPM PATW

But I’m aware of my smells

88

Page 89: Smell your Code! @ IET-KFUPM PATW

I try my best to prevent them

89

Page 90: Smell your Code! @ IET-KFUPM PATW

I don’t ignore them; I deal with them

90

Page 91: Smell your Code! @ IET-KFUPM PATW

I smell my code

91

Page 92: Smell your Code! @ IET-KFUPM PATW

You should smell your code too

92

Page 93: Smell your Code! @ IET-KFUPM PATW

When you code, take note of your nose It should be open, not close

For an open nose leads to an open mind And that’s the best rhyme I was able to find

93

Page 94: Smell your Code! @ IET-KFUPM PATW

If you want to sniff more…

94

Page 96: Smell your Code! @ IET-KFUPM PATW

…</presentation> <questions>…

96