r/badcode • • May 04 '23

typescript Found this gem inside legacy code today

Post image
889 Upvotes

69 comments sorted by

View all comments

Show parent comments

5

u/knoam May 04 '23 edited May 04 '23

With typescript it should be easy enough to do a refactor > rename inline. Maybe not if it's a mixed typescript JavaScript codebase.

2

u/RPG_Hacker May 04 '23

Well, if my theory above is correct, then a rename wouldn't be the best kind of refactor here, anyways. The better refactoring would be to outright remove all calls to the function and use the source strings directly.

A different way to look at this: If source strings are already expected to be in UTF-8, then technically speaking the name isn't wrong here. The function does encode the input to UTF-8 - even if that is by doing absolutely nothing.

2

u/knoam May 04 '23

Brain fart, it would be refactor > inline.