Slide 1

Slide 1 text

Ruby: The Bad Parts narrated by Bozhidar I. Batsov

Slide 2

Slide 2 text

Вiтаю!

Slide 3

Slide 3 text

Доброго ранку!

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

I love Ruby

Slide 6

Slide 6 text

I’m an Emacs zealot

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

bbatsov

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

(think) http://batsov.com

Slide 11

Slide 11 text

Emacs Redux http://emacsredux.com

Slide 12

Slide 12 text

@bbatsov

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

github.com/ bbatsov

Slide 18

Slide 18 text

I’m a mythbuster!

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

The Myth

Slide 22

Slide 22 text

Ruby is perfect!

Slide 23

Slide 23 text

The harsh truth

Slide 24

Slide 24 text

No, it’s not!

Slide 25

Slide 25 text

No programming language is perfect

Slide 26

Slide 26 text

(not even Clojure)

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

The problems

Slide 29

Slide 29 text

Ruby is object- oriented

Slide 30

Slide 30 text

Ruby is dynamically typed

Slide 31

Slide 31 text

Ruby doesn’t have immutable data structures

Slide 32

Slide 32 text

Ruby doesn’t have strong concurrency primitives

Slide 33

Slide 33 text

Ruby doesn’t have enough parentheses

Slide 34

Slide 34 text

Ruby is not Clojure!

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

The REAL problems

Slide 37

Slide 37 text

Problems with the runtime

Slide 38

Slide 38 text

Ruby is slow wrong

Slide 39

Slide 39 text

MRI is slow indeed

Slide 40

Slide 40 text

Ruby’s threads suck wrong

Slide 41

Slide 41 text

MRI’s threads suck indeed

Slide 42

Slide 42 text

Running Ruby on Windows is a pain in the ass wrong

Slide 43

Slide 43 text

Running MRI on Windows is a pain in the ass indeed

Slide 44

Slide 44 text

Ruby doesn’t do JIT compilation wrong

Slide 45

Slide 45 text

MRI doesn’t do JIT compilation indeed

Slide 46

Slide 46 text

The core library is not very approachable for Rubyists

Slide 47

Slide 47 text

Array#compact! static VALUE rb_ary_compact_bang(VALUE ary) { VALUE *p, *t, *end; long n; rb_ary_modify(ary); p = t = (VALUE *)RARRAY_CONST_PTR(ary); /* WB: no new reference */ end = p + RARRAY_LEN(ary); while (t < end) { if (NIL_P(*t)) t++; else *p++ = *t++; } n = p - RARRAY_CONST_PTR(ary); if (RARRAY_LEN(ary) == n) { return Qnil; } ary_resize_smaller(ary, n); return ary; } lame

Slide 48

Slide 48 text

Array#compact! def compact! Rubinius.check_frozen if (deleted = @tuple.delete(@start, @total, nil)) > 0 @total -= deleted reallocate_shrink() return self else return nil end end Rubinius

Slide 49

Slide 49 text

Even Java got this right!

Slide 50

Slide 50 text

Language != Runtime

Slide 51

Slide 51 text

We need a better “standard” runtime

Slide 52

Slide 52 text

Rubygems & Bundler

Slide 53

Slide 53 text

bundle exec rake

Slide 54

Slide 54 text

RubyGems 2.2 introduced support for Gemfile

Slide 55

Slide 55 text

gem bundle

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

The Rails Effect

Slide 58

Slide 58 text

Ruby (2005)

Slide 59

Slide 59 text

No content

Slide 60

Slide 60 text

Ruby (2006)

Slide 61

Slide 61 text

OMG, Rails is amazing!

Slide 62

Slide 62 text

Ruby (2008)

Slide 63

Slide 63 text

OMG, Rails is amazing & useful!

Slide 64

Slide 64 text

Ruby (today)

Slide 65

Slide 65 text

4% 96% Web Development Other

Slide 66

Slide 66 text

10% 90% Rails Other

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

Ruby 2.2 includes many new features and improvements for the increasingly diverse and expanding demands for Ruby. For example, Ruby’s Garbage Collector is now able to collect Symbol type objects. This reduces memory usage of Symbols; because GC was previously unable to collect them before 2.2. Since Rails 5.0 will require Symbol GC, it will support only Ruby 2.2 or later. (See Rails 4.2 release post for details.) Also, a reduced pause time thanks to the new Incremental Garbage Collector will be helpful for running Rails applications. Recent developments mentioned on the Rails blog suggest that Rails 5.0 will take advantage of Incremental GC as well as Symbol GC.

Slide 69

Slide 69 text

