when code cries
play

When Code Cries Cory Foy @cory_foy foyc@coryfoy.com - PDF document

When Code Cries Cory Foy @cory_foy foyc@coryfoy.com http://www.coryfoy.com #gotober @cory_foy foyc@coryfoy.com Friday, October 18, 13 1 Reading from Timeless Way. Then: All of us here are technologists in some way. We desire to build


  1. When Code Cries Cory Foy @cory_foy foyc@coryfoy.com http://www.coryfoy.com #gotober @cory_foy foyc@coryfoy.com Friday, October 18, 13 1 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:

  2. Bad Code #gotober @cory_foy foyc@coryfoy.com Friday, October 18, 13 2 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?

  3. Is this quality code? #gotober @cory_foy foyc@coryfoy.com Friday, October 18, 13 3 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.

  4. Cognitively Undemanding Where we want our software Context Context Embedded Reduced Modifying Software we Modifying Software we wrote didn’t write Cognitively Demanding #gotober @cory_foy foyc@coryfoy.com Friday, October 18, 13 4 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

  5. #gotober @cory_foy foyc@coryfoy.com Friday, October 18, 13 5 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?

  6. Code Smells #gotober @cory_foy foyc@coryfoy.com Friday, October 18, 13 6 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.

  7. Code Talks #gotober @cory_foy foyc@coryfoy.com Friday, October 18, 13 7 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

  8. Code Cries Because No One Understands What It Is Saying #gotober @cory_foy foyc@coryfoy.com Friday, October 18, 13 8 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.

  9. “...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 W ay of Building” #gotober @cory_foy foyc@coryfoy.com Friday, October 18, 13 9 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.

  10. #gotober @cory_foy foyc@coryfoy.com Friday, October 18, 13 10 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 o fg the impending - and inevitable - change (http://www.adammandelman.net/tag/harold-fisk/)

  11. #gotober @cory_foy foyc@coryfoy.com Friday, October 18, 13 11 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)

  12. TenThousand Hours #gotober @cory_foy foyc@coryfoy.com Friday, October 18, 13 12 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

  13. bloody #gotober @cory_foy foyc@coryfoy.com Friday, October 18, 13 13 So, confusion and frustration, or this

  14. #gotober @cory_foy foyc@coryfoy.com Friday, October 18, 13 14 Empty promises! (Beaker story). Can you imagine learning C++ in 24 hours? Well, you might be able to learn syntax, but programming isn’t about syntax. It’s about communication, precisely why they are called programming languages. But learning communication is hard, and we don’t have time for that! (Jr vs Sr next)

  15. Number of Results for “X Developer” Linked In: Junior Developer: 17,157 Senior Developer: 123,634 Google: Junior Developer: 1,060,000 Senior Developer: 4,290,000 #gotober @cory_foy foyc@coryfoy.com Friday, October 18, 13 15 We have a gap there. If we really want to make it better, we have to figure out how to fill that gap. And it turns out we can look at how we classify and learn natural languages and create some interesting parallels to software

  16. Imperative Programming Functional Programming Logic Programming Dynamic Typing Static Typing #gotober @cory_foy foyc@coryfoy.com Friday, October 18, 13 16 The first is how di fg erent languages - and paradigms - can a fg ect our viewpoints. Linguist Roman Jakobson points out “Languages di fg er essentially in what they must convey and not in what they may convey”. For example, if I said, in English, I had dinner with a neighbor last night, I wouldn’t have to reveal if it was a male or female. But if I said the same thing in French or German, I would be obliged to (voisin vs voisine and Nachbar vs Nachbarin). So they same can be said for programming languages. Functional must express problems in the context of reduction of terms. Imperative expresses problems as a statement of the process, and logic expresses problems as a statement of the result. Static typing forces us to abstractions sooner, while dynamic typing allows the abstraction to be held o fg

  17. Coding Standards Define Dialects #gotober @cory_foy foyc@coryfoy.com Friday, October 18, 13 17 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?

  18. Cognitively Undemanding BICS - Copying from the board - Following a class schedule - Reading a Map - Telephone Conversation - Face to Face Conversation - Oral Presentations - Selecting food in the - Getting an absence excuse lunchroom Context Context Embedded Reduced - Demonstrations - Standardized Tests - Basic Math - Math Concepts and Computations Applications - Science Experiments - Listening to a Lecture CALP Cognitively Demanding #gotober @cory_foy foyc@coryfoy.com Friday, October 18, 13 18 The process of learning a natural language has been mapped in two ways. If we look at this model, we can now do something similar with programming. We can create a model to show where our gaps are - both in teaching, and in our own learning.

  19. Foy-Z Cognitively Undemanding BICS Katas Koans Context Context Embedded Reduced Principles and Writing Production Patterns Code CALP Cognitively Demanding #gotober @cory_foy foyc@coryfoy.com Friday, October 18, 13 19 This model, which I’m calling the “Foy-Z” model, since my name isn’t Jay, looks like this. We need to start by providing context. Katas provide low cognitive challenge to practice expanding viewpoints. Koans provide language specific nuances. Principles and Patterns provide guides for forces you’ll encounter, and it takes all of the above to write production code.

  20. Katas #gotober @cory_foy foyc@coryfoy.com Friday, October 18, 13 20 Let’s start with Katas. First described in the software world by Pragmatic Dave Thomas, they o fg er the ability to practice without the solution being the cognitive challenge. In short, they allow developers to practice varying externally motivated viewpoints.

  21. 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 #gotober @cory_foy foyc@coryfoy.com Friday, October 18, 13 21

  22. Conway’s Game of Life - If Statement #gotober @cory_foy foyc@coryfoy.com Friday, October 18, 13 22

  23. Conway’s Game of Life - No Conditional #gotober @cory_foy foyc@coryfoy.com Friday, October 18, 13 23

Recommend


More recommend