SlideShare uma empresa Scribd logo
1 de 78
Baixar para ler offline
The Art
of
Clean Code
The Basics
Our Goal: Preventing
This!
Yael Zaritsky-Peretz
Developer @ CI team @ Wix
Over
90 million
users
Wix
Over
1000
employees
~400
developers
First Feature - Product
First Feature - Code
public class MyConsole {
public static void go() throws IOException {
BufferedReader inputReader = new BufferedReader(new
InputStreamReader(System.in));
while (true) {
System.out.print("> ");
System.out.println(inputReader.readLine());
}
}
}
public class MyConsole {
public static void go() throws IOException {
BufferedReader inputReader = new BufferedReader(new
InputStreamReader(System.in));
while (true) {
System.out.print("> ");
System.out.println(inputReader.readLine());
}
}
}
public class MyConsole {
public static void go() throws IOException {
BufferedReader inputReader = new BufferedReader(new
InputStreamReader(System.in));
while (true) {
System.out.print("> ");
System.out.println(inputReader.readLine());
}
}
}
Second Feature - Product
public static void go() throws IOException {
BufferedReader inputReader =
new BufferedReader(new InputStreamReader(System.in));
while (true) {
System.out.println("Please enter one of ... sum / copycat");
String input = inputReader.readLine();
if ("copycat".equals(input)) {
System.out.print(">");
System.out.println(inputReader.readLine());
}
public static void go() throws IOException {
BufferedReader inputReader =
new BufferedReader(new InputStreamReader(System.in));
while (true) {
System.out.println("Please enter one of ... sum / copycat");
String input = inputReader.readLine();
if ("copycat".equals(input)) {
System.out.print(">");
System.out.println(inputReader.readLine());
}
Second Feature - Code
else if ("sum".equals(input)) {
System.out.println("Enter numbers to sum...");
String nToSIn = inputReader.readLine();
String[] nToS = nToSIn.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < numbersToSum.length; i++) {
str += nToS[i] + ", ";
sum += Integer.parseInt(nToS[0]);
}
str = str.substring(0, str.length() - 2);
str += "is " + sum;
System.out.println(str);
}…}
else if ("sum".equals(input)) {
System.out.println("Enter numbers to sum...");
String nToSIn = inputReader.readLine();
String[] nToS = nToSIn.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < numbersToSum.length; i++) {
str += nToS[i] + ", ";
sum += Integer.parseInt(nToS[0]);
}
str = str.substring(0, str.length() - 2);
str += "is " + sum;
System.out.println(str);
}…}
else if ("sum".equals(input)) {
System.out.println("Enter numbers to sum...");
String nToSIn = inputReader.readLine();
String[] nToS = nToSIn.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < numbersToSum.length; i++) {
str += nToS[i] + ", ";
sum += Integer.parseInt(nToS[0]);
}
str = str.substring(0, str.length() - 2);
str += "is " + sum;
System.out.println(str);
}…}
else if ("sum".equals(input)) {
System.out.println("Enter numbers to sum...");
String nToSIn = inputReader.readLine();
String[] nToS = nToSIn.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < numbersToSum.length; i++) {
str += nToS[i] + ", ";
sum += Integer.parseInt(nToS[0]);
}
str = str.substring(0, str.length() - 2);
str += "is " + sum;
System.out.println(str);
}…}
else if ("sum".equals(input)) {
System.out.println("Enter numbers to sum...");
String nToSIn = inputReader.readLine();
String[] nToS = nToSIn.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < numbersToSum.length; i++) {
str += nToS[i] + ", ";
sum += Integer.parseInt(nToS[0]);
}
str = str.substring(0, str.length() - 2);
str += "is " + sum;
System.out.println(str);
}…}
else if ("sum".equals(input)) {
System.out.println("Enter numbers to sum...");
String nToSIn = inputReader.readLine();
String[] nToS = nToSIn.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < numbersToSum.length; i++) {
str += nToS[i] + ", ";
sum += Integer.parseInt(nToS[0]);
}
str = str.substring(0, str.length() - 2);
str += "is " + sum;
System.out.println(str);
}…}
else if ("sum".equals(input)) {
System.out.println("Enter numbers to sum...");
String nToSIn = inputReader.readLine();
String[] nToS = nToSIn.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < numbersToSum.length; i++) {
str += nToS[i] + ", ";
sum += Integer.parseInt(nToS[0]);
}
str = str.substring(0, str.length() - 2);
str += "is " + sum;
System.out.println(str);
}…}
public static void go() throws IOException {
BufferedReader inputReader =
new BufferedReader(new InputStreamReader(System.in));
while (true) {
System.out.println("Please enter one of … sum/copycat");
String input = inputReader.readLine();
if ("copycat".equals(input)) {
// print a line from the user
System.out.print(">");
System.out.println(inputReader.readLine());
}
else if ("sum".equals(input)) {
// read numbers separated by space and print their sum
System.out.println("Enter numbers to sum...");
String nToSIn = inputReader.readLine();
String[] nToS = nToSIn.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < numbersToSum.length; i++) {
str += nToS[i] + ", ";
sum += Integer.parseInt(nToS[0]);
}
str = str.substring(0, str.length() - 2);
str += "is " + sum;
System.out.println(str);
}
}
}
Agenda
● What is Clean Code?
● Example
● Some Basic Rules
● Culture
What is Clean
Code?
KISS
KISS
Test Coverage
public class NumberTest {
@Test
public void testMultiplyByTwo() {
assertThat(Number.multiplyByTwo(2),is(4));
}
}
public class Number {
public static int multiplyByTwo(int number) {
return number;
}
}
public class NumberTest {
@Test
public void testMultiplyByTwo() {
assertThat(Number.multiplyByTwo(2),is(4));
}
}
public class Number {
public static int multiplyByTwo(int number) {
return number;
}
}
public class NumberTest {
@Test
public void testMultiplyByTwo() {
assertThat(Number.multiplyByTwo(2),is(4));
}
}
public class Number {
public static int multiplyByTwo(int number) {
return number;
}
}
public class NumberTest {
@Test
public void testMultiplyByTwo() {
assertThat(Number.multiplyByTwo(2),is(4));
}
}
public class Number {
public static int multiplyByTwo(int number) {
return number * 2;
}
}
public class NumberTest {
@Test
public void testMultiplyByTwo() {
assertThat(Number.multiplyByTwo(2),is(4));
}
}
public class Number {
public static int multiplyByTwo(int number) {
return number * 2;
}
}
Test Coverage
Example
public static void go() throws IOException {
BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in));
while (true) {
System.out.println("Please enter one of the following actions: sum / copycat");
String input = inputReader.readLine();
if ("copycat".equals(input)) {
System.out.print(">");
System.out.println(inputReader.readLine());
} else if ("sum".equals(input)) {
System.out.println("Enter numbers to sum, separated by space. For example: '233 67 8 456086'");
String nToSIn = inputReader.readLine();
String[] nToS = nToSIn.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < nToS.length; i++) {
str += nToS[i] + ", ";
sum += Integer.parseInt(nToS[0]);
}
str = str.substring(0, str.length() - 2);
str += "is " + sum;
System.out.println(str);
}
}
}
public static void go() throws IOException {
BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in));
while (true) {
System.out.println("Please enter one of the following actions: sum / copycat");
String input = inputReader.readLine();
if ("copycat".equals(input)) {
System.out.print(">");
System.out.println(inputReader.readLine());
} else if ("sum".equals(input)) {
System.out.println("Enter numbers to sum, separated by space. For example: '233 67 8 456086'");
String nToSIn = inputReader.readLine();
String[] nToS = nToSIn.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < nToS.length; i++) {
str += nToS[i] + ", ";
sum += Integer.parseInt(nToS[0]);
}
str = str.substring(0, str.length() - 2);
str += "is " + sum;
System.out.println(str);
}
}
}
public static void go() throws IOException {
BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in));
while (true) {
System.out.println("Please enter one of the following actions: sum / copycat");
String input = inputReader.readLine();
if ("copycat".equals(input)) {
// print a line from the user
System.out.print(">");
System.out.println(inputReader.readLine());
} else if ("sum".equals(input)) {
// read numbers separated by space and print their sum
System.out.println("Enter numbers to sum, separated by space. For example: '233 67 8 456086'");
String nToSIn = inputReader.readLine();
String[] nToS = nToSIn.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < nToS.length; i++) {
str += nToS[i] + ", ";
sum += Integer.parseInt(nToS[0]);
}
str = str.substring(0, str.length() - 2);
str += "is " + sum;
System.out.println(str);
}
}
}
BUG found
TDD
Test Driven Design
else if ("sum".equals(input)) {
// read numbers separated by space and print their sum
System.out.println("Enter numbers to sum...");
String nToSIn = inputReader.readLine();
String[] nToS = nToSIn.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < nToS.length; i++) {
str += nToS[i] + ", ";
sum += Integer.parseInt(nToS[0]);
}
str = str.substring(0, str.length() - 2);
str += "is " + sum;
System.out.println(str);
}
Make sure that func("3 3") returns "Sum of 3, 3 is 6"
else if ("sum".equals(input)) {
// read numbers separated by space and print their sum
System.out.println("Enter numbers to sum...");
String nToSIn = inputReader.readLine();
String[] nToS = nToSIn.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < nToS.length; i++) {
str += nToS[i] + ", ";
sum += Integer.parseInt(nToS[0]);
}
str = str.substring(0, str.length() - 2);
str += "is " + sum;
System.out.println(str);
}
else if ("sum".equals(input)) {
// read numbers separated by space and print their sum
System.out.println("Enter numbers to sum...");
String nToSIn = inputReader.readLine();
String str = NumbersToSum.getOutputString(nToSIn);
System.out.println(str);
}
public class NumbersToSum {
public static String getOutputString(String … nToSIn) {
String[] nToS = nToSIn.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < nToS.length; i++) {
str += nToS[i] + ", ";
sum += Integer.parseInt(nToS[0]);
}
str = str.substring(0, str.length() - 2);
str += "is " + sum;
return str;
}}
else if ("sum".equals(input)) {
System.out.println("Enter numbers to sum...");
String nToSIn = inputReader.readLine();
String str = NumbersToSum.getOutputString(nToSIn);
System.out.println(str);
}
@Test
public void testGetOutputStringForSingleNumber() {
assertThat(NumbersToSum.getOutputString("3 3"),
is("Sum of 3, 3 is 6"));
}
public class NumbersToSum {
public static String getOutputString(String … nToSIn) {
String[] nToS = nToSIn.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < nToS.length; i++) {
str += nToS[i] + ", ";
sum += Integer.parseInt(nToS[0]);
}
str = str.substring(0, str.length() - 2);
str += "is " + sum;
return str;
}
}
public class NumbersToSum {
public static String getOutputString(String … nToSIn) {
String[] nToS = nToSIn.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < nToS.length; i++) {
str += nToS[i] + ", ";
sum += Integer.parseInt(nToS[0]);
}
str = str.substring(0, str.length() - 2);
str += " is " + sum;
return str;
}
}
BUG FIXED ! ! ! Test is GREEN
public class NumbersToSum {
public static String getOutputString(String … nToSIn) {
String[] nToS = nToSIn.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < nToS.length; i++) {
str += nToS[i] + ", ";
sum += Integer.parseInt(nToS[0]);
}
str = str.substring(0, str.length() - 2);
str += " is " + sum;
return str;
}
}
else if ("sum".equals(input)) {
System.out.println("Enter numbers to sum...");
String nToSIn = inputReader.readLine();
String str = NumbersToSum.getOutputString(nToSIn);
System.out.println(str);
}
else if ("sum".equals(input)) {
System.out.println("Enter numbers to sum...");
String numbersToSumInput = inputReader.readLine();
String str = NumbersToSum.getOutputString(numbersToSumInput);
System.out.println(str);
}
else if ("sum".equals(input)) {
System.out.println("Enter numbers to sum...");
String numbersToSumInput = inputReader.readLine();
String str = NumbersToSum.getOutputString(numbersToSumInput);
System.out.println(str);
}
public class NumbersToSum {
public static String getOutputString(String … nToSIn) {
String[] nToS = nToSIn.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < nToS.length; i++) {
str += nToS[i] + ", ";
sum += Integer.parseInt(nToS[0]);
}
str = str.substring(0, str.length() - 2);
str += " is " + sum;
return str;
}
}
public class NumbersToSum {
public static String getOutputString(String … numbersToSumInput) {
String[] nToS = numbersToSumInput.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < nToS.length; i++) {
str += nToS[i] + ", ";
sum += Integer.parseInt(nToS[0]);
}
str = str.substring(0, str.length() - 2);
str += " is " + sum;
return str;
}
}
public class NumbersToSum {
public static String getOutputString(String … numbersToSumInput) {
String[] nToS = numbersToSumInput.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < nToS.length; i++) {
str += nToS[i] + ", ";
sum += Integer.parseInt(nToS[0]);
}
str = str.substring(0, str.length() - 2);
str += " is " + sum;
return str;
}
}
public class NumbersToSum {
public static String getOutputString(String … numbersToSumInput) {
String[] numbersToSum = numbersToSumInput.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < numbersToSum.length; i++) {
str += numbersToSum[i] + ", ";
sum += Integer.parseInt(numbersToSum[0]);
}
str = str.substring(0, str.length() - 2);
str += " is " + sum;
return str;
}
}
public class NumbersToSum {
public static String getOutputString(String … numbersToSumInput) {
String[] numbersToSum = numbersToSumInput.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < numbersToSum.length; i++) {
str += numbersToSum[i] + ", ";
sum += Integer.parseInt(numbersToSum[0]);
}
str = str.substring(0, str.length() - 2);
str += " is " + sum;
return str;
}
}
Another BUG found
public class NumbersToSum {
public static String getOutputString(String … numbersToSumInput) {
String[] numbersToSum = numbersToSumInput.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < numbersToSum.length; i++) {
str += numbersToSum[i] + ", ";
sum += Integer.parseInt(numbersToSum[0]);
}
str = str.substring(0, str.length() - 2);
str += " is " + sum;
return str;
}
}
@Test
public void testGetOutputString() {
assertThat(NumbersToSumPrinter.getOutputString("3 231"),
is("Sum of 3, 231 is 234"));
}
@Test
public void testSumOfMoreThanOneNumber() {
assertThat(NumbersToSum.sum(3, 231),
is(234));
}
public class NumbersToSum {
public static String getOutputString(String … numbersToSumInput) {
String[] numbersToSum = numbersToSumInput.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < numbersToSum.length; i++) {
str += numbersToSum[i] + ", ";
sum += Integer.parseInt(numbersToSum[0]);
}
str = str.substring(0, str.length() - 2);
str += " is " + sum;
return str;
}
}
public class NumbersToSumPrinter {
public static String getOutputString(String numbersToSumInput) {
String[] numbersToSum = numbersToSumInput.split(" ");
String str = "Sum of ";
for (int i = 0; i < numbersToSum.length; i++) {
str += numbersToSum[i] + ", ";
}
str = str.substring(0, str.length() - 2);
int sum = NumbersToSum.sum(intArrayFromStrings(numbersToSum));
str += " is " + sum;
return str;
}
}
public class NumbersToSumPrinter {
public static String getOutputString(String numbersToSumInput) {
String[] numbersToSum = numbersToSumInput.split(" ");
String str = "Sum of ";
for (int i = 0; i < numbersToSum.length; i++) {
str += numbersToSum[i] + ", ";
}
str = str.substring(0, str.length() - 2);
int sum = NumbersToSum.sum(intArrayFromStrings(numbersToSum));
str += " is " + sum;
return str;
}
}
public class NumbersToSum {
public static int sum(int ... numbersToSum) {
int sum = 0;
for (int i = 0; i < numbersToSum.length; i++) {
sum += numbersToSum[0];
}
return sum;
}
}
public class NumbersToSum {
public static int sum(int ... numbersToSum) {
int sum = 0;
for (int i = 0; i < numbersToSum.length; i++) {
sum += numbersToSum[0];
}
return sum;
}
}
public class NumbersToSum {
public static int sum(int ... numbersToSum) {
int sum = 0;
for (int i = 0; i < numbersToSum.length; i++) {
sum += numbersToSum[i];
}
return sum;
}
}
BUG FIXED ! ! ! Test is GREEN
Reminder
public static void go() throws IOException {
BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in));
while (true) {
System.out.println("Please enter one of the following actions: sum / copycat");
String input = inputReader.readLine();
if ("copycat".equals(input)) {
// print a line from the user
System.out.print(">");
System.out.println(inputReader.readLine());
} else if ("sum".equals(input)) {
// read numbers separated by space and print their sum
System.out.println("Enter numbers to sum ...");
String nToSIn = inputReader.readLine();
String[] nToS = nToSIn.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < nToS.length; i++) {
str += nToS[i] + ", ";
sum += Integer.parseInt(nToS[0]);
}
str = str.substring(0, str.length() - 2);
str += "is " + sum;
System.out.println(str);
}
}
}
public class MyConsole {
public void go() throws IOException {
BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in));
while (true) {
System.out.println("Please enter one … sum / copycat");
String input = inputReader.readLine();
if ("copycat".equals(input)) {
// print a line from the user
System.out.print(">");
System.out.println(inputReader.readLine());
} else if ("sum".equals(input)) {
// read numbers separated by space and print their sum
System.out.println("Enter numbers to sum ...");
String numbersToSumInput = inputReader.readLine();
String str = NumbersToSumPrinter.getOutputString(numbersToSumInput);
System.out.println(str);
}
}
}
}
public class MyConsole {
public void go() throws IOException {
BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in));
while (true) {
System.out.println("Please enter one … sum / copycat");
String input = inputReader.readLine();
if ("copycat".equals(input)) {
// print a line from the user
System.out.print(">");
System.out.println(inputReader.readLine());
} else if ("sum".equals(input)) {
// read numbers separated by space and print their sum
System.out.println("Enter numbers to sum ...");
String numbersToSumInput = inputReader.readLine();
String str = NumbersToSumPrinter.getOutputString(numbersToSumInput);
System.out.println(str);
}
}
}
}
public class MyConsole {
public void go() throws IOException {
BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in));
while (true) {
System.out.println("Please enter one … sum / copycat");
String input = inputReader.readLine();
if ("copycat".equals(input)) {
// print a line from the user
System.out.print(">");
System.out.println(inputReader.readLine());
} else if ("sum".equals(input)) {
// read numbers separated by space and print their sum
System.out.println("Enter numbers to sum ...");
String numbersToSumInput = inputReader.readLine();
String str = NumbersToSumPrinter.getOutputString(numbersToSumInput);
System.out.println(str);
}
}
}
}
public class MyConsole {
public void go() throws IOException {
BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in));
while (true) {
System.out.println("Please enter one … sum / copycat");
String input = inputReader.readLine();
if ("copycat".equals(input)) {
// print a line from the user
System.out.print(">");
System.out.println(inputReader.readLine());
} else if ("sum".equals(input)) {
// read numbers separated by space and print their sum
System.out.println("Enter numbers to sum ...");
String numbersToSumInput = inputReader.readLine();
String str = NumbersToSumPrinter.getOutputString(numbersToSumInput);
System.out.println(str);
}
}
}
}
public class MyConsole {
public void go() throws IOException {
BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in));
while (true) {
System.out.println("Please enter one of the following actions: sum / copycat");
String input = inputReader.readLine();
if ("copycat".equals(input)) {
waitForInputAndCopy(inputReader);
} else if ("sum".equals(input)) {
// read numbers separated by space and print their sum
System.out.println("Enter numbers to sum ...");
String numbersToSumInput = inputReader.readLine();
String str = NumbersToSumPrinter.getOutputString(numbersToSumInput);
System.out.println(str);
}
}
}
private void waitForInputAndCopy(BufferedReader inputReader) throws IOException {
System.out.print(">");
System.out.println(inputReader.readLine());
}
}
public class MyConsole {
public void go() throws IOException {
BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in));
while (true) {
System.out.println("Please enter one of the following actions: sum / copycat");
String input = inputReader.readLine();
if ("copycat".equals(input)) {
waitForInputAndCopy(inputReader);
} else if ("sum".equals(input)) {
waitForInputAndSumNumbers(inputReader);
}
}
}
private void waitForInputAndSumNumbers(BufferedReader inputReader) throws IOException {
System.out.println("Enter numbers to sum, separated by space. For example: '233 67 8 456086'");
String numbersToSumInput = inputReader.readLine();
String str = NumbersToSumPrinter.getOutputString(numbersToSumInput);
System.out.println(str);
}
private void waitForInputAndCopy(BufferedReader inputReader) throws IOException {
System.out.print(">");
System.out.println(inputReader.readLine());
}
}
Some Basic
Rules
Use Pronounceable, Meaningful Names
String numbersToSumInput = inputReader.readLine();
String[] nToS = numbersToSumInput.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < nToS.length; i++) {
str += nToS[i] + ", ";
sum += Integer.parseInt(nToS[0]);
}
vs.
String numbersToSumInput = inputReader.readLine();
String[] numbersToSum = numbersToSumInput.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < numbersToSum.length; i++) {
str += numbersToSum[i] + ", ";
sum += Integer.parseInt(numbersToSum[0]);
}
Do Only One Thing
FUNCTIONS / CLASSES / MODULES SHOULD DO ONE THING.
THEY SHOULD DO IT WELL.
THEY SHOULD DO IT ONLY.
while (true) {
System.out.println("Please enter one … sum / copycat");
String input = inputReader.readLine();
if ("copycat".equals(input)) {
System.out.print(">");
System.out.println(inputReader.readLine());
} else if ("sum".equals(input)) {
System.out.println("Enter numbers to sum ...");
String numbersToSumInput = inputReader.readLine();
String str = NumbersToSumPrinter.getOutputString(numbersToSumInput);
System.out.println(str);
}
}
No Need for Comments
Formatting
public class NumbersToSum {
public static String getOutputString(String … numbersToSumInput) {
String[] numbersToSum = numbersToSumInput.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < numbersToSum.length; i++) {
str += numbersToSum[i] + ", ";
sum += Integer.parseInt(numbersToSum[0]);
}
str = str.substring(0, str.length() - 2);
str += " is " + sum;
return str;
}
}
public class NumbersToSum {
public static String getOutputString(String … numbersToSumInput) {
String[] numbersToSum = numbersToSumInput.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < numbersToSum.length; i++) {
str += numbersToSum[i] + ", ";
sum += Integer.parseInt(numbersToSum[0]);
}
str = str.substring(0, str.length() - 2);
str += " is " + sum;
return str;
}
}
public class NumbersToSum {
public static String getOutputString(String … numbersToSumInput) {
String[] numbersToSum = numbersToSumInput.split(" ");
String str = "Sum of ";
int sum = 0;
for (int i = 0; i < numbersToSum.length; i++) {
str += numbersToSum[i] + ", ";
sum += Integer.parseInt(numbersToSum[0]);
}
str = str.substring(0, str.length() - 2);
str += " is " + sum;
return str;
}
}
DO NOT Treat Test Code Differently
Culture
Insights
● Reading Code is Hard
● Code Rots
Refactor Until Your Code is Clean
● Hard to Get Done Right on First Try
● Reading clean code should make you smile
the way a well-crafted music box or well-designed car would
Leave the Campground
Cleaner Than You’ve Found it
● Change one variable name for the better,
● Break up one function that’s a little too large,
● Eliminate one small bit of duplication
The cleanup doesn’t have to be something big:
No Ego
I’m here to learn
Smart Ass
(Don’t be one)
How YOU can take it from here
● Make it a priority
● It seems to take longer
● Read / see about it
● Talk to your peers
Questions?
Yael Zaritsky yaelzyaelz@wix.com
yaelzaritsky@gmail.com
Thank You
Yael Zaritsky yaelzyaelz@wix.com
yaelzaritsky@gmail.com
Sources
Clean Code (pdf)
GOOS style TDD by Example - Sagy Rozman
Cultural Learning of Testing - Gil Tayar
Finding Your Organization’s Code Deodorant - Ittai Zeidman
private static int[] intArrayFromStrings(String[] numbersToSum) {
int[] intArray = new int[numbersToSum.length];
for(int i=0 ; i<numbersToSum.length ; i++) {
intArray[i]=Integer.parseInt(numbersToSum[i]);
}
return intArray;
}
}

