Why Do We Call It TextEncoder and TextDecoder?

0
6
Asked By CuriousCat99 On

I've been puzzled about the naming of TextEncoder and TextDecoder in JavaScript. It feels like they should be switched around because a TextEncoder converts a stream of code points into a byte stream, which seems like it should be called 'decoding' since it's taking encoded data and producing output. Can anyone shed light on the reasoning behind these names? Also, I'm curious if there are any resources on the history of these naming decisions.

2 Answers

Answered By NerdyNavigator42 On

The naming actually follows a consistent pattern that's seen in many media encoders. You take some text or media and encode it into bytes, then when you decode, you're going back from bytes to that original format. It gets tricky because different platforms might represent strings differently, but nonetheless, it's about encoding and decoding according to chosen formats, not just raw code points.

SkepticalScribe73 -

I like how you clarified that. Your explanation is much clearer than mine!

Answered By TechieTango88 On

It might just be a matter of perspective. To me, TextEncoder makes sense because it encodes text into bytes, which is pretty intuitive. But hey, maybe you could grab a beer for whoever named it and ask them yourself! 😂

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.