18

I never know what is the correct name for a function that writes/stores/saves something in a file. When should I use save() vs store() vs write() and what is the difference in meaning between those?

I guess storeis used if I write to a database, writefor text files and savefor binary data, is that correct? What about XML files?

Konrad Höffner
  • 11,100
  • 16
  • 60
  • 118

4 Answers4

5

Well, it is up to you. I personally use saveXXX() and loadXXX() for most of such code and it's quite not important how the data is saved technically (file, DB etc). From application point of view it makes no difference. Code that saves just needs data to put it in the storage, more or less persistent, and it does not really bother how it is done by the storage layer. I simply suggest to stick to one naming, basically for sake of simplicity and consistency.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
5

I use load / save for methods that implicitly know or infer where to get or put the data, whereas read and write methods explicitly need to be told so. I guess that in the end it's completely arbitrary, but a community consensus on when to use which word would be nice to know.

grg rsr
  • 558
  • 5
  • 13
4

I would say that save and store are more or less interchangeable. I prefer save though.

write I interpret as writing out the content and do nothing else, while save also closes the file.

aioobe
  • 413,195
  • 112
  • 811
  • 826
1

My suggestion here:

set/get:    change/grab var value.
store:      copy/pointer value(s) to var/array.
read/write: deal with files (.txt, .json .png ...etc).
save/load:  store/grab objects/instance to var. 
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
johnsir
  • 11
  • 1