ruby
ruby copied to clipboard
[Lasagna]: Update instructions.md
I spent 3 days stuck on this problem not understanding why my solution was incorrect after I solved this challenge in 3 other languages. Very infuriating and frustrating as a new coder to bang your head against the wall thinking you're doing something wrong solving the problem. When all you needed to do was remove the raise command and your efforts to solve the problem were correct. I didn't need to do this in the other languages. My other proposal is to comment out the raise the command initially.
That can be frustrating indeed.
The code that is delivered for this concept exercise is definitely different that the ones for the practice exercise where we have a comment that is in the file to direct a student as to what should be do.
If we have not covered exceptions, I wonder why we are raising exception in the code. This is a concept exercise, and so it may be inappropriate on several levels to do this.
I would be for removing the raising of the exceptions and let the tests do the job of guiding to a solution, rather than raising and using a concept that is not learned yet in the solution file.
The solution might be to just add and remove this line
to the end of the message that comes up when the errors are raised.
The update may be misleading, as it will not avoid argument errors but RuntimeError
instead.
The commit history story does not say why we chose to raise exceptions.
@Crucibl Could you paste the code you ran that didn't work please so I can understand more what's happening. Thanks.
That can be frustrating indeed.
The code that is delivered for this concept exercise is definitely different that the ones for the practice exercise where we have a comment that is in the file to direct a student as to what should be do.
If we have not covered exceptions, I wonder why we are raising exception in the code. This is a concept exercise, and so it may be inappropriate on several levels to do this.
I would be for removing the raising of the exceptions and let the tests do the job of guiding to a solution, rather than raising and using a concept that is not learned yet in the solution file.
The solution might be to just add
and remove this line
to the end of the message that comes up when the errors are raised.The update may be misleading, as it will not avoid argument errors but
RuntimeError
instead.The commit history story does not say why we chose to raise exceptions.
Ok sounds great I think and yes sure. Or you can include a brief paragraph on "Raise" and what it means/does in Ruby
LasagnaTest#test_total_time_in_minutes_for_multiple_layer:
ArgumentError: wrong number of arguments (given 1, expected 0)
/Users/u/Exercism/ruby/lasagna/lasagna.rb:22:in `total_time_in_minutes'
lasagna_test.rb:31:in `test_total_time_in_minutes_for_multiple_layer'
2) Error:
LasagnaTest#test_remaining_minutes_in_oven:
ArgumentError: wrong number of arguments (given 1, expected 0)
/Users/u/Exercism/ruby/lasagna/lasagna.rb:7:in `remaining_minutes_in_oven'
lasagna_test.rb:12:in `test_remaining_minutes_in_oven'
3) Error:
LasagnaTest#test_preparation_time_in_minutes_with_multiple_layers:
ArgumentError: wrong number of arguments (given 1, expected 0)
/Users/u/Exercism/ruby/lasagna/lasagna.rb:14:in `preparation_time_in_minutes'
lasagna_test.rb:20:in `test_preparation_time_in_minutes_with_multiple_layers'
4) Error:
LasagnaTest#test_preparation_time_in_minutes_with_one_layer:
ArgumentError: wrong number of arguments (given 1, expected 0)
/Users/u/Exercism/ruby/lasagna/lasagna.rb:14:in `preparation_time_in_minutes'
lasagna_test.rb:16:in `test_preparation_time_in_minutes_with_one_layer'
5) Error:
LasagnaTest#test_total_time_in_minutes_for_one_layer:
ArgumentError: wrong number of arguments (given 1, expected 0)
/Users/u/Exercism/ruby/lasagna/lasagna.rb:22:in `total_time_in_minutes'
lasagna_test.rb:24:in `test_total_time_in_minutes_for_one_layer' ```
class Lasagna
EXPECTED_MINUTES_IN_OVEN = 40
PREPARATION_TIME = 2
def remaining_minutes_in_oven(actual_minutes_in_oven)
return EXPECTED_MINUTES_IN_OVEN - actual_minutes_in_oven
end
def preparation_time_in_minutes(number_of_layers)
return number_of_layers * 2
end
def total_time_in_minutes(number_of_layers, actual_minutes_in_oven)
return number_of_layers * 2 + actual_minutes_in_oven
end
end
class Lasagna
EXPECTED_MINUTES_IN_OVEN = 40
PREPARATION_TIME = 2
def remaining_minutes_in_oven(actual_minutes_in_oven)
return EXPECTED_MINUTES_IN_OVEN - actual_minutes_in_oven
end
def preparation_time_in_minutes(number_of_layers)
return number_of_layers * 2
end
def total_time_in_minutes(number_of_layers, actual_minutes_in_oven)
return number_of_layers * 2 + actual_minutes_in_oven
end
end
class Lasagna
EXPECTED_MINUTES_IN_OVEN = 40
PREPARATION_TIME = 2
def remaining_minutes_in_oven(actual_minutes_in_oven)
return EXPECTED_MINUTES_IN_OVEN - actual_minutes_in_oven
end
def preparation_time_in_minutes(number_of_layers)
return number_of_layers * PREPARATION_TIME
end
def total_time_in_minutes(number_of_layers, actual_minutes_in_oven)
return number_of_layers * PREPARATION_TIME + actual_minutes_in_oven
end
end
Now the only error I get is
1) Error:
LasagnaTest#test_total_time_in_minutes_for_multiple_layer:
ArgumentError: wrong number of arguments (given 1, expected 2)
/Users/u/Exercism/ruby/lasagna/lasagna.rb:20:in `total_time_in_minutes'
lasagna_test.rb:31:in `test_total_time_in_minutes_for_multiple_layer'
2) Error:
LasagnaTest#test_total_time_in_minutes_for_one_layer:
ArgumentError: wrong number of arguments (given 1, expected 2)
/Users/u/Exercism/ruby/lasagna/lasagna.rb:20:in `total_time_in_minutes'
lasagna_test.rb:24:in `test_total_time_in_minutes_for_one_layer'
The reason is probably due to losing the keyword arguments. Do not change the signature of the methods that are delivered to you, the code is there for you to use, and to benefit from. And yes, deleting the raise
lines is a thing you would want to do, but you want to leave the argument list for the methods intact.
This is not clear to a beginner at all. I understand that. And we are wrong for assuming one would understand this.
Was there a consensus on how to move forward here?
As we've not heard anything further here, I'm going to go ahead and close this. Thanks, all, for taking the time to discuss it.