Very few books and articles ever go into detail about a) why multiple methods are provided to complete a specific task in a specific scenario and b) what considerations a developer should take when choosing between methods.
My specific case in point is the simple opening of a text file (classic first section of any IO chapter). Most books/articles just say "Hey, here's how to open a text file: StreamReader with file path. Tada and end of section!"
Some do at least list the fact that there are multiple classes that allow you to do this e.g:
- File class
- FileInfo class
- FileStream class
- StreamReader class
- etc, etc, etc
Fewer discuss that there are even more overloads so you can use each class in several different ways.
Even fewer even try to enter into any discussion about how to select the best method for the task at hand. (Some of course do and these are the ones that usually end up in the top three when someone posts a poll-like question about "best" books.)
This lack of discussion drives me mad. I feel like I should toss a coin.
This question has the joint purposes of:
- Finding out if anyone thinks this is a worthwhile topic in the first place
- Offering people an opportunity to list any interesting articles or books that specifically go into these kinds of discussions
I've made this a wiki because other similar questions were made into wikis. And if people feel this question has no merit, I apologize and feel free to vote it closed.
Another Example
I am currently reading about BinaryWriter and BinaryReader. The last 20 articles I have hit using google and at least 5 books on O'Reilly Safari have shown me how to write a single integer and read it back. A couple included an example of how to use WriteString and ReadString. Exactly ONE let me know that WriteString() and ReadString() use a special encdoding meaning if you do WriteString() and ReadChar() you get a prefix. There are lots of ways to use these classes. Why do hardly any articles discuss this?
One More
Another example of what I mean is when a book or article lists class members and descriptions word for word from MSDN without adding any value. I do not need a list of class members because I can get that from MSDN. From an author, I need experience, real world knowledge i.e. stuff that will expand me as a developer. Not stuff I can look up in five seconds. All the member lists and simple i-don't-do-anything-useful examples in the world aren't going to really help anyone who wants to learn their stuff.
Last One - I promise
Just reading about StringWriter and StringReader. Same thing. Lots of articles and books giving simple i-don't-do-anything-useful examples. Some at least say something vague like I may want to use StringWriter if I want to write characters to an underlying buffer. How would I know if I want to do that? What real world scenarios would require it? I could go on all night.
OK So I Lied...
This question has answers from Merhdad and jalf that both explain how you would choose between two methods of generating a random number and demonstrates (I think) the kind of information I am talking about. jalf says, something along the lines of "In most cases use Option A. But in this specific case when you are trying to achieve Result X, use Option B. And by the way, this will have Negative Effect M."
X vs Y articles
I figured out I can get what I want by searching for X vs Y articles e.g. this one that discusses how to choose between the Directory and DirectoryInfo classes (and File and FileInfo classes).
So now this question is:
Can you list any useful X vs Y articles?