This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # aleph (7)
- # announcements (1)
- # aws (12)
- # beginners (118)
- # calva (15)
- # cider (17)
- # clj-kondo (1)
- # cljdoc (11)
- # cljsrn (1)
- # clojure (108)
- # clojure-dev (32)
- # clojure-europe (3)
- # clojure-italy (4)
- # clojure-kc (1)
- # clojure-nl (4)
- # clojure-portugal (1)
- # clojure-spec (29)
- # clojure-uk (69)
- # clojurescript (91)
- # cursive (14)
- # datomic (8)
- # emacs (13)
- # figwheel-main (12)
- # graphql (4)
- # jackdaw (1)
- # jobs (14)
- # lambdaisland (3)
- # luminus (3)
- # nyc (1)
- # off-topic (14)
- # onyx (23)
- # pedestal (8)
- # re-frame (4)
- # reitit (3)
- # shadow-cljs (6)
- # spacemacs (7)
- # specter (2)
- # tools-deps (3)
- # unrepl (4)
- # vim (7)
- # xtdb (10)
(defn string-substring-after-first-instance-of-character[character string] (subs string (.indexOf character string) (- 1 (.-length string)))
do you want subs to return all the way to the end of the string?
If so, the 3rd arg is unnecessary
also what dpsutton said
also this is the error i get > StringIndexOutOfBoundsException begin 1, end -3, length 3 java.lang.String.checkBoundsBeginEnd (String.java:3319) which is pretty good i think
that's a particularly good one - it even shows the index asked for
does that code even work? length is not a public field of String, it's a method
so should be .length, not .-length
also the parameter name "character" is misleading
and the args to indexOf are reversed in order
is it okay to extend protocol to 2 classes belonging to same hierarchy? If
Parent, and I extend protocol to both
Parent, and I invoke protocol function on an instance of
Child, is it guaranteed
Child's extension will be called, and not
That should work. The basic case is that the "parent" is
(defprotocol testik (printik [x])) (extend-protocol testik String (printik [x] (println "String: " x)) Object (printik [x] (println x)) ) (printik "hello")
Yes, the closest ancestor is preferred
Anyone used Jib (https://github.com/GoogleContainerTools/jib) with Leiningen to build containers with Clojure apps?
lein, but worth noting that
pack.alpha recently added support for this: https://github.com/juxt/pack.alpha/pull/42
Thanks, I'd seen that, was wondering if anyone had done similar work with Leiningen. I'll have a look at the
Ah, there's this: https://github.com/vehvis/lein-jib-build
hey guys, do you know any code static analysis tool that handles Clojure well? (https://www.sonarqube.org/) Sonarqube is not working fine for us here. Many incompatibilities with eastwood, nvd and cloverage to work around
@iagwanderson the closest I ever got was to codeclimate + coverage tracking with cloverage and codeclimate-kibit engine. I
I'm now looking into creating a code climate engine for clj-kondo and figuring out how I can merge the two into one reporter for CC
@lukaszkorecki I would like to test the your setup here. For now, I am looking at cloverage and eastwood integrations. Do you had to do specific workarounds to make it work?
@iagwanderson What functionality in specific are you desiring from "static analysis"? I make tools at home for this kind of stuff sometimes and I'm interested in the usecase you're desiring.
@iagwanderson codeclimate-kibit repo is itself plugged into codeclimate (both kibit and cloverage) https://github.com/lukaszkorecki/codeclimate-kibit - so you can see the setup there. One thing that's out of date is coverage tracking, as there were issues around lcov format but are now fixed in latest cloverage version. Also, this repo will soon migrate to codeclimate's own org giving Clojure somewhat a first-class support in code climate
(I'm not affiliated with CodeClimate btw, I just needed things to work as our team has 20+ Clojure repos , so we need automated tools for code linting and test coverage)
this view is from sonarqube and I find it just perfect. The Vulnerabilities are provided by
lein-nvd, code smells and code duplication are provided by
eastwood and other linters, coverage from
@lanejo01 the problem right now are the integrations of these plugins with the sonarqube job
@lukaszkorecki thanks, I will try CC here, that's probably good enough for my use case
@lukaszkorecki just found this https://gist.github.com/lukaszkorecki/60093e57cbb4b178547e4a7ff23c703d pure gold =P
you have to ignore this line though https://gist.github.com/lukaszkorecki/60093e57cbb4b178547e4a7ff23c703d#file-circle-yml-L47
can someone talk about the things they are doing with static analysis (besides vulnerability scanning) ?
@ghadi one thing that is very nice in some python projects is to analyse code complexity.
look at this amazing report from
sonarqube with python. I would love to see something like this to clojure
I used to use a bunch of coverage stuff for python -- but python cyclomatic complexity is different than clojure's
@ghadi my coworkers heavily rely on clojure-lsp. not sure if that falls under the notion of static analysis discussed right now
they probably only connect to nrepl once a week and do all development "statically" in that sense.
to the extent that
eastwood is static analysis: we use it because it finds bugs in a microservice in code paths that would otherwise require complex scaffolding or a full running system to find
arguably we wouldn't need it if we designed the microservice properly with testable code, but there's a lot of institutional friction to rewriting code to be more testable (and I have seen this in every other workplace as well)
I'm not sure if I'd call it "static" analysis, but I've been off and on working on a tool called REDEX which identifies Reducible Expressions (in the lambda calculus sense) and suggests how to refactor them into their minimal form. It can parse clojure code from files, but it also has a repl. Uses logic programming, inspired by kibit but has heavily departed from it. I'm hesitant to call it static because it works both statically and at runtime with information available at runtime.
@iagwanderson here's the updated gist, https://gist.github.com/lukaszkorecki/60093e57cbb4b178547e4a7ff23c703d - I didn't test it but it's almost the same as our internal ones (we add cloverage as a plugin in project.clj so we don't have to download lein-cloverage on each test run)
@lukaszkorecki thanks, I'm on it right now
Interop Bindings for all JDK classes (with docs): https://github.com/clojure-interop/java-jdk
@potapenko It looks like you'd get a lot of reflection warnings from using that library? There are no type hints on return types or on
this in any of the argument lists.
^. ? Not seen that before...
Seems like that should be the class type that the namespace is a wrapper for?
I know what a type hint is -- I've never seen
^. before. I don't think that is legal.
All of the
this parameters seem to have
^. in front of them instead of
Everything in here https://github.com/clojure-interop/java-jdk/blob/master/java.sql/src/jdk/sql/PreparedStatement.clj
And here https://github.com/clojure-interop/java-jdk/blob/master/javax.sql/src/javax/sql/DataSource.clj#L45-L58
Those were the first two things I checked because I work with JDBC so much (as the maintainer of
clojure.java.jdbc in Contrib and
Nice. Any thoughts on type hinting return types? Is that harder?
https://clojure.org/reference/java_interop#typehints 🙂 At the end of that section, just before the Aliases section.
Hah, yeah, what @lukaszkorecki said 🙂
I mean, it seems like maybe you put a lot of time in, and it would be a useful way to see an and check out the apis, but outside of being a learning experience, wrappers without additional functionality are not something I would use
1. Autocomplete (instance members first) 2. Docs lookup 3. code native look I did a lot interop, and in almost all projects the same interop code. I thought that I needed to solve this problem radically. Make a binding generator. I plan to create some more libraries of bindings. If you have any ideas - welcome.
@lukaszkorecki sure - if you're OK with an app that's 10-100x slower
(in all fairness that's a hypothetical and it really depends on how you are using the reflective functions and where)
Yeah, ignoring reflection warnings is def not a good idea (although I found a couple of places where it's hard to type hint the code because of var-args in Java)
thanx @seancorfield i’ll add type hints soon.
@lukaszkorecki fakeup of my workflow for that:
user=> (type (into-array ["foo"])) [Ljava.lang.String; user=> (defn foo [^ "[Ljava.lang.String;" args] ...)
some people even make an empty <some type> array at compile time then get the string of the class automatically but to me just pasting the right string in usually makes more sense
Does anyone know what the best way to configure timbre for running tests with
lein test is? Where do I call
@antonmos It probably depends on exactly what you're trying to do but I would probably make it a
:once test fixture and include it in the namespaces where logging configuration matters?
my favorite thing to do with logging in tests is to have a logging configuration that is only active for tests that directs logs to a file in ./logs
it is great, you get nice clean output, and the logs are there if you need to look at them
Hi, can record constructors be annotated?
I don't think so - because they are auto-generated
honestly for something that requires an annotated constructor I'd be tempted to make a java shim - it can use interop to call clojure for the bodies of all its methods, but I think that's simpler in the end than sculpting something that works using
gen-class - maybe someone whose better with gen-class has a better suggestion though
calling clojure functions from java code (as long as you are the one writing the java and the clojure) is simple
oh ok, thanks! will use .java then
it would have been nice though
to me it's one of two corners of dev (the other being simple, performant numerics) that are sadly just easier to do in a java file most of the time
luckily mixed java/clojure in arbitrary combinations is easy to do
others opinions may vary (I'm surprised nobody has argued for gen-class yet actually)
@paulocuneo @noisesmith turns out you can annotate with gen-class https://clojuredocs.org/clojure.core/gen-class#example-5cec04bde4b0ca44402ef72b
@lukaszkorecki yes - this is why I mention it, also it's clumsy to use and more complex than the equivalent java imho
or maybe it's just that I find a java file much more readable than the weird hash-map dsl of gen-class clauses