-
-
Notifications
You must be signed in to change notification settings - Fork 944
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add comments for crystal analyzer 1.3 (#2357)
* Add comments for crystal analyzer 1.3 * Update analyzer-comments/crystal/darts/hypot.md Co-authored-by: Isaac Good <[email protected]> * Update analyzer-comments/crystal/darts/hypot.md Co-authored-by: Isaac Good <[email protected]> * Update analyzer-comments/crystal/weighing-machine/missing_method.md Co-authored-by: Isaac Good <[email protected]> --------- Co-authored-by: Isaac Good <[email protected]>
- Loading branch information
1 parent
7812c02
commit 8bc4e26
Showing
4 changed files
with
24 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Pow | ||
|
||
Using `pow`, `sqrt` or `**` is totally valid and can be necessary in many situations. | ||
However when we want a distance in Cartesian space we can use the [`hypot` method][hypot] which returns the hypotenuse of a right angle triangle with sides x and y. | ||
|
||
```crystal | ||
# Rather than: | ||
Math.sqrt(number ** 2 + another_number ** 2) | ||
# Consider: | ||
Math.hypot(number, another_number) | ||
``` | ||
|
||
[hypot]: https://crystal-lang.org/api/Math.html#hypot%28value1%2Cvalue2%29-instance-method |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Uses the hypot method | ||
|
||
Congratulations, your solution uses the hypot method! | ||
|
||
Your solution uses an efficient way of calculating the distance from the center of a dartboard and that's worth taking a moment to celebrate. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Missing %{method_name} method call | ||
|
||
Like the instructions mention, the purpose of this exercise is to learn about getters and setters. | ||
Manually defining these methods is not inherently bad, but can lead to code which is more verbose and harder to maintain. |