Mais conteúdo relacionado

Mais procurados

Application-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta LanguageApplication-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta LanguageESUG
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)gekiaruj
 
The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88Mahmoud Samir Fayed
 
Python3 cheatsheet
Python3 cheatsheetPython3 cheatsheet
Python3 cheatsheetGil Cohen
 
Some examples of the 64-bit code errors
Some examples of the 64-bit code errorsSome examples of the 64-bit code errors
Some examples of the 64-bit code errorsPVS-Studio
 
Cheat sheet python3
Cheat sheet python3Cheat sheet python3
Cheat sheet python3sxw2k
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語ikdysfm
 
Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge O T
 
Network security
Network securityNetwork security
Network securitybabyangle
 
MySQL 5.7 NF – JSON Datatype 활용
MySQL 5.7 NF – JSON Datatype 활용MySQL 5.7 NF – JSON Datatype 활용
MySQL 5.7 NF – JSON Datatype 활용I Goo Lee
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a ElixirSvet Ivantchev
 
The Ring programming language version 1.5.2 book - Part 45 of 181
The Ring programming language version 1.5.2 book - Part 45 of 181The Ring programming language version 1.5.2 book - Part 45 of 181
The Ring programming language version 1.5.2 book - Part 45 of 181Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184Mahmoud Samir Fayed
 
