# Best line-by-line code explanation prompt I found so far

**URL:** <https://community.openai.com/t/best-line-by-line-code-explanation-prompt-i-found-so-far/12272>\
**Category:** API\
**Tags:** codex\
**Created:** [November 4, 2021, 11:39am UTC](https://community.openai.com/t/best-line-by-line-code-explanation-prompt-i-found-so-far/12272 "2021-11-04T11:39:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ldorigo](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/ldorigo/32/86_2.png) [@ldorigo](https://community.openai.com/u/ldorigo)\
**Post date:** [November 4, 2021, 11:39am UTC](https://community.openai.com/t/best-line-by-line-code-explanation-prompt-i-found-so-far/12272/1 "2021-11-04T11:39:47Z")

</div>

I tried quite a few code explanation prompts - sharing this one I found recently, it works way better than anything I tried before:

* * *

````auto
We have the following [xxx] code:

```[xxx]
	<your code here>
        <many lines of it>
\```

Let's explain what it does line by line:

```[xxx]

````

* * *

(remove the backslash before the closing ``` - I had to put it or it breaks the formatting of this post)

This produced by far the most detailed and easy to understand outputs I ever had. I think it works particularly well because it emulates the style of tutorial/blog posts/readme’s in markdown, and thus the model replicates the easy to understand and detailed language they use. I used it on some ancient fortran code from an obscure scientific paper and the amount of details and contextual information it gives is mind blowing:

> We have the following fortran code:
> 
> ```fortran
> common /fun/ pr(35),ob(35)
> real d(35,82)
> external funk,pp
> call sas('82.dat','82m1.lst','82m1.fit')
> write(7,"(' ***82Ss - model 1: FLMP***')")
> read(9,"(5f8.5)")d
> call runstp(funk,10,35,82,d,ob,pr,pp)
> stop
> end
> 
> subroutine funk
> common /step/ nv,ntrace,matrix,chisq,mask(100),x(100)
> common /fun/ pr(35),ob(35)
> c a v a v
> real bi(5,5),au(5),vi(5)
> equivalence (pr(1),bi),(pr(26),au),(pr(31),vi)
> integer a,v
> real xv(5),xa(5),ntop
> equivalence (x(1),xv),(x(6),xa)
> 
> do 40 v=1,5
> 40 vi(v)=xv(v)
> 
> do 50 a=1,5
> 50 au(a)=xa(a)
> 
> do 60 v=1,5
> do 60 a=1,5
> top=xv(v)*xa(a)
> ntop=(1.-xv(v))*(1.-xa(a))
> 60 bi(a,v)=top/(top+ntop)
> call cchi(ob,pr,35)
> return
> entry pp(is,rmsd)
> write(7,117)is,rmsd,xv,xa
> 117	format(/' Sub 'i2' rms= 'f7.4/' v = '5f7.4/' a = '5f7.4)
> return
> end
> 
> ```
> 
> Let’s explain what it does line by line:
> 
> ```fortran
> common /fun/ pr(35),ob(35)
> 
> ```
> 
> This is the common block that contains the observed and predicted values.
> 
> ```fortran
> real d(35,82)
> 
> ```
> 
> This is the data array. It is a 35x82 array of real numbers. The first  
> dimension is the number of observed values, and the second dimension is the  
> number of predicted values. The first observed value is `pr(1)`, the second  
> is `pr(2)`, and so on. The first predicted value is `ob(1)`, the second is  
> `ob(2)`, and so on.
> 
> ```fortran
> external funk,pp
> 
> ```
> 
> This is the external declaration of the `funk` and `pp` subroutines. These  
> are the subroutines that do the actual work of the program.
> 
> ```fortran
> call sas('82.dat','82m1.lst','82m1.fit')
> 
> ```
> 
> This is the call to the SAS program. It reads the observed and predicted  
> values from the files `82.dat` and `82m1.lst`. The `82m1.fit` file contains  
> the initial values for the parameters.
> 
> ```fortran
> write(7,"(' ***82Ss - model 1: FLMP***')")
> 
> ```
> 
> This is a message to the SAS log.
> 
> ```fortran
> read(9,"(5f8.5)")d
> 
> ```
> 
> This reads the data array from the SAS data file. The data file is  
> `82m1.dat`. The `5f8.5` means that each number is a real number with 5  
> digits, 8 of which are after the decimal point, and 5 digits after that.
> 
> ```fortran
> call runstp(funk,10,35,82,d,ob,pr,pp)
> 
> ```
> 
> This is the call to the `runstp` subroutine. The `funk` subroutine is the  
> one that does the actual work of the program. The `10` is the number of  
> iterations. The `35` is the number of observed values. The `82` is the  
> number of predicted values. The `d` is the data array. The `ob` is the  
> observed values. The `pr` is the predicted values. The `pp` is the  
> parameter values.

---

<div class="post-metadata">

**Author:** ![LexiTheTT](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/lexithett/32/6638_2.png) [@LexiTheTT](https://community.openai.com/u/LexiTheTT)\
**Post date:** [November 4, 2021, 12:45pm UTC](https://community.openai.com/t/best-line-by-line-code-explanation-prompt-i-found-so-far/12272/2 "2021-11-04T12:45:48Z")

</div>

Ooh! I was thinking about how to get this to teach me more! This’ll help! Thanks!

---

<div class="post-metadata">

**Author:** ![Coderr](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/coderr/32/189_2.png) [@Coderr](https://community.openai.com/u/Coderr)\
**Post date:** [November 8, 2021, 6:32am UTC](https://community.openai.com/t/best-line-by-line-code-explanation-prompt-i-found-so-far/12272/3 "2021-11-08T06:32:22Z")

</div>

What’s the scientific paper?

---

<div class="post-metadata">

**Author:** ![LexiTheTT](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/lexithett/32/6638_2.png) [@LexiTheTT](https://community.openai.com/u/LexiTheTT)\
**Post date:** [November 8, 2021, 8:10am UTC](https://community.openai.com/t/best-line-by-line-code-explanation-prompt-i-found-so-far/12272/4 "2021-11-08T08:10:56Z")

</div>

None, I’m using it as a teaching to for me so I can learn to program.

---

<div class="post-metadata">

**Author:** ![calum](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/calum/32/61_2.png) [@calum](https://community.openai.com/u/calum)\
**Post date:** [November 9, 2021, 9:45pm UTC](https://community.openai.com/t/best-line-by-line-code-explanation-prompt-i-found-so-far/12272/5 "2021-11-09T21:45:53Z")

</div>

This is really fascinating - what parameters were you using (temperature, top-p, etc.)? I’m working on a project that is documenting code in an automated manner, and it’s always neat to see new prompt designs!

---

<div class="post-metadata">

**Author:** ![pappachuck](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/pappachuck/32/643_2.png) [@pappachuck](https://community.openai.com/u/pappachuck)\
**Post date:** [November 13, 2021, 6:19pm UTC](https://community.openai.com/t/best-line-by-line-code-explanation-prompt-i-found-so-far/12272/6 "2021-11-13T18:19:35Z")

</div>

“We speak the right words. Then we create life itself… Out of chaos.” - Dr. Ford (Anthony Hopkins).

---

<div class="post-metadata">

**Author:** ![ediardo](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/ediardo/32/7283_2.png) [@ediardo](https://community.openai.com/u/ediardo)\
**Post date:** [January 13, 2022, 10:11pm UTC](https://community.openai.com/t/best-line-by-line-code-explanation-prompt-i-found-so-far/12272/7 "2022-01-13T22:11:28Z")

</div>

Hi @ldorigo , thanks for sharing your prompt.

I’m using a similar structure for getting code explanations. In my tests, I noticed that providing metadata like programming language name, helps Codex to deduce the programming language effectively. This is particularly useful is the code snippet is not long enough or the sample syntax is similar to other programming languages.
