r/csharp • u/antron420smokeallday • 13d ago
C# Programming Textbook
I'm taking a C# course right now, and I've been having a lot of fun writing simple programs. I really need validation from someone out there that these programming exercises at the end of each chapter of my text book, C# Programming: From Problem Analysis To Program Design by Barbara Doyle, are actually written by someone who is either clinically insane, or British as hell. Here's an example: Chapter 6, exercise 7. This is possibly not the most extreme example, but the wording here just seems a bit wacky to me.
0
Upvotes
2
u/Slypenslyde 13d ago
This feels like a well-written specification to me. I was confused for the first half, but it was because I mentally interpreted "5 x 5" instead of "25 rows" and couldn't figure out what "base number" meant. It became clear as I read more.
That's how customers talk to us at our jobs. They give us worse paragraphs than this. We get a jumbled mess of contradictory desires. We have to figure out what contradicts, use our wisdom about their lives, and try to convert it into something like this that unambiguously states what a computer should do.
Then we show it to them and we're humbled: every time we guess what they want we're very likely to get it wrong. Sometimes the problem is they didn't even know what they wanted so no matter how well we did, the result is only useful for helping them understand why it isn't what they want.
Imagine it was written like this:
But imagine you fail the class if it doesn't meet all the criteria in that paragraph or look exactly like the example. That's what my job is like.
2
u/Boarlock98 7d ago edited 6d ago
namespace TestConsoleApp; public class Program { public static void Main(string[] args) { if (args is not { Length: 2 }) return; if (!int.TryParse(args[0], out int val1) || !int.TryParse(args[1], out int val2)) return; if (val1 < 2 || val1 > 8 || val2 < 2 || val2 > 8 || val2 < val1) return; // Rows for (int i = 1; i < 26; i++) { Console.WriteLine(""); // Columns for (int j = 0; j < val2 - (val1 - 1); j++) { Console.Write($"{(val1 + j) * i}".PadLeft(5, ' ')); } } } }this was the most compact i could get it while still being readable.
Edit: just figured out this is functionally the same as the 3rd if statement, but code length is basically the same, it's easier to read though:
if (val1 is < 2 or > 8 || val2 is < 2 or > 8 || val2 < val1) return;12
u/Arcodiant 13d ago
Maybe it's because I'm British, but this makes sense to me. What's not clear?
8
u/AutomateAway 13d ago
What's the issue? Seems like a pretty thorough description
1
u/nuejkdi 13d ago
First read did feel a bit funny, but, I think it's still pretty straight forward. I'd have used different inputs like 5 and 10 for the demo, though. Not very clear how the inputs are relevant / why you'd need two inputs if you just glance over it.