DEV Community

Discussion on: The Coolest Programming Language Features

Collapse
 
rhymes profile image
rhymes

Great article Jeremy! Thanks.

Funny because I didn't know what extension methods were and instead of some voodoo thing they are just what you can achieve in Ruby with open classes:

2.6.1 :001 > class String
2.6.1 :002?>   def mutate()
2.6.1 :003?>     return self + " mutation"
2.6.1 :004?>   end
2.6.1 :005?> end
 => :mutate
2.6.1 :006 > s = "Hello, world!"
 => "Hello, world!"
2.6.1 :007 > s.mutate
 => "Hello, world! mutation"

or JavaScript extensions using prototype inheritance:

> String.prototype.mutate = function() { return this + " mutation"; }
> a = "Hello, world!"
> a.mutate()
"Hello, world! mutation"

Optional chaining should be added to all languages with the concept of null 😭

Collapse
 
vicentemaldonado profile image
Vicente Maldonado

en.wikipedia.org/wiki/Extension_me...

"The Ruby community often describes an extension method as a kind of monkey patch." πŸ˜€

But yes, they can be useful.

Collapse
 
renegadecoder94 profile image
Jeremy Grifski

Wow. Clearly, I haven’t played around enough with ruby or JavaScript. I really thought Kotlin was changing the game. Haha thanks for the tip!