Ruby 2.2 includes many new features and improvements for the increasingly diverse and expanding demands for Ruby. For example, Ruby’s Garbage Collector is now able to collect Symbol type objects. This reduces memory usage of Symbols; because GC was previously unable to collect them before 2.2. Since Rails 5.0 will require Symbol GC, it will support only Ruby 2.2 or later. (See Rails 4.2 release post for details.) Also, a reduced pause time thanks to the new Incremental Garbage Collector will be helpful for running Rails applications. Recent developments mentioned on the Rails blog suggest that Rails 5.0 will take advantage of Incremental GC as well as Symbol GC.

Slide 70

Slide 70 text

Ruby 2.2 includes many new features and improvements for the increasingly diverse and expanding demands for Ruby. For example, Ruby’s Garbage Collector is now able to collect Symbol type objects. This reduces memory usage of Symbols; because GC was previously unable to collect them before 2.2. Since Rails 5.0 will require Symbol GC, it will support only Ruby 2.2 or later. (See Rails 4.2 release post for details.) Also, a reduced pause time thanks to the new Incremental Garbage Collector will be helpful for running Rails applications. Recent developments mentioned on the Rails blog suggest that Rails 5.0 will take advantage of Incremental GC as well as Symbol GC.

Slide 71

Slide 71 text

Ruby 2.2 includes many new features and improvements for the increasingly diverse and expanding demands for Ruby. For example, Ruby’s Garbage Collector is now able to collect Symbol type objects. This reduces memory usage of Symbols; because GC was previously unable to collect them before 2.2. Since Rails 5.0 will require Symbol GC, it will support only Ruby 2.2 or later. (See Rails 4.2 release post for details.) Also, a reduced pause time thanks to the new Incremental Garbage Collector will be helpful for running Rails applications. Recent developments mentioned on the Rails blog suggest that Rails 5.0 will take advantage of Incremental GC as well as Symbol GC.

Slide 72

Slide 72 text

Ruby 2.2 includes many new features and improvements for the increasingly diverse and expanding demands for Ruby. For example, Ruby’s Garbage Collector is now able to collect Symbol type objects. This reduces memory usage of Symbols; because GC was previously unable to collect them before 2.2. Since Rails 5.0 will require Symbol GC, it will support only Ruby 2.2 or later. (See Rails 4.2 release post for details.) Also, a reduced pause time thanks to the new Incremental Garbage Collector will be helpful for running Rails applications. Recent developments mentioned on the Rails blog suggest that Rails 5.0 will take advantage of Incremental GC as well as Symbol GC.

Slide 73

Slide 73 text

Ruby 2.2 includes many new features and improvements for the increasingly diverse and expanding demands for Ruby. For example, Ruby’s Garbage Collector is now able to collect Symbol type objects. This reduces memory usage of Symbols; because GC was previously unable to collect them before 2.2. Since Rails 5.0 will require Symbol GC, it will support only Ruby 2.2 or later. (See Rails 4.2 release post for details.) Also, a reduced pause time thanks to the new Incremental Garbage Collector will be helpful for running Rails applications. Recent developments mentioned on the Rails blog suggest that Rails 5.0 will take advantage of Incremental GC as well as Symbol GC.

Slide 74

Slide 74 text

Fuck this shit!!!

Slide 75

Slide 75 text

We need grow out of Rails’s shadow!

Slide 76

Slide 76 text

Problems with the community

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

–George S. Patton “If everyone is thinking alike, then somebody isn’t thinking.”

Slide 79

Slide 79 text

Stewardship

Slide 80

Slide 80 text

Benevolent dictators are still dictators

Slide 81

Slide 81 text

No clear vision

Slide 82

Slide 82 text

No standard

Slide 83

Slide 83 text

Informal deprecation policy

Slide 84

Slide 84 text

Limited collaboration with alternative implementations

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

There’s nothing notable here!

Slide 87

Slide 87 text

Where’s the innovation?

Slide 88

Slide 88 text

rubydramas.com

Slide 89

Slide 89 text

rubydrama.com

Slide 90

Slide 90 text

Problems with the language

Slide 91

Slide 91 text

The useless stuff

Slide 92

Slide 92 text

No content

Slide 93

Slide 93 text

for loops

Slide 94

Slide 94 text

for name in names puts name end

Slide 95

Slide 95 text

names.each do |name| puts name end

Slide 96

Slide 96 text

BEGIN & END

Slide 97

Slide 97 text

END { puts 'Bye!' } puts 'Processing...' BEGIN { puts 'Starting...' }

Slide 98

Slide 98 text

puts 'Bye!' puts 'Starting...' puts 'Processing...'

Slide 99

Slide 99 text

Kernel#at_exit, anyone?

Slide 100

Slide 100 text

flip-flops

Slide 101