Python Programming: Data Structure
Python Programming: Data StructurePython Programming: Data Structure
Python Programming: Data StructureChan Shik Lim
 
Dive into EXPLAIN - PostgreSql
Dive into EXPLAIN  - PostgreSqlDive into EXPLAIN  - PostgreSql
Dive into EXPLAIN - PostgreSqlDmytro Shylovskyi
 

Mais procurados (20)

Application-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta LanguageApplication-Specific Models and Pointcuts using a Logic Meta Language
Application-Specific Models and Pointcuts using a Logic Meta Language
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
 
The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88The Ring programming language version 1.3 book - Part 83 of 88
The Ring programming language version 1.3 book - Part 83 of 88
 
Python3 cheatsheet
Python3 cheatsheetPython3 cheatsheet
Python3 cheatsheet
 
Some examples of the 64-bit code errors
Some examples of the 64-bit code errorsSome examples of the 64-bit code errors
Some examples of the 64-bit code errors
 
Python_ 3 CheatSheet
Python_ 3 CheatSheetPython_ 3 CheatSheet
Python_ 3 CheatSheet
 
Cheat sheet python3
Cheat sheet python3Cheat sheet python3
Cheat sheet python3
 
PDBC
PDBCPDBC
PDBC
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge
 
Network security
Network securityNetwork security
Network security
 
