Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/fhdsl/AI_for_software into …
Browse files Browse the repository at this point in the history
…main
  • Loading branch information
jhudsl-robot committed Jul 13, 2023
2 parents b02a478 + d1fe975 commit cdc03d5
Show file tree
Hide file tree
Showing 30 changed files with 222 additions and 118 deletions.
6 changes: 3 additions & 3 deletions docs/04-refactoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ proc.time() - start_time

```
## user system elapsed
## 12.058 0.004 12.061
## 13.910 0.008 13.919
```

:::{.query}
Expand Down Expand Up @@ -575,7 +575,7 @@ proc.time() - start_time

```
## user system elapsed
## 0.625 0.320 0.638
## 0.792 0.428 0.820
```

The `outer()` function performs the same calculation as the nested loop in the original code, but more efficiently. It returns a matrix of all possible combinations of x and y values, with each element of the matrix being the product of the corresponding x and y values. The `rowSums()` function is then used to sum the elements of each row of the matrix, which is equivalent to summing the products of x and y for each index `i` in the original loop. This method avoids the need for the nested loop, resulting in a faster and more efficient computation.
Expand Down Expand Up @@ -603,7 +603,7 @@ proc.time() - start_time

```
## user system elapsed
## 0.296 0.292 0.374
## 0.386 0.381 0.491
```

One optimized way to perform the same calculation is by using the `%*%` operator to perform matrix multiplication. This can be done by converting x and y to matrices and transposing one of them so that their dimensions align for matrix multiplication. This code should be much faster than the original implementation because it takes advantage of highly optimized matrix multiplication algorithms in R.
Expand Down
21 changes: 21 additions & 0 deletions docs/06-understanding_other_ppl_code.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,27 @@ What are some possible issues with this code?

(And if you do ever run across an expression like this in your code, you can check out our chapter on [refactoring code](https://hutchdatascience.org/AI_for_software/refactoring-code.html#refactoring-code) using AI to fix it!)

## Limitations

Although chatbots can be extremely helpful for better understanding someone else's code, if there is a lack of annotation or documentation, it will be difficult to discern more about the context of the development.

Cases where developers may not have provided context information include:

1) Not stating their purpose for writing this code.
2) Not describing what they planned to do next.
3) Not describing (or being aware of) possible parts of the code that need updating or maybe have security or privacy issues.
4) Not describing how they made certain decisions in the development process.

Although we can't truly understand some of this information, it is however possible to get some assistance from chatbots with prompts such as:

1) What do you think the purpose of this code is?
2) What might be possible next steps to further develop this code?
3) What are possible issues with this code, particularly for security or privacy?
4) Why was the code possibly written with this structure? What other options are possible?

Chatbot tools are also limited in terms of how up-to-date their training data is to know about current possible issues with code.



## Hands-On Exercise