Slide 101 text

DATA.each_line do |line| print(line) if (line =~ /begin/)..(line =~ /end/) end

Slide 102

Slide 102 text

–Matz “Under the current plan, I am not going to remove flip-flop from 2.0, since we are not going to made incompatible changes anytime soon. We have to wait until 3.0.” https://bugs.ruby-lang.org/issues/5400

Slide 103

Slide 103 text

block comments

Slide 104

Slide 104 text

=begin comment line another comment line =end

Slide 105

Slide 105 text

Must be placed at the very beginning of a line

Slide 106

Slide 106 text

class SomeClass =begin This is a top comment. Or is it? =end def some_method end end

Slide 107

Slide 107 text

class SomeClass =begin This is a top comment. Or is it? =end def some_method end end

Slide 108

Slide 108 text

Character literals

Slide 109

Slide 109 text

pry(main)> ?a => "a"

Slide 110

Slide 110 text

The redundant stuff

Slide 111

Slide 111 text

There’s more than one way to do it

Slide 112

Slide 112 text

(There are way too many ways to do it)

Slide 113

Slide 113 text

core lib aliases

Slide 114

Slide 114 text

collect => map inject => reduce detect => find select => find_all sprintf => format length => size raise => fail

Slide 115

Slide 115 text

Where the f*ck is filter?

Slide 116

Slide 116 text

procs

Slide 117

Slide 117 text

Proc.new or Kernel#proc

Slide 118

Slide 118 text

No arity check

Slide 119

Slide 119 text

Non-local return

Slide 120

Slide 120 text

Do we really need them?

Slide 121

Slide 121 text

So many languages are getting by just fine with only lambdas…

Slide 122

Slide 122 text

Single-quoted string literals

Slide 123

Slide 123 text

No content

Slide 124

Slide 124 text

A ton of obscure %- something literals

Slide 125

Slide 125 text

%s, %x, %w, %W, %r, %q, %Q, %, %i

Slide 126

Slide 126 text

Two types of block syntax

Slide 127

Slide 127 text

3.times { puts "Hello!" }

Slide 128

Slide 128 text

3.times do puts "Hello!" end

Slide 129

Slide 129 text

So excited to be here!

Slide 130

Slide 130 text

puts "Hello, Kiev!" puts "Hello, Kiev!" puts "Hello, Kiev!"

Slide 131

Slide 131 text

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

Slide 132

Slide 132 text

3.times { puts "Hello, Kiev!" }

Slide 133

Slide 133 text

3.times do puts "Hello, Kiev!" end

Slide 134

Slide 134 text

3.times do puts %(Hello, Kiev!) end

Slide 135

Slide 135 text

3.times do puts %Q(Hello, Kiev!) end

Slide 136

Slide 136 text

3.times do puts 'Hello, Kiev!' end

Slide 137

Slide 137 text

3.times do puts %q(Hello, Kiev!) end

Slide 138

Slide 138 text

result = [] for name in names result << name.upcase end

Slide 139

Slide 139 text

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

Slide 140

Slide 140 text

names.collect { |name| name.upcase }

Slide 141

Slide 141 text

names.collect(&:upcase)

Slide 142

Slide 142 text

names.map(&:upcase)

Slide 143

Slide 143 text

No content

Slide 144

Slide 144 text

Are all those options worth our while?

Slide 145

Slide 145 text

No content

Slide 146

Slide 146 text

The bad stuff

Slide 147

Slide 147 text

So many nils floating around

Slide 148

Slide 148 text

pry(main)> "TOP".upcase => "TOP" pry(main)> "TOP".upcase! => nil

Slide 149

Slide 149 text

autoload (deprecated & scheduled for removal in 3.0)

Slide 150

Slide 150 text

and, or, not

Slide 151

Slide 151 text

Those are not flow of control operators!

Slide 152

Slide 152 text

and & or have the same precedence

Slide 153

Slide 153 text

Mutable strings

Slide 154

Slide 154 text

Even JavaScript got this right…

Slide 155

Slide 155 text

Reassignable constants

Slide 156

Slide 156 text

pry(main)> A = 5 => 5 pry(main)> A = 6 (pry):39: warning: already initialized constant A (pry):38: warning: previous definition of A was here => 6 pry(main)> Class = 3 (pry):40: warning: already initialized constant Class => 3 pry(main)> Class => 3

Slide 157

Slide 157 text

Class variables

Slide 158

Slide 158 text

class Parent @@class_var = 'parent' def self.print_class_var puts @@class_var end end class Child < Parent @@class_var = 'child' end Parent.print_class_var # => will print "child"

Slide 159

Slide 159 text

Just forget about them…

Slide 160

Slide 160 text

