KarthickNarayana / toy_robot

0 stars 0 forks source link

Case statement limits maintainability #6

Open scepticalcat opened 3 years ago

scepticalcat commented 3 years ago

https://github.com/KarthickNarayana/toy_robot/blob/3d570a92d5c8b027e2456ec4f7bce47223719ecf/lib/toy_robot/command.rb#L5

The case statement here is unnecessarily onerous. If the signature of any of the commands were to change then case conditions would also need to be updated. While it does catch invalid commands, this could be done in other ways and this entire method could be simplified with a smartly written regex.

KarthickNarayana commented 3 years ago

Yes for simple formats Regex could be used but in case the format changed to a particularly complex one then RegEx - are error prone - and for tricky situation the regex can take forever to resolve.

When it comes to input command I prefer to fail and someone look into it. Worth the investment of time.