Clojure Dev Environment

526 views
Skip to first unread message

Miguel Ping

unread,
Oct 5, 2015, 6:00:37 AM10/5/15
to Clojure
Hi Guys,

I've been doing some personal clj for a while, but I never quite grokked the whole REPL thing. I normally use Lighttable and/or Cursive as editors, I can set up breakpoints and debug the code, but for web I'd like to know how seasoned developers work.
AFAIK people fire up the repl and "do everything from there" but I still don't understand some parts:

- do you code functions in the repl and copy them to respective files?
- do you edit files directly and hook them into the repl?
- how do you set breakpoints?
- can you do hot-replacement easily? I always see a bunch of stack traces while using lein and ring with reload flags
- is there an article or screencast explaining the "feel" of this?

My current worfklow is just starting > lein ring server and developing, but my general impression is that I need to restart it sometimes.

As I understand it, the repl workflow is very much a lisp thing.
Thanks!

Robin Heggelund Hansen

unread,
Oct 5, 2015, 6:55:53 AM10/5/15
to Clojure
Basically, I use stuart sierra's tools.namespace and component libraries to write an application that can be easily reloaded. So I write my code in regular files, then i tell the repl to reload my application with the latest changes from disk. I can also test the application while it's running, because I have access to every function. Hot-replacement is a matter of calling 'reset. Although that does technically shut down the application, so maybe it can't be called "hot".

Anyway, you can read more here: https://github.com/stuartsierra/component

Erik Price

unread,
Oct 5, 2015, 1:34:22 PM10/5/15
to clo...@googlegroups.com
vim-fireplace lets you compile individual S-expressions into an existing nREPL (one in which the rest of your code is typically also loaded and available), so I typically make all my code changes right in the editor against the actual file I'm working on. Then I just compile the function I'm editing and send it to the REPL. I'll usually just add a comment block near the changes I'm making and put test expressions inside of it, and execute those expressions as needed to test my changes. It's awesome.

(Of course, I delete that comment block prior to committing my work.)

e


On Monday, October 5, 2015, Robin Heggelund Hansen <skinn...@gmail.com> wrote:
Basically, I use stuart sierra's tools.namespace and component libraries to write an application that can be easily reloaded. So I write my code in regular files, then i tell the repl to reload my application with the latest changes from disk. I can also test the application while it's running, because I have access to every function. Hot-replacement is a matter of calling 'reset. Although that does technically shut down the application, so maybe it can't be called "hot".

Anyway, you can read more here: https://github.com/stuartsierra/component

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nelson Morris

unread,
Oct 5, 2015, 2:04:05 PM10/5/15
to Clojure
http://www.parens-of-the-dead.com/ is a screencast series that shows a nice emacs/cider workflow with some additional usage of figwheel for the cljs frontend development. No showing off of the debugger yet though. Cursive should be able to do something similar with keybindings for running tests and refactorings.

There is little direct repl interaction in this series.  However, many of the commands use the connection to the development environment to run things for the user.  For example, clj-autotest runs 
https://github.com/magnars/.emacs.d/blob/master/site-lisp/clj-autotest.el#L4 over the connection. Hot swapping works by the tooling sending the new code over the connection.

Personally, I use the repl a bit more, but for exploratory testing. Does `(repeat 1 2)` return '(1 1) or '(2) type things.  The majority of writing code happens in the file, and I let the tooling load it for me.  Additionally, for web development I use a ring server component much like the screencasts, instead of `lein ring server`. Then I can use the reloaded/refresh style system to restart everything when needed rather then needing to kill the whole jvm.

--

Sean Corfield

unread,
Oct 5, 2015, 3:07:32 PM10/5/15
to clo...@googlegroups.com
Miguel Ping wrote on Monday, October 5, 2015 at 3:00 AM:
- do you code functions in the repl and copy them to respective files?

I use Emacs/CIDER and code functions in a file, then use C-M-x to evaluate each one into the running REPL. I usually keep the REPL in the user namespace and require in the namespace I’m working on (C-c C-z to jump to the REPL as needed) and then type in expressions to test functions as I go. Later I’ll take a transcript of parts of the REPL and add them to my unit test namespace — usually just copy’n’paste, followed by some minor edits to turn them into Expectations format: (expect {expected} {actual}) which means using C-M-t to swap REPL output which has:

user> (some test expression)
{the actual output}

=>

(expect {the actual output}
        (some test expression))

Put the cursor after the prompt: user>| then M-delete, type (expect) and slurp twice M-) then forward one s-exp C-M-f and swap C-M-t

