Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

Привет!

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Божидар

Slide 6

Slide 6 text

@bbatsov

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Why am I here?

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

size=2 start=0 c=['Н', 'Н' ,'Н' ,'Н' ,'Н','Н','Н','Н','Н','Н','Н','Н','Н','Н'] code_dictionary=Array.new() begin_size_code_dictionary=Array.new() end_string=String.new() code_dictionary=c.uniq.to_a decode_dictionary=c.uniq.to_a for i in 0...code_dictionary.size begin_size_code_dictionary[i]=i end c.size.times{ if !code_dictionary.include?(c[start,size].to_s)#Comparation code_dictionary.push(c[start,size].to_s.chomp) start=start+(code_dictionary.last.size)/2-1 size=2 else size+=1; end } end_code=Array.new(code_dictionary.size) for i in begin_size_code_dictionary.size...code_dictionary.size end_code[i]=code_dictionary.index(code_dictionary[i].chop.chop)+1 end_string+=code_dictionary[i].chop.chop end govnokod.ru

Slide 13

Slide 13 text

The Elements of Style in Programming by Bozhidar Batsov

Slide 14

Slide 14 text

Languages are hard

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

Basic usage of a language is easy

Slide 17

Slide 17 text

Айн-цу-цвайн-цу-дрън

Slide 18

Slide 18 text

"Ту партс, съмтаймс люн, съмтаймс уин, соу, фърст дей релякс"

Slide 19

Slide 19 text

The correct usage of a language is hard

Slide 20

Slide 20 text

The effective usage of a language is very hard

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

Българската политика е лайно в целофан.

Slide 23

Slide 23 text

На малко прасе и нов началник никога не се радвам.

Slide 24

Slide 24 text

Всичко хубаво в тая държава сме го направили ние, те не могат да го боядисат - от метрото до Северната дъга, Тракия, Марица, Струма…

Slide 25

Slide 25 text

Живков и царя са ми като два университета. В една тема и двамата бяха много единни, че България и държавата са над всичко.

Slide 26

Slide 26 text

Да мачкаш Цветанов е все едно с голо дупе таралеж да мачкаш.

Slide 27

Slide 27 text

not really

Slide 28

Slide 28 text

try 10 years

Slide 29

Slide 29 text

http://norvig.com/21-days.html Teach Yourself Programming in Ten Years Peter Norvig

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

Laziness is a virtue

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

Use the active voice.

Slide 34

Slide 34 text

My first visit to Pernik will always be remembered by me. lame

Slide 35

Slide 35 text

I shall always remember my first visit to Pernik. legit

Slide 36

Slide 36 text

The word personally is often unnecessary.

Slide 37

Slide 37 text

Personally, I love Emacs.

Slide 38

Slide 38 text

A Style Guide • a curated set of (supposedly) good practices • spares you the process of making trivial decisions • allows you to focus on the actual problems • simple and concise

Slide 39

Slide 39 text

Style guides aren’t a replacement for thinking

Slide 40

Slide 40 text

Programs must be written for people to read, and only incidentally for machines to execute. — Hal Abelson

Slide 41

Slide 41 text

Similar rules apply to natural and programming languages

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

English

Slide 44

Slide 44 text

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Chapter I

Slide 45

Slide 45 text

LOREM IPSUM DOLOR SIT AMET, CONSECTETUR ADIPISCING ELIT, SED DO EIUSMOD TEMPOR INCIDIDUNT UT LABORE ET DOLORE MAGNA ALIQUA. UT ENIM AD MINIM VENIAM, QUIS NOSTRUD EXERCITATION ULLAMCO LABORIS NISI UT ALIQUIP EX EA COMMODO CONSEQUAT. DUIS AUTE IRURE DOLOR IN REPREHENDERIT IN VOLUPTATE VELIT ESSE CILLUM DOLORE EU FUGIAT NULLA PARIATUR. EXCEPTEUR SINT OCCAECAT CUPIDATAT NON PROIDENT, SUNT IN CULPA QUI OFFICIA DESERUNT MOLLIT ANIM ID EST LABORUM. LOREM IPSUM DOLOR SIT AMET, CONSECTETUR ADIPISCING ELIT, SED DO EIUSMOD TEMPOR INCIDIDUNT UT LABORE ET DOLORE MAGNA ALIQUA. UT ENIM AD MINIM VENIAM, QUIS NOSTRUD EXERCITATION ULLAMCO LABORIS NISI UT ALIQUIP EX EA COMMODO CONSEQUAT. DUIS AUTE IRURE DOLOR IN REPREHENDERIT IN VOLUPTATE VELIT ESSE CILLUM DOLORE EU FUGIAT NULLA PARIATUR. EXCEPTEUR SINT OCCAECAT CUPIDATAT NON PROIDENT, SUNT IN CULPA QUI OFFICIA DESERUNT MOLLIT ANIM ID EST LABORUM. chapter i

Slide 46

Slide 46 text

Български

Slide 47

Slide 47 text

Правителство трябва да има на всяка цена, каза премиерът проф. Георги Близнашки пред журналисти в Котел, където беше по повод Деня на будителите. "Силно се надявам, че в следващите няколко дни, особено след като бъде връчен проучвателен мандат, разговорите ще придобият по-спокоен тон и ще се стигне до съставяне на правителство", заяви министър- председателят, цитиран от правителствената информационна служба. Той прогнозира тежки първи месеци за следващия кабинет, който трябва да предприеме неотложни и "не особено популярни мерки". Близнашки изрази надежда, че след това нещата ще тръгнат във възходяща линия, благодарение на финансовия ресурс, предвиден за страната ни по Споразумението за партньорство на ЕК с България до 2020 година. Глава 1

Slide 48

Slide 48 text

ПРАВИТЕЛСТВО ТРЯБВА ДА ИМА НА ВСЯКА ЦЕНА, КАЗА ПРЕМИЕРЪТ ПРОФ. ГЕОРГИ БЛИЗНАШКИ ПРЕД ЖУРНАЛИСТИ В КОТЕЛ, КЪДЕТО БЕШЕ ПО ПОВОД ДЕНЯ НА БУДИТЕЛИТЕ. "СИЛНО СЕ НАДЯВАМ, ЧЕ В СЛЕДВАЩИТЕ НЯКОЛКО ДНИ, ОСОБЕНО СЛЕД КАТО БЪДЕ ВРЪЧЕН ПРОУЧВАТЕЛЕН МАНДАТ, РАЗГОВОРИТЕ ЩЕ ПРИДОБИЯТ ПО-СПОКОЕН ТОН И ЩЕ СЕ СТИГНЕ ДО СЪСТАВЯНЕ НА ПРАВИТЕЛСТВО", ЗАЯВИ МИНИСТЪР-ПРЕДСЕДАТЕЛЯТ, ЦИТИРАН ОТ ПРАВИТЕЛСТВЕНАТА ИНФОРМАЦИОННА СЛУЖБА. гЛаВа 1 ТОЙ ПРОГНОЗИРА ТЕЖКИ ПЪРВИ МЕСЕЦИ ЗА СЛЕДВАЩИЯ КАБИНЕТ, КОЙТО ТРЯБВА ДА ПРЕДПРИЕМЕ НЕОТЛОЖНИ И "НЕ ОСОБЕНО ПОПУЛЯРНИ МЕРКИ". БЛИЗНАШКИ ИЗРАЗИ НАДЕЖДА, ЧЕ СЛЕД ТОВА НЕЩАТА ЩЕ ТРЪГНАТ ВЪВ ВЪЗХОДЯЩА ЛИНИЯ, БЛАГОДАРЕНИЕ НА ФИНАНСОВИЯ РЕСУРС, ПРЕДВИДЕН ЗА СТРАНАТА НИ ПО СПОРАЗУМЕНИЕТО ЗА ПАРТНЬОРСТВО НА ЕК С БЪЛГАРИЯ ДО 2020 ГОДИНА.

Slide 49

Slide 49 text

Ruby

Slide 50

Slide 50 text

def some_method do_something do_more do_more end

Slide 51

Slide 51 text

def some_method do_something do_more do_more end

Slide 52

Slide 52 text

sum = 1 + 2 a, b = 1, 2 [1, 2, 3].each { |e| puts e } class FooError < StandardError; end

Slide 53

Slide 53 text

sum=1+2 a,b=1,2 [1,2,3].each{|e|puts e} class FooError

Slide 54

Slide 54 text

Elementary Rules of Usage

Slide 55

Slide 55 text

English

Slide 56

Slide 56 text

Form possessive singular of nouns by adding ’s.

Slide 57

Slide 57 text

Bozhidar’s talk Batman’s batclaw Emacs’s magic

Slide 58

Slide 58 text

Ruby

Slide 59

Slide 59 text

Form predicate method names by adding “?”.

Slide 60

Slide 60 text

even? completed? batman?

Slide 61

Slide 61 text

No content

Slide 62

Slide 62 text

Elementary Principles of Composition

Slide 63

Slide 63 text

English

Slide 64

Slide 64 text

Make the paragraph the unit of composition.

Slide 65

Slide 65 text

Ruby

Slide 66

Slide 66 text

Make the method the unit of composition.

Slide 67

Slide 67 text

English

Slide 68

Slide 68 text

Omit needless words.

Slide 69

Slide 69 text

he is a man who

Slide 70

Slide 70 text

Her story is a strange one.

Slide 71

Slide 71 text

Ruby

Slide 72

Slide 72 text

Omit needless words.

Slide 73

Slide 73 text

if some_condition then # body omitted end

Slide 74

Slide 74 text

def some_method # ... return result end

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

Words and Expressions Commonly Misused

Slide 77

Slide 77 text

English

Slide 78

Slide 78 text

farther further

Slide 79

Slide 79 text

Do we have to go much farther?

Slide 80

Slide 80 text

I decided to pursue the subject further.

Slide 81

Slide 81 text

Ruby

Slide 82

Slide 82 text

== === equal? eql?

Slide 83

Slide 83 text

No content

Slide 84

Slide 84 text

An Approach to Style

Slide 85

Slide 85 text

Be consistent

Slide 86

Slide 86 text

English

Slide 87

Slide 87 text

The user should update his config accordingly. They should also check…

Slide 88

Slide 88 text

The user should update his config accordingly. They should also check…

Slide 89

Slide 89 text

Ruby

Slide 90

Slide 90 text

def something coll coll.collect(&:ala) end def something2(coll) coll.map { |x| x.bala } end

Slide 91

Slide 91 text

Be clear

Slide 92

Slide 92 text

Български

Slide 93

Slide 93 text

БМВ

Slide 94

Slide 94 text

Бързо мощно возило

Slide 95

Slide 95 text

КТБ

Slide 96

Slide 96 text

Коварен Терански Батълкруузър

Slide 97

Slide 97 text

АБПФК

Slide 98

Slide 98 text

Активен борец против фашизма и капитализма

Slide 99

Slide 99 text

Ruby

Slide 100

Slide 100 text

$:

Slide 101

Slide 101 text

$LOAD_PATH

Slide 102

Slide 102 text

$;

Slide 103

Slide 103 text

$FIELD_SEPARATOR

Slide 104

Slide 104 text

$*

Slide 105

Slide 105 text

$ARGV

Slide 106

Slide 106 text

'%d %d' % [20, 10]

Slide 107

Slide 107 text

sprintf('%d %d', 20, 10)

Slide 108

Slide 108 text

sprintf( '%{first} %{second}', first: 20, second: 10 )

Slide 109

Slide 109 text

format('%{first} %{second}', first: 20, second: 10)

Slide 110

Slide 110 text

Ruby is optimized for programmer happiness

Slide 111

Slide 111 text

Ruby is a huge language

Slide 112

Slide 112 text

Making the “right” decisions is hard

Slide 113

Slide 113 text

No content

Slide 114

Slide 114 text

puts "Hello, HackConf!" puts "Hello, HackConf!" puts "Hello, HackConf!”

Slide 115

Slide 115 text

for i in 1..3 puts "Hello, HackConf!” end

Slide 116

Slide 116 text

3.times do puts "Hello, HackConf!” end

Slide 117

Slide 117 text

result = [] names.each do |word| result << name.upcase end

Slide 118

Slide 118 text

names.map { |name| name.upcase }

Slide 119

Slide 119 text

names.map(&:upcase)

Slide 120

Slide 120 text

names.map(_1.upcase)

Slide 121

Slide 121 text

No content

Slide 122

Slide 122 text

No content

Slide 123

Slide 123 text

Are all those options even worth our while?

Slide 124

Slide 124 text

No content

Slide 125

Slide 125 text

No content

Slide 126

Slide 126 text

No content

Slide 127

Slide 127 text

56 simple rules

Slide 128

Slide 128 text

Format a program to help the reader understand it.

Slide 129

Slide 129 text

Write clearly -- don't be too clever.

Slide 130

Slide 130 text

def user_signed_in? !!@current_user end def user_signed_in? !@current_user.nil? end

Slide 131

Slide 131 text

Don't sacrifice clarity for small gains in efficiency.

Slide 132

Slide 132 text

i = 1 res = 0 while i <= 10 res += i i += 1 end

Slide 133

Slide 133 text

(1..10).reduce(:+)

Slide 134

Slide 134 text

(N * (N + 1)) / 2

Slide 135

Slide 135 text

(10 * (10 + 1)) / 2

Slide 136

Slide 136 text

Don't diddle code to make it faster -- find a better algorithm.

Slide 137

Slide 137 text

•Make it right before you make it faster. •Make it fail-safe before you make it faster. •Make it clear before you make it faster.

Slide 138

Slide 138 text

Instrument your programs. Measure before making efficiency changes.

Slide 139

Slide 139 text

Use variable names that mean something.

Slide 140

Slide 140 text

a s l

Slide 141

Slide 141 text

age sex location

Slide 142

Slide 142 text

age_over_18?

Slide 143

Slide 143 text

adult?

Slide 144

Slide 144 text

Don’t repeat yourself.

Slide 145

Slide 145 text

Parenthesize to avoid ambiguity.

Slide 146

Slide 146 text

x || y && z

Slide 147

Slide 147 text

x || (y && z)

Slide 148

Slide 148 text

Keep the code & its comments in sync.

Slide 149

Slide 149 text

# This method does bla bla bla. # It returns an array of results. def bla_bla_bla res = Set.new # ... res end

Slide 150

Slide 150 text

bla_bla_bla[0] # => Boom Boom Pow bla_bla_bla.uniq # => Kaboom!

Slide 151

Slide 151 text

//private instance variable for storing age public static int age;

Slide 152

Slide 152 text

//private instance variable for storing age public static int age;

Slide 153

Slide 153 text

//private instance variable for storing age public static int age;

Slide 154

Slide 154 text

No content

Slide 155

Slide 155 text

Don’t repeat the code in the comments.

Slide 156

Slide 156 text

# increment counter by 1 counter += 1

Slide 157

Slide 157 text

Don’t comment shitty code — fix it.

Slide 158

Slide 158 text

// // Dear maintainer: // // Once you are done trying to 'optimize' this routine, // and have realized what a terrible mistake that was, // please increment the following counter as a warning // to the next guy: // // total_hours_wasted_here = 42 //

Slide 159

Slide 159 text

Fuck this shit!!!

Slide 160

Slide 160 text

No content

Slide 161

Slide 161 text

Style guides for programming languages

Slide 162

Slide 162 text

Python

Slide 163

Slide 163 text

PEP-8 http://legacy.python.org/dev/peps/pep-0008/

Slide 164

Slide 164 text

Java

Slide 165

Slide 165 text

Sun Style Guide http://www.oracle.com/technetwork/java/codeconvtoc-136057.html

Slide 166

Slide 166 text

Google Style Guide https://google-styleguide.googlecode.com/svn/trunk/javaguide.html

Slide 167

Slide 167 text

Go

Slide 168

Slide 168 text

Effective Go https://golang.org/doc/effective_go.html

Slide 169

Slide 169 text

gofmt

Slide 170

Slide 170 text

No content

Slide 171

Slide 171 text

StandardJS https://standardjs.com/

Slide 172

Slide 172 text

No content

Slide 173

Slide 173 text

PHP FIG Coding Style Guide http://www.php-fig.org/psr/psr-1/ http://www.php-fig.org/psr/psr-2/

Slide 174

Slide 174 text

No content

Slide 175

Slide 175 text

Ruby Style Guide https://rubystyle.guide

Slide 176

Slide 176 text

No content

Slide 177

Slide 177 text

Clojure Style Guide https://guide.clojure.style

Slide 178

Slide 178 text

Languages are always evolving

Slide 179

Slide 179 text

Good style practices are evolving as well

Slide 180

Slide 180 text

{ :batman => 'Bruce', :superman => 'Clark', :zorro => 'Diego', :catwoman => 'Selina' }

Slide 181

Slide 181 text

{ batman: 'Bruce', superman: 'Clark', zorro: 'Diego', catwoman: 'Selina' }

Slide 182

Slide 182 text

Style consistency is of paramount importance

Slide 183

Slide 183 text

Community Personal Project Company

Slide 184

Slide 184 text

Community Project Company

Slide 185

Slide 185 text

Style separates the good from the great

Slide 186

Slide 186 text

Felina

Slide 187

Slide 187 text

One more thing…

Slide 188

Slide 188 text

No content