Expand Down
9 changes: 5 additions & 4 deletions docs/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,13 @@
<li class="chapter" data-level="6.5" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#example-two-identifying-a-coding-language"><i class="fa fa-check"></i><b>6.5</b> Example Two: Identifying a Coding Language</a></li>
<li class="chapter" data-level="6.6" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#example-three-interpreting-regex"><i class="fa fa-check"></i><b>6.6</b> Example Three: Interpreting Regex</a></li>
<li class="chapter" data-level="6.7" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#example-four-demystifying-functions"><i class="fa fa-check"></i><b>6.7</b> Example Four: Demystifying Functions</a></li>
<li class="chapter" data-level="6.8" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#hands-on-exercise-2"><i class="fa fa-check"></i><b>6.8</b> Hands-On Exercise</a>
<li class="chapter" data-level="6.8" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#limitations"><i class="fa fa-check"></i><b>6.8</b> Limitations</a></li>
<li class="chapter" data-level="6.9" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#hands-on-exercise-2"><i class="fa fa-check"></i><b>6.9</b> Hands-On Exercise</a>
<ul>
<li class="chapter" data-level="6.8.1" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#the-code-1"><i class="fa fa-check"></i><b>6.8.1</b> The Code</a></li>
<li class="chapter" data-level="6.8.2" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#questions-2"><i class="fa fa-check"></i><b>6.8.2</b> Questions</a></li>
<li class="chapter" data-level="6.9.1" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#the-code-1"><i class="fa fa-check"></i><b>6.9.1</b> The Code</a></li>
<li class="chapter" data-level="6.9.2" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#questions-2"><i class="fa fa-check"></i><b>6.9.2</b> Questions</a></li>
</ul></li>
<li class="chapter" data-level="6.9" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#summary-4"><i class="fa fa-check"></i><b>6.9</b> Summary</a></li>
<li class="chapter" data-level="6.10" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#summary-4"><i class="fa fa-check"></i><b>6.10</b> Summary</a></li>
</ul></li>
<li class="chapter" data-level="" data-path="about-the-authors.html"><a href="about-the-authors.html"><i class="fa fa-check"></i>About the Authors</a></li>
<li class="chapter" data-level="" data-path="appendix.html"><a href="appendix.html"><i class="fa fa-check"></i>Appendix</a>
Expand Down
9 changes: 5 additions & 4 deletions docs/about-the-authors.html
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,13 @@
<li class="chapter" data-level="6.5" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#example-two-identifying-a-coding-language"><i class="fa fa-check"></i><b>6.5</b> Example Two: Identifying a Coding Language</a></li>
<li class="chapter" data-level="6.6" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#example-three-interpreting-regex"><i class="fa fa-check"></i><b>6.6</b> Example Three: Interpreting Regex</a></li>
<li class="chapter" data-level="6.7" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#example-four-demystifying-functions"><i class="fa fa-check"></i><b>6.7</b> Example Four: Demystifying Functions</a></li>
<li class="chapter" data-level="6.8" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#hands-on-exercise-2"><i class="fa fa-check"></i><b>6.8</b> Hands-On Exercise</a>
<li class="chapter" data-level="6.8" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#limitations"><i class="fa fa-check"></i><b>6.8</b> Limitations</a></li>
<li class="chapter" data-level="6.9" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#hands-on-exercise-2"><i class="fa fa-check"></i><b>6.9</b> Hands-On Exercise</a>
<ul>
<li class="chapter" data-level="6.8.1" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#the-code-1"><i class="fa fa-check"></i><b>6.8.1</b> The Code</a></li>
<li class="chapter" data-level="6.8.2" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#questions-2"><i class="fa fa-check"></i><b>6.8.2</b> Questions</a></li>
<li class="chapter" data-level="6.9.1" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#the-code-1"><i class="fa fa-check"></i><b>6.9.1</b> The Code</a></li>
<li class="chapter" data-level="6.9.2" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#questions-2"><i class="fa fa-check"></i><b>6.9.2</b> Questions</a></li>
</ul></li>
<li class="chapter" data-level="6.9" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#summary-4"><i class="fa fa-check"></i><b>6.9</b> Summary</a></li>
<li class="chapter" data-level="6.10" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#summary-4"><i class="fa fa-check"></i><b>6.10</b> Summary</a></li>
</ul></li>
<li class="chapter" data-level="" data-path="about-the-authors.html"><a href="about-the-authors.html"><i class="fa fa-check"></i>About the Authors</a></li>
<li class="chapter" data-level="" data-path="appendix.html"><a href="appendix.html"><i class="fa fa-check"></i>Appendix</a>
Expand Down
9 changes: 5 additions & 4 deletions docs/annotating-your-code.html
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,13 @@
<li class="chapter" data-level="6.5" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#example-two-identifying-a-coding-language"><i class="fa fa-check"></i><b>6.5</b> Example Two: Identifying a Coding Language</a></li>
<li class="chapter" data-level="6.6" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#example-three-interpreting-regex"><i class="fa fa-check"></i><b>6.6</b> Example Three: Interpreting Regex</a></li>
<li class="chapter" data-level="6.7" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#example-four-demystifying-functions"><i class="fa fa-check"></i><b>6.7</b> Example Four: Demystifying Functions</a></li>
<li class="chapter" data-level="6.8" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#hands-on-exercise-2"><i class="fa fa-check"></i><b>6.8</b> Hands-On Exercise</a>
<li class="chapter" data-level="6.8" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#limitations"><i class="fa fa-check"></i><b>6.8</b> Limitations</a></li>
<li class="chapter" data-level="6.9" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#hands-on-exercise-2"><i class="fa fa-check"></i><b>6.9</b> Hands-On Exercise</a>
<ul>
<li class="chapter" data-level="6.8.1" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#the-code-1"><i class="fa fa-check"></i><b>6.8.1</b> The Code</a></li>
<li class="chapter" data-level="6.8.2" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#questions-2"><i class="fa fa-check"></i><b>6.8.2</b> Questions</a></li>
<li class="chapter" data-level="6.9.1" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#the-code-1"><i class="fa fa-check"></i><b>6.9.1</b> The Code</a></li>
<li class="chapter" data-level="6.9.2" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#questions-2"><i class="fa fa-check"></i><b>6.9.2</b> Questions</a></li>
</ul></li>
<li class="chapter" data-level="6.9" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#summary-4"><i class="fa fa-check"></i><b>6.9</b> Summary</a></li>
<li class="chapter" data-level="6.10" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#summary-4"><i class="fa fa-check"></i><b>6.10</b> Summary</a></li>
</ul></li>
<li class="chapter" data-level="" data-path="about-the-authors.html"><a href="about-the-authors.html"><i class="fa fa-check"></i>About the Authors</a></li>
<li class="chapter" data-level="" data-path="appendix.html"><a href="appendix.html"><i class="fa fa-check"></i>Appendix</a>
Expand Down
9 changes: 5 additions & 4 deletions docs/appendix.html
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,13 @@
<li class="chapter" data-level="6.5" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#example-two-identifying-a-coding-language"><i class="fa fa-check"></i><b>6.5</b> Example Two: Identifying a Coding Language</a></li>
<li class="chapter" data-level="6.6" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#example-three-interpreting-regex"><i class="fa fa-check"></i><b>6.6</b> Example Three: Interpreting Regex</a></li>
<li class="chapter" data-level="6.7" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#example-four-demystifying-functions"><i class="fa fa-check"></i><b>6.7</b> Example Four: Demystifying Functions</a></li>
<li class="chapter" data-level="6.8" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#hands-on-exercise-2"><i class="fa fa-check"></i><b>6.8</b> Hands-On Exercise</a>
<li class="chapter" data-level="6.8" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#limitations"><i class="fa fa-check"></i><b>6.8</b> Limitations</a></li>
<li class="chapter" data-level="6.9" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#hands-on-exercise-2"><i class="fa fa-check"></i><b>6.9</b> Hands-On Exercise</a>
<ul>
<li class="chapter" data-level="6.8.1" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#the-code-1"><i class="fa fa-check"></i><b>6.8.1</b> The Code</a></li>
<li class="chapter" data-level="6.8.2" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#questions-2"><i class="fa fa-check"></i><b>6.8.2</b> Questions</a></li>
<li class="chapter" data-level="6.9.1" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#the-code-1"><i class="fa fa-check"></i><b>6.9.1</b> The Code</a></li>
<li class="chapter" data-level="6.9.2" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#questions-2"><i class="fa fa-check"></i><b>6.9.2</b> Questions</a></li>
</ul></li>
<li class="chapter" data-level="6.9" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#summary-4"><i class="fa fa-check"></i><b>6.9</b> Summary</a></li>
<li class="chapter" data-level="6.10" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#summary-4"><i class="fa fa-check"></i><b>6.10</b> Summary</a></li>
</ul></li>
<li class="chapter" data-level="" data-path="about-the-authors.html"><a href="about-the-authors.html"><i class="fa fa-check"></i>About the Authors</a></li>
<li class="chapter" data-level="" data-path="appendix.html"><a href="appendix.html"><i class="fa fa-check"></i>Appendix</a>
Expand Down
9 changes: 5 additions & 4 deletions docs/ethics-of-using-ai.html
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,13 @@
<li class="chapter" data-level="6.5" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#example-two-identifying-a-coding-language"><i class="fa fa-check"></i><b>6.5</b> Example Two: Identifying a Coding Language</a></li>
<li class="chapter" data-level="6.6" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#example-three-interpreting-regex"><i class="fa fa-check"></i><b>6.6</b> Example Three: Interpreting Regex</a></li>
<li class="chapter" data-level="6.7" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#example-four-demystifying-functions"><i class="fa fa-check"></i><b>6.7</b> Example Four: Demystifying Functions</a></li>
<li class="chapter" data-level="6.8" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#hands-on-exercise-2"><i class="fa fa-check"></i><b>6.8</b> Hands-On Exercise</a>
<li class="chapter" data-level="6.8" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#limitations"><i class="fa fa-check"></i><b>6.8</b> Limitations</a></li>
<li class="chapter" data-level="6.9" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#hands-on-exercise-2"><i class="fa fa-check"></i><b>6.9</b> Hands-On Exercise</a>
<ul>
<li class="chapter" data-level="6.8.1" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#the-code-1"><i class="fa fa-check"></i><b>6.8.1</b> The Code</a></li>
<li class="chapter" data-level="6.8.2" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#questions-2"><i class="fa fa-check"></i><b>6.8.2</b> Questions</a></li>
<li class="chapter" data-level="6.9.1" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#the-code-1"><i class="fa fa-check"></i><b>6.9.1</b> The Code</a></li>
<li class="chapter" data-level="6.9.2" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#questions-2"><i class="fa fa-check"></i><b>6.9.2</b> Questions</a></li>
</ul></li>
<li class="chapter" data-level="6.9" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#summary-4"><i class="fa fa-check"></i><b>6.9</b> Summary</a></li>
<li class="chapter" data-level="6.10" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#summary-4"><i class="fa fa-check"></i><b>6.10</b> Summary</a></li>
</ul></li>
<li class="chapter" data-level="" data-path="about-the-authors.html"><a href="about-the-authors.html"><i class="fa fa-check"></i>About the Authors</a></li>
<li class="chapter" data-level="" data-path="appendix.html"><a href="appendix.html"><i class="fa fa-check"></i>Appendix</a>
Expand Down
9 changes: 5 additions & 4 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,13 @@
<li class="chapter" data-level="6.5" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#example-two-identifying-a-coding-language"><i class="fa fa-check"></i><b>6.5</b> Example Two: Identifying a Coding Language</a></li>
<li class="chapter" data-level="6.6" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#example-three-interpreting-regex"><i class="fa fa-check"></i><b>6.6</b> Example Three: Interpreting Regex</a></li>
<li class="chapter" data-level="6.7" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#example-four-demystifying-functions"><i class="fa fa-check"></i><b>6.7</b> Example Four: Demystifying Functions</a></li>
<li class="chapter" data-level="6.8" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#hands-on-exercise-2"><i class="fa fa-check"></i><b>6.8</b> Hands-On Exercise</a>
<li class="chapter" data-level="6.8" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#limitations"><i class="fa fa-check"></i><b>6.8</b> Limitations</a></li>
<li class="chapter" data-level="6.9" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#hands-on-exercise-2"><i class="fa fa-check"></i><b>6.9</b> Hands-On Exercise</a>
<ul>
<li class="chapter" data-level="6.8.1" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#the-code-1"><i class="fa fa-check"></i><b>6.8.1</b> The Code</a></li>
<li class="chapter" data-level="6.8.2" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#questions-2"><i class="fa fa-check"></i><b>6.8.2</b> Questions</a></li>
<li class="chapter" data-level="6.9.1" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#the-code-1"><i class="fa fa-check"></i><b>6.9.1</b> The Code</a></li>
<li class="chapter" data-level="6.9.2" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#questions-2"><i class="fa fa-check"></i><b>6.9.2</b> Questions</a></li>
</ul></li>
<li class="chapter" data-level="6.9" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#summary-4"><i class="fa fa-check"></i><b>6.9</b> Summary</a></li>
<li class="chapter" data-level="6.10" data-path="understanding-unfamiliar-code.html"><a href="understanding-unfamiliar-code.html#summary-4"><i class="fa fa-check"></i><b>6.10</b> Summary</a></li>
</ul></li>
<li class="chapter" data-level="" data-path="about-the-authors.html"><a href="about-the-authors.html"><i class="fa fa-check"></i>About the Authors</a></li>
<li class="chapter" data-level="" data-path="appendix.html"><a href="appendix.html"><i class="fa fa-check"></i>Appendix</a>
Expand Down
Loading

0 comments on commit cdc03d5

Please sign in to comment.