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.
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 ).
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.
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.
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.
Read APIs are about:
Load APIs on the other end:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With