Live data from Hacker News

Try Clojure

tryclojure.org

191–200 of 404 posts

Re: Try Clojure

#191

I'm happy with TypeScript, Go, and Rust. Don't feel like learning anything else.

Weirdly appropriate that the first thing on the website is this quote:

> If you want everything to be familiar, you'll never learn anything new. - Rich Hickey

Re: Try Clojure

#192
post #110
post #4

I love clojure, but it's really lost a lot of the momentum it had as many imperative languages have adopted parts of functional programming (and much for the better) over the last many years. On the other side I've felt a lot of the ecosystem work that was done has a more "timeless" quality. Coupled with java interop I haven't ever felt wanting when I do reach for it for some hobby projects I keep up with. One thing…

Should have maintained a python interoperable runtime. Less and less people use JVM languages for things like web apps, data eng, data science, ML, etc.

https://github.com/clj-python/libpython-clj has deep support for leveraging the Python ecosystem and it works great.

Re: Try Clojure

#193
post #164
post #144

Earlier quoted context omitted.

This is a good starting point if you want to get a web app going quickly: https://biffweb.com It uses XTDB by default but you can switch to Postgres: https://biffweb.com/p/how-to-use-postgres-with-biff/ People don't really use ORMs in Clojure, they just write SQL directly and abstract the details from consumers using functions. That said, HoneySQL is a common alternative to writing SQL that makes it a lot less painfu…

Biff looks neat, thanks! I mainly just don't want to write raw sql/mappers to structures for simple queries. Looks like most sql libraries with clojure can just return maps so that's neat.

Here's a quick example of how DB access generally looks in production:

    (ns rads.sql-example
      (:require [next.jdbc :as jdbc]
                [honey.sql :as sql]
                [clojure.string :as str]))

    ;; DB Table: posts
    ;; +----+-------+
    ;; | id | title |
    ;; +----+-------+
    ;; |  1 | hello |
    ;; +----+-------+

    (def ds (jdbc/get-datasource (System/getenv "DATABASE_URL")))

    (defn row->post [row]
      ;; This is your optional mapping layer (a plain function that takes a map).
      ;; You can hide DB details here.
      (update row :title str/capitalize))

    (defn get-posts [ds]
      ;; Write a SQL query using Clojure data structures.
      (let [query {:select [:*] :from [:posts]}]
        ;; Run the query.
        (->> (jdbc/execute! ds (sql/format query))
             ;; Convert each raw DB map to a "post" map
             (map row->post))))

    (println (get-posts ds))
    ;; => [{:id 1, :title "Hello"}]

Re: Try Clojure

#194
post #193
post #164

Earlier quoted context omitted.

Biff looks neat, thanks! I mainly just don't want to write raw sql/mappers to structures for simple queries. Looks like most sql libraries with clojure can just return maps so that's neat.

Here's a quick example of how DB access generally looks in production: (ns rads.sql-example (:require [next.jdbc :as jdbc] [honey.sql :as sql] [clojure.string :as str])) ;; DB Table: posts ;; +----+-------+ ;; | id | title | ;; +----+-------+ ;; | 1 | hello | ;; +----+-------+ (def ds (jdbc/get-datasource (System/getenv "DATABASE_URL"))) (defn row->post [row] ;; This is your optional mapping layer (a plain function t…

You would abstract away the jdbc/execute part though, right? otherwise that's terribly unproductive compared to django etc.

Re: Try Clojure

#195
post #194
post #193

Earlier quoted context omitted.

Here's a quick example of how DB access generally looks in production: (ns rads.sql-example (:require [next.jdbc :as jdbc] [honey.sql :as sql] [clojure.string :as str])) ;; DB Table: posts ;; +----+-------+ ;; | id | title | ;; +----+-------+ ;; | 1 | hello | ;; +----+-------+ (def ds (jdbc/get-datasource (System/getenv "DATABASE_URL"))) (defn row->post [row] ;; This is your optional mapping layer (a plain function t…

You would abstract away the jdbc/execute part though, right? otherwise that's terribly unproductive compared to django etc.

In practice I do wrap `jdbc/execute!` with my own `execute!` function to set some default options. However, there is no ORM layer. What makes you think the code above is terribly unproductive?

Edit: Not trying to dismiss your concerns, by the way. In Clojure you can often get away with doing less than you might think so I'm genuinely curious about the critique.

Re: Try Clojure

#196

