exercism / go

Exercism exercises in Go.
https://exercism.org/tracks/go
MIT License
999 stars 655 forks source link

New exercise teaching alternative number types #1612

Open iHiD opened 3 years ago

iHiD commented 3 years ago

This is part of our September Spring to get the Go Track in shape. Please read the Overview issue for more details. This exercise is unclaimed. To claim it, please comment below.


Before building this exercise (or exercises), please read up on the documentation.

Cars Assemble teaches int and float64. We need an extra exercise to teach the other number types that are commonly used and returned in Go. This can go into greater detail on more advanced numerical concepts.

It is also entirely possible to create two exercises: one on integral numbers, and one on floating-point numbers. This is the approach taken by C#, see the https://github.com/exercism/csharp/tree/main/exercises/concept/interest-is-interesting and https://github.com/exercism/csharp/tree/main/exercises/concept/hyper-optimized-telemetry exercises.

ErikSchierboom commented 3 years ago

@junedev Any thoughts on what exactly this exercise should teach? I know we should be teaching about float32 and the various integer types other than int, but you mentioned advanced numerical concepts IIRC?

Also, do you have a suggestion for an existing exercise to port? We could use one of the C# exercises, but you might have a better idea.

junedev commented 3 years ago

In JavaScript there is only "number" so I never looked for number type related exercises. I had a quick look now but most tracks are not that far into the syllabus yet it seems.

The integer exercise could work for Go as well but I would have to try it to be sure. That would cover all the integer related types.

Then we could expand the "interest" exercise a little to cover the two floats and introduce the math package https://pkg.go.dev/math.

The special topic I mentioned before was about numeric constants in Go. They can be defined without a type and will take on the type they need to have when used. This can be part of the interest exercise or can be added to the constants exercise.

ErikSchierboom commented 3 years ago

The interest-is-interesting exercise in C# uses decimal, which is a type specifically designed to be used with money (which the exercise uses) as it offers very high precision. I googled a bit and found that Go has arbitrary-precision numbers too: https://pkg.go.dev/math/big Do you think we would need to introduce that or could we use float64 for the balance?

junedev commented 3 years ago

I would keep big and complex for separate exercises later in the track.

junedev commented 3 years ago

Status on this: The floating point numbers part is done. We are still missing an exercise on all the integer types which could be a port of https://github.com/exercism/csharp/tree/main/exercises/concept/hyper-optimized-telemetry as Erik suggested.