This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-11-23
Channels
- # announcements (66)
- # babashka (41)
- # beginners (93)
- # calva (10)
- # cider (2)
- # clj-kondo (112)
- # cljs-dev (6)
- # cljsrn (1)
- # clojure (44)
- # clojure-dev (10)
- # clojure-europe (35)
- # clojure-italy (15)
- # clojure-nl (3)
- # clojure-uk (2)
- # clojurescript (38)
- # conjure (1)
- # datalevin (1)
- # datomic (16)
- # deps-new (4)
- # events (7)
- # figwheel-main (1)
- # fulcro (59)
- # graalvm (21)
- # integrant (3)
- # introduce-yourself (8)
- # jobs-discuss (2)
- # malli (23)
- # membrane (11)
- # membrane-term (2)
- # missionary (17)
- # off-topic (7)
- # pathom (23)
- # pedestal (6)
- # polylith (7)
- # portal (25)
- # releases (1)
- # remote-jobs (3)
- # reveal (5)
- # shadow-cljs (43)
- # spacemacs (7)
- # sql (18)
- # tools-deps (33)
- # vim (10)
- # xtdb (36)
Alternatively: https://clojurians.slack.com/archives/C0DF8R51A/p1637624321089500?thread_ts=1637623256.089300&cid=C0DF8R51A 🙂
I have a Figwheel project in which I want to have multiple pages such that each page has its corresponding ClojureScript file. How can I make sure that for a given HTML page a particular ClojureScript namespace is used? Let's say I have this HTML page:
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="css/style.css" rel="stylesheet" type="text/css">
<link rel="icon" href="">
</head>
<body>
<div id="reg">
<h2>Figwheel template</h2>
<p>Checkout your developer console.</p>
</div>
<script src="js/compiled/migration_to_russia.js" type="text/javascript"></script>
</body>
</html>
And I have this CloureScript file:
(ns migration-to-russia.reg
(:require
[reagent.core :as reagent :refer [atom]]
[reagent.dom :as rd]))
(enable-console-print!)
(println "This text is printed from src/migration-to-russia/core.cljs. Go ahead and edit it and see reloading in action.")
;; define your app data so that it doesn't get over-written on reload
(defonce app-state (atom {:text "Test"}))
;; Registration, reg.html (start)
(defn reg []
[:div
[:h1 "Регистрация"]
[:h3 "Проверка"]])
(rd/render [reg]
(. js/document (getElementById "reg")))
;; Registration, reg.html (start)
(defn on-js-reload []
;; optionally touch your app-state to force rerendering depending on
;; your application
;; (swap! app-state update-in [:__figwheel_counter] inc)
)
How can I make sure that the HTML page uses the code from the above ClojureScript file (i. e. uses that code to bind reg
in HTML to whatever is defined in the above ClojureScript file)?Short answer - just add print somewhere in the namespace and check developer console after loading. Long - your should check with your figwheel configuration and check into which bundle file that namespace will be rendered. And if that file is different from migration_to_russia.js then unlikely it will be used
@U04V4KLKC Thanks for the hint!
(assoc-some
{}
:foo 10
:bar nil)
=> {:foo 10}
what is the closest to this assoc-some
I'm thinking of? It should only add items when the value is not nilI use cond->
a lot for this kind of thing
(cond-> {:foo 10} bar (assoc :bar bar))
would be in practice (where you don't know if bar is nil or not)
How can I setup logging easily? There's https://github.com/clojure/tools.logging but this https://lambdaisland.com/blog/2020-06-12-logging-in-clojure-making-sense-of-the-mess seems to suggest there are better ways? I'm looking for something simple that a beginner can use to log to plain txt file. https://clojuredocs.org/clojure.core/spit perhaps?
it's a mess, and I haven't found an easy way to set it all up without just stealing it from existing projects
I use clojure.tools logging, with slf4j behind it. It's pretty straight forward methinks
I've been meaning to try out timbre
I find it a bit clunky to use and not as intuitive, dare I say it, as a simple xml file controlled by slf4j!
@dharrigan have you ever found docs on how to set those up properly?
https://github.com/dharrigan/startrek/blob/cbb200c8cf37224b803644536ba3bed8ab04e2ca/src/startrek/components/starship/impl.clj#L4 and https://github.com/dharrigan/startrek/blob/cbb200c8cf37224b803644536ba3bed8ab04e2ca/src/startrek/components/starship/impl.clj#L44
that's what I meant about cribbing it from existing projects
and there's a big presumption that you already understand java's logging ecosystem
it's not a great situation, currently
sure, I guess I just mean that my original point stands, that it's a bit of a mess and mostly just need to steal it from existing projects
imho, we all borrow from other projects, not only logging. I stand on the shoulders of mightier giants than I.
sure, but even that's not ideal
is my point
Why? I mean, there's far to much NIH in many projects, causing things to be done time and time again, solving the same problems over and over.
If you can learn from others who when before us, how those problems where solved and how it can apply to our own projects, then that's incorporating the wisdom of others and their experiences into your own learning.
So, I think it is quite ideal, to learn from others and not ignore the lessons from the past.
ok this is veering way off course from what I was taking about. my point was clear documentation that explains the setups holistically is superior to just copy/pasting
no one is saying don't learn from other projects
I'm saying that the only/best way to setup logging being copy/pasting is inferior to having well-rounded documentation, including examples, for solving the problem
I'm not here for "they should just read the code", it has been settled since forever that documentation is much, much better than slinging a mountain of code at people and hoping for the best
I don't understand any of them well enough to do that
if you do, then please do
that's the Curse of Knowledge in play
beginners and those who don't understand are the best judge of whether documentation is sufficient
because the proof of sufficiency is whether it's good enough to teach and to learn
because that's what it's there for
Beyond just Clojure, I have never been able to get a sense of the trade-off between different logging frameworks. I have certainly felt the trade-offs after making an arbitrary choice, spending the time to learn, and then regretting/enjoying it. I find the docs for most logging projects all read very similarly because they focus on the basic mechanics (and often speed). The tricky stuff is usually in the configuration or something that gets glossed over as just “setup”.
that's a great point, too, there are different documentation needs at different levels of expertise.
you're at the point of not just "how do I do this?" but at "how do I do this well?" and "what are the implications of choices?"
all super valid levels to be at and grow from, all poorly served by code you copy/paste
this is my dead horse I flog from time to time
thanks for coming to my TED talk
I have had success getting some code to work by just copy-pasting. In my opinion the critical piece that is missing the “why” for any of the choices made.
And if we want to solve interesting problems that tackle meaningful complexity over long stretches of time, just “getting it to work” isn’t enough.
sure, the setup need is served by copy/paste, but not the most critical part: understanding why
serving beginners needs with docs yields big results later, too. give an on-ramp for beginners to become intermediate and you suddenly have more people to write different levels of docs at intermediate and novice levels
but if we create bottlenecks at the beginning then fewer people reach intermediate or mastery
it's a sweet positive reinforcement loop once you get it going at a cultural level
the dynamics of culture that yields great tools and docs and all that goodness depends on a strong inflow of people. otherwise the community shrinks or you end up with some wild survivorship bias that limits diversity of experience and needs
tl;dr: The “what” matters to get things working, but the “why” matters to get things working well and allows for knowledge and understanding growth?
The culture of incomplete and downright bad documentation has a creeping effect as well. I'm constantly surprised when beginners ask questions about those Clojure projects that are well documented where the answer is right there in the docs. Then I remember that they've just grown to expect bad docs and likely don't bother looking.
or it's hard to find in the docs
Yes, I see that too. Sometimes I wonder what’s the difference between languages, how to present Clojure in the best light (I’ll make a hungarian Clojure site) and that’s hard, how to build a successful project from the ground up. My experience in ad agencies (head of digital) dates back 15 years... but Clojure is different. What’s the difference between Golang/ Python/ R vs Clojure? Why would people try Clojure? Why is it so difficult to start for a complete beginner? How solve this? Eg. at R.. so easy to understand the documentation.. you can solve difficult problems quickly (I create my own LAMR environment (not PHP, I used R).. within 2 months..). So, I’m really thinking how to create one site, what is really helpful from early students like 8-12 yo, and they can learn like me Basic language.. So, I’m not sure.. complex examples bad.. ofc with documentation better; but how we can build more easier start for Clojure.
and they're already drowning in a sea of information and don't have the necessary context to zero in on the information they need
they're big questions. @pez has done so much wonderful work on addressing the needs of beginners. and @jr0cket has an awesome website that contains a huge number of resources for learning and growing in clojure
For me, I came here because clojure.tools.logging by default logs to terminal. I wanted to change the default to log to a file but couldn't find it from the official docs (and the many other frequently used docs resources for clojure) after 15 minutes. Googling turned up too many results and so I hoped to get some tips from Clojurians
If you are going down the logback.xml route, then I can help you by showing you what should go into that file to log to a file
I'm still reading/trying to understand the logback.xml part, but I really just wanted something easy to log to file quickly
One defines appenders, console and file are two such appenders, then you tell the logger (root in this case) which appenders to use.
I don't have a java background. Is logback.xml part of the SLF4J library? where should I look for documentation on logback.xml?
logback and slf4j are by the same person. There is extensive documentation here: http://logback.qos.ch/documentation.html
that's awesome feedback! I love it 💜
if there are issues with tools.logging docs, would welcome a question at https://ask.clojure.org to move towards fixing it
human brains are great search engines 😂
@seancorfield had an awesome writeup of jars, the context around it and such for those who don't come from a java background. I'd love if someone wrote up something about the logging ecosystem on the jvm
because i'm still clueless on it and I've been working in Clojure professionally for two years now
this is the guide https://cljdoc.org/d/com.github.seancorfield/depstar/2.1.267/doc/terminology-convention
it was a great read for me, from someone coming from outside of the jvm world
at the risk of tooting my own horn, I think https://github.com/clojure/clojure-site/pull/141/files is pretty good, I just haven't gotten it over line so it can be merged (in coming up on 6 years)
looks good 👍