MySQL 5.7 NF – JSON Datatype 활용
MySQL 5.7 NF – JSON Datatype 활용MySQL 5.7 NF – JSON Datatype 활용
MySQL 5.7 NF – JSON Datatype 활용
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a Elixir
 
The Ring programming language version 1.5.2 book - Part 45 of 181
The Ring programming language version 1.5.2 book - Part 45 of 181The Ring programming language version 1.5.2 book - Part 45 of 181
The Ring programming language version 1.5.2 book - Part 45 of 181
 
Java Basics - Part1
Java Basics - Part1Java Basics - Part1
Java Basics - Part1
 
The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184
 
C programs
C programsC programs
C programs
 
Python Programming: Data Structure
Python Programming: Data StructurePython Programming: Data Structure
Python Programming: Data Structure
 
Mcq cpup
Mcq cpupMcq cpup
Mcq cpup
 
Dive into EXPLAIN - PostgreSql
Dive into EXPLAIN  - PostgreSqlDive into EXPLAIN  - PostgreSql
Dive into EXPLAIN - PostgreSql
 

Semelhante a The Art of Clean Code

Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptxKimVeeL
 
JAVA PRACTICE QUESTIONS v1.4.pdf
JAVA PRACTICE QUESTIONS v1.4.pdfJAVA PRACTICE QUESTIONS v1.4.pdf
JAVA PRACTICE QUESTIONS v1.4.pdfRohitkumarYadav80
 
