Reply to post: Re: It's actually not that hard

'Trust no one' is good enough for the X Files but not for software devs: How do you use third-party libs and stay secure, experts mull on stage

Loyal Commenter Silver badge

Re: It's actually not that hard

I'm not arguing that delimited files aren't the right solution for certain jobs. The point I was trying to make is that simple solutions to quick-and-dirty problems aren't always the most robust. The reason things like XML and JSON are more "wordy" than a delimited file (or even a fixed width SDF) is that they often have considerations built in to deal with the real-life problems that come from users being able to mash their keyboards and come up with all sorts of weird and wonderful input.

If you're talking about files that come from one automated process and get pushed into another, then firstly, are you making the right choice by putting the data into a "file" in the first place. If you're talking about some sort of IPC, or data structures used internally to a process, why are you even thinking about what the data would look like in a file? Do you seriously need to write it to a file system (and deal with all the exceptions that can raise?)

Context is the key here; if you aren't writing stuff into a file at all, and, for instance, pushing it to an API somewhere, I'm going to assume you are using modern methodologies to do so, and that API is RESTful. Why the hell would you not want to use JSON for that? There might be some niche considerations where you want to minimize the payload for performance optimisation, in which case, is a delimited format appropriate either? And just because you don't think you're going to need to escape things, doesn't mean that the requirements won't change in future to mean that you will?

In my professional experience, there are very few situations where something needs to be output to a CSV (not least because some idiot is going to go and open them with Excel and then save them again all reformatted). If it needs to be machine-readable, use something machine-readable, even if it's a chunk of binary in a proprietary format. If it needs to be human and machine readable, use JSON. If it needs to follow a complex schema, maybe use XML.

Of course, it all depends on your use case, but use the right tool for the job. There are situations where you need to handle data that is supplied in a certain format, that is out of your control. I'm not sure I've come across any problem in the last 15 years or so where the solution was to output something to a CSV and then read it back in again.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon