-
-
Notifications
You must be signed in to change notification settings - Fork 556
triangle interface - why take a list? #729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Well, as mentioned in #722, the Google JSON Style Guide usually recommends avoiding nesting structures in favor of flatter ones, but that is not a rule:
However, it is not stated explicitly that we try to adhere to this style guide, so maybe that is something that we should add? |
My initial implementation was guided by the canonical data, so my functions took a list. I'm suggesting that:
is clearer than
|
I think the generator, in this case this means the person translating for the purpose of using that file, can interpret as it sees fit. In the Ruby generator, there is no arguments given to The only method that takes any arguments there is the constructor, and indeed they chose to take the list (as an array) for the argument that is accepted. Which implementation, @stevejb71 on the exercism site or for creating a generator, or for creating the exercise example for a track? I can see that the first example that is "clearer" makes some assumptions for naming the sides as well. It happens to be the same names that are used in the example Ruby exercise as well, which I am assuming comes from the canonical data as well. So even without the explicit mention of 'a, b, c' this did happen. So is the first example required to have this happen, or can this happen fairly naturally from your second example? |
Certainly not!
I don't share your certainty. 😄 Using an array, we need to assume that it has length three. Using an object, we have to assume that is has just the keys for Both solutions try to encode a triple, but - because JSON has no explicit support for tuples - there is no perfect choice here. I think the array named That said, I agree it is a little annoying to use an array to represent a tuple. |
I meant to put a question mark after that :). I still think there are downsides to using a list instead of separate json keys:
|
From a general design perspective, all other things being equal, if I have a piece of data of known shape, using a data structure of exactly that shape is more concrete (and by definition requires less inference). Admittedly, in this case, the difference is slim. A triangle will never have fewer or more than three sides... forever. Is that "permission" enough to express that "rule" concretely? For those who want to iterate over the tuple, they could implement that interface/protocol/contract? |
This will become relevant to other exercises, not just this exercise. As a result of #721 or #722, either queen-attack or robot-simulator could end up using arrays as their inputs. I agree that arrays simply an artifact of the fact that JSON has no tuples. A similar decision, I imagine, had to be made in #755 which instead of using However, I do prefer side1/side2/side3 over a/b/c though.
This is also a concern of mine. I agree that even though it's encoded in JSON as an array, generated tests shouldn't. I don't particularly care which solution is taken:
They're both better than what happens now. |
I like It's already like this. |
I think a comment, advising that the function should take 3 arguments rather than a list, would be sufficient. |
In some languages arguments are a list. |
Good point. I think we're at the point where we can write a PR and examine how a proposed comment would or would not fit certain languages. |
I thought that one of the principles of exercism was that we don't push folks towards a specific implementation. |
Indeed, that is a subpart of the decision not to test intermediate functions (exercism/discussions#41). There are two places where it's necessary for us to be careful:
Since this issue doesn't deal with the former, it's important to consider how the choice we make affects the latter. I believe a comment is appropriate. |
Was a PR ever opened? I have not been able to find any closed PRs that might to relate to this issue. Is this issue still worth pursuing? |
In the triangle exercise, the canonical data shows a list as the input to functions like
equilateral
.Is part of the exercise to check that the list is of length 3? If so, there are no tests on the case of incorrectly sized lists.
If not - surely it would be better to have 3 number parameters as the inputs.
The text was updated successfully, but these errors were encountered: