Draft
Very Simple Inheritance for Beginners
70 of 307Dana
Loading description...
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Please use new python test framework.
For Python, the example code in the Instructions tab is not properly indented, and results in IndentationError being thrown if executed as-is.
handle the division by zero error
First of all, you should not access the result variable dirctly by having it public but instead use a private variable with a get method which only returns the value of the result variable, espacially when working with inheritence.
Secondly, I saw that you named the result variable as Result with a capitalized R instead of using all lowercase as in the other languages. I missed that while reading the description and used the C# variable name while trying to solve it in Java which of course resulted in an error. I can't see a strong argument for not having the same variable names between languages so that is something I think should be corrected.
If you think I'm wrong on any point please let me know why, it's always fun to learn something new.
Otherwise I think this was a great introduction to inheritance at least for Java (as that is the language I'm most familiar with and have taken a few courses in), so thanks for that.
You will teach people to bad things with this kata, having classes doesn't meaning have oop. Remove public variable result and make method that execute operation return result directly. Correct signature of this method will be "double execute(double one, double another);
No explicit sample tests showing why they shouldn't just be separate classes that don't share the Operation base.
It does not make sense that division by 0 should result in 0 - in fact, in mathematical terms it could result in any number up to infinity. I think you should not test for division by 0, or at least have an error be saved in the result variable, e.g. 'Zero Division'
A couple of people have made the same comment. Luckily C# and Java handle division by zero nicely (returns infinity), so you can return the result directly. For Python, I specified that you should return None, since it will otherwise result in an exception.
Nice kata, but I don't think the division operation should result in 0.0 when encountering a divide by zero error. None would make more sense to me.
This kata was fun, but I think it should either be trimmed to just one operation implementation or made a little more interesting. As it is now, it's basically just repeating the same code four times.
It's meant to be very simple so I don't think there is any way to make this more interesting without changing the concept (i.e. using something besides math operations). You could make your own kata with a more intersting idea.
This comment has been hidden.
Great idea! I've updated the test cases.
Python translation added. Check please.
Hi Dana. Good beginner kata. I do have 2 remarks:
Hi FrankK,
I agree, since 'm_Result' is available outide the class, it should be named 'Result'. If I were to change it, I would create a public property. I'm not sure how to change this since 'm_Result' is used in all the submitted solutions. Is there a nice way to do this?
To keep the kata simple, I want the base class to already exist - I didn't consider putting it in the initial solution. It was something required that didn't need to change, so I just automatically placed it in the preloaded section. I'm not sure what the guidelines are for this.
Thanks for the feedback! :)
Dana
Hi Dana.
I think that there isn't a nice solution for your m_Result problem... :)
About the preloaded: I know that it is a matter of taste but I do not like preloaded because, against the nature of C# because C# is a type safe language, you have to guess an interface (or blindly believe a description).
And for
Java
the names are different again...For example, something like below might be more conventional:
m_Result
->mResult
orresult
Execute
->execute
But it's hard to strike the right balance...
~
Anyway, it's good Kata idea. CW needs more OOP Katas :-)
I think the naming was a bit confusing. Why not just make a quick list in the description that maps language to variable name?
I guess codewars doesn't have a way to make a language specific description for the same kata. That would be nice.
I think I've fixed all the naming problems and added some better code specific information in the description. Sorry, but all the solutions will now be obsolete...