seancorfield / usermanager-example

A little demo web app in Clojure, using Component, Ring, Compojure, Selmer (and a database)
Other
338 stars 38 forks source link

Webserver does not restart upon component/start /stop /start #2

Closed kloimhardt closed 4 years ago

kloimhardt commented 4 years ago

Step 0: successful initialisation of application

With original code unchanged, in the repl I evaluated the following two forms:

(def system (new-system 8888))
(alter-var-root #'system component/start)

Then, I modified the route handlers in the function my-handler. After doing a top-level evaluation of my-handler, the application did still not reflect the changes.

Unsuccessful activation of new handlers

After Step 0, I evaluated two forms:

(alter-var-root #'system component/stop)
(alter-var-root #'system component/start)

As opposed to my expectation, the function start in the WebServer record was not called, whereas this function start was indeed called upon Step 0 (see screenshot, note the expected but missing message "in record WebServer: start" after the last line). Naturally enough, the application showed a "localhost refused to connect." error.

Screenshot_usermanager_repl

Successful activation of new handlers

After Step 0, I evaluated three forms:

(alter-var-root #'system component/stop)
(def system (new-system 8888))
(alter-var-root #'system component/start)

Is this is the right way to activate the modified handlers? It seems odd to create another system for that.

seancorfield commented 4 years ago

You found a bug! Fixed on master so you'll need to apply the fix I just pushed.

kloimhardt commented 4 years ago

But the only way to activate changes in usermanager.main/my-handler is to stop/start, right? If so, can you maybe again add a short code-comment? I am unsure about start/stop, because to activate a changed handler-function like usermanager.controllers.user/default, it suffices to simply eval that function in the repl. And after lots of JVM-restarts, I'd like to get that all elusive repl workflow right. To this end, I need to get as confident in using stop/start+eval in the right situations as being confident in JVM-restart. This JVM restart is so enticing because it always satisfies the need. (In other words, the wannabe Repl-Odysseus must be bound(!) to the mast of the repl-ship in order to resist the restart-song of the JVM-Sirens.) Because I was not able to find the bug myself, one thing became clear to me: it is impossible for a beginner to write a repl-friendly codebase. One has to have understood the repl-concept in order to write a repl-friendly codebase. And understanding the repl-concept means being confident in using the repl in an existing repl-friendly codebase. I came to the conclusion, that the best thing is to give an already existing repl-friendly codebase to a beginner and tell him: "play with it, but never save your files, it does not mean anything". Do you agree? It took me long to come to this (maybe wrong?) conclusion, because the figwheel concept for Clojurescript is completely based on saving files (at the moment I do not know what to make of that, here certainly is a source of confusion). It urges me to clarify one thing of my last comment to issue #1: what I meant by "democratic", I have from Wallace's essay Tense Present. In that sense, usermanager-axample is like a usage-dictionary, which, in an ideal language community, embodies the articles final message: that the purposes of the expert authority and the purposes of the lay reader are identical, which is about as Democratic as you get. (The whole essay is rather long, but already the section "Articles Crux" of its last two pages give so much guidance about language and community).

seancorfield commented 4 years ago

No, if you use the #' Var reference, then you can redefine that function while the app is running and the new version is picked up immediately. No need for a restart.

GitHub issues are not a very productive way to have a discussion: I think you'd do much better to join the Clojurians Slack and ask about REPL-driven development in the #beginners channel there. https://clojurians.slack.com/ for chatting, http://clojurians.net/ to sign up.