Fork me on GitHub
#beginners
<
2016-04-06
>
zzamboni08:04:01

From Clojure for the Brave and True: "It’s frowned upon to use use in production code” - may I ask why this is the case? Why is this better/worse than using require/refer or include it from :require in the (ns …) declaration?

zzamboni08:04:55

Sorry, that was a bit succint. This is about namespaces and learning to use them, including require, use, refer and ns

zzamboni08:04:29

After explaining use, the book says "It’s frowned upon to use use in production code”, and I was just wondering why.

zzamboni08:04:43

Maybe it’s best to ask @nonrecursive directly what he meant 😉

sveri08:04:27

@zzamboni: There are several reasons to this. I think the biggest one is that use imports everything from that namespace, which may override other declarations. For me, the biggest reason to use (:required [foo.bar :as b]) is that there is such a good tooling support around it in cursive.

zzamboni08:04:56

I see, makes sense

krchia12:04:26

how do i find the name for this dependency?

krchia12:04:27

[commons-fileupload/commons-fileupload "1.3.1"]

krchia12:04:10

the library ring uses this, and they call it from (:import [org.apache.commons.fileupload …)

krchia12:04:13

but it fails for me

sveri12:04:57

@krchia: What do you mean with "name"? and what exactly fails for you?

krchia12:04:13

i want to import it into my repl to play w the functions

krchia12:04:05

so i would be calling it (:import [org.apache.commons.fileupload …) like the ring library does right?

krchia12:04:24

oh, i omitted the : when i made the call in the repl

krchia12:04:36

i guess i’m a little fuzzy about the details

nonrecursive13:04:53

@zzamboni: another reason is that often I’ll want to look up a function to see what it does, and if that function was added via usethen it’s more difficult to pull up the function’s namespace

zzamboni13:04:30

@nonrecursive: thanks, another good point

krchia14:04:23

what’s the clojure equivalent of FileItemFactory factory = new DiskFileItemFactory(fContent.length(), null);

krchia14:04:17

both (new DiskFileItemFactory) and (new DiskFileItemFactory 1 nil) works

krchia14:04:49

but im not really sure about the left part

krchia14:04:26

(def factory (new DiskFileItemFactory 1 nil)) ?

roberto14:04:10

(def factory (DiskFileItemFactory. 1 nil))

krchia14:04:11

what about the FileItemFactory part?

roberto14:04:24

what about it?

krchia14:04:50

does that mean factory is of type FileItemFactory?

roberto14:04:13

it will be of whatever type (DiskFileItemFactory. 1 nil) is

roberto14:04:25

you can verify on the repl with class or type

krchia14:04:43

so why is the FileItemFactory is there in the declaration?

krchia14:04:56

sorry, quite new to java (and clojure)

roberto14:04:08

what declaration?

roberto14:04:18

are you referring to the java code?

roberto14:04:28

well, that is java

roberto14:04:31

clojure doesn’t need it

krchia14:04:34

these 2 lines

krchia14:04:38

FileItemFactory factory = new DiskFileItemFactory(fContent.length(), null); this.item = factory.createItem("field1", " text/html", true, "temp.txt");

roberto14:04:42

because that is java

roberto14:04:48

clojure doesn’t need it

krchia14:04:52

hmm, alright

roberto14:04:05

java’s type system is not the most friendly. It doesn’t have type inference

roberto14:04:12

clojure can infer the type

krchia14:04:44

what does the “this” refer to?

krchia14:04:10

i’m using that as reference

krchia14:04:18

but don’t really see this pop out anywhere

roberto14:04:21

I’m not sure where this is coming from

roberto14:04:32

normally, it is used inside a class declaration to refer to the instance

roberto14:04:52

what other programming languages do you know?

krchia14:04:52

so i guess if these 2 lines are inside a public class blabla it probably refers to blabla?

roberto14:04:14

this would be the equivalent of self in python

roberto14:04:40

it doesn’t refer to blabla, it refers to an instance of blabla

krchia14:04:01

is it an exercise in futility to try to convert java code to clojure code?

krchia14:04:06

you know, just as a learning exercise

roberto14:04:26

hehehe, not really, as long as you have some basic understanding of both languages

roberto14:04:26

a lot of clojure libraries are just wrappers around java libraries

krchia14:04:43

i’ll keep at it, thanks simple_smile

roberto14:04:29

I suggest you read this chapter http://www.braveclojure.com/java/

krchia14:04:49

are there any efforts to auto generate clojure wrappers around java lbiraries?

roberto14:04:52

it does a good job of explaining the relationship b/w clojure and java and how to interop with java from clojure

krchia14:04:54

is such a thing possible?

roberto14:04:01

I don’t think that would be possible

krchia14:04:06

i’m at that web page actually, it just misses a few points here and ther

roberto14:04:07

libraries are different

roberto14:04:17

they don’t all act the same way

roberto14:04:21

nor follow the same conventions

krchia14:04:34

different from?

krchia14:04:48

c headers?

roberto14:04:55

there are no c headers

roberto14:04:23

but java code is not as uniform as lisp code, for example

roberto14:04:59

you can’t really box java code into one form and structure

krchia14:04:39

hrmmm 😐