sqe boston - when code cries

136
@cory_foy [email protected] When Code Cries Cory Foy @cory_foy [email protected] http://www.coryfoy.com 1 Thursday, November 14, 13 Reading from Timeless Way. Then: All of us here are technologists in some way. We desire to build things that people will use. Living software. But if you look at our industry, the fruit of our labors is not living software. The majority of software out there has a common attribute. It is:

Upload: cory-foy

Post on 14-May-2015

333 views

Category:

Technology


0 download

DESCRIPTION

In this talk from Boston's SQE Conference, Cory Foy talks about the strategies for developing and architecting quality code by changing how we learn about code and how we can let go of design and architecture in some ways to be able to listen to what the code is telling us - leading to happy code!

TRANSCRIPT

Page 1: SQE Boston - When Code Cries

@cory_foy [email protected]

When Code Cries

Cory Foy@cory_foy

[email protected]://www.coryfoy.com

1Thursday, November 14, 13

Reading from Timeless Way. Then: All of us here are technologists in some way. We desire to build things that people will use. Living software. But if you look at our industry, the fruit of our labors is not living software. The majority of software out there has a common attribute. It is:

Page 2: SQE Boston - When Code Cries

@cory_foy [email protected]

Bad Code

2Thursday, November 14, 13

Bad Code is the bane of the software industry. Why is it that, over time, code becomes harder and harder to work with - and how can we prevent ours from ending up with the same fate? To answer that, perhaps we should start with identifying what quality code is. So, is this quality code?

Page 3: SQE Boston - When Code Cries

@cory_foy [email protected]

Is this quality code?

3Thursday, November 14, 13

Why do we like Easy to Change code? Because it is a lower cognitive burden. Because writing code is hard enough, as we’ll see.

Page 4: SQE Boston - When Code Cries

@cory_foy [email protected]

Is this quality code?

3Thursday, November 14, 13

Why do we like Easy to Change code? Because it is a lower cognitive burden. Because writing code is hard enough, as we’ll see.

Page 5: SQE Boston - When Code Cries

@cory_foy [email protected]

ContextReduced

ContextEmbedded

Cognitively Undemanding

Cognitively Demanding

Where we want our software

Modifying Software we wrote

Modifying Software we didn’t write

4Thursday, November 14, 13

We want code that is in the upper right quadrant. But, if we’re lucky to be modifying our own code, it’s in the lower left. Worse case, we don’t even have the context, so it’s in the lower right. Now, if we have tests, that helps increase the context. But when we don’t, we can end up with code that looks like

Page 6: SQE Boston - When Code Cries

@cory_foy [email protected]

ContextReduced

ContextEmbedded

Cognitively Undemanding

Cognitively Demanding

Where we want our software

Modifying Software we wrote

Modifying Software we didn’t write

4Thursday, November 14, 13

We want code that is in the upper right quadrant. But, if we’re lucky to be modifying our own code, it’s in the lower left. Worse case, we don’t even have the context, so it’s in the lower right. Now, if we have tests, that helps increase the context. But when we don’t, we can end up with code that looks like

Page 7: SQE Boston - When Code Cries

@cory_foy [email protected]

ContextReduced

ContextEmbedded

Cognitively Undemanding

Cognitively Demanding

Where we want our software

Modifying Software we wrote

Modifying Software we didn’t write

4Thursday, November 14, 13

We want code that is in the upper right quadrant. But, if we’re lucky to be modifying our own code, it’s in the lower left. Worse case, we don’t even have the context, so it’s in the lower right. Now, if we have tests, that helps increase the context. But when we don’t, we can end up with code that looks like

Page 8: SQE Boston - When Code Cries

@cory_foy [email protected]

ContextReduced

ContextEmbedded

Cognitively Undemanding

Cognitively Demanding

Where we want our software

Modifying Software we wrote

Modifying Software we didn’t write

4Thursday, November 14, 13

We want code that is in the upper right quadrant. But, if we’re lucky to be modifying our own code, it’s in the lower left. Worse case, we don’t even have the context, so it’s in the lower right. Now, if we have tests, that helps increase the context. But when we don’t, we can end up with code that looks like

Page 9: SQE Boston - When Code Cries

@cory_foy [email protected], November 14, 13

Code that isn’t a joy. That is anti-joy. Code which is frustrating to be around. This is not code that is alive - this is code which has problems. And these problems - we tend to name them something. When we see something not right in code, what do we say?

Page 10: SQE Boston - When Code Cries

@cory_foy [email protected], November 14, 13

Code that isn’t a joy. That is anti-joy. Code which is frustrating to be around. This is not code that is alive - this is code which has problems. And these problems - we tend to name them something. When we see something not right in code, what do we say?

Page 11: SQE Boston - When Code Cries

@cory_foy [email protected], November 14, 13

Code that isn’t a joy. That is anti-joy. Code which is frustrating to be around. This is not code that is alive - this is code which has problems. And these problems - we tend to name them something. When we see something not right in code, what do we say?

Page 12: SQE Boston - When Code Cries

@cory_foy [email protected], November 14, 13

Code that isn’t a joy. That is anti-joy. Code which is frustrating to be around. This is not code that is alive - this is code which has problems. And these problems - we tend to name them something. When we see something not right in code, what do we say?

Page 13: SQE Boston - When Code Cries

@cory_foy [email protected], November 14, 13

Code that isn’t a joy. That is anti-joy. Code which is frustrating to be around. This is not code that is alive - this is code which has problems. And these problems - we tend to name them something. When we see something not right in code, what do we say?

Page 14: SQE Boston - When Code Cries

@cory_foy [email protected], November 14, 13

Code that isn’t a joy. That is anti-joy. Code which is frustrating to be around. This is not code that is alive - this is code which has problems. And these problems - we tend to name them something. When we see something not right in code, what do we say?

Page 15: SQE Boston - When Code Cries

@cory_foy [email protected], November 14, 13