Is there a version of Clojure that compiles to LLVM or something? Sort of like what Scala-native was supposed to be (but never materialized). I like functional programming but I can't abide the Java ecosystem in 2024, it's just too archaic for my taste.

There's an ongoing effort to create a Clang/LLVM implementation of Clojure's runtime with hot reloading and other very interesting features. You can take a look at it at https://jank-lang.org/. It still hasn't reached feature parity with full blown JVM Clojure but we've paying close attention to its development.

Re: Try Clojure

#197
post #153

Earlier quoted context omitted.

You guys can make all the baloney claims about this you want. The day that Haskell stops being 10x slower than languages providing mutable data is the day we can start to seriously entertain your claims.

There's nothing baloney about SSA form. I'm sorry to say it, but C is just not close to the metal any more. Even if you are able to hand optimise something so it works well on one architecture, it likely won't be optimal for another. As for Haskell, it does pretty well being 100 times faster than Python with 100 times less the number of people working on it.

I believe that your interpretation of what’s actually happening is what’s baloney.

The fact is that you Haskell people only talk about the optimizations that can sometimes open on immutable data in specific circumstances. What you generally ignore is the optimizations that immutable data permanently locks you out of with no recourse.

As with most things programming, immutability should be considered a tool, not a rule.

Re: Try Clojure

#198
post #118

I know many people will have problems with this post, but I am posting as information for clorjure-ophiles. Not reasons, but personal reasons why I don't do Clojure and will not try it. 1. When I read about Clojure (repeatedly) I like it. I am especially interested in transducers. I even built a half baked transducer engine in JavaScript using generators. There is clearly something here of value here. Any system that…

Running on the JVM is one of the best things about Clojure. The JVM is an impressive piece of engineering where uncounted bajillions of man-hours were invested into making a good and performant VM with modern GC. I've been using Clojure heavily for the last 9 years or so and I can't see any reasons to dislike the JVM. Also, I barely ever touch any Java. You don't need to.

I can hardly write a correct Hello World in Java. I can read it, I can probably write it, but I've never really used it. Yet I've been writing Clojure daily for the last 9 years.

This means that you really don't need Java in order to use Clojure.

Coming from a C++ background, I used to dislike the JVM out of principle just like yourself, especially since it needs to run on my local machine and it uses so much memory and is slow to start up.

However, once your app is started, you're in the REPL and that's the only time you need to start your app.. You can keep developing for days without restarting your app once.

Once I finished developing my app and I deploy it to a server, I'm kind of happy it runs on the JVM - that thing is super tuned, very fast and runs on a myriad of hardware platforms.. I don't have to spend one minute thinking about those details.

So while the JVM is somewhat inconvenient on the dev machine, it helps a lot when you deploy it to production.

Things became a lot simpler when I stopped worrying about it and just used the language for its power and beauty.

Re: Try Clojure

#199

> unlike full-JVM Clojure it has a very fast startup time I can't believe that after all these years Java still didn't fix their startup time.

It's a tradeoff. The startup time of Clojure on the JVM is slower than most, but the runtime is faster than most. It also needs a lot of memory to get going. This means it's optimized toward long-running programs like web servers. During development, you use the REPL interactively which makes this a non-issue, but it does take some getting used to at first.

That said, there are alternative runtimes that have different tradeoffs. For example, Babashka is a runtime for Clojure that uses GraalVM instead of the JVM as the foundation. Babashka scripts have about a 10ms startup time on my M1 MacBook Air.

Re: Try Clojure

#200
post #90
post #79

Earlier quoted context omitted.

As a side note, I'm always amazed by people who can use a highly expressive language (Clojure, Rust, even TS) but switch to Go when they feel like it (especially pre-1.18). To me, switching to a less expressive language is painful and infuriating. I remember having to switch from Python to Java 5, and how everything started to take 3 to 5 times longer code to express. Maybe the key thing is to only write small things…

Development in Go will always be more painful for some people than in Clojure or TS, because the language is intentionally hostile to abstraction, so you're thinking in higher level concepts, but you implement them in more steps than necessary. The program can never reflect the shape of the problem, because it will be riddled with "glue code" that implements the obvious dull steps that you abstract away when reasonin…

> they can focus on the small: this is a loop that iterates through a slice, this is an if condition that depends on this variable.

Then a week later, the squinty mole discovers the code is dead; not called at all. There is no slice and no variable.

Post reply on HN