Skip to content

Conversation

@Aurea-Li
Copy link

@Aurea-Li Aurea-Li commented Aug 8, 2018

Calculator

Congratulations! You're submitting your assignment.

Comprehension Questions

Question Answer
Describe how you stored user input in your program? I stored user input using variables, namely the operator, first_num, and second_num variables.
How did you determine what operation to perform? I use a case when conditional that checks what kind of operator the user has inputted in (see line starting at 63).
Do you feel like you used consistent indentation throughout your code? Yes.
If you had more time, what would you have added to or changed about the program? Because of how I am checking that the user input is numeric, my program does not accept as valid input any numbers that have extraneous trailing or leading zeros (ex: 1.010, 0.000, 003). I would have changed the program to fix this so that these types of numbers are accepted and simplified to their appropriate format.

@tildeee
Copy link
Collaborator

tildeee commented Aug 12, 2018

Calculator

What We're Looking For

Feature Feedback
Takes in two numbers and an operator and performs the mathematical operation. x
Readable code with consistent indentation. x

Great job!

The code works well and as expected, and the code looks good.

I like that you reserved making methods for things that were reused. You also pulled out complexity into different methods -- I like the difference between the methods is_valid_numeric_input and is_numeric.

I'm leaving a few minor comments, but none of them are anything major.

Overall, the code remained simple and elegant. Good work!

when "divide", "/"

# Handle cases when trying to divide by zero
if second_num == 0 then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you add in the then keyword to this... which is cool! I just wanted to call out that I don't see this syntax much, and I have no expectations for you to use it, unless it makes you happy.

second = simplify_integer(second_num)
answer = simplify_integer(answer)

puts "#{first} #{symbol} #{second} = #{answer}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if i were to prioritize conciseness over clarity/readability, i may suggest the following refactorings:

  1. renaming simplify_integer to simply the name format, as if it were a method responsible for formatting the number to a human-readable string
  2. renaming first_num to first and second_num to second...
  3. by getting those variable names back by inlining everything:
puts "#{format(first)} #{symbol} #{format(second)} = #{answer}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants