r/badcode • evil • Jan 14 '21

js Dynamically created functions are the future!

Post image
795 Upvotes

102 comments sorted by

View all comments

Show parent comments

60

u/NotSteve_ evil Jan 14 '21

Haha seriously? What possible use could writing functions in strings have

77

u/[deleted] Jan 14 '21 edited Jan 14 '21

You can dynamically create methods. It's useful for reducing boilerplate. Sometimes you find yourself just having to implement almost identical methods. That's when it's useful to reach for Ruby's metaprogramming.

I've found it useful when doing Ruby and missed it using other languages that don't have it.

Not something you would use very often though.

34

u/NotSteve_ evil Jan 14 '21

Oh looking into it a bit that does seem neat and useful. I wouldn't mind maintaining that kind of code, unlike the code in the OP...

17

u/[deleted] Jan 14 '21

Yeah dude. I miss Ruby. Such a great language, and such a pity it's fallen out of use. There's Elixir as well, that has gained a bit popularity recently. But still, nothing mainstream.

-3

u/TigreDeLosLlanos Jan 15 '21

When did it was used outside some scripting?

9

u/wilwizard Jan 15 '21

Ruby on Rails was a massively popular backend framework

10

u/fun_egg Jan 15 '21

Ruby on Rails was is a massively popular backend framework

5

u/NotSteve_ evil Jan 15 '21

Yeah Shopify is built nearly entirely with it from what I remember

7

u/[deleted] Jan 15 '21

and Github is build on Ruby on Rails.

2

u/[deleted] Jan 15 '21

Rails was one of the top frameworks for the past 10 years or so, where have you been?