Fork me on GitHub
#beginners
<
2021-11-23
>
Dmitrii Pisarenko07:11:33

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 regin HTML to whatever is defined in the above ClojureScript file)?

delaguardo07:11:59

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

Benjamin16:11:33

(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 nil

alexmiller16:11:32

I use cond-> a lot for this kind of thing

alexmiller16:11:24

(cond-> {:foo 10} bar (assoc :bar bar)) would be in practice (where you don't know if bar is nil or not)

👀 1
✔️ 1
dharrigan17:11:17

that is pretty darn neato!

j16:11:50

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?

Cora (she/her)16:11:54

it's a mess, and I haven't found an easy way to set it all up without just stealing it from existing projects

dharrigan16:11:13

I use clojure.tools logging, with slf4j behind it. It's pretty straight forward methinks

Cora (she/her)16:11:57

I've been meaning to try out timbre

dharrigan16:11:15

I'm not a fan of timbre tbh

dharrigan16:11:46

I find it a bit clunky to use and not as intuitive, dare I say it, as a simple xml file controlled by slf4j!

j17:11:53

I'll check out both ways and see what works. Thank you both for the suggestions!

Cora (she/her)17:11:21

@dharrigan have you ever found docs on how to set those up properly?

dharrigan17:11:36

clojure.tools.logging and slf4j?

dharrigan17:11:47

even better, I have a demo project 🙂

Cora (she/her)17:11:27

that's what I meant about cribbing it from existing projects

Cora (she/her)17:11:26

and there's a big presumption that you already understand java's logging ecosystem

Cora (she/her)17:11:49

it's not a great situation, currently

dharrigan17:11:04

For sure, yes, however I believe it's not beyond anyone to grok it.

Cora (she/her)17:11:31

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

dharrigan17:11:04

imho, we all borrow from other projects, not only logging. I stand on the shoulders of mightier giants than I.

Cora (she/her)17:11:30

sure, but even that's not ideal

dharrigan17:11:08

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.

dharrigan17:11:46

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.

dharrigan17:11:55

at least, thats how I like to look at it.

dharrigan17:11:29

So, I think it is quite ideal, to learn from others and not ignore the lessons from the past.

Cora (she/her)17:11:21

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

☝️ 1
Cora (she/her)17:11:58

no one is saying don't learn from other projects

Cora (she/her)17:11:02

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

dharrigan17:11:29

Perhaps a PR to the project that includes better examples would help others?

Cora (she/her)17:11:41

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

Cora (she/her)17:11:03

I don't understand any of them well enough to do that

Cora (she/her)17:11:18

if you do, then please do

dharrigan17:11:35

I find the documentation quite sufficient

dharrigan17:11:43

but then again, I suppose, I have a different background.

Cora (she/her)17:11:30

that's the Curse of Knowledge in play

Cora (she/her)17:11:09

beginners and those who don't understand are the best judge of whether documentation is sufficient

Cora (she/her)17:11:39

because the proof of sufficiency is whether it's good enough to teach and to learn

Cora (she/her)17:11:49

because that's what it's there for

Eddie17:11:20

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”.

Cora (she/her)17:11:29

that's a great point, too, there are different documentation needs at different levels of expertise.

Cora (she/her)17:11:32

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?"

👍 1
Cora (she/her)17:11:17

all super valid levels to be at and grow from, all poorly served by code you copy/paste

Cora (she/her)17:11:01

this is my dead horse I flog from time to time

Cora (she/her)17:11:09

thanks for coming to my TED talk

Eddie17:11:38

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.

Eddie17:11:14

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.

1
Cora (she/her)17:11:17

sure, the setup need is served by copy/paste, but not the most critical part: understanding why

👍 2
Cora (she/her)17:11:48

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

Cora (she/her)17:11:12

but if we create bottlenecks at the beginning then fewer people reach intermediate or mastery

Cora (she/her)17:11:54

it's a sweet positive reinforcement loop once you get it going at a cultural level

Cora (she/her)17:11:57

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

☝️ 1
cdeszaq17:11:31

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?

R.A. Porter17:11:57

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.

Cora (she/her)17:11:01

or it's hard to find in the docs

sb17:11:28

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.

Cora (she/her)17:11:45

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

sb17:11:56

I know that is bigger part of this question.. but this is .. what is in my mind.

Cora (she/her)17:11:31

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

👍 4
❤️ 1
j17:11:56

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

dharrigan18:11:31

Did you manage to find a solution?

j18:11:06

I didn't unfortunately, for now I'm making do with spit...

dharrigan18:11:41

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

j18:11:43

I thought I was missing something obvious, so I thought maybe someone here would know

j18:11:56

I'm still reading/trying to understand the logback.xml part, but I really just wanted something easy to log to file quickly

dharrigan18:11:47

I've pushed up a change to that project that shows logging to a file

j18:11:23

I see it, thanks!

dharrigan18:11:55

One defines appenders, console and file are two such appenders, then you tell the logger (root in this case) which appenders to use.

j18:11:25

I don't have a java background. Is logback.xml part of the SLF4J library? where should I look for documentation on logback.xml?

dharrigan18:11:57

logback and slf4j are by the same person. There is extensive documentation here: http://logback.qos.ch/documentation.html

dharrigan18:11:07

Din dins for me...

j18:11:55

Thanks for taking the time! Enjoy dinner!

Cora (she/her)18:11:32

that's awesome feedback! I love it 💜

alexmiller18:11:44

if there are issues with tools.logging docs, would welcome a question at https://ask.clojure.org to move towards fixing it

👍 2
j18:11:46

Very often #beginners give me valuable advice that I can't find on the internet

Cora (she/her)18:11:18

human brains are great search engines 😂

Cora (she/her)18:11:59

@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

👍 1
Cora (she/her)18:11:33

because i'm still clueless on it and I've been working in Clojure professionally for two years now

Cora (she/her)18:11:34

it was a great read for me, from someone coming from outside of the jvm world

hiredman18:11:12

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)

Cora (she/her)19:11:00

looks good 👍