What is good code?
-
Upload
jane-prusakova -
Category
Software
-
view
124 -
download
2
Transcript of What is good code?
![Page 1: What is good code?](https://reader036.fdocuments.net/reader036/viewer/2022062514/55b8ff9ebb61eb690d8b4720/html5/thumbnails/1.jpg)
©2010 Improving Enterprises, Inc.
Good CodeWhat, Why, and How to Get There
Houston Java Group 2015
Jane Prusakova
Josh Rizzo
@Improving Enterprises College Station
![Page 2: What is good code?](https://reader036.fdocuments.net/reader036/viewer/2022062514/55b8ff9ebb61eb690d8b4720/html5/thumbnails/2.jpg)
©2010 Improving Enterprises, Inc.
What is “good”?
Functional
Bug-free
Performant
Good design
Tested
Testable
Easy to change
READABLE
![Page 3: What is good code?](https://reader036.fdocuments.net/reader036/viewer/2022062514/55b8ff9ebb61eb690d8b4720/html5/thumbnails/3.jpg)
©2010 Improving Enterprises, Inc.
Usability
Users and clients Developers
![Page 4: What is good code?](https://reader036.fdocuments.net/reader036/viewer/2022062514/55b8ff9ebb61eb690d8b4720/html5/thumbnails/4.jpg)
©2010 Improving Enterprises, Inc.
![Page 5: What is good code?](https://reader036.fdocuments.net/reader036/viewer/2022062514/55b8ff9ebb61eb690d8b4720/html5/thumbnails/5.jpg)
©2010 Improving Enterprises, Inc.
“Programs must be written for people to read, and only incidentally for machines to execute.”
– Abelson and Sussman
![Page 6: What is good code?](https://reader036.fdocuments.net/reader036/viewer/2022062514/55b8ff9ebb61eb690d8b4720/html5/thumbnails/6.jpg)
©2010 Improving Enterprises, Inc.
Readability has valueNOW
Code is an asset
affects productivity
monetary value
![Page 7: What is good code?](https://reader036.fdocuments.net/reader036/viewer/2022062514/55b8ff9ebb61eb690d8b4720/html5/thumbnails/7.jpg)
Readability has value OVER TIME
Software evolves over time
Work by many different teams
Changes affect value
![Page 8: What is good code?](https://reader036.fdocuments.net/reader036/viewer/2022062514/55b8ff9ebb61eb690d8b4720/html5/thumbnails/8.jpg)
©2010 Improving Enterprises, Inc.
Readability has cost
More hard work
More time
More training
![Page 9: What is good code?](https://reader036.fdocuments.net/reader036/viewer/2022062514/55b8ff9ebb61eb690d8b4720/html5/thumbnails/9.jpg)
©2010 Improving Enterprises, Inc.
How good code does not happen
![Page 10: What is good code?](https://reader036.fdocuments.net/reader036/viewer/2022062514/55b8ff9ebb61eb690d8b4720/html5/thumbnails/10.jpg)
©2010 Improving Enterprises, Inc.
Readable code
Easy to read
Has a narrative
UnambiguousWYSIWYG
Follows convention
![Page 11: What is good code?](https://reader036.fdocuments.net/reader036/viewer/2022062514/55b8ff9ebb61eb690d8b4720/html5/thumbnails/11.jpg)
©2010 Improving Enterprises, Inc.
It was hard to write
It should be hard to read
Who is responsible?
![Page 12: What is good code?](https://reader036.fdocuments.net/reader036/viewer/2022062514/55b8ff9ebb61eb690d8b4720/html5/thumbnails/12.jpg)
©2010 Improving Enterprises, Inc.
Lets make code more…
READABLE
See: https://github.com/joshrizzo/ReadabilityJava
![Page 13: What is good code?](https://reader036.fdocuments.net/reader036/viewer/2022062514/55b8ff9ebb61eb690d8b4720/html5/thumbnails/13.jpg)
©2010 Improving Enterprises, Inc.
Visible code
White space!
Spacing and indent matter
The Law of Demeter
– avoid the “train wreck” coding style
Step 1
![Page 14: What is good code?](https://reader036.fdocuments.net/reader036/viewer/2022062514/55b8ff9ebb61eb690d8b4720/html5/thumbnails/14.jpg)
©2010 Improving Enterprises, Inc.
Small stepsOne thing at a time
Glance-sized chunks
“Programming can be fun, so can cryptography; however they should not be combined.”
– Kreitzberg and Shneiderman
Step 2
![Page 15: What is good code?](https://reader036.fdocuments.net/reader036/viewer/2022062514/55b8ff9ebb61eb690d8b4720/html5/thumbnails/15.jpg)
©2010 Improving Enterprises, Inc.
Code with a narrativeUse naming to show intent
Testable code
“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
– Brian W. Kernighan
Step 3
![Page 16: What is good code?](https://reader036.fdocuments.net/reader036/viewer/2022062514/55b8ff9ebb61eb690d8b4720/html5/thumbnails/16.jpg)
©2010 Improving Enterprises, Inc.
Single Responsibility
Architecture
Interface design
"Good design adds value faster than it adds cost."
- Thomas C. Gale
Step 4
![Page 17: What is good code?](https://reader036.fdocuments.net/reader036/viewer/2022062514/55b8ff9ebb61eb690d8b4720/html5/thumbnails/17.jpg)
©2010 Improving Enterprises, Inc.
Easy to read
Single level of abstraction
“The purpose of abstraction is not to be vague, but to create a new semantic level in which one can be absolutely precise.”
– Edsger Dijkstra
Step 5
![Page 18: What is good code?](https://reader036.fdocuments.net/reader036/viewer/2022062514/55b8ff9ebb61eb690d8b4720/html5/thumbnails/18.jpg)
©2010 Improving Enterprises, Inc.
Readable++Simplicity
![Page 19: What is good code?](https://reader036.fdocuments.net/reader036/viewer/2022062514/55b8ff9ebb61eb690d8b4720/html5/thumbnails/19.jpg)
©2010 Improving Enterprises, Inc.
“Everything should be made as simple as possible, but not simpler.”
– Albert Einstein
![Page 20: What is good code?](https://reader036.fdocuments.net/reader036/viewer/2022062514/55b8ff9ebb61eb690d8b4720/html5/thumbnails/20.jpg)
©2010 Improving Enterprises, Inc.
Simple vs Fast
Correctness more important than speedSimple code is more likely to be and stay correct
Modularize code w/ performance concernsOptimize locally
![Page 21: What is good code?](https://reader036.fdocuments.net/reader036/viewer/2022062514/55b8ff9ebb61eb690d8b4720/html5/thumbnails/21.jpg)
©2010 Improving Enterprises, Inc.
![Page 22: What is good code?](https://reader036.fdocuments.net/reader036/viewer/2022062514/55b8ff9ebb61eb690d8b4720/html5/thumbnails/22.jpg)
©2010 Improving Enterprises, Inc.
Simple vs FlexibleRe-use is rare
Predictions of re-use are poor
Raises complexity significantly
Unused => not working
![Page 23: What is good code?](https://reader036.fdocuments.net/reader036/viewer/2022062514/55b8ff9ebb61eb690d8b4720/html5/thumbnails/23.jpg)
©2010 Improving Enterprises, Inc.
Simple vs Clever
Over engineering
Mixing abstractions
Inappropriate patterns
Complicated syntax
![Page 24: What is good code?](https://reader036.fdocuments.net/reader036/viewer/2022062514/55b8ff9ebb61eb690d8b4720/html5/thumbnails/24.jpg)
©2010 Improving Enterprises, Inc.
Good CodeWhat, Why, and How to Get There
https://github.com/joshrizzo/ReadabilityJava/
Houston Java Group 2015
Jane Prusakova
Josh Rizzo
@Improving Enterprises College Station