Code that isn’t a joy. That is anti-joy. Code which is frustrating to be around. This is not code that is alive - this is code which has problems. And these problems - we tend to name them something. When we see something not right in code, what do we say?

Page 16: SQE Boston - When Code Cries

@cory_foy [email protected], November 14, 13

Code that isn’t a joy. That is anti-joy. Code which is frustrating to be around. This is not code that is alive - this is code which has problems. And these problems - we tend to name them something. When we see something not right in code, what do we say?

Page 17: SQE Boston - When Code Cries

@cory_foy [email protected]

Code Smells

6Thursday, November 14, 13

Right - “Smelly Code”. But what I’d like to do today is reframe the discussion slightly. Instead of telling our code that it smells, let’s recognize something else - our code is trying to talk to us.

Page 18: SQE Boston - When Code Cries

@cory_foy [email protected]

Code Talks

7Thursday, November 14, 13

And imagine trying to talk to someone about something important - say, the building is on fire - and them not understanding your strange gestures and telling you you are smelly. Would that make you happy? It doesn’t make our code happy. And if I can take some poetic license, I’d even say that code cries

Page 19: SQE Boston - When Code Cries

@cory_foy [email protected]

Code Cries

8Thursday, November 14, 13

And our code cries not because it is smelly, but because no one understands what it is trying to say. It’s trying to point out what it wants to do, what is important, and how to use it. And it isn’t happy about that! Too often we try to force what we want, what we think is best.

Page 20: SQE Boston - When Code Cries

@cory_foy [email protected]

Because No One Understands What It Is

Saying

Code Cries

8Thursday, November 14, 13

And our code cries not because it is smelly, but because no one understands what it is trying to say. It’s trying to point out what it wants to do, what is important, and how to use it. And it isn’t happy about that! Too often we try to force what we want, what we think is best.

Page 21: SQE Boston - When Code Cries

@cory_foy [email protected]

“...we have so far beset ourselves with rules, and concepts, and ideas...that we have become afraid of

what will happen naturally, and convinced that we must work within a “system” and with “methods” [or] our

surroundings will come tumbling down in chaos.”

Christopher Alexander - “The Timeless Way of Building”

9Thursday, November 14, 13

We turn to our UML and architecture diagrams and design documents, trying to brute force a system that will work, afraid that if we don’t - chaos. But nature *dictates* an iterative design - one where the best path is not only discovered, but continually chosen. We literally can not build software any other way. 

Page 22: SQE Boston - When Code Cries

@cory_foy [email protected], November 14, 13

