Fork me on GitHub
#clojure-uk
<
2017-03-26
>
seancorfield00:03:27

README updated. Argument handling is in a pure function that either returns an :exit-message or returns an :action and the :options. This is more amenable to testing. And if you really want to call -main in the REPL, you could wrap that call with a with-redefs to change the exit function (defined in the cli-example.core namespace to just println instead of calling System/exit (which you could have done before, but this new structure has all the validation in one place instead of mixed with the actual program actions).

mattford07:03:12

🙂 well that was some nice coincidence

korny08:03:48

Yeah, I was wondering if you could call with-redefs - does that work for Java static methods? You could redefine it to throw an exception which your tests could catch

korny08:03:03

Ah, I see you are calling 'exit' not System/exit - please ignore me :-)

mattford12:03:09

What’s the best practice regarding namespacing - is there a good doc?

mattford12:03:21

I created a namespace sa

mattford12:03:01

And in it a whole bunch of functions like sa/read, sa/write

mattford12:03:22

But there’s warnings about read being defined already.

mattford12:03:28

(obviously)

mattford12:03:21

Doesn’t seem much of a namespace if I have to have the fn name altered to refelct sa

mattford12:03:31

Any thoughts/pointers?

mattford12:03:18

Also having to declare functions in order is consistently tripping me up. What's that all about?

agile_geek13:03:45

@mattford it's a warning so you can ignore it but obviously it's there to tell you that you've shadowed a core fn. It's useful if somewhere in the namespace you call read and expect it to resolve to clojure.core/read to be reminded that you shadowed that fn otherwise you would get unexpected results. See this discussion by Rich Hickey on what defines a compilation unit and how interning at read time would change Clojure's REPL driven dynamic. https://news.ycombinator.com/item?id=2467359

dominicm13:03:20

@mattford to get rid of the warning, the ns macro takes a :refer-clojure option, as in: (:refer-clojure :exclude [read])

mattford13:03:58

Cheers both!

mattford13:03:10

Interest read above.

mattford13:03:18

The ordering requirement feels very much at odd with repl based dev.

dominicm13:03:06

It's Clojure's one compile time check 😛

agile_geek14:03:18

Ordering declaration makes complete sense in a REPL. If you didn't then a fn you typed at the repl would not necessarily be immediately usable as it could have a hanging unresolved ref.

mattford16:03:51

That's true but the work flow is to iterate continuously on the functions so that the initial ordering is lost. Lost that is in my mind :-)

otfrom21:03:50

mattford I usually don't defn a function in the repl. I do lots of lets that I refactor into functions (and copy paste the repl output into a test). I guess I've gotten used to the single pass compiler over time, so it doesn't usually bother me. I do usually restart my repl after defining a lot of things to make sure I haven't copied over dummy things, got my stuff out of order or depended on something in my repl environment to make things work (as I want them to work later)

otfrom21:03:19

I make sure I've got the repl history saved tho so I can go back and get the things I need if I've forgotten something tho

seancorfield21:03:25

I tend to have a source file open and write code there but evaluate it inline (into the REPL), so I naturally just sort of write it bottom-up, i.e., the order Clojure expects. Or maybe as a function gets too big, I'll refactor it into smaller functions just above it.

seancorfield21:03:30

I did that with Emacs and now I do the same with Atom/ProtoREPL. I don't tend to write much directly in the REPL -- just a few test expressions -- since it's easy to just write code in the source file and evaluate it piece by piece.

otfrom21:03:07

seancorfield I sort of force myself to do it in the repl first in a let so that moving it to the source code buffer is the first refactoring (as I have the test captured from my let in the repl)

seancorfield21:03:06

When I used LightTable for a while, I developed a workflow where I write fragments of code in a source file and evaluate them inline, instead of using a separate REPL. I've carried that over into Emacs and then ProtoREPL... so I probably follow the same pattern as you, just inside a source file as it grows and refactors into actual functions...

otfrom22:03:45

I do get that my workflow is a bit old and doesn't take full advantage of the latest things in cider/atom/intellij/other

seancorfield22:03:54

The inline evaluation with LightTable really inspired me to work differently. That's when I found myself no longer needing or wanting the REPL as a separate thing. I'll often still spin up a REPL from the command line, with Boot, so I can pull in a specific library to just play with.

seancorfield22:03:04

Mostly I do that when I'm helping someone here on Slack, if it's with a library we're not already using in our code base.