exercism / v3

The work-in-progress project for developing v3 tracks
https://v3.exercism.io
Other
170 stars 163 forks source link

[C#] Implement new Concept Exercise: tuples #963

Closed ErikSchierboom closed 4 years ago

ErikSchierboom commented 4 years ago

This issue describes how to implement the tuples concept exercise for the C# track.

Getting started

Please please please read the docs before starting. Posting PRs without reading these docs will be a lot more frustrating for you during the review cycle, and exhaust Exercism's maintainers' time. So, before diving into the implementation, please read up on the following documents:

Please also watch the following video:

Goal

The goal of this exercise is to teach the student the basics of the Concept of Tuples in C#.

Learning objectives

Out of scope

Concepts

This Concepts Exercise's Concepts are:

Prequisites

This Concept Exercise's prerequisites Concepts are:

Any data types used in this exercise (e.g. strings) should also be added as prerequisites.

Resources to refer to

Hints

After

Representer

This exercise does not require any specific representation logic to be added to the representer.

Analyzer

This exercise does not require any specific analyzer logic to be added to the analyzer.

Implementing

To implement this exercise, please follow these instructions.

Help

If you have any questions while implementing the exercise, please post the questions as comments in this issue.

mikedamay commented 4 years ago

An exercise in tuples is rather challenging. They are very much "syntactic sugar".

Common uses:

  1. Assignment (looks good for boilerplate assignment in a constructor)
  2. Swapping/cycling values between variables
  3. Return value
  4. Method argument
  5. Used instead of a struct in a collection
  6. Pattern matching in a switch statement (out of scope here)
  7. Use in LINQ (out of scope here)

The only one of the in-scope uses I would promote is 3. a return value containing unrelated or casually related values. 4 and 5 usually turn out to create a lot of noise. 1, 2 and 5 should be used very judiciously.

Is it possible / worth the candle to use an analyzer or representer to address 1, 2 and 5 e.g. to have the instruction "Implement this assignment/collection/swap using tuples"? 1 and 2 would be difficult to test and with 5 we could test only by revealing the syntax up front.

As for 3 and 4, return type and method argument, are we comfortable leaving place holders in the template code? For example:

public int ExctractResult(-SOME TUPLE-) {}

With instructions to take a tuple containg an int and a bool.

Any ideas and suggestions specifically for 1 to 5 would be useful including "don't bother".

A note on any other common uses would be good.

ErikSchierboom commented 4 years ago

The only one of the in-scope uses I would promote is 3. a return value containing unrelated or casually related values. 4 and 5 usually turn out to create a lot of noise. 1, 2 and 5 should be used very judiciously.

I agree with this. The only real valid use case is return values. As such, it is linked to out parameters, so maybe those two concepts can be combined?

As for 3 and 4, return type and method argument, are we comfortable leaving place holders in the template code? For example:

I'm thinking that we should either:

I think I have a slight preference for the second. What about you?

Assignment (looks good for boilerplate assignment in a constructor)

Personally this is a thing that I really like. This is definitely something that we can mention in an after.md document, but I don't think it should be part of the exercise.

Personally, I've used tuples for:

So I think you've got the uses covered. With that, there is relatively little to work with. The only thing that could make sense is to pair this with another concept like out parameters, as that is also related to returning multiple values.

mikedamay commented 4 years ago

The only thing that could make sense is to pair this with another concept like out parameters, as that is also related to returning multiple values.

out is currently in the parameters exercise. I think it would be difficult to explain ref in that exercise without explaining out at the same time. And I don't think ref would fit here.

A parameters+tuples exercise does not appeal to me.

Have the method be fully fleshed out

I agree that a fully fleshed out method or methods featuring tuple arguments and return types in the signature(s) would work.

I propose a static class comprising 2 methods covering arguments and return values. Everything else is covered in after.md.

1. Determine the characteristics of the integer values

A method should return an indication of whether the product of 3 values is a square and/or a cube and also return the product.

Detector.DetectPowers(2, 2, 2);
// => (true, true, 8)

2. Extract the product from the results returned by task 1.

Detector.ExtractProduct(DetectPowers(2,2,2));
// => 8

Extracts from Example.cs:

public static (bool IsSquare, bool IsCube, int Product) DetectPowers(int num1, int num2, int num3){…}

public static int ExtractProduct((bool, bool, bool) powersDetected) {…}

Comments please.

ErikSchierboom commented 4 years ago

I agree that a fully fleshed out method or methods featuring tuple arguments and return types in the signature(s) would work.

I propose a static class comprising 2 methods covering arguments and return values. Everything else is covered in after.md.

I like this.

As a side note, maybe we could come up with a different domain than maths. We're trying to stay away from maths as much as possible. Ignore this if the above was just an illustration of the path to be taken.

mikedamay commented 4 years ago

We're trying to stay away from maths

Sure I will do something with telephone numbers as strings. Parsing a well formed phone number and returning whether it is Manhattan, Fake and the local digits. e.g. "212-555-1234" => (true, true, "1234")

I would however argue, as a non-mathematician, that our audience can handle squares and cubes. The beauty of maths you don't need to spend any time looking up library methods as students typically have to with strings. Still, I like my telephone number idea so I will do that.

ErikSchierboom commented 4 years ago

Sure I will do something with telephone numbers as strings. Parsing a well formed phone number and returning whether it is Manhattan, Fake and the local digits. e.g. "212-555-1234" => (true, true, "1234")

I like this! It has some overlap with the phone-number v2 exercise, but I think it works well here.

mikedamay commented 4 years ago

closed by https://github.com/exercism/v3/pull/1601