4 ms·
> The idea that there are text files and binary files has been toxic for a whole generation of coders. It really is nonsense isn't it? Its like asking a low le
by Skunkleton 6y ago
> The idea that there are text files and binary files has been toxic for a whole generation of coders.
It really is nonsense isn't it? Its like asking a low level api for opening files as a .doc, or as a pdf. Why would that be part of the file io layer?
- aidos 6y agoWell, I guess it’s easy to argue that it’s so common that beginners would expect to open files as text. You can see how it would evolve that way. Now I’m more familiar with it I’m careful to be explicit with the decoding when using text to make it super obvious what’s going on.
- heavenlyblue 6y agoMy first mistake I made as a beginner was dumping a bunch of binary data as text. Something would happen in the way and not the whole data would be written because I was writing it in text mode. It just never appeared to me that the default mode of writing the file would _not_ write the array I was passing it. It’s much more important for beginners to be able to learn clear recipes rather than having double standards with a bunch of edge cases.
- aidos 6y agoI’ve done worse. Using MySQL from php and not having the encoding right somewhere along the way so all my content was being mojibaked on the way in and un-mojibaked on the way out so I didn’t notice it until deep into a project when I needed to extract it to another system. EDIT thanks, I knew that didn't look quite right. "Mojibaked" - such a great term.
- mark-r 6y agoThe term is actually "Mojibake", not "emoji baked". https://en.wikipedia.org/wiki/Mojibake#Etymology https://en.wikipedia.org/wiki/Mojibake#Etymology
- signal11 6y agoI suspect it’s also to do with Python’s history as a scripting language. Because of Perl’s obvious strengths in this area, any scripting language pretty much has to make it very easy to work with text files. Ruby does something similar for instance. Even languages like Java now recognise the need to provide convenient access to text files as part of the standard API, with Files.readAllLines() in 7, Files.lines() in 8, and Files.readString() in 11.
- BiteCode_dev 6y agoYou can make it easy to deal with text file without lying to your API users. open("foo", mode="t") could become open("foo").as_text(). Besides, Python has pathlib now, which allows you to do Path("foo").read_text() for quick and dirty text handling already.
- a1369209993 6y agoMore to the point, it's so common that it ought to be supported out of the box by any decent programming language, the same way you'd expect any language to support IEEE floats. That doesn't mean the mechanism for it shouldn't be (effectively) textfile(file("foo.txt")), though.