Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Semantic difference of Read and Load

I wonder what the semantic difference is between Read and Load (in C#). I don't see a difference when comparing e.g.

  • System.IO.MemoryStream.Read()
  • System.Console.Read()
  • System.IO.StreamReader.Read()
  • System.IO.File.ReadAllText()

vs

  • System.Xml.XmlDocument.Load()
  • System.Xml.Linq.XDocument.Load()
  • System.Reflection.Assembly.Load()

Since I want a consistent naming over my program that deals a lot with simply getting files from persistent storage and higher level functions that also initialize, cross reference and errorcheck I kindly ask for your input.

like image 247
codingdave Avatar asked Nov 05 '15 07:11

codingdave


People also ask

What is the difference between read () and Load ()?

read is usually associated reading data from a permanent storage (HDD, USB Stick etc.). load on the other hand is loading data you have previously read from RAM into a CPU register/accumulator (Assembly command lda ).

What is the difference between save and load?

Load definition imports a new resource into a project while Save definition saves it for export to another system. For example you may want to reuse an activity or data source which has already been defined for a different task.

What is the difference between reading and writing to memory?

After a "read", the information from the file/table is available to the computer program but none of the information that was read from the file/table is changed in any way. Write:- A "Write" operation occurs when a computer program adds new information, or changes existing information in a computer file/table.


2 Answers

In your examples, "Read" generally refers to reading a portion of the data. Whether this is for the purpose of limiting the amount of data that needs to be stored and/or handled in a given operation, or because the data itself is not immediately available in its entirety (e.g. Console.Read() or reading from a network stream), the fundamental behavior is the same: data is processed in pieces smaller than the entire set of data that can or will be processed.

There is the exception ReadAllText(), which does in fact read all of the data at once. But that's in a type where all the other methods that perform similarly also use the word "Read". Using "Read" in that context keeps the API consistent, and failing to use "Load" doesn't significantly hinder comprehension of the API (especially since the method name also explicitly states "All Text"…no one should be surprised to see all of the text read in that case, right? :) ).

In your examples that use "Load", they consume all of the data at once, and turn it into something else, e.g. an XML DOM or an assembly. This is a distinctly different kind of operation from just reading data and at most doing minimal processing on it (e.g. decoding some text format). In contrast to "Read" operations, "Load" will always consume all of the data, rather than allowing the option of reading just a portion at a time.

like image 152
Peter Duniho Avatar answered Oct 27 '22 20:10

Peter Duniho


Read APIs are about:

  • Reading data in smaller units like bytes, characters
  • Have a pointer, which is mostly forward only type like DataReader
  • Connected and reading from the source
  • Works fine for all kinds of data, but may be a costly option if a live connection is maintained over a period of time
  • Needs consistent connectivity, throughout the process
  • ADO.Net connected architecture is the example

Load APIs on the other end:

  • Load all data in memory in one go
  • Opens connection, Read everything and close it, doesn't maintain a live connection
  • Can work with data to apply logic, move forward / backward in the memory
  • Works fine for smaller sets, may have trouble for larger sets of data due to memory and network requirements
  • Once loaded and can be worked upon at convenience over a period of time as its a disconnected data
  • ADO.Net disconnected architecture, Dataset, DataTable and IEnumerable are valid examples
like image 24
Mrinal Kamboj Avatar answered Oct 27 '22 20:10

Mrinal Kamboj