Slide 1

Slide 1 text

Nullability — между добром и злом Тагир Валеев 1

Slide 2

Slide 2 text

2

Slide 3

Slide 3 text

Nullability — между добром и злом Тагир Валеев 3

Slide 4

Slide 4 text

4

Slide 5

Slide 5 text

5

Slide 6

Slide 6 text

6

Slide 7

Slide 7 text

7 http://geek-and-poke.com/

Slide 8

Slide 8 text

8

Slide 9

Slide 9 text

9

Slide 10

Slide 10 text

10

Slide 11

Slide 11 text

11

Slide 12

Slide 12 text

12

Slide 13

Slide 13 text

13

Slide 14

Slide 14 text

Динамическая типизация А нам особо-то без разницы http://www.fowllanguagecomics.com/ 14

Slide 15

Slide 15 text

Типизация Динамическая Статическая Явная Неявная Сильная Слабая 15

Slide 16

Slide 16 text

16

Slide 17

Slide 17 text

17

Slide 18

Slide 18 text

18

Slide 19

Slide 19 text

19

Slide 20

Slide 20 text

20

Slide 21

Slide 21 text

21

Slide 22

Slide 22 text

22

Slide 23

Slide 23 text

23

Slide 24

Slide 24 text

24

Slide 25

Slide 25 text

25

Slide 26

Slide 26 text

lan@box:/test$ gcc test.c -o test lan@box:/test$ ./test Segmentation fault (core dumped) lan@box:/test$ 26

Slide 27

Slide 27 text

§6.5.3.3 The unary * operator denotes indirection. If the operand points to a function, the result is a function designator; if it points to an object, the result is an lvalue designating the object. If the operand has type ‘‘pointer to type’’, the result has type ‘‘type’’. If an invalid value has been assigned to the pointer, the behavior of the unary * operator is undefined. 84) 84) ... Among the invalid values for dereferencing a pointer by the unary * operator are a null pointer, an address inappropriately aligned for the type of object pointed to, and the address of an object after the end of its lifetime. ISO/IEC 9899 International Standard – Programming Languages – C 27

Slide 28

Slide 28 text

§6.5.3.3 The unary * operator denotes indirection. If the operand points to a function, the result is a function designator; if it points to an object, the result is an lvalue designating the object. If the operand has type ‘‘pointer to type’’, the result has type ‘‘type’’. If an invalid value has been assigned to the pointer, the behavior of the unary * operator is undefined. 84) 84) ... Among the invalid values for dereferencing a pointer by the unary * operator are a null pointer, an address inappropriately aligned for the type of object pointed to, and the address of an object after the end of its lifetime. ISO/IEC 9899 International Standard – Programming Languages – C 28

Slide 29

Slide 29 text

29 lan@box:/test$ clang-3.5 –O3 test.c -o test lan@box:/test$ ./test 0 lan@box:/test$

Slide 30

Slide 30 text

http://copy1cat.deviantart.com/art/lol-i-dunno-base-255335342 30

Slide 31

Slide 31 text

31

Slide 32

Slide 32 text

I call it my billion-dollar mistake. It was the invention of the null reference in 1965. At that time, I was designing the first comprehensive type system for references in an object oriented language (ALGOL W). My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years. Tony Hoare, 2009 32

Slide 33

Slide 33 text

33

Slide 34

Slide 34 text

34

Slide 35

Slide 35 text

35

Slide 36

Slide 36 text

36

Slide 37

Slide 37 text

37 http://geek-and-poke.com/

Slide 38

Slide 38 text

38

Slide 39

Slide 39 text

39

Slide 40

Slide 40 text

40

Slide 41

Slide 41 text

41

Slide 42

Slide 42 text

42

Slide 43

Slide 43 text

43

Slide 44

Slide 44 text

44

Slide 45

Slide 45 text

45

Slide 46

Slide 46 text

46

Slide 47

Slide 47 text

47

Slide 48

Slide 48 text

48

Slide 49

Slide 49 text

49

Slide 50

Slide 50 text

50

Slide 51

Slide 51 text

51

Slide 52

Slide 52 text

52

Slide 53

Slide 53 text

53

Slide 54

Slide 54 text

54

Slide 55

Slide 55 text

55

Slide 56

Slide 56 text

public class Person { private String name; private String surname; public Person(Company company) :name(""), surname("") { company.chief = this; } ... } 56

Slide 57

Slide 57 text

57 Вас здесь не стояло! Я вчера ещё занимала!

Slide 58

Slide 58 text

58

Slide 59

Slide 59 text

59

Slide 60

Slide 60 text

60

Slide 61

Slide 61 text

61

Slide 62

Slide 62 text

62

Slide 63

Slide 63 text

63

Slide 64

Slide 64 text

64

Slide 65

Slide 65 text

65

Slide 66

Slide 66 text

66

Slide 67

Slide 67 text

67

Slide 68

Slide 68 text

68

Slide 69

Slide 69 text

69

Slide 70

Slide 70 text

70

Slide 71

Slide 71 text

71

Slide 72

Slide 72 text

72

Slide 73

Slide 73 text

73

Slide 74

Slide 74 text

74

Slide 75

Slide 75 text

75

Slide 76

Slide 76 text

76

Slide 77

Slide 77 text

77

Slide 78

Slide 78 text

78

Slide 79

Slide 79 text

79

Slide 80

Slide 80 text

80

Slide 81

Slide 81 text

81

Slide 82

Slide 82 text

82

Slide 83

Slide 83 text

83

Slide 84

Slide 84 text

84

Slide 85

Slide 85 text

85

Slide 86

Slide 86 text

86

Slide 87

Slide 87 text

87

Slide 88

Slide 88 text

88

Slide 89

Slide 89 text

89

Slide 90

Slide 90 text

90

Slide 91

Slide 91 text

91

Slide 92

Slide 92 text

92

Slide 93

Slide 93 text

93

Slide 94

Slide 94 text

94

Slide 95

Slide 95 text

95

Slide 96

Slide 96 text

96

Slide 97

Slide 97 text

97

Slide 98

Slide 98 text

98

Slide 99

Slide 99 text

99

Slide 100

Slide 100 text

100

Slide 101

Slide 101 text

101

Slide 102

Slide 102 text

102

Slide 103

Slide 103 text

GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help Prelude> :l ParentChild.hs [1 of 1] Compiling ParentChild (ParentChild.hs, interpreted ) Ok, modules loaded: ParentChild. *ParentChild> (p, c) = create "Курица" "Яйцо" *ParentChild> p Parent named Курица *ParentChild> c Child named Яйцо *ParentChild> child p Child named Яйцо *ParentChild> parent c Parent named Курица *ParentChild> child (parent (child p)) Child named Яйцо 103

Slide 104

Slide 104 text

Выводы • Используйте статическую типизацию • Прорабатывайте систему типов • Используйте статический анализ • Верьте спецификации, а не реализации • Учитесь пользоваться и не пользоваться новыми API • Изучайте языки программирования • Расширяйте кругозор 104

Slide 105

Slide 105 text

https://twitter.com/tagir_valeev https://habrahabr.ru/users/lany https://github.com/amaembo [email protected] Спасибо за внимание — jetbrains.com 105