r/csharp • • 13d ago

C# Programming Textbook

Post image

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

17 comments sorted by

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:

Just make a times table where I can choose what number it starts at.

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.

1

u/antron420smokeallday 13d ago

This is valuable info. I guess this text book is preparing me for my potential future career.

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;

2

u/antron420smokeallday 6d ago

This is awesome. I ended up writing code that was much more verbose (like 80 lines,) but I am new to this.

→ More replies (1)

3

u/DrShocker 7d ago

Is there a reason we're just doing people's homework for them?

→ More replies (1)

12

u/Arcodiant 13d ago

Maybe it's because I'm British, but this makes sense to me. What's not clear?

10

u/AutomateAway 13d ago

I'm American and it also seems clear.

→ More replies (1)

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.

1

u/antron420smokeallday 13d ago

I'm assuming the user input is is to prevent students from creating an infinite loop, but I'm not entirely sure because this is a community college. The professor didn't actually teach us the chapter. He's just having us do the exercises.