Driver.java import java.util.Scanner; import java.text.Decimal.pdf
Driver.java import java.util.Scanner; import java.text.Decimal.pdfDriver.java import java.util.Scanner; import java.text.Decimal.pdf
Driver.java import java.util.Scanner; import java.text.Decimal.pdfanandhomeneeds
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple ProgramsUpender Upr
 
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdfJava AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdfeyewatchsystems
 
Deep dumpster diving 2010
Deep dumpster diving 2010Deep dumpster diving 2010
Deep dumpster diving 2010RonnBlack
 
import java.io.BufferedReader;import java.io.File;import java.io.pdf
import java.io.BufferedReader;import java.io.File;import java.io.pdfimport java.io.BufferedReader;import java.io.File;import java.io.pdf
import java.io.BufferedReader;import java.io.File;import java.io.pdfmanojmozy
 
Below is my code for a line editor import java.io.BufferedReader;.pdf
Below is my code for a line editor import java.io.BufferedReader;.pdfBelow is my code for a line editor import java.io.BufferedReader;.pdf
Below is my code for a line editor import java.io.BufferedReader;.pdfalankarshoe84
 
import java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdfimport java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdfstopgolook
 
Hi, Please find my codeimport java.util.Random;public class Pro.pdf
Hi, Please find my codeimport java.util.Random;public class Pro.pdfHi, Please find my codeimport java.util.Random;public class Pro.pdf
Hi, Please find my codeimport java.util.Random;public class Pro.pdfanujsharmaanuj14
 
Example of JAVA Program
Example of JAVA ProgramExample of JAVA Program
Example of JAVA ProgramTrenton Asbury
 
Code javascript
Code javascriptCode javascript
Code javascriptRay Ray
 

Semelhante a The Art of Clean Code (20)

Java file
Java fileJava file
Java file
 
Java file
Java fileJava file
Java file
 
Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
 
Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptx
 
JAVA PRACTICE QUESTIONS v1.4.pdf
JAVA PRACTICE QUESTIONS v1.4.pdfJAVA PRACTICE QUESTIONS v1.4.pdf
JAVA PRACTICE QUESTIONS v1.4.pdf
 
Driver.java import java.util.Scanner; import java.text.Decimal.pdf
Driver.java import java.util.Scanner; import java.text.Decimal.pdfDriver.java import java.util.Scanner; import java.text.Decimal.pdf
Driver.java import java.util.Scanner; import java.text.Decimal.pdf
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
 
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdfJava AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
 
Studyx4
Studyx4Studyx4
Studyx4
 
Deep dumpster diving 2010
Deep dumpster diving 2010Deep dumpster diving 2010
Deep dumpster diving 2010
 
import java.io.BufferedReader;import java.io.File;import java.io.pdf
import java.io.BufferedReader;import java.io.File;import java.io.pdfimport java.io.BufferedReader;import java.io.File;import java.io.pdf
import java.io.BufferedReader;import java.io.File;import java.io.pdf
 
Ann
AnnAnn
Ann
 
Utility.ppt
Utility.pptUtility.ppt
Utility.ppt
 
Below is my code for a line editor import java.io.BufferedReader;.pdf
Below is my code for a line editor import java.io.BufferedReader;.pdfBelow is my code for a line editor import java.io.BufferedReader;.pdf
Below is my code for a line editor import java.io.BufferedReader;.pdf
 
