Visualstudio-docs: Very bad example of recursion

Created on 22 Feb 2018  Â·  9Comments  Â·  Source: MicrosoftDocs/visualstudio-docs

If you have to explain factorial to explain recursion that means example is wrong. There are so many intuitive examples you could have given but you chose to explain docs to math major instead of JS programmer.


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

  • ID: e391bc6b-eb62-016e-7a19-137f9fdcfc1b
  • Version Independent ID: 4af94735-aefb-88e3-787d-6607c2c3fef3
  • Content
  • Content Source
  • Service: unspecified

Most helpful comment

const countDownFrom = num => {
  if (num>0) {
    console.log(num)
    return countDownFrom(num-1)
  }
}

countDownFrom(5)

Sorry I don't want to be rude. I'm just giving feedback that the docs should have an example that's easy to understand for everybody. Then maybe your example could go afterwards once everybody gets the initial idea.

All 9 comments

@bterlson for input

Factorial is a canonical example when teaching recursion as far as I know. If someone wants to suggest a better alternative I'm sure we'd be open to it, but I can't come up with anything clearer off the top of my head.

const countDownFrom = num => {
  if (num>0) {
    console.log(num)
    return countDownFrom(num-1)
  }
}

countDownFrom(5)

Sorry I don't want to be rude. I'm just giving feedback that the docs should have an example that's easy to understand for everybody. Then maybe your example could go afterwards once everybody gets the initial idea.

Yep

@jakubrpawlowski do you think it's confusing that countDownFrom is not a case when you would use recursion in reality? A maximally practical and simple example seems ideal, just not sure countDownFrom fits that bill.

@jakubrpawlowski great example, thanks!

Planning to close this unless we have a simple real-world example that I can add to the docs.

This issue is captured in a work item for our backlog.

@jakubrpawlowski is right. The Microsoft docs are infamous for containing overly complex code to make it more "realistic", instead of just explaining the actual functionality of something with easy examples. A countdown example is a great way of explaining recursive functions. In fact, that's what they do in many other places like in this article (https://www.sitepoint.com/recursion-functional-javascript/).

First teach the bare minimum to give the reader a basic understanding of how it works, then after that you can start giving more advanced examples that requires knowledge about factorials for example.

Was this page helpful?
0 / 5 - 0 ratings