This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-03-23
Channels
- # admin-announcements (6)
- # aleph (3)
- # beginners (38)
- # boot (119)
- # braid-chat (15)
- # braveandtrue (1)
- # clara (4)
- # cljs-dev (56)
- # cljsfiddle (12)
- # cljsjs (15)
- # cljsrn (6)
- # clojars (4)
- # clojure (113)
- # clojure-art (1)
- # clojure-berlin (1)
- # clojure-dusseldorf (3)
- # clojure-india (15)
- # clojure-new-zealand (3)
- # clojure-poland (1)
- # clojure-russia (83)
- # clojure-uk (18)
- # clojurescript (97)
- # community-development (9)
- # cursive (1)
- # data-science (1)
- # datomic (12)
- # emacs (14)
- # hoplon (350)
- # immutant (2)
- # jobs (2)
- # jobs-discuss (23)
- # keechma (74)
- # liberator (1)
- # off-topic (1)
- # om (127)
- # onyx (54)
- # parinfer (74)
- # pedestal (1)
- # proton (5)
- # re-frame (6)
- # reagent (4)
- # remote-jobs (17)
- # ring-swagger (1)
- # slack-help (5)
- # untangled (16)
- # yada (21)
hey if I want to manage my routing on the client side, how can I make it so that on the backend ring always serves up my index.html and does not care what the url is?
@adamkowalski: implement a catch all route like "*"
and respond with index.html there
@adamkowalski: this is an example: https://gist.github.com/yeehaa123/d73304e2516cf1ae4c32
not-found
is probably better than *
as well
@roberto: I'm sure there are better ways but one option could be to throw an exception, catch it and inspect it's stacktrace.
my problem is that I have a logger
that wraps around timbre
. Mostly it is there to do some calculations before we log. I want to include the namespace from where the logger function was called.
timbre
has a :?ns
key I can use in the appenders, but it always defaults to my logger
wrapper, which defeats the entire purpose of wanting to include the ns
@roberto: ah, probably then have logging macros that pass *ns*
from the callsite?
@roberto: I'd suggest asking in #C03S1KBA2 as well, not a beginners question I'd say
another question. I’m trying to implement a protocol that is in a different ns using extend
, but it isn’t working for me. I might be missing something obvious. E.g:
(ns prots.blues
(:require [prots.protocols :as p]))
(deftype BluesPlayer [fname lname]
p/Speaks
(speak [this] "HOO"))
(extend BluesPlayer
p/Rocks
{:rocks (fn [this] "HOOOO")})
(def wolf (BluesPlayer. "Wolfy" "Howls"))
if I implement p/Rocks when I declare the
BluesPlayer` type, then it works. Or if I declare the protocol in the same namespace as the type declaration, then using extend
works.
it is normal to add a bang ! to the end of a clojure function that has side effects, right?
@lmergen: I usually add it to stuff that "changes the outside world"
but, that means that bangs should bubble up, right? a function calling a function with a ! should, by definition, also have a !
@lmergen @stuartsierra has a very good post about naming functions. It also discusses the ! you might find it useful https://stuartsierra.com/2016/01/09/how-to-name-clojure-functions
@jmayaalv: thanks! so, people basically do not know what to do and there is no real standard
> If I do use an exclamation mark, it’s to signal a change to a mutable reference, not other side-effects such as I/O.
I think that, if you start using it for too broad a range of different function, it starts to lose its value
if you consider 'impure / side effects' the reason to add an exclamation mark, you basically have to add an exclamation mark whenever you would have something inside an IO Monad in Haskell
as in, every Ring handler function should probably have a ! if it talks with a database / does anything useful
Part of the problem with !
is that if you use it to indicate code that isn’t safe in a retry situation (i.e., you can’t just re-run a function repeatedly and get the same result), then you end up with !
all over the place — as you surmised.
In java.jdbc
, I took feedback from the Clojure/core folks way back and the consensus was that query
was OK (even tho’ the DB could change under you and give you back different results on each call) but execute!
, insert!
, and delete!
should indicate "unsafe" because they’re (almost) guaranteed to change the world.
But it’s certainly not clear cut in most cases.
In our own codebase, we have almost no !
functions because so much code ultimately depends on the database (and often modifying the database). But I’m not very happy with that and would prefer to separate out queries (of any data sources) from updates (to any data sinks). If only to make code more testable.
We're phasing out our aggressive use !
to mean "side-effecty" or even "mutates stuff" and transitioned to "dangerous or at least destructive". we have too many idempotent database update operations to make it really useful. When everything has a !
, then really nothing does
(Though, amusingly, our internal wrapper for JDBC's query
is still query!
because we use for inserts where we use returning
)
query!
in jdbc is reasonably defensible as it can very much have side effects, depending on your isolation level
@martinklepsch: thanks, that is very helpful!
donaldball: and there we have the problem, in a language such as Haskell, this would have been exposed by an IO monad. in Clojure, there is no such thing. I think the best thing to do is to just be very conservative with using a !
, because otherwise they will literally be all over the place, and we would end up with main!
.