Fork me on GitHub

I had a shower thought on perhaps a good idea to learn the language: 1. I search for the top N popular Clojure code repositories on GitHub (or use a tool that does that), and count usages of every built-in syntax construct used in that project 2. Apply some weighting function per code repo to make it so one big project (which could be one author) doesn't have more impact on the data than smaller projects, to account for how individuals' syntax preferences can have too much representation when actually the wider use of that syntax is lower in other users. 3. Sort that in descending order of weighted usage counts This would make for a "syntax by usage" statistic that I can use as the order by which I may choose to learn the syntax of the language, prioritizing more commonly used syntax over more obscure ones. As an exercise I could try to do this stuff with Clojure and learn some while making it 😁


Hmmm. If we were studying English this way, our study path would be: be, I, you, the, a, to, it, not, that, and and. Would an ascending sort be better? Start with the most obscure construct? Hell, I would prolly benefit from that. I remember discovering quite powerful stuff quite late in my Common Lisp days. But, yes, good exercise.


Hey @U0PUGPSFR 😃 Your analogy isn't that far off. But there ain't nothin' wrong with learning the: be, I, you, the, a, to, etc. of Clojure especially if you're like me and aren't in a good environment to learn Clojure e.g. with other Clojure programmers sitting next to me and showing me stuff. Consider how kids spend the first several years of their lives in the company of adults until they start being able to speak their parents' tongue. And they are only exposed to the very basics at first. Not to mention that different parents differ in how much vocabulary they expose their kids in those years. So to that analogy I say, let's take what most adults say on a regular basis and teach that to kids by usage frequency. Heck that might not be a bad idea to learn any spoken language whatsoever.

Michael W14:02:44

I read somewhere that with a vocabulary of only 400-500 words in a new language you can communicate. You might sound like a child to fluent speakers, but you can at least communicate. Clojure has some 600ish keywords last I looked. So why not just learn them all? The best advice I got was to just read the entire documentation for everything included in the language.

Alex Miller (Clojure team)15:02:07

this has actually been done a couple times - Eric Normand did a thing like this, and I think maybe the new dewey thing has something like that?

😮 2
Alex Miller (Clojure team)15:02:07

but to answer the original theory, no I don't think this is a very good way to learn the language :)

Alex Miller (Clojure team)15:02:04

far better to actually read a book or guide where an expert Clojure user has done this and can give you things in a logical order


Very good links @U064X3EF3 this is fascinating.


Also, I didn't intend this to be the only thing I would use for learning, but this info gives more context and may motivate learning. Obviously the curated learning materials should do a good job in explaining most of these results anyway, and in a logical sequence. However, in case there are things there that aren't covered in the materials I go through, I can ask "why is this thing that's being used so much, not more emphasized in the material?" or "why is this thing that's so prominently emphasized missing from code projects?" these questions may lead to unexpected discoveries like: "this thing that I learned about is only a private case of a more general concept and thus most Clojure programmers don't bother using the specific tool. For example, you could use sum or you could use reduce and provide a function, which is a more generalized option. Or is-even? is cool but you can just do (% ... 2) . (btw I don't know if these expressions exist, I just made it up)

Sam Ritchie17:02:54

Definitely don’t overthink it IMO. I am coming to believe strongly that “just do something, anything at all” is the way forward for every skillful activity . Then come here, ask questions, and develop the skill of FIRST trying to answer for yourself to anticipate the follow up questions. @U064X3EF3 ‘s advice is excellent since you get a considered expert tour from someone

Sam Ritchie17:02:16

But don’t stress about efficiency …


My mileage varies so much I may be dead. When I encounter a new language I get to chapter two or three, achieve Turing equivalence escape velocity and get on with the app I had in mind. Good for the laughs a month later when I look back at the code having learned a bit more. Just me?


I am trying honeysql and wrote below code, any suggestions?

(with-open [conn (jdbc/get-connection db)]
  (jdbc/execute! conn (-> (h/insert-into :student)
                          (h/columns :id :first_name :last_name :email :date_of_birth
                                     :enrollment_date :graduation_date :major)
                          (h/values [[1 "john" "Cena" ""
                                      "02-02-1990" "02-05-2005" "02-05-2011" "CS"]])
                          (sql/format {:pretty true}))))

getting ; Execution error (IllegalArgumentException) at (jdbc.clj:430).
; db-spec is a raw Connection object!
; Did you call get-connection in the wrong context?
; You should only call that to pass a Connection into prepare-statement.
; (and don't forget to close it via with-open or .close)


doesn't have anything to do with honeysql


The error is coing from the get-connection call which is


the error is pretty clear. is getting passed a Connection not a db spec


(and I'd strongly recommend using next.jdbc instead of at this point since the latter hasn't had any updates for years and the former is the actively maintained version)


ok let me try with next.jdbc


Your code will still be wrong -- you'll likely end up closing your Connection multiple times.


You pretty much never need to call get-connection directly.


(even with c.j.j)


I see, I just wrote sample code, will refactor it


You'll need to show us more of the code -- including how you set up db -- for us to be able to provide more guidance.


db i created is

(def db {:dbname   (or (System/getenv "DEV_DBNAME") "it_data")
         :user     (or (System/getenv "DEV_USER") "myuser")
         :password (or (System/getenv "DEV_PASSWORD") "mypassword")
         :host     (or (System/getenv "DEV_PASSWORD") "localhost")
         :port     (or (System/getenv "DEV_PASSWORD") 5432)
         :dbtype   "postgresql"})


At some point prior to the code above, you're turning that db-spec hash map into a Connection object so I suspect you're calling get-connection somewhere else?


Or perhaps you're calling that code above inside a transaction? In either case you should not be calling get-connection -- just pass db to execute!


is it something like? I am using next.jdbc now

(jdbc/execute! db (-> (h/insert-into :student)
                      (h/columns :id :first_name :last_name :email :date_of_birth
                                 :enrollment_date :graduation_date :major)
                      (h/values [[1 "john" "Cena" ""
                                  "02-02-1990" "02-05-2005" "02-05-2011" "CS"]])
                      (sql/format {:pretty true})))


That will automatically create a Connection behind the scenes, use it for the INSERT, and then close it. So it's fine for playing around with but you would want to use a connection pool for production work. The next.jdbc docs are fairly extensive and cover that stuff (the c.j.j docs are terrible by comparison).


If this is the first time you're using next.jdbc, I would recommend reading through the docs as completely as possible -- there's a lot of material there.


You can also ask deep dive questions about next.jdbc in #C1Q164V29 along with more general SQL questions. And there's #C66EM8D5H if you get stuck with that and need more help.


thanks @U04V70XH6 for your help, I got what is expected now, But I will go through the doc

❤️ 1

I ended up on this rabbit hole, using hugsql forgetting to call set-adapter!. It defaults to

      {:builder-fn rs/as-unqualified-maps}))