This is a map of the Mississippi River in the United States. What’s special about it is that it is all of the routes the river has run through the years. We create a design. We settle down, build a house, have a family. But the code doesn't want that. It has plans beyond our design. And if we don't listen to those plans, our days will become filled with holding off the impending - and inevitable - change (http://www.adammandelman.net/tag/harold-fisk/)

Page 23: SQE Boston - When Code Cries

@cory_foy [email protected], November 14, 13

For example, in 2011, the Mississippi River tried to change course, I believe to the Orange area. And it normally would have - except for the millions of dollars the Army Corp of Engineers spent to erect dams, flood farm fields and otherwise keep it on the course best for us - not for it. But trying to brute force design into nature’s iterative process isn’t the only problem. (10k next)

Page 24: SQE Boston - When Code Cries

@cory_foy [email protected]

Ten Thousand Hours

12Thursday, November 14, 13

There’s a common figure that is given to developers about what it takes to become great in software. Does anyone know that number? <Click> This is the number of hours to “master” a skill. But as much as we tout this, we don’t really act like this is important. People new to software either get this

Page 25: SQE Boston - When Code Cries

@cory_foy [email protected]

Ten Thousand Hours

Ten Thousand Hours

12Thursday, November 14, 13

There’s a common figure that is given to developers about what it takes to become great in software. Does anyone know that number? <Click> This is the number of hours to “master” a skill. But as much as we tout this, we don’t really act like this is important. People new to software either get this

Page 26: SQE Boston - When Code Cries

@cory_foy [email protected]

bloody

13Thursday, November 14, 13

So, confusion and frustration, or this

Page 27: SQE Boston - When Code Cries

@cory_foy [email protected], November 14, 13

Empty promises! (Beaker story). Can you imagine learning C++ in 24 hours? Well, you might be able to learn syntax, but building great software isn’t just about learning syntax. Or diagrams. At the start of the talk, I quoted Alexander talking about a Timeless Way of Building - and that this way - this timeless way - is the only way buildings - or software - that are alive can be built. And if we go right to the kernel of that way, he says

Page 28: SQE Boston - When Code Cries

@cory_foy [email protected], November 14, 13

Empty promises! (Beaker story). Can you imagine learning C++ in 24 hours? Well, you might be able to learn syntax, but building great software isn’t just about learning syntax. Or diagrams. At the start of the talk, I quoted Alexander talking about a Timeless Way of Building - and that this way - this timeless way - is the only way buildings - or software - that are alive can be built. And if we go right to the kernel of that way, he says

Page 29: SQE Boston - When Code Cries

@cory_foy [email protected], November 14, 13

Empty promises! (Beaker story). Can you imagine learning C++ in 24 hours? Well, you might be able to learn syntax, but building great software isn’t just about learning syntax. Or diagrams. At the start of the talk, I quoted Alexander talking about a Timeless Way of Building - and that this way - this timeless way - is the only way buildings - or software - that are alive can be built. And if we go right to the kernel of that way, he says

Page 30: SQE Boston - When Code Cries

@cory_foy [email protected], November 14, 13

Empty promises! (Beaker story). Can you imagine learning C++ in 24 hours? Well, you might be able to learn syntax, but building great software isn’t just about learning syntax. Or diagrams. At the start of the talk, I quoted Alexander talking about a Timeless Way of Building - and that this way - this timeless way - is the only way buildings - or software - that are alive can be built. And if we go right to the kernel of that way, he says

Page 31: SQE Boston - When Code Cries

@cory_foy [email protected]

“To make a building {alive}...the builder must let go of all his

willful images, and start with a void...At this stage the building’s life will come directly from your

language”Christopher Alexander - “The Timeless Way of Building”

15Thursday, November 14, 13

So for us to be able to build great software, we have to be willing to let go of the diagrams. Of the syntax. Of the “Point A, Point B, flow”. And let go of the fear

Page 32: SQE Boston - When Code Cries

@cory_foy [email protected]

“You are able to do this only when you no longer fear that

nothing will happen”

Christopher Alexander - “The Timeless Way of Building”

16Thursday, November 14, 13

of the fear that if we let go, nothing will happen. Or chaos will happen. So, how do we get to the point where we feel comfortable enough to let go. And, more importantly, how do we teach others to get to that point? I think that the way that we do that is by recognizing that the heart of programming isn’t code, but communication. That’s why we call them programming languages. And we can learn a lot from how people learn languages to help us along our ten thousand hour path to get to the point where we can build alive systems by letting go

Page 33: SQE Boston - When Code Cries

@cory_foy [email protected]

Functional Programming

Imperative Programming

Logic Programming

Static Typing

Dynamic Typing

17Thursday, November 14, 13

This first is the understanding of how languages/paradigms affect our viewpoints. Roman Jakobson points out “Languages differ...must convey vs what they may convey”. “dinner with a neighbor last night”, doesn’t reveal if it was a male or female. But if I said in German, I would be obliged to (Nachbar vs Nachbarin). Functional: context of reduction of terms. Imperative: statement of the process, and logic: statement of the result. Static: abstractions sooner, dynamic: abstraction to be held off

Page 34: SQE Boston - When Code Cries

@cory_foy [email protected]

Coding Standards Define Dialects

18Thursday, November 14, 13

The second is that even within languages we have dialects. We have to agree on what that common dialect is going to be. This is traditionally the essence of coding standards - what is our agreed upon dialect?

Page 35: SQE Boston - When Code Cries

@cory_foy [email protected]

Coding Standards Define Dialects

18Thursday, November 14, 13

The second is that even within languages we have dialects. We have to agree on what that common dialect is going to be. This is traditionally the essence of coding standards - what is our agreed upon dialect?

Page 36: SQE Boston - When Code Cries

@cory_foy [email protected]

Coding Standards Define Dialects

18Thursday, November 14, 13

The second is that even within languages we have dialects. We have to agree on what that common dialect is going to be. This is traditionally the essence of coding standards - what is our agreed upon dialect?

Page 37: SQE Boston - When Code Cries

@cory_foy [email protected]

BICS

CALP

19Thursday, November 14, 13

The third is that the way we approach and learn languages is somewhat haphazard. You only need to look at any programming language book to see they all do them differently. But the process of learning a natural language is well known, and standardized regardless of the language. We can apply a similar framework to develop the skills we need to listen and understand our code

Page 38: SQE Boston - When Code Cries

@cory_foy [email protected]

BICS

CALP

19Thursday, November 14, 13

The third is that the way we approach and learn languages is somewhat haphazard. You only need to look at any programming language book to see they all do them differently. But the process of learning a natural language is well known, and standardized regardless of the language. We can apply a similar framework to develop the skills we need to listen and understand our code

Page 39: SQE Boston - When Code Cries

@cory_foy [email protected]

BICS

CALP

ContextReduced

ContextEmbedded

19Thursday, November 14, 13

The third is that the way we approach and learn languages is somewhat haphazard. You only need to look at any programming language book to see they all do them differently. But the process of learning a natural language is well known, and standardized regardless of the language. We can apply a similar framework to develop the skills we need to listen and understand our code

Page 40: SQE Boston - When Code Cries

@cory_foy [email protected]

BICS

CALP

ContextReduced

ContextEmbedded

Cognitively Undemanding

Cognitively Demanding

- Copying from the board- Reading a Map- Face to Face Conversation- Selecting food in the lunchroom

19Thursday, November 14, 13

The third is that the way we approach and learn languages is somewhat haphazard. You only need to look at any programming language book to see they all do them differently. But the process of learning a natural language is well known, and standardized regardless of the language. We can apply a similar framework to develop the skills we need to listen and understand our code

Page 41: SQE Boston - When Code Cries

@cory_foy [email protected]

BICS

CALP

ContextReduced

ContextEmbedded

Cognitively Undemanding

Cognitively Demanding

- Copying from the board- Reading a Map- Face to Face Conversation- Selecting food in the lunchroom

- Following a class schedule- Telephone Conversation- Oral Presentations- Getting an absence excuse

19Thursday, November 14, 13

The third is that the way we approach and learn languages is somewhat haphazard. You only need to look at any programming language book to see they all do them differently. But the process of learning a natural language is well known, and standardized regardless of the language. We can apply a similar framework to develop the skills we need to listen and understand our code

Page 42: SQE Boston - When Code Cries

@cory_foy [email protected]

BICS

CALP

ContextReduced

ContextEmbedded

Cognitively Undemanding

Cognitively Demanding

- Copying from the board- Reading a Map- Face to Face Conversation- Selecting food in the lunchroom

- Following a class schedule- Telephone Conversation- Oral Presentations- Getting an absence excuse

- Demonstrations- Basic Math Computations- Science Experiments

19Thursday, November 14, 13

The third is that the way we approach and learn languages is somewhat haphazard. You only need to look at any programming language book to see they all do them differently. But the process of learning a natural language is well known, and standardized regardless of the language. We can apply a similar framework to develop the skills we need to listen and understand our code

Page 43: SQE Boston - When Code Cries

@cory_foy [email protected]

BICS

CALP

ContextReduced

ContextEmbedded

Cognitively Undemanding

Cognitively Demanding

- Copying from the board- Reading a Map- Face to Face Conversation- Selecting food in the lunchroom

- Following a class schedule- Telephone Conversation- Oral Presentations- Getting an absence excuse

- Demonstrations- Basic Math Computations- Science Experiments

- Standardized Tests- Math Concepts and Applications- Listening to a Lecture

19Thursday, November 14, 13

The third is that the way we approach and learn languages is somewhat haphazard. You only need to look at any programming language book to see they all do them differently. But the process of learning a natural language is well known, and standardized regardless of the language. We can apply a similar framework to develop the skills we need to listen and understand our code

Page 44: SQE Boston - When Code Cries

@cory_foy [email protected]

BICS

CALP

ContextReduced

ContextEmbedded

Cognitively Undemanding

Cognitively Demanding20Thursday, November 14, 13

This framework, which I’m calling the “Foy-Z” model (with great irreverence), looks like this. We need to start by providing context. Katas provide a container to operate with in. Koans provide language specific nuances. Principles help us analyze our code in a higher context way, while patterns forces us to think about our overall goals. So let’s look at these a little more.

Page 45: SQE Boston - When Code Cries

@cory_foy [email protected]

BICS

CALP

ContextReduced

ContextEmbedded

Cognitively Undemanding

Cognitively Demanding

Foy-Z

20Thursday, November 14, 13

This framework, which I’m calling the “Foy-Z” model (with great irreverence), looks like this. We need to start by providing context. Katas provide a container to operate with in. Koans provide language specific nuances. Principles help us analyze our code in a higher context way, while patterns forces us to think about our overall goals. So let’s look at these a little more.

Page 46: SQE Boston - When Code Cries

@cory_foy [email protected]

BICS

CALP

ContextReduced

ContextEmbedded

Cognitively Undemanding

Cognitively Demanding

Katas

Foy-Z

20Thursday, November 14, 13

This framework, which I’m calling the “Foy-Z” model (with great irreverence), looks like this. We need to start by providing context. Katas provide a container to operate with in. Koans provide language specific nuances. Principles help us analyze our code in a higher context way, while patterns forces us to think about our overall goals. So let’s look at these a little more.

Page 47: SQE Boston - When Code Cries

@cory_foy [email protected]

BICS

CALP

ContextReduced

ContextEmbedded

Cognitively Undemanding

Cognitively Demanding

Katas Koans

Foy-Z

20Thursday, November 14, 13

This framework, which I’m calling the “Foy-Z” model (with great irreverence), looks like this. We need to start by providing context. Katas provide a container to operate with in. Koans provide language specific nuances. Principles help us analyze our code in a higher context way, while patterns forces us to think about our overall goals. So let’s look at these a little more.

Page 48: SQE Boston - When Code Cries

@cory_foy [email protected]

BICS

CALP

ContextReduced

ContextEmbedded

Cognitively Undemanding

Cognitively Demanding

Katas Koans

Principles

Foy-Z

20Thursday, November 14, 13

This framework, which I’m calling the “Foy-Z” model (with great irreverence), looks like this. We need to start by providing context. Katas provide a container to operate with in. Koans provide language specific nuances. Principles help us analyze our code in a higher context way, while patterns forces us to think about our overall goals. So let’s look at these a little more.

Page 49: SQE Boston - When Code Cries

@cory_foy [email protected]

BICS

CALP

ContextReduced

ContextEmbedded

Cognitively Undemanding

Cognitively Demanding

Katas Koans

Principles Patterns

Foy-Z

20Thursday, November 14, 13

This framework, which I’m calling the “Foy-Z” model (with great irreverence), looks like this. We need to start by providing context. Katas provide a container to operate with in. Koans provide language specific nuances. Principles help us analyze our code in a higher context way, while patterns forces us to think about our overall goals. So let’s look at these a little more.

Page 50: SQE Boston - When Code Cries

@cory_foy [email protected]

Katas

21Thursday, November 14, 13

Let’s start with Katas. First described in the software world by Pragmatic Dave Thomas, they offer the ability to practice without the solution being the cognitive challenge. In short, they allow developers to practice varying externally motivated viewpoints.

Page 51: SQE Boston - When Code Cries

@cory_foy [email protected]

Conway’s Game of Life

- Infinite Grid of Cells- Each Cell has two states - alive or dead- Interacts with neighbors in a well known way

http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life

22Thursday, November 14, 13

Page 52: SQE Boston - When Code Cries

@cory_foy [email protected]

Conway’s Game of Life

- Infinite Grid of Cells- Each Cell has two states - alive or dead- Interacts with neighbors in a well known way

http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life

22Thursday, November 14, 13

Page 53: SQE Boston - When Code Cries

@cory_foy [email protected]

Conway’s Game of Life

- Infinite Grid of Cells- Each Cell has two states - alive or dead- Interacts with neighbors in a well known way

http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life

22Thursday, November 14, 13

Page 54: SQE Boston - When Code Cries

@cory_foy [email protected]

Conway’s Game of Life

- Infinite Grid of Cells- Each Cell has two states - alive or dead- Interacts with neighbors in a well known way

http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life

22Thursday, November 14, 13

Page 55: SQE Boston - When Code Cries

@cory_foy [email protected]

Conway’s Game of Life - If Statement

23Thursday, November 14, 13

Page 56: SQE Boston - When Code Cries

@cory_foy [email protected]

Conway’s Game of Life - If Statement

23Thursday, November 14, 13

Page 57: SQE Boston - When Code Cries

@cory_foy [email protected]

Conway’s Game of Life - No Conditional

24Thursday, November 14, 13

Page 58: SQE Boston - When Code Cries

@cory_foy [email protected]

BICS

CALP

ContextReduced

ContextEmbedded

Cognitively Undemanding

Cognitively Demanding

Katas

Foy-Z

25Thursday, November 14, 13

So Katas allow us to not focus on solving the problem, but instead using the problem to explore the space of viewpoints. The context is very high - we cognitively understand the problem, so we can focus on practice. But at some point we need more - and that’s where

Page 59: SQE Boston - When Code Cries

@cory_foy [email protected]

BICS

CALP

ContextReduced

ContextEmbedded

Cognitively Undemanding

Cognitively Demanding

Katas Koans

Foy-Z

25Thursday, November 14, 13

So Katas allow us to not focus on solving the problem, but instead using the problem to explore the space of viewpoints. The context is very high - we cognitively understand the problem, so we can focus on practice. But at some point we need more - and that’s where

Page 60: SQE Boston - When Code Cries

@cory_foy [email protected]

Koans

26Thursday, November 14, 13

Koans come in. Koans provide language-specific nuances - the grammar if you will. They tend to be language specific, but lower context. It’s like practicing nouns and verbs - great to do, but much better if you have some context to put them in. For example (next Edgecase Koans)

Page 61: SQE Boston - When Code Cries

@cory_foy [email protected]

https://github.com/neo/ruby_koans

27Thursday, November 14, 13

one of the more famous software Koans was by Edgecase (now called Neo). You can see in the structure it was very specific to the Ruby language - arrays, assets, blocks, etc.

Page 62: SQE Boston - When Code Cries

@cory_foy [email protected]

Ruby Koans Asserts

28Thursday, November 14, 13

Page 63: SQE Boston - When Code Cries

@cory_foy [email protected]

Ruby Koans Arrays

29Thursday, November 14, 13

Page 64: SQE Boston - When Code Cries

@cory_foy [email protected]

BICS

CALP

ContextReduced

ContextEmbedded

Cognitively Undemanding

Cognitively Demanding

Katas Koans

Foy-Z

30Thursday, November 14, 13

So far, we’ve stayed in the BICS realm. BUT! We’ve learned something interesting. The Koans taught us Ruby array management, and we needed that for our exercise, so let’s revisit the Katas

Page 65: SQE Boston - When Code Cries

@cory_foy [email protected]

Conway’s Game of Life - With Map

31Thursday, November 14, 13

Page 66: SQE Boston - When Code Cries

@cory_foy [email protected]

Conway’s Game of Life - With Map

31Thursday, November 14, 13

Page 67: SQE Boston - When Code Cries

@cory_foy [email protected]

BICS

CALP

ContextReduced

ContextEmbedded

Cognitively Undemanding

Cognitively Demanding

Katas Koans

Foy-Z

32Thursday, November 14, 13

At this point, we have enough basic skills that we can begin to get into cognitively demanding work. We have the context, and the grammar, but we don’t know the optimal ways to apply the grammar. That’s where coding principles come in to play

Page 68: SQE Boston - When Code Cries

@cory_foy [email protected]

BICS

CALP

ContextReduced

ContextEmbedded

Cognitively Undemanding

Cognitively Demanding

Katas Koans

Principles

Foy-Z

32Thursday, November 14, 13

At this point, we have enough basic skills that we can begin to get into cognitively demanding work. We have the context, and the grammar, but we don’t know the optimal ways to apply the grammar. That’s where coding principles come in to play

Page 69: SQE Boston - When Code Cries

@cory_foy [email protected]

Principles

33Thursday, November 14, 13

Our principles guide us in how we apply our code within the context of what we’re writing.

Page 70: SQE Boston - When Code Cries

@cory_foy [email protected]

SOLID Principles

Do we have duplication

(implementation or conceptual)?

Single responsibilities?

LoD violations?

LSP violations?

34Thursday, November 14, 13

Transition to patterns

Page 71: SQE Boston - When Code Cries

@cory_foy [email protected]

4 Rules of Simple Design

Does this code express all of the ideas we want to express?

35Thursday, November 14, 13

Patterns. 4 Rules of Simple Design. Fowler. SOLID

Page 72: SQE Boston - When Code Cries

@cory_foy [email protected]

4 Rules of Simple Design

Does this code express all of the ideas we want to express?

35Thursday, November 14, 13

Patterns. 4 Rules of Simple Design. Fowler. SOLID

Page 73: SQE Boston - When Code Cries

@cory_foy [email protected]

4 Rules of Simple Design

Does this code express all of the ideas we want to express?

35Thursday, November 14, 13

Patterns. 4 Rules of Simple Design. Fowler. SOLID

Page 74: SQE Boston - When Code Cries

@cory_foy [email protected]

4 Rules of Simple Design

Does this code express all of the ideas we want to express?

Are there concepts from our domain that can be expressed?

35Thursday, November 14, 13

Patterns. 4 Rules of Simple Design. Fowler. SOLID

Page 75: SQE Boston - When Code Cries

@cory_foy [email protected]

4 Rules of Simple Design

Does this code express all of the ideas we want to express?

Are there concepts from our domain that can be expressed?

35Thursday, November 14, 13

Patterns. 4 Rules of Simple Design. Fowler. SOLID

Page 76: SQE Boston - When Code Cries

@cory_foy [email protected]

Fowler’s Perspectives (from UML Distilled)

Are we operating at the right level -

Conceptual, Specification or Implementation?

36Thursday, November 14, 13

Patterns. 4 Rules of Simple Design. Fowler. SOLID

Page 77: SQE Boston - When Code Cries

@cory_foy [email protected]

Fowler’s Perspectives (from UML Distilled)

Are we operating at the right level -

Conceptual, Specification or Implementation?

36Thursday, November 14, 13

Patterns. 4 Rules of Simple Design. Fowler. SOLID

Page 78: SQE Boston - When Code Cries

@cory_foy [email protected]

BICS

CALP

ContextReduced

ContextEmbedded

Cognitively Undemanding

Cognitively Demanding

Katas Koans

Principles

Foy-Z

37Thursday, November 14, 13

At this point, we have enough basic skills that we can begin to get into cognitively demanding work. As I mentioned earlier, Design Patterns

Page 79: SQE Boston - When Code Cries

@cory_foy [email protected]

BICS

CALP

ContextReduced

ContextEmbedded

Cognitively Undemanding

Cognitively Demanding

Katas Koans

Principles Patterns

Foy-Z

37Thursday, November 14, 13

At this point, we have enough basic skills that we can begin to get into cognitively demanding work. As I mentioned earlier, Design Patterns

Page 80: SQE Boston - When Code Cries

@cory_foy [email protected]

Patterns

38Thursday, November 14, 13

Design Patterns provide a guide for the forces encountered. What does that mean? We have a tendency to think of Design Patterns as recipes to make our code look a certain way. But

Page 81: SQE Boston - When Code Cries

@cory_foy [email protected], November 14, 13

Patterns are something else.

Page 82: SQE Boston - When Code Cries

@cory_foy [email protected]

Naming something the name of a pattern does not make it that pattern

39Thursday, November 14, 13

Patterns are something else.

Page 83: SQE Boston - When Code Cries

@cory_foy [email protected]

Naming something the name of a pattern does not make it that pattern

Putting patterns in our code does not make our code good

39Thursday, November 14, 13

Patterns are something else.

Page 84: SQE Boston - When Code Cries

@cory_foy [email protected]

Porch Swing

40Thursday, November 14, 13

Page 85: SQE Boston - When Code Cries

@cory_foy [email protected]

Porch Swing

40Thursday, November 14, 13

Page 86: SQE Boston - When Code Cries

@cory_foy [email protected]

Swimming Pool

41Thursday, November 14, 13

Page 87: SQE Boston - When Code Cries

@cory_foy [email protected]

Swimming Pool

41Thursday, November 14, 13

Page 88: SQE Boston - When Code Cries

@cory_foy [email protected]

Hedge Trimmer

42Thursday, November 14, 13

Not a pattern, but a death trap (next GoF Book / Structure of Patterns)

Page 89: SQE Boston - When Code Cries

@cory_foy [email protected]

Hedge Trimmer

42Thursday, November 14, 13

Not a pattern, but a death trap (next GoF Book / Structure of Patterns)

Page 90: SQE Boston - When Code Cries

@cory_foy [email protected]

• Pattern Name• Intent• Also Known As• Motivation / Forces• Applicability• Structure• Participants• Collaboration• Consequences• Implementation• Sample Code• Known Uses• Related Patterns

43Thursday, November 14, 13

The GoF Book wasn’t a beginners guide. It was Erich’s PhD Thesis. Patterns are designed to put into form the forces you may run into while building code. What does that mean?

Page 91: SQE Boston - When Code Cries

@cory_foy [email protected]

Server

44Thursday, November 14, 13

Let’s imagine a mobile application to upload pictures. So what forces are at play here? We know we have to associate multiple pictures to data. Data can have new types added, which need to be available on all other phones. The phone needs to be able to send the pictures to the server, as well as send and receive data updates. And deal with offline conditions.

Page 92: SQE Boston - When Code Cries

@cory_foy [email protected]

- Countries- Products- Locations

Server

44Thursday, November 14, 13

Let’s imagine a mobile application to upload pictures. So what forces are at play here? We know we have to associate multiple pictures to data. Data can have new types added, which need to be available on all other phones. The phone needs to be able to send the pictures to the server, as well as send and receive data updates. And deal with offline conditions.

Page 93: SQE Boston - When Code Cries

@cory_foy [email protected]

- Countries- Products- Locations

Server

- Send Data- Receive Data

44Thursday, November 14, 13

Let’s imagine a mobile application to upload pictures. So what forces are at play here? We know we have to associate multiple pictures to data. Data can have new types added, which need to be available on all other phones. The phone needs to be able to send the pictures to the server, as well as send and receive data updates. And deal with offline conditions.

Page 94: SQE Boston - When Code Cries

@cory_foy [email protected]

- Countries- Products- Locations

MultiplePictures

Server

- Send Data- Receive Data

44Thursday, November 14, 13

Let’s imagine a mobile application to upload pictures. So what forces are at play here? We know we have to associate multiple pictures to data. Data can have new types added, which need to be available on all other phones. The phone needs to be able to send the pictures to the server, as well as send and receive data updates. And deal with offline conditions.

Page 95: SQE Boston - When Code Cries

@cory_foy [email protected]

- Countries- Products- Locations

MultiplePictures

SendPictures

Server

- Send Data- Receive Data

44Thursday, November 14, 13

Let’s imagine a mobile application to upload pictures. So what forces are at play here? We know we have to associate multiple pictures to data. Data can have new types added, which need to be available on all other phones. The phone needs to be able to send the pictures to the server, as well as send and receive data updates. And deal with offline conditions.

Page 96: SQE Boston - When Code Cries

@cory_foy [email protected]

- Countries- Products- Locations

MultiplePictures

SendPictures

Server

- Send Data- Receive Data

Storage Options44Thursday, November 14, 13

Let’s imagine a mobile application to upload pictures. So what forces are at play here? We know we have to associate multiple pictures to data. Data can have new types added, which need to be available on all other phones. The phone needs to be able to send the pictures to the server, as well as send and receive data updates. And deal with offline conditions.

Page 97: SQE Boston - When Code Cries

@cory_foy [email protected]

Offline

45Thursday, November 14, 13

One way is by knowing the forces at play and comparing them to previous events. For example, the phone (or server) could be offline. What can we do if we are offline?

Page 98: SQE Boston - When Code Cries

@cory_foy [email protected]

Offline

Not allow send Queue items to send

45Thursday, November 14, 13

One way is by knowing the forces at play and comparing them to previous events. For example, the phone (or server) could be offline. What can we do if we are offline?

Page 99: SQE Boston - When Code Cries

@cory_foy [email protected]

Offline

Not allow send Queue items to send

Automatically Manually

45Thursday, November 14, 13

One way is by knowing the forces at play and comparing them to previous events. For example, the phone (or server) could be offline. What can we do if we are offline?

Page 100: SQE Boston - When Code Cries

@cory_foy [email protected]

Offline

Not allow send Queue items to send

Automatically Manually

Forces: - User has to remember to send - User can’t do other tasks until sent - User has to send each one

45Thursday, November 14, 13

One way is by knowing the forces at play and comparing them to previous events. For example, the phone (or server) could be offline. What can we do if we are offline?

Page 101: SQE Boston - When Code Cries

@cory_foy [email protected]

Offline

Not allow send Queue items to send

Automatically Manually

Forces: - Store multiple requests - Schedule to run them - Handle failed requests - Allow user to see status

Forces: - User has to remember to send - User can’t do other tasks until sent - User has to send each one

45Thursday, November 14, 13

One way is by knowing the forces at play and comparing them to previous events. For example, the phone (or server) could be offline. What can we do if we are offline?

Page 102: SQE Boston - When Code Cries

@cory_foy [email protected]

http://www.soapatterns.org/asynchronous_queuing.php

46Thursday, November 14, 13

So the patterns we choose are a result of the forces we are trying to resolve - the forces inherent in the solution itself.

Page 103: SQE Boston - When Code Cries

@cory_foy [email protected]

BICS

CALP

ContextReduced

ContextEmbedded

Cognitively Undemanding

Cognitively Demanding

Foy-Z

47Thursday, November 14, 13

So now that we’ve got a framework on how to get the point of understanding, now what? Well, our code is getting happier, because

Page 104: SQE Boston - When Code Cries

@cory_foy [email protected], November 14, 13

we’ve begun addressing some of the key issues in being able to listen to it.

Page 105: SQE Boston - When Code Cries

@cory_foy [email protected]

We don’t understand the

language

48Thursday, November 14, 13

we’ve begun addressing some of the key issues in being able to listen to it.

Page 106: SQE Boston - When Code Cries

@cory_foy [email protected]

We don’t understand the

language

We don’t have common context

48Thursday, November 14, 13

we’ve begun addressing some of the key issues in being able to listen to it.

Page 107: SQE Boston - When Code Cries

@cory_foy [email protected]

We don’t understand the

language

We don’t have common context

We don’t know the grammar

48Thursday, November 14, 13

we’ve begun addressing some of the key issues in being able to listen to it.

Page 108: SQE Boston - When Code Cries

@cory_foy [email protected]

We don’t understand the

language

We don’t have common context

We don’t know the grammar

We don’t know how to apply the

grammar

48Thursday, November 14, 13

we’ve begun addressing some of the key issues in being able to listen to it.

Page 109: SQE Boston - When Code Cries

@cory_foy [email protected]

We don’t understand the

language

We don’t have common context

We don’t know the grammar

We don’t know how to apply the

grammar

We don’t know what’s

appropriate

48Thursday, November 14, 13

we’ve begun addressing some of the key issues in being able to listen to it.

Page 110: SQE Boston - When Code Cries

@cory_foy [email protected]

http://www.flickr.com/photos/jakeandlindsay/5524669257

49Thursday, November 14, 13

So how to we apply it? How do we use that to now let go? First, diagrams aren’t bad. There’s nothing wrong with sketching out a plan. But, “No plan survives first contact with the enemy”. So pay attention to the forces more than the plan.

Page 111: SQE Boston - When Code Cries

@cory_foy [email protected]

http://www.soapatterns.org/asynchronous_queuing.php

50Thursday, November 14, 13

For example, looking at this pattern again, notice the impacts. We may say to ourselves, we want an Aysnc Queue, so fine, be on the lookout for that. But don’t blindly just shove an async queue in. Watch for your code to tell you it needs it. (This also applies to databases and many other things we “Know we need”)

Page 112: SQE Boston - When Code Cries

@cory_foy [email protected]

http://marchoeijmans.blogspot.com/2013/03/test-driven-development-tdd.html(Although I disagree with the article)

51Thursday, November 14, 13

Second: If you haven’t done TDD, or aren’t doing it, I’d highly recommend spending some time with Katas trying it out. What I find powerful is that it makes no qualms about your design. Don’t write a design, and then write tests to prove you are writing your design. Let the tests guide you. See what design emerges from them.

Page 113: SQE Boston - When Code Cries

@cory_foy [email protected], November 14, 13

Third: Technical Vision. In a team environment, you want to make sure you all are on the same page. Traditionally we’ve built software bottom up. But this doesn’t give us an opportunity to learn. “Tracer Bullets”

Page 114: SQE Boston - When Code Cries

@cory_foy [email protected]

Database

52Thursday, November 14, 13

Third: Technical Vision. In a team environment, you want to make sure you all are on the same page. Traditionally we’ve built software bottom up. But this doesn’t give us an opportunity to learn. “Tracer Bullets”

Page 115: SQE Boston - When Code Cries

@cory_foy [email protected]

Database

Stored Procedures

52Thursday, November 14, 13

Third: Technical Vision. In a team environment, you want to make sure you all are on the same page. Traditionally we’ve built software bottom up. But this doesn’t give us an opportunity to learn. “Tracer Bullets”

Page 116: SQE Boston - When Code Cries

@cory_foy [email protected]

Database

Stored Procedures

Service Layer

52Thursday, November 14, 13

Third: Technical Vision. In a team environment, you want to make sure you all are on the same page. Traditionally we’ve built software bottom up. But this doesn’t give us an opportunity to learn. “Tracer Bullets”

Page 117: SQE Boston - When Code Cries

@cory_foy [email protected]

Database

Stored Procedures

Service Layer

API Layer

52Thursday, November 14, 13

Third: Technical Vision. In a team environment, you want to make sure you all are on the same page. Traditionally we’ve built software bottom up. But this doesn’t give us an opportunity to learn. “Tracer Bullets”

Page 118: SQE Boston - When Code Cries

@cory_foy [email protected]

Database

Stored Procedures

Service Layer

API Layer

Front End Layer

52Thursday, November 14, 13

Third: Technical Vision. In a team environment, you want to make sure you all are on the same page. Traditionally we’ve built software bottom up. But this doesn’t give us an opportunity to learn. “Tracer Bullets”

Page 119: SQE Boston - When Code Cries

@cory_foy [email protected]

Database

Stored Procedures

Service Layer

API Layer

Front End Layer

52Thursday, November 14, 13

Third: Technical Vision. In a team environment, you want to make sure you all are on the same page. Traditionally we’ve built software bottom up. But this doesn’t give us an opportunity to learn. “Tracer Bullets”

Page 120: SQE Boston - When Code Cries

@cory_foy [email protected]

Database

Stored Procedures

Service Layer

API Layer

Front End Layer

52Thursday, November 14, 13

Third: Technical Vision. In a team environment, you want to make sure you all are on the same page. Traditionally we’ve built software bottom up. But this doesn’t give us an opportunity to learn. “Tracer Bullets”

Page 121: SQE Boston - When Code Cries

@cory_foy [email protected]

Database

Stored Procedures

Service Layer

API Layer

Front End Layer

52Thursday, November 14, 13

Third: Technical Vision. In a team environment, you want to make sure you all are on the same page. Traditionally we’ve built software bottom up. But this doesn’t give us an opportunity to learn. “Tracer Bullets”

Page 122: SQE Boston - When Code Cries

@cory_foy [email protected]

Database

Stored Procedures

Service Layer

API Layer

Front End Layer

52Thursday, November 14, 13

Third: Technical Vision. In a team environment, you want to make sure you all are on the same page. Traditionally we’ve built software bottom up. But this doesn’t give us an opportunity to learn. “Tracer Bullets”

Page 123: SQE Boston - When Code Cries

@cory_foy [email protected]

Database

Stored Procedures

Service Layer

API Layer

Front End Layer

52Thursday, November 14, 13

Third: Technical Vision. In a team environment, you want to make sure you all are on the same page. Traditionally we’ve built software bottom up. But this doesn’t give us an opportunity to learn. “Tracer Bullets”

Page 124: SQE Boston - When Code Cries

@cory_foy [email protected]

Database

Stored Procedures

Service Layer

API Layer

Front End Layer

53Thursday, November 14, 13

There’s nothing wrong with a vision. And as you work on slices, you can check against the overall vision to see if you are on the path you expected, or if your vision needs to change. Not the code, but the vision.

Page 125: SQE Boston - When Code Cries

@cory_foy [email protected]

Database

Stored Procedures

Service Layer

API Layer

Front End Layer

Vision

53Thursday, November 14, 13

There’s nothing wrong with a vision. And as you work on slices, you can check against the overall vision to see if you are on the path you expected, or if your vision needs to change. Not the code, but the vision.

Page 126: SQE Boston - When Code Cries

@cory_foy [email protected]

Database

Stored Procedures

Service Layer

API Layer

Front End Layer

Vision

53Thursday, November 14, 13

There’s nothing wrong with a vision. And as you work on slices, you can check against the overall vision to see if you are on the path you expected, or if your vision needs to change. Not the code, but the vision.

Page 127: SQE Boston - When Code Cries

@cory_foy [email protected]

Database

Stored Procedures

Service Layer

API Layer

Front End Layer

Vision

53Thursday, November 14, 13

There’s nothing wrong with a vision. And as you work on slices, you can check against the overall vision to see if you are on the path you expected, or if your vision needs to change. Not the code, but the vision.

Page 128: SQE Boston - When Code Cries

@cory_foy [email protected]

Pay attention to the forcesLet the code (and tests!) guide your design

Develop a vision, but use it as a guide, not a whipping post

54Thursday, November 14, 13

These things together, along with the solid understanding of the different paradigms and approaches are going to get you to the point where you can let go of the “willful images” and start really listening to your code. And when you listen to your code

Page 129: SQE Boston - When Code Cries

@cory_foy [email protected], November 14, 13

you end up with happy code. And when you don’t, you end up with unhappy code, baffled at why you are even bothering to build it if you aren’t going to listen.

Page 130: SQE Boston - When Code Cries

@cory_foy [email protected]

if coder_listens?

55Thursday, November 14, 13

you end up with happy code. And when you don’t, you end up with unhappy code, baffled at why you are even bothering to build it if you aren’t going to listen.

Page 131: SQE Boston - When Code Cries

@cory_foy [email protected]

if coder_listens? puts “:-)”

