Ad
  • Default User Avatar

    I like this solution, very readable.

  • Default User Avatar

    I don't see any 'good' or 'bad' practices here.
    Please, correct me if I'm wrong.
    For me, this question is rather a matter of taste. Because at the end of the day you end with the same instructions, the only difference is the structure of the code.
    Hence there are no other differences the choice must be based on readability. And as for me, for-loop is more readable due to its conciseness.

  • Default User Avatar

    In general, it's not a good practice to reassign the method argument.
    If you are curious why - then please look at these method signatures.
    It's a pretty helpful example because Node arguments have a meaningful name (and in general they must be meaningful).
    And then if we treat an argument head as a usual variable its name becomes pointless.
    And moreover in the case, if a method is much larger than a few lines or has an intricate logic then it's easy to introduce a bug because you forget that 'head' no longer points to the head.

  • Custom User Avatar

    i agree a while loop might be more readable here, thanks

  • Default User Avatar

    Having a for loop that stops on a condition not related to the defined variable "i" is not a good practice. Usually for loops are used to traverse exhaustively, for example in an array or collection. If you don't know for sure when a loop should stop and you depend on an external condtion as in this case, it is better to use a while loop.

  • Custom User Avatar

    Sometimes I would also like more fine-grained upvotes. Clever doesn't feel right for readable / maintainable but with underwhelming performance; Best practice is only for maintainable and performant.

    Downvotes are a minefield I can see CodeWars not getting into.

  • Default User Avatar

    Yeah I know I can use them for those. But I would rather if I could mark one solution as it has good performance and is readable and some other with clever as it is nice one-liner than to have to mark both with clever/best practices and have no option other than comments to differentiate between those two.

    I think performance is important feature enough to have its own label.

  • Custom User Avatar

    even though the slowness of it is sometimes frustrating.

    It is not new, there are several issues on github like https://github.com/Codewars/codewars.com/issues/1891

    Something like 'Good/bad performance'.

    You use 'best practices' and 'clever' for those too.

  • Default User Avatar

    Hello there, nice site, even though the slowness of it is sometimes frustrating.

    I have a suggestion about labeling solutions of a particular kata. To this day user can label each solution with 'Best practice' and/or 'Clever'. I think it would be nice if there would be more:

    Something like 'Most readable' or 'Nice to read' (that doesn't always has to mean best practice).

    Something like 'Good/bad performance'.

    I found it often that there are solutions on top of ratings that are both not so easy to read and have a bad performance. And people have to write these in the comments.
    As this should serve as a learning platform it would be nice if also solutions that are easier to read and therefore easier to maintain, perform better and are less error prone had some more praise here.

  • Default User Avatar

    Isn't it possible that the execution would end with StackOverflowError for really large Linked list? Because of the recursion? Just to make myself sure...