Skip to content

Commit

Permalink
Add comments for crystal analyzer 1.3 (#2357)
Browse files Browse the repository at this point in the history
* 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
meatball133 and IsaacG authored Aug 22, 2024
1 parent 7812c02 commit 8bc4e26
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
14 changes: 14 additions & 0 deletions analyzer-comments/crystal/darts/hypot.md
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
5 changes: 5 additions & 0 deletions analyzer-comments/crystal/darts/uses_hypot.md
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.
2 changes: 1 addition & 1 deletion analyzer-comments/crystal/sieve/do_not_use_div_rem.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Like the instructions mention, the purpose of this exercise is to build a Sieve of Eratosthenes without the use of operations such as division or modulo division.
Please refer to the [Wikipedia link][wikipedia] for a description of the algorithm.

Building the Sieve of Eratosthenes in an immutable language such as Crystal may feel a bit unnatural,
Building the Sieve of Eratosthenes without operations such as division or modulo division can be tricky.
but it is a beautiful algorithm invented more than two millennia ago that is worth learning and implementing.

[wikipedia]: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
4 changes: 4 additions & 0 deletions analyzer-comments/crystal/weighing-machine/missing_method.md
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.

0 comments on commit 8bc4e26

Please sign in to comment.