markjprice / cs12dotnet8

Repository for the Packt Publishing book titled "C# 12 and .NET 8 - Modern Cross-Platform Development Fundamentals" by Mark J. Price
638 stars 200 forks source link

Page 120 vs page 101 #44

Closed rmantel23 closed 5 months ago

rmantel23 commented 6 months ago

On page 120 you use ReadLine() as an example of a method that can return null.

image

However, on page 101 you state:

image

markjprice commented 5 months ago

Both of those are true. The ReadLine method is defined to state that it can return a string value or null. Since the compiler has to accept that, and it ignores the practical reality, we must handle that possibility even if it can't in practice happen. I've added an improvement item here: https://github.com/markjprice/cs12dotnet8/blob/main/docs/errata/improvements.md#page-101---getting-text-input-from-the-user-and-page-120---null-coalescing-operators

rmantel23 commented 5 months ago

Hi Mark. Understood they are both true, and thanks for adding the improvement, but wouldn't it be better to use something else than ReadLine() on page 120 to explain the Null-coalescing operators? It just seems clearer to not use the same example to explain two different solutions (Null-coalescing operators vs. the null forgiving operator). You actually repeat the same information from page 101 on page 157 and 158 (explaining ReadLine() cannot be null normally).

markjprice commented 5 months ago

What if I changed the method to GetAuthorName?

rmantel23 commented 5 months ago

Yes, I think that would be an improvement. And you wouldn't have to go into the details of explaining why ReadLine() can return null but normally won't.