Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove duplication in asynchttpserver examples #16586

Merged

Conversation

timotheecour
Copy link
Member

@timotheecour timotheecour commented Jan 4, 2021

fixes bug 2 in #16506 (comment)

followup after #16580
can test server with:
nim doc -r --doccmd:-d:nimAsynchttpserverEnableTest lib/pure/asynchttpserver.nim

@timotheecour timotheecour force-pushed the pr_followup_16580_runnableExamples branch from b10138e to 21d336d Compare January 4, 2021 20:48
@narimiran
Copy link
Member

So, instead of some code duplication, we now have a runnable example which most likely will never be run.

People found the previous bug just by copy-pasting and running the example. If they do the same now, nothing will happen because of if (!) defined, with no mention in the example when this condition is true, i.e. how to enable it.

@timotheecour
Copy link
Member Author

timotheecour commented Jan 5, 2021

--docCmd is documented already; in any case I've added a comment to show how to run this; no copy paste needed. And anyone with more than a few hours of experience with nim should know how to pass -d:foo on cmdline. Much better than duplication anyways.

@Araq
Copy link
Member

Araq commented Jan 5, 2021

Why is this an if defined? What's wrong wtih when defined?

@timotheecour
Copy link
Member Author

timotheecour commented Jan 5, 2021

@Araq

Why is this an if defined? What's wrong wtih when defined?

it's intentional, otherwise the code is never semchecked and makes the runnableExamples much less useful for CI; it's a good pattern IMO, to use whenever we want the example to keep compiling but not run by default unless a flag is specified

case in point: see nim-lang/fusion#67 (just today), where a bug was found thanks to if defined(fusionJsFormdataTests): being used instead of when defined(fusionJsFormdataTests): in runnableExamples

@Araq Araq merged commit 3b2f948 into nim-lang:devel Jan 5, 2021
@timotheecour timotheecour deleted the pr_followup_16580_runnableExamples branch January 6, 2021 09:59
mildred pushed a commit to mildred/Nim that referenced this pull request Jan 11, 2021
* remove duplication in asynchttpserver examples

* fixup

* add comment showing how to run snippet locally
@ghost
Copy link

ghost commented Feb 28, 2021

IMO that example will be very confusing for people who read asynchttpserver's docs. I understand that it reduces code duplication, but generally, the examples in stdlib that we have don't need to be run from the module itself.

ardek66 pushed a commit to ardek66/Nim that referenced this pull request Mar 26, 2021
* remove duplication in asynchttpserver examples

* fixup

* add comment showing how to run snippet locally
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants