7 kyu

Merging vectors without reallocation

Description
Loading description...
Fundamentals
Refactoring
Debugging
  • Please sign in or sign up to leave a comment.
  • akar-0 Avatar

    I really appreciate the effort of this kind of educative katas, especially for a language like Rust (lifetimes give me frequently headaches), but, with the new version of this kata (I mean the function's signature that has been amended) I have tried something out intuitively and it worked immediately, I don't feel like I learnt anything (yesterday I was unable to solve it, though reading the documentation...). Maybe it would be nice to have something more elaborated but with more step by step / documented instructions? Just an idea...

  • FArekkusu Avatar

    The error message generated by the compiler gives away the solution entirely. Unless it is possible to suppress it somehow (which I doubt you can), this is a really bad idea to make a kata of.

    • dfhwze Avatar

      I wouldn't say "entirely". As a kuy8, the intended audience would still need to figure out what to do.

    • FArekkusu Avatar

      I wouldn't say "entirely".

      I literally copy-pasted it and passed the tests, what do you mean "not entirely"?

      the intended audience would still need to figure out what to do

      There's no such thing as "intended audience".

    • Heiss Avatar

      Hey. Thanks for your comment. There are katas already with missing characters like ; or {, which can be autofilled by compiler. So I thought it would be a good idea to create a kata to show a first example about the lifetime concept of rust. And for a kyu 8; is it not okay to learn to work with the compiler messages?

    • FArekkusu Avatar

      There are katas already with missing characters like ; or {, which can be autofilled by compiler

      Can you give an example that is relevant to the issue I raised?

      And for a kyu 8; is it not okay to learn to work with the compiler messages?

      Do you even understand why I raised this issue?

    • Heiss Avatar

      I cannot find the first kata, i solved on codewars. But it was such a task to add { to a function signature.

      But i found this one: https://www.codewars.com/kata/50654ddff44f800200000004 Is this not relevant to your issue? The compiler says, what you can do to fix.

      Can i extend the kata to solve your issue? This is a fundamental concept of rust to show. I want to focus on this concept, but without any need to change the function implementation code. Maybe you have a suggestion.

    • FArekkusu Avatar

      But i found this one: https://www.codewars.com/kata/50654ddff44f800200000004. Is this not relevant to your issue? The compiler says, what you can do to fix.

      In that case, Rust is simply not the right language for this type of bugfixing problems - you can't make a meaningful kata if the compiler is giving away the exact code that you have to type in to make it work.

    • Heiss Avatar

      you can't make a meaningful kata if the compiler is giving away the exact code that you have to type in to make it work.

      You are right.

      I changed the signature, so the compiler does not show the solution, but helps to figure it out. And more; if you use the compiler it suggests the wrong fix at first.

    • FArekkusu Avatar

      That's an improvement, although I'm not sure whether I really like the fix. IMO, it'd be better if ys had a lifetime of &'b instead of an undeclared &'c, so that the task is focused solely on resolving the lifetimes problem rather than have an additional step of fixing a typo (only to arrive at the following code anyway):

      fn merge<'a, 'b>(xs: &'a Vec<usize>, ys: &'b Vec<usize>) -> Vec<&'a usize> {
          xs.iter().chain(ys).collect()
      }
      

      Perhaps you could change the initial solution to make the user debug an incorrect attempt at fixing the lifetimes instead, which I think would be more interesting:

      fn merge<'a, 'b, 'c: 'a + 'b>(xs: &'a Vec<usize>, ys: &'b Vec<usize>) -> Vec<&'c usize> {
          xs.iter().chain(ys).collect()
      }
      

      but that's up to you, whichever thing you choose, the original issue is okay resolve as is.

    • Heiss Avatar

      Thank you. Wonderful suggestions. I like the second idea more.

      Issue marked resolved by Heiss 3 years ago
  • Unnamed Avatar

    https://www.codewars.com/kata/reviews/617dcc247df1ed0001ffed07/groups/617e58b6301d7a00012cb7d9 Maybe it doesn't matter too much for an easy kata, but testing against this is easy too, so I think this solution shouldn't pass.

    • Heiss Avatar

      Thank you for your input. I am a beginner for rust and codewars, so i want to learn more about both while i create a kata. So i try to figure out, how to handle static lifetimes. But currently i have no clue.

    • FArekkusu Avatar

      @Unnamed all of the solutions you've submitted do not pass anymore; please, check whether the issue can be resolved now.

    • Unnamed Avatar

      Well, some workarounds are still possible, but they require managing lifetimes at least to some extend, so I guess it may be OK...

      Issue marked resolved by Unnamed 3 years ago
  • dfhwze Avatar

    You should add the "refactoring" tag.