- do you edit files directly and hook them into the repl?

Yes, but I don’t save them every time since I can use C-M-x to evaluate the current form as I type.

- how do you set breakpoints?

I don’t bother. I’ve never liked step debuggers in any language in my 30+ years of development :(

- can you do hot-replacement easily? I always see a bunch of stack traces while using lein and ring with reload flags

If I want to hot-swap into a running process, I just start a REPL server inside the process and connect CIDER to that, instead of starting a standalone REPL in Emacs. I tend to use standalone REPLs only for running Expectations anyway (where I use a slightly different workflow and keep the REPL in the same namespace as the Expectations file (C-c M-n to swap REPL namespaces).

- is there an article or screencast explaining the "feel" of this?

I don’t know, sorry.

Sean

Miguel Ping

unread,
Oct 6, 2015, 4:41:47 AM10/6/15
to Clojure
Thanks guys!

For me the ideal flow would be something that would allow me to save an incoming http req (I do mostly web dev) onto some variable/def, and replay it against some code I'm writing in the repl.
Also I like to use step debuggers when I'm new to the language or lib, it allows me to go down the rabbit hole and see how things work. Sometimes you find some surprises!

I think documentation on this is something that's missing on the clj community, because everyone does things a little different, but it makes it hard for beginners to get the gist of it.
I know some people that don't even have auto-reload on lein/ring and end up stopping/starting the jvm which is crazy because it takes a while.

I may write something up, I would appreciate if you guys had any more suggestions, including suggestions about where to put this info.

This is what I think it's standard practice:

- ideally you don't restart jvm
- on ring, use hot-reload/auto-reload
- app can be started from repl
- ide can eval clj expressions (send it to repl)
- people code small bits on ide, eval it, loop on this until its working - can do this for tests also
- basically the whole idea is to have components built upon functional style that can be started and invoked from the repl at any layer depth

- As for debuggers, I know some people other than Sean that dont use step debuggers at all (specially oldschool ppl), but I think its helpful for newbies


I will keep you guys updated if I ever write something. First have to learn it ;)

Erlis Vidal

unread,
Oct 6, 2015, 10:18:00 AM10/6/15
to Clojure
I think it will be very helpful to the Clojure community to have something done with Videos (screencasts) ... Clojure University? somewhere we can see how the more seasoned developers work. At least I won't have to discover by myself, I can copy the best guys..

I'll like to read whatever you write.

Keep the good work. 
Erlis 

Sven Richter

unread,
Oct 7, 2015, 8:11:34 AM10/7/15
to Clojure
Hi Miguel,

When I started clojure and web development I faced the same questions for some long time. Also it took me a lot to figure out how to have the best developer experience (regarding web stuff).
All my findings boil down into this leiningen template: https://github.com/sveri/closp

It delivers

* two different environments (development and production)
* figwheel for clojurescript during development (no need to restart)
* a combination of components and ring dev environment for not having to restart the JVM

While figwheel delivers everything needed for cljs side it was not so easy for clojure development.
The trickiest part was to make the reloading of namespaces work in a web environment, I tried several libraries, but none gave the full experience. So I chose to integrate Stuart Sierras component library.
This wayI finally gained hot code deployment where it works, templates reloading (selmer templates) and a manual restarting option, which I only need when I change compojure routes.
Manual restart does not mean to restart the server, but running a "restart" function which will just reload all changed namespace and pick up changed routes.

You might want to try it out or just look at this namespace: https://github.com/sveri/closp/tree/master/resources/leiningen/new/closp/clj/components plus https://github.com/sveri/closp/blob/master/resources/leiningen/new/closp/clj/user.clj

I do all this using a command line for fighweel and cursive with a repl started inside cursive for the server environment.

Best Regards,
Sven

PS: It might be that the template does not compile currently, if so, you just have to adopt the namespace that the compiler complains about. I will fix that in the next version.

Sven Richter

unread,
Oct 7, 2015, 8:14:11 AM10/7/15
to Clojure, er...@erlisvidal.com
Hi Erlis,

Not considering myself a seasoned developer, still I stream from time to time on: https://www.livecoding.tv/sveri/
I am always happy to talk about things and explain everything to my best knowledge.

Best Regards,
Sven

Erlis Vidal

unread,
Oct 7, 2015, 9:24:33 AM10/7/15
to Sven Richter, Clojure
Sven!

Thans for sharing!
Reply all
Reply to author
Forward
0 new messages