…and use class instance variables instead

Slide 161

Slide 161 text

Sets are not first-class citizens

Slide 162

Slide 162 text

Poorly named methods

Slide 163

Slide 163 text

Kernel#puts

Slide 164

Slide 164 text

Kernel#println, anyone?

Slide 165

Slide 165 text

Kernel#print

Slide 166

Slide 166 text

defined?

Slide 167

Slide 167 text

[1] pry(main)> defined? 10 => "expression" [2] pry(main)> defined? Test => nil [3] pry(main)> defined? TrueClass => "constant"

Slide 168

Slide 168 text

Is any of the values returned by defined? a boolean?

Slide 169

Slide 169 text

Is this the right behaviour for a predicate method?

Slide 170

Slide 170 text

Enumerable#include?

Slide 171

Slide 171 text

Enumerable#includes?

Slide 172

Slide 172 text

Kernel#%

Slide 173

Slide 173 text

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

Slide 174

Slide 174 text

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

Slide 175

Slide 175 text

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

Slide 176

Slide 176 text

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

Slide 177

Slide 177 text

In what universe would you prefer this over Kernel#format???

Slide 178

Slide 178 text

Perl-style global variables

Slide 179

Slide 179 text

$:

Slide 180

Slide 180 text

$LOAD_PATH

Slide 181

Slide 181 text

$;

Slide 182

Slide 182 text

$FIELD_SEPARATOR

Slide 183

Slide 183 text

$*

Slide 184

Slide 184 text

$ARGV

Slide 185

Slide 185 text

JRuby defines the English aliases by default

Slide 186

Slide 186 text

Let’s pray MRI will follow suit soon

Slide 187

Slide 187 text

WTF? Global variables?

Slide 188

Slide 188 text

Even Java doesn’t have globals…

Slide 189

Slide 189 text

Ruby 1.9 hash syntax

Slide 190

Slide 190 text

{ :one => 1, :two => 2 } { :'one.1' => 1, :'two.2' => 2 } { 'one' => 1, 'two' => 2 } { 1 => 'one', 2 => 'two' }

Slide 191

Slide 191 text

{ one: 1, two: 2 } { 'one.1': 1, 'two.2': 2 }

Slide 192

Slide 192 text

{ ala: :bala, porto: :kala, trala: :lala }

Slide 193

Slide 193 text

Perl-style regexp interactions

Slide 194

Slide 194 text

irb(main)> 'Bruce' =~ /B(.*)/ => 0 irb(main)> $~ => # irb(main)> $1 => "ruce" irb(main)> Regexp.last_match => # irb(main)> Regexp.last_match(0) => "Bruce" irb(main)> Regexp.last_match(1) => "ruce"

Slide 195

Slide 195 text

irb(main)> 'Bruce'.match(/B(.*)/) => # irb(main)> 'Bruce'.match(/B(.*)/) do |m| irb(main)> puts m[0] irb(main)> puts m[1] irb(main)> end Bruce ruce => nil

Slide 196

Slide 196 text

The documentation is somewhat lacking

Slide 197

Slide 197 text

irb(main)> 'x' !~ /x/ => false irb(main)> 'x' !~ /y/ => true

Slide 198

Slide 198 text

Try finding it on http://ruby-doc.org/

Slide 199

Slide 199 text

Problems with the standard library

Slide 200

Slide 200 text

The Ruby Stdlib is a Ghetto http://www.mikeperham.com/2010/11/22/the-ruby-stdlib- is-a-ghetto/

Slide 201

Slide 201 text

A ton of legacy code (often last updated 2000-2003)

Slide 202

Slide 202 text

Horrible APIs

Slide 203

Slide 203 text

net/http anyone?

Slide 204

Slide 204 text

The Kill List • Net::* • DRb • REXML • RSS • Rinda • WEBrick • XML

Slide 205

Slide 205 text

What are the parts of the standard library you dislike the most? Why so?

Slide 206

Slide 206 text

No content

Slide 207

Slide 207 text

No content

Slide 208

Slide 208 text

No content

Slide 209

Slide 209 text

No content

Slide 210

Slide 210 text

Epilogue

Slide 211

Slide 211 text

So f*cking what?

Slide 212

Slide 212 text

Stewardship: The Sobering Parts https://www.youtube.com/watch?v=2y5Pv4yN0b0

Slide 213

Slide 213 text

File tickets

Slide 214

Slide 214 text

Send patches

Slide 215

Slide 215 text

Blog about the issues

Slide 216

Slide 216 text

Speak about the issues

Slide 217

Slide 217 text

Let’s make Ruby better together!

Slide 218

Slide 218 text

Ruby Ruby

Slide 219

Slide 219 text

Кінець