Giter Club home page Giter Club logo

Comments (8)

kytrinyx avatar kytrinyx commented on August 25, 2024

@stevejb71 @petertseng @NobbZ -- do you have any ideas about how we could solve this?

from rust.

NobbZ avatar NobbZ commented on August 25, 2024

To be honest, this is the exercise I'm stuck with too, I don't even know
why I'm called in here 😁

But yes, here the tests do a very strongly depend on the data structure
where possibly is no need for.

Also for the sake of the exercise it should not matter if you use the named
fields or tuple syntax.

Anyway, I will take a closer look tomorrow when I'm back at my laptop and
no one else chimed in.

Katrina Owen [email protected] schrieb am Mo., 11. Jan. 2016 20:26:

@stevejb71 https://github.com/stevejb71 @petertseng
https://github.com/petertseng @NobbZ https://github.com/NobbZ -- do
you have any ideas about how we could solve this?


Reply to this email directly or view it on GitHub
#64 (comment).

from rust.

kytrinyx avatar kytrinyx commented on August 25, 2024

@NobbZ I called you because you've commented a lot in the rust track :)

from rust.

andrey-gvrd avatar andrey-gvrd commented on August 25, 2024

@kytrinyx A reasonable approach is taken here.

from rust.

kytrinyx avatar kytrinyx commented on August 25, 2024

Yeah, that looks good.

from rust.

petertseng avatar petertseng commented on August 25, 2024

Yeah, the expected interface being thrown in a comment somewhere seems good. Probably in the stub file would be in a more visible location than the test file, even?

On a related note, I've been trying to think about getting tests to be less constraining of implementation details these days. Do you think doing Allergies(0) is too constraining and it should be Allergies::new(0) instead?

(and the example impl can just have fn new(n: uint) -> Allergies { Allergies(n) } or similar, and anyone else can do whatever they want)

from rust.

NobbZ avatar NobbZ commented on August 25, 2024

Yeah, one could give a list of functions and signatures in the impl, thats one good thing, but not the solution to the OPs problem.

The OP assumed the design of the type would be as usual. So he designed a struct using record-syntax and used a static function new in the impl to create new values of the type. This is quite a common pattern in rust.

There is another kind of structs, using tuplesyntax. There fields don't have a name, and the structs name is used as if it were the new function.

Both have some pros and cons, eg tuplesyntax is much nicer to pattern match on, while recordsyntax is much more self documenting due to the named fields.

I have seen both in the wild, but the section about tuple syntax in the official rust manual is very short, while record syntax is explained exhaustively.

So I'd prefer to not make any assumption in any future tests that make assumptions about the used syntax, but always use a static constructor in the impl and document signature as shown above.

from rust.

petertseng avatar petertseng commented on August 25, 2024

So I'd prefer to not make any assumption in any future tests that make assumptions about the used syntax, but always use a static constructor in the impl and document signature as shown above.

Agree.

from rust.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.