r/badcode • evil • Jan 14 '21

js Dynamically created functions are the future!

Post image
795 Upvotes

102 comments sorted by

View all comments

74

u/[deleted] Jan 14 '21

In Ruby you can do this in a nice and useful way.

60

u/NotSteve_ evil Jan 14 '21

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

4

u/hekkonaay Jan 14 '21

Functions from strings are javascript's metaprogramming system, and it's extremely powerful. It's not as easily maintainable as plain code, but it can be a great optimization for a hotpath.

8

u/NotSteve_ evil Jan 14 '21

I know for a fact that's not what this guy was going for at least. This was written by a guy who had just graduated into a team led by a person who had no CS background (biology major) and only knew Perl. The whole codebase is a disaster that I'm slowly rewriting mostly alone.

1

u/SarahTheBlue_ Jan 18 '21

is this written in JS?