marijnh / Eloquent-JavaScript

The sources for the Eloquent JavaScript book
https://eloquentjavascript.net
3.01k stars 796 forks source link

Code example has redundant `else` block #295

Closed sangupta closed 6 years ago

sangupta commented 6 years ago

The else block in the code example below is redundant - as it is immediately preceded by a return statement. Code sample is as under:

image

The code block is available on this page: https://eloquentjavascript.net/3rd_edition/00_intro.html

There are other occurrences where the same pattern is used. I can help send a PR if needed.

mxschumacher commented 6 years ago

You are right in this particular instance, but Eloquent Javascript is a beginner's book, so I think it is sensible to spell out the full example. Without memoization this just a toy implementation anyway.

sangupta commented 6 years ago

Agreed. Just a thought around adding a comment to the code to let reader's know that they may skip it out.

marijnh commented 6 years ago

Yeah this is intentional. Sure it's technically redundant, but it's entirely harmless and makes the code easier to scan. You'll see more code like that throughout the book.