import java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdfimport java.util.Scanner;public class Main {private static i.pdf
import java.util.Scanner;public class Main {private static i.pdf
 
Hi, Please find my codeimport java.util.Random;public class Pro.pdf
Hi, Please find my codeimport java.util.Random;public class Pro.pdfHi, Please find my codeimport java.util.Random;public class Pro.pdf
Hi, Please find my codeimport java.util.Random;public class Pro.pdf
 
Example of JAVA Program
Example of JAVA ProgramExample of JAVA Program
Example of JAVA Program
 
Los dskn
Los dsknLos dskn
Los dskn
 
Code javascript
Code javascriptCode javascript
Code javascript
 

Último

8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024VictoriaMetrics
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Hararemasabamasaba
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 

Último (20)

8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 

The Art of Clean Code

  • 2.
  • 6.
  • 7. First Feature - Product
  • 8. First Feature - Code public class MyConsole { public static void go() throws IOException { BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); while (true) { System.out.print("> "); System.out.println(inputReader.readLine()); } } } public class MyConsole { public static void go() throws IOException { BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); while (true) { System.out.print("> "); System.out.println(inputReader.readLine()); } } } public class MyConsole { public static void go() throws IOException { BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); while (true) { System.out.print("> "); System.out.println(inputReader.readLine()); } } }
  • 10. public static void go() throws IOException { BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); while (true) { System.out.println("Please enter one of ... sum / copycat"); String input = inputReader.readLine(); if ("copycat".equals(input)) { System.out.print(">"); System.out.println(inputReader.readLine()); } public static void go() throws IOException { BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); while (true) { System.out.println("Please enter one of ... sum / copycat"); String input = inputReader.readLine(); if ("copycat".equals(input)) { System.out.print(">"); System.out.println(inputReader.readLine()); } Second Feature - Code else if ("sum".equals(input)) { System.out.println("Enter numbers to sum..."); String nToSIn = inputReader.readLine(); String[] nToS = nToSIn.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < numbersToSum.length; i++) { str += nToS[i] + ", "; sum += Integer.parseInt(nToS[0]); } str = str.substring(0, str.length() - 2); str += "is " + sum; System.out.println(str); }…} else if ("sum".equals(input)) { System.out.println("Enter numbers to sum..."); String nToSIn = inputReader.readLine(); String[] nToS = nToSIn.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < numbersToSum.length; i++) { str += nToS[i] + ", "; sum += Integer.parseInt(nToS[0]); } str = str.substring(0, str.length() - 2); str += "is " + sum; System.out.println(str); }…} else if ("sum".equals(input)) { System.out.println("Enter numbers to sum..."); String nToSIn = inputReader.readLine(); String[] nToS = nToSIn.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < numbersToSum.length; i++) { str += nToS[i] + ", "; sum += Integer.parseInt(nToS[0]); } str = str.substring(0, str.length() - 2); str += "is " + sum; System.out.println(str); }…} else if ("sum".equals(input)) { System.out.println("Enter numbers to sum..."); String nToSIn = inputReader.readLine(); String[] nToS = nToSIn.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < numbersToSum.length; i++) { str += nToS[i] + ", "; sum += Integer.parseInt(nToS[0]); } str = str.substring(0, str.length() - 2); str += "is " + sum; System.out.println(str); }…} else if ("sum".equals(input)) { System.out.println("Enter numbers to sum..."); String nToSIn = inputReader.readLine(); String[] nToS = nToSIn.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < numbersToSum.length; i++) { str += nToS[i] + ", "; sum += Integer.parseInt(nToS[0]); } str = str.substring(0, str.length() - 2); str += "is " + sum; System.out.println(str); }…} else if ("sum".equals(input)) { System.out.println("Enter numbers to sum..."); String nToSIn = inputReader.readLine(); String[] nToS = nToSIn.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < numbersToSum.length; i++) { str += nToS[i] + ", "; sum += Integer.parseInt(nToS[0]); } str = str.substring(0, str.length() - 2); str += "is " + sum; System.out.println(str); }…} else if ("sum".equals(input)) { System.out.println("Enter numbers to sum..."); String nToSIn = inputReader.readLine(); String[] nToS = nToSIn.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < numbersToSum.length; i++) { str += nToS[i] + ", "; sum += Integer.parseInt(nToS[0]); } str = str.substring(0, str.length() - 2); str += "is " + sum; System.out.println(str); }…}
  • 11. public static void go() throws IOException { BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); while (true) { System.out.println("Please enter one of … sum/copycat"); String input = inputReader.readLine(); if ("copycat".equals(input)) { // print a line from the user System.out.print(">"); System.out.println(inputReader.readLine()); } else if ("sum".equals(input)) { // read numbers separated by space and print their sum System.out.println("Enter numbers to sum..."); String nToSIn = inputReader.readLine(); String[] nToS = nToSIn.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < numbersToSum.length; i++) { str += nToS[i] + ", "; sum += Integer.parseInt(nToS[0]); } str = str.substring(0, str.length() - 2); str += "is " + sum; System.out.println(str); } } }
  • 12.
  • 13.
  • 14. Agenda ● What is Clean Code? ● Example ● Some Basic Rules ● Culture
  • 16. KISS
  • 17. KISS
  • 19. public class NumberTest { @Test public void testMultiplyByTwo() { assertThat(Number.multiplyByTwo(2),is(4)); } } public class Number { public static int multiplyByTwo(int number) { return number; } } public class NumberTest { @Test public void testMultiplyByTwo() { assertThat(Number.multiplyByTwo(2),is(4)); } } public class Number { public static int multiplyByTwo(int number) { return number; } } public class NumberTest { @Test public void testMultiplyByTwo() { assertThat(Number.multiplyByTwo(2),is(4)); } } public class Number { public static int multiplyByTwo(int number) { return number; } }
  • 20. public class NumberTest { @Test public void testMultiplyByTwo() { assertThat(Number.multiplyByTwo(2),is(4)); } } public class Number { public static int multiplyByTwo(int number) { return number * 2; } } public class NumberTest { @Test public void testMultiplyByTwo() { assertThat(Number.multiplyByTwo(2),is(4)); } } public class Number { public static int multiplyByTwo(int number) { return number * 2; } }
  • 23. public static void go() throws IOException { BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); while (true) { System.out.println("Please enter one of the following actions: sum / copycat"); String input = inputReader.readLine(); if ("copycat".equals(input)) { System.out.print(">"); System.out.println(inputReader.readLine()); } else if ("sum".equals(input)) { System.out.println("Enter numbers to sum, separated by space. For example: '233 67 8 456086'"); String nToSIn = inputReader.readLine(); String[] nToS = nToSIn.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < nToS.length; i++) { str += nToS[i] + ", "; sum += Integer.parseInt(nToS[0]); } str = str.substring(0, str.length() - 2); str += "is " + sum; System.out.println(str); } } } public static void go() throws IOException { BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); while (true) { System.out.println("Please enter one of the following actions: sum / copycat"); String input = inputReader.readLine(); if ("copycat".equals(input)) { System.out.print(">"); System.out.println(inputReader.readLine()); } else if ("sum".equals(input)) { System.out.println("Enter numbers to sum, separated by space. For example: '233 67 8 456086'"); String nToSIn = inputReader.readLine(); String[] nToS = nToSIn.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < nToS.length; i++) { str += nToS[i] + ", "; sum += Integer.parseInt(nToS[0]); } str = str.substring(0, str.length() - 2); str += "is " + sum; System.out.println(str); } } } public static void go() throws IOException { BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); while (true) { System.out.println("Please enter one of the following actions: sum / copycat"); String input = inputReader.readLine(); if ("copycat".equals(input)) { // print a line from the user System.out.print(">"); System.out.println(inputReader.readLine()); } else if ("sum".equals(input)) { // read numbers separated by space and print their sum System.out.println("Enter numbers to sum, separated by space. For example: '233 67 8 456086'"); String nToSIn = inputReader.readLine(); String[] nToS = nToSIn.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < nToS.length; i++) { str += nToS[i] + ", "; sum += Integer.parseInt(nToS[0]); } str = str.substring(0, str.length() - 2); str += "is " + sum; System.out.println(str); } } }
  • 25.
  • 26.
  • 28. else if ("sum".equals(input)) { // read numbers separated by space and print their sum System.out.println("Enter numbers to sum..."); String nToSIn = inputReader.readLine(); String[] nToS = nToSIn.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < nToS.length; i++) { str += nToS[i] + ", "; sum += Integer.parseInt(nToS[0]); } str = str.substring(0, str.length() - 2); str += "is " + sum; System.out.println(str); }
  • 29. Make sure that func("3 3") returns "Sum of 3, 3 is 6"
  • 30. else if ("sum".equals(input)) { // read numbers separated by space and print their sum System.out.println("Enter numbers to sum..."); String nToSIn = inputReader.readLine(); String[] nToS = nToSIn.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < nToS.length; i++) { str += nToS[i] + ", "; sum += Integer.parseInt(nToS[0]); } str = str.substring(0, str.length() - 2); str += "is " + sum; System.out.println(str); } else if ("sum".equals(input)) { // read numbers separated by space and print their sum System.out.println("Enter numbers to sum..."); String nToSIn = inputReader.readLine(); String str = NumbersToSum.getOutputString(nToSIn); System.out.println(str); }
  • 31. public class NumbersToSum { public static String getOutputString(String … nToSIn) { String[] nToS = nToSIn.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < nToS.length; i++) { str += nToS[i] + ", "; sum += Integer.parseInt(nToS[0]); } str = str.substring(0, str.length() - 2); str += "is " + sum; return str; }} else if ("sum".equals(input)) { System.out.println("Enter numbers to sum..."); String nToSIn = inputReader.readLine(); String str = NumbersToSum.getOutputString(nToSIn); System.out.println(str); }
  • 32. @Test public void testGetOutputStringForSingleNumber() { assertThat(NumbersToSum.getOutputString("3 3"), is("Sum of 3, 3 is 6")); }
  • 33.
  • 34. public class NumbersToSum { public static String getOutputString(String … nToSIn) { String[] nToS = nToSIn.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < nToS.length; i++) { str += nToS[i] + ", "; sum += Integer.parseInt(nToS[0]); } str = str.substring(0, str.length() - 2); str += "is " + sum; return str; } } public class NumbersToSum { public static String getOutputString(String … nToSIn) { String[] nToS = nToSIn.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < nToS.length; i++) { str += nToS[i] + ", "; sum += Integer.parseInt(nToS[0]); } str = str.substring(0, str.length() - 2); str += " is " + sum; return str; } }
  • 35.
  • 36.
  • 37. BUG FIXED ! ! ! Test is GREEN
  • 38. public class NumbersToSum { public static String getOutputString(String … nToSIn) { String[] nToS = nToSIn.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < nToS.length; i++) { str += nToS[i] + ", "; sum += Integer.parseInt(nToS[0]); } str = str.substring(0, str.length() - 2); str += " is " + sum; return str; } } else if ("sum".equals(input)) { System.out.println("Enter numbers to sum..."); String nToSIn = inputReader.readLine(); String str = NumbersToSum.getOutputString(nToSIn); System.out.println(str); } else if ("sum".equals(input)) { System.out.println("Enter numbers to sum..."); String numbersToSumInput = inputReader.readLine(); String str = NumbersToSum.getOutputString(numbersToSumInput); System.out.println(str); } else if ("sum".equals(input)) { System.out.println("Enter numbers to sum..."); String numbersToSumInput = inputReader.readLine(); String str = NumbersToSum.getOutputString(numbersToSumInput); System.out.println(str); } public class NumbersToSum { public static String getOutputString(String … nToSIn) { String[] nToS = nToSIn.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < nToS.length; i++) { str += nToS[i] + ", "; sum += Integer.parseInt(nToS[0]); } str = str.substring(0, str.length() - 2); str += " is " + sum; return str; } } public class NumbersToSum { public static String getOutputString(String … numbersToSumInput) { String[] nToS = numbersToSumInput.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < nToS.length; i++) { str += nToS[i] + ", "; sum += Integer.parseInt(nToS[0]); } str = str.substring(0, str.length() - 2); str += " is " + sum; return str; } } public class NumbersToSum { public static String getOutputString(String … numbersToSumInput) { String[] nToS = numbersToSumInput.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < nToS.length; i++) { str += nToS[i] + ", "; sum += Integer.parseInt(nToS[0]); } str = str.substring(0, str.length() - 2); str += " is " + sum; return str; } } public class NumbersToSum { public static String getOutputString(String … numbersToSumInput) { String[] numbersToSum = numbersToSumInput.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < numbersToSum.length; i++) { str += numbersToSum[i] + ", "; sum += Integer.parseInt(numbersToSum[0]); } str = str.substring(0, str.length() - 2); str += " is " + sum; return str; } }
  • 39. public class NumbersToSum { public static String getOutputString(String … numbersToSumInput) { String[] numbersToSum = numbersToSumInput.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < numbersToSum.length; i++) { str += numbersToSum[i] + ", "; sum += Integer.parseInt(numbersToSum[0]); } str = str.substring(0, str.length() - 2); str += " is " + sum; return str; } }
  • 41.
  • 42. public class NumbersToSum { public static String getOutputString(String … numbersToSumInput) { String[] numbersToSum = numbersToSumInput.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < numbersToSum.length; i++) { str += numbersToSum[i] + ", "; sum += Integer.parseInt(numbersToSum[0]); } str = str.substring(0, str.length() - 2); str += " is " + sum; return str; } }
  • 43. @Test public void testGetOutputString() { assertThat(NumbersToSumPrinter.getOutputString("3 231"), is("Sum of 3, 231 is 234")); } @Test public void testSumOfMoreThanOneNumber() { assertThat(NumbersToSum.sum(3, 231), is(234)); }
  • 44. public class NumbersToSum { public static String getOutputString(String … numbersToSumInput) { String[] numbersToSum = numbersToSumInput.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < numbersToSum.length; i++) { str += numbersToSum[i] + ", "; sum += Integer.parseInt(numbersToSum[0]); } str = str.substring(0, str.length() - 2); str += " is " + sum; return str; } }
  • 45. public class NumbersToSumPrinter { public static String getOutputString(String numbersToSumInput) { String[] numbersToSum = numbersToSumInput.split(" "); String str = "Sum of "; for (int i = 0; i < numbersToSum.length; i++) { str += numbersToSum[i] + ", "; } str = str.substring(0, str.length() - 2); int sum = NumbersToSum.sum(intArrayFromStrings(numbersToSum)); str += " is " + sum; return str; } }
  • 46. public class NumbersToSumPrinter { public static String getOutputString(String numbersToSumInput) { String[] numbersToSum = numbersToSumInput.split(" "); String str = "Sum of "; for (int i = 0; i < numbersToSum.length; i++) { str += numbersToSum[i] + ", "; } str = str.substring(0, str.length() - 2); int sum = NumbersToSum.sum(intArrayFromStrings(numbersToSum)); str += " is " + sum; return str; } }
  • 47. public class NumbersToSum { public static int sum(int ... numbersToSum) { int sum = 0; for (int i = 0; i < numbersToSum.length; i++) { sum += numbersToSum[0]; } return sum; } }
  • 48.
  • 49. public class NumbersToSum { public static int sum(int ... numbersToSum) { int sum = 0; for (int i = 0; i < numbersToSum.length; i++) { sum += numbersToSum[0]; } return sum; } }
  • 50. public class NumbersToSum { public static int sum(int ... numbersToSum) { int sum = 0; for (int i = 0; i < numbersToSum.length; i++) { sum += numbersToSum[i]; } return sum; } }
  • 51.
  • 52. BUG FIXED ! ! ! Test is GREEN
  • 54. public static void go() throws IOException { BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); while (true) { System.out.println("Please enter one of the following actions: sum / copycat"); String input = inputReader.readLine(); if ("copycat".equals(input)) { // print a line from the user System.out.print(">"); System.out.println(inputReader.readLine()); } else if ("sum".equals(input)) { // read numbers separated by space and print their sum System.out.println("Enter numbers to sum ..."); String nToSIn = inputReader.readLine(); String[] nToS = nToSIn.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < nToS.length; i++) { str += nToS[i] + ", "; sum += Integer.parseInt(nToS[0]); } str = str.substring(0, str.length() - 2); str += "is " + sum; System.out.println(str); } } }
  • 55. public class MyConsole { public void go() throws IOException { BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); while (true) { System.out.println("Please enter one … sum / copycat"); String input = inputReader.readLine(); if ("copycat".equals(input)) { // print a line from the user System.out.print(">"); System.out.println(inputReader.readLine()); } else if ("sum".equals(input)) { // read numbers separated by space and print their sum System.out.println("Enter numbers to sum ..."); String numbersToSumInput = inputReader.readLine(); String str = NumbersToSumPrinter.getOutputString(numbersToSumInput); System.out.println(str); } } } }
  • 56. public class MyConsole { public void go() throws IOException { BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); while (true) { System.out.println("Please enter one … sum / copycat"); String input = inputReader.readLine(); if ("copycat".equals(input)) { // print a line from the user System.out.print(">"); System.out.println(inputReader.readLine()); } else if ("sum".equals(input)) { // read numbers separated by space and print their sum System.out.println("Enter numbers to sum ..."); String numbersToSumInput = inputReader.readLine(); String str = NumbersToSumPrinter.getOutputString(numbersToSumInput); System.out.println(str); } } } }
  • 57. public class MyConsole { public void go() throws IOException { BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); while (true) { System.out.println("Please enter one … sum / copycat"); String input = inputReader.readLine(); if ("copycat".equals(input)) { // print a line from the user System.out.print(">"); System.out.println(inputReader.readLine()); } else if ("sum".equals(input)) { // read numbers separated by space and print their sum System.out.println("Enter numbers to sum ..."); String numbersToSumInput = inputReader.readLine(); String str = NumbersToSumPrinter.getOutputString(numbersToSumInput); System.out.println(str); } } } } public class MyConsole { public void go() throws IOException { BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); while (true) { System.out.println("Please enter one … sum / copycat"); String input = inputReader.readLine(); if ("copycat".equals(input)) { // print a line from the user System.out.print(">"); System.out.println(inputReader.readLine()); } else if ("sum".equals(input)) { // read numbers separated by space and print their sum System.out.println("Enter numbers to sum ..."); String numbersToSumInput = inputReader.readLine(); String str = NumbersToSumPrinter.getOutputString(numbersToSumInput); System.out.println(str); } } } }
  • 58. public class MyConsole { public void go() throws IOException { BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); while (true) { System.out.println("Please enter one of the following actions: sum / copycat"); String input = inputReader.readLine(); if ("copycat".equals(input)) { waitForInputAndCopy(inputReader); } else if ("sum".equals(input)) { // read numbers separated by space and print their sum System.out.println("Enter numbers to sum ..."); String numbersToSumInput = inputReader.readLine(); String str = NumbersToSumPrinter.getOutputString(numbersToSumInput); System.out.println(str); } } } private void waitForInputAndCopy(BufferedReader inputReader) throws IOException { System.out.print(">"); System.out.println(inputReader.readLine()); } }
  • 59. public class MyConsole { public void go() throws IOException { BufferedReader inputReader = new BufferedReader(new InputStreamReader(System.in)); while (true) { System.out.println("Please enter one of the following actions: sum / copycat"); String input = inputReader.readLine(); if ("copycat".equals(input)) { waitForInputAndCopy(inputReader); } else if ("sum".equals(input)) { waitForInputAndSumNumbers(inputReader); } } } private void waitForInputAndSumNumbers(BufferedReader inputReader) throws IOException { System.out.println("Enter numbers to sum, separated by space. For example: '233 67 8 456086'"); String numbersToSumInput = inputReader.readLine(); String str = NumbersToSumPrinter.getOutputString(numbersToSumInput); System.out.println(str); } private void waitForInputAndCopy(BufferedReader inputReader) throws IOException { System.out.print(">"); System.out.println(inputReader.readLine()); } }
  • 61. Use Pronounceable, Meaningful Names String numbersToSumInput = inputReader.readLine(); String[] nToS = numbersToSumInput.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < nToS.length; i++) { str += nToS[i] + ", "; sum += Integer.parseInt(nToS[0]); } vs. String numbersToSumInput = inputReader.readLine(); String[] numbersToSum = numbersToSumInput.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < numbersToSum.length; i++) { str += numbersToSum[i] + ", "; sum += Integer.parseInt(numbersToSum[0]); }
  • 62. Do Only One Thing FUNCTIONS / CLASSES / MODULES SHOULD DO ONE THING. THEY SHOULD DO IT WELL. THEY SHOULD DO IT ONLY. while (true) { System.out.println("Please enter one … sum / copycat"); String input = inputReader.readLine(); if ("copycat".equals(input)) { System.out.print(">"); System.out.println(inputReader.readLine()); } else if ("sum".equals(input)) { System.out.println("Enter numbers to sum ..."); String numbersToSumInput = inputReader.readLine(); String str = NumbersToSumPrinter.getOutputString(numbersToSumInput); System.out.println(str); } }
  • 63. No Need for Comments
  • 64. Formatting public class NumbersToSum { public static String getOutputString(String … numbersToSumInput) { String[] numbersToSum = numbersToSumInput.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < numbersToSum.length; i++) { str += numbersToSum[i] + ", "; sum += Integer.parseInt(numbersToSum[0]); } str = str.substring(0, str.length() - 2); str += " is " + sum; return str; } } public class NumbersToSum { public static String getOutputString(String … numbersToSumInput) { String[] numbersToSum = numbersToSumInput.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < numbersToSum.length; i++) { str += numbersToSum[i] + ", "; sum += Integer.parseInt(numbersToSum[0]); } str = str.substring(0, str.length() - 2); str += " is " + sum; return str; } } public class NumbersToSum { public static String getOutputString(String … numbersToSumInput) { String[] numbersToSum = numbersToSumInput.split(" "); String str = "Sum of "; int sum = 0; for (int i = 0; i < numbersToSum.length; i++) { str += numbersToSum[i] + ", "; sum += Integer.parseInt(numbersToSum[0]); } str = str.substring(0, str.length() - 2); str += " is " + sum; return str; } }
  • 65. DO NOT Treat Test Code Differently
  • 67. Insights ● Reading Code is Hard ● Code Rots
  • 68. Refactor Until Your Code is Clean ● Hard to Get Done Right on First Try ● Reading clean code should make you smile the way a well-crafted music box or well-designed car would
  • 69. Leave the Campground Cleaner Than You’ve Found it
  • 70. ● Change one variable name for the better, ● Break up one function that’s a little too large, ● Eliminate one small bit of duplication The cleanup doesn’t have to be something big:
  • 71. No Ego I’m here to learn
  • 73. How YOU can take it from here ● Make it a priority ● It seems to take longer ● Read / see about it ● Talk to your peers
  • 76. Thank You Yael Zaritsky yaelzyaelz@wix.com yaelzaritsky@gmail.com
  • 77. Sources Clean Code (pdf) GOOS style TDD by Example - Sagy Rozman Cultural Learning of Testing - Gil Tayar Finding Your Organization’s Code Deodorant - Ittai Zeidman
  • 78. private static int[] intArrayFromStrings(String[] numbersToSum) { int[] intArray = new int[numbersToSum.length]; for(int i=0 ; i<numbersToSum.length ; i++) { intArray[i]=Integer.parseInt(numbersToSum[i]); } return intArray; } }