55Thursday, November 14, 13

you end up with happy code. And when you don’t, you end up with unhappy code, baffled at why you are even bothering to build it if you aren’t going to listen.

Page 132: SQE Boston - When Code Cries

@cory_foy [email protected]

if coder_listens? puts “:-)”else

55Thursday, November 14, 13

you end up with happy code. And when you don’t, you end up with unhappy code, baffled at why you are even bothering to build it if you aren’t going to listen.

Page 133: SQE Boston - When Code Cries

@cory_foy [email protected]

if coder_listens? puts “:-)”else puts “:`-(“

55Thursday, November 14, 13

you end up with happy code. And when you don’t, you end up with unhappy code, baffled at why you are even bothering to build it if you aren’t going to listen.

Page 134: SQE Boston - When Code Cries

@cory_foy [email protected]

if coder_listens? puts “:-)”else puts “:`-(“end

55Thursday, November 14, 13

you end up with happy code. And when you don’t, you end up with unhappy code, baffled at why you are even bothering to build it if you aren’t going to listen.

Page 135: SQE Boston - When Code Cries

@cory_foy [email protected]

if coder_listens? puts “:-)”else puts “:`-(“end

55Thursday, November 14, 13

you end up with happy code. And when you don’t, you end up with unhappy code, baffled at why you are even bothering to build it if you aren’t going to listen.