-
-
Notifications
You must be signed in to change notification settings - Fork 181
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
Implement the exercise "custom-set" #748
Comments
Will definitely welcome such a PR! Some thoughts:
Open to any approach really. Some general thoughts though:
This might be a nice exercise to introduce varargs which, as you pointed out, is not used in any other exercise on the track yet.
Not sure - nothing springs to mind at the moment.
I see no reason not to add it and I feel it would be a welcome addition! An additional thought, one of the slight sticking points I have come across before with exercises that can imply opaque data types, is that naive implementations can lead to the tests having to rely on the implementation to query the underlying data. Obviously it would be good to avoid that if possible, such that each test only tests one function, rather than some foo function plus inherently testing an accessor type function at the same time. |
A very small thought about the samples you have added: Instead of always needing to refer to Other than that the first sample looks like a slightly simpler interface and includes the varargs which, as mentioned would be good to add to the track. |
I agree with @wolf99's comments. I'll add also that pushing for a red-black tree or hash would probably be a mistake as the complexity of the both of these far exceeds the complexity of set operations. If possible it would be nice to be as implementation-agnostic as possible so that students can start with a sorted (or even unsorted!) array and go with another representation if they're looking for a challenge. |
I haven't thought about that at all. Can you help with that?
Then maybe we should have a C-specific exercise for that, e.g. implement dynamic array for elements with a size specified by the caller, with a few "generic" functions like
OK, I will ditch the "generic" version.
I'm not sure I understand. Do you mind rephrasing that? I think there are just two alternatives:
I tend to go with calling
Actually that was a deliberate decision (just like the "east const"). As far as I can tell there's no consensus in the C community about whether to "always typedef" or "never typedef". The proponents for the I did not use the
All the programming languages I know implement sets either with balanced binary trees or hash tables. |
An example of the logic of a sample test function (psuedo code):
The first line is fine, that's the mutator that is under test. The problem is avoided if the data type is transparent, i.e. the struct is defined in the
Agreed, |
Anyone know where that track curriculum visualiser is and whether it works with v3? (asking on slack: https://exercism-team.slack.com/archives/CAQP7JL3T/p1643749842495399) |
I'm not at a computer now, but it used to be part of configlet and may still be. |
This is the tool I was thinking of but it does not work with v3 configs :( |
@ryanplusplus wrote
@wolf99 wrote
I have thought long and hard about that, and I can't see how I can both keep the tests implementation-agnostic and avoid relying on the implementation (e.g. avoiding having to call I believe the statement "Having the tests rely on the implementation is bad practice as it effectively means that actually two things are under test" is wrong. In consequence that would mean when some function changes some state we would always need some way to inspect the changed state directly. The could be no hidden state, I would like to test the public interface through the functions of the set. Objections? Did I miss or misunderstand anything? |
Hi, But reading your thoughts above I agree that this does not need to be a hard requirement. |
💯 This is what I was trying to advocate. Using only the public API means that we don't couple the tests to the implementation details so that a wide variety of implementations (with varying performance and difficulty!) are possible. |
I want a translation of the exercise custom-set to C.
But I want YOUR input before I submit a PR.
Q: Which approaches do we want to allow/encourage?
The three most "obvious" approaches are
Pro: Probably the easiest to implement, cache-friendly.
Con:
insert()
is in O(n).Pro: In my experience having implemented it correctly is a great achievement.
Con: That's hard to implement and time-consuming to mentor.
Pro:
insert()
is in amortized O(1),contains()
is in expected O(1).Con: For beginners that's a hard task, they have to choose a hash function, an approach for collision resolution, and they might even have to resize it. And it's probably hard to mentor, too.
The tests and the initial
.h
file can be written in a way that encourages/allows/disallows those three approaches, e.g. ifcustom_set_create()
takes a hash function or if thestruct custom_set
is defined in the.h
file that would steer the students in a certain direction.Q: Is there a fixed limit for the size of the set?
Q: Do we want to allow/encourage/enforce arbitrary element types?
qsort()
andbsearch()
work.(BTW: The tests mention "mixed-type sets" in a comment, but I wouldn't know how to do that properly in C without hard-coding the allowed types or having some sort of "base struct".)
The canonical tests require these operations:
some sort of creation, add, empty, contains, subset, disjoint, equal, intersection, difference, and union.
Q: Do we want anything further, e.g. size or some sort of access to the elements?
And last not least, Q: Should be have this exercise at all in the C track?
Please be candid, I'm open to all sorts of constructive criticism.
I already did some of the work and created two translations. Both have a Python script that reads the canonical-data.json and prints the complete
test_custom_set.c
. Both implement thestruct custom_set
with a dynamically allocated sorted array.In the first one the type of the elements is
int
, the functioncustom_test_create()
takes a size and a variable argument list (probably a first in the C track, right?). The.h
file looks like this:The second one is more generic, its
custom_test_create()
takes the size of the element type and a comparison function. The.h
file looks like this:Both translations compile, pass the tests and
make memcheck
.Let me know what you think.
The text was updated successfully, but these errors were encountered: