7. Why do we write bad code ??? Rush (duck tape programmer) Laziness Careless We don’t know how good code looks like Lack of resources We like to do new things (create)
8. „Its harder to read the code than to write it” Joel Spolsky
9. How to improve work quality ? Dont give developers money rewardsbigger reward == worse performance Let them work on what they like and how they like (Google, Atlassian, Facebook) Allow and encourage self improvement
16. Scala case class caseclass Person(name: String, age: Int) Dostajemy za darmo: equals(), hashCode() oraz toString() oraz niezmienną klasę (immutable).
17. To equal or not to equal ? Person p = new Person("Jan Kowalski", 30); Set<Person> set = new HashSet<Person>(); set.add(p); System.out.println(set.contains(p)); // true p.setAge(p.getAge()+1); System.out.println(set.contains(p)); // false ... WTF ???
18. To equal or not to equal ? Iterator<Person> it = set.iterator(); booleancontainedP = false; while (it.hasNext()) { Person nextP = it.next(); if (nextP.equals(p)) { containedP = true; break; } } System.out.println(containedP); // true // ... ???
19.
20. Java – working with Person Object x = new Person("Bill Clinton", 64); if(x instanceof Person) { Person p = (Person)x; System.out.println(„Person name: "+p.getName()); } else { System.out.println("Not a person"); } x = "Lukasz Kuczera"; if(x instanceof Person) { Person p = (Person)x; System.out.println("hello "+p.getName()); } elseif(x instanceof String) { String s = (String)x; if(s.equals("Bill Clinton")) System.out.println("Hello Bill"); else System.out.println("hello: "+s); } else System.out.println("err, ???");
21. Scala – Pattern Matching var x: Any = Person("Lukasz", 28); x match { case Person(name, age) => println("Person name: "+name); case _ => println("Not a person") } x = "Lukasz Kuczera" x match { case Person(name, age) => println("Person name: "+name) case"Bill Clinton" => println("hello Bill") case s: String => println("hello "+s) case _ => "err, ???" } Person name: Lukasz hello Lukasz Kuczera