Fork me on GitHub
#beginners
<
2016-05-30
>
naomarik14:05:27

I've just refactored an experimental/exploration project and have ran into a circular dependency issue. Having spent sometime in google and reading steve yegge's rant 5 years ago, it seems the two options that will stick is "put everything in one file" which I find unacceptable or "refactor." I saw Shaun's solution here: https://github.com/shaunlebron/cljs-circular-dependency but I'm not really feeling it. Since modeling my current problem fits most naturally with a circular dependencies with my previous experience in breaking down applications, I'm wondering what resources exist that provide alternatives to thinking about how to break apart an application to avoid these issues completely.

sveri14:05:24

@naomarik: I am not sure what else to add, but, generally circular dependencies are considered to be a code smell, showing bad design / architecture. From my own experience I only hit this once (once when I can remember) and was able to solve it by splitting things into more granular namespaces. What helped me in that case, was to visualize the dependency graph, not sure if you did that already?

urbanslug16:05:51

sequence and collection mean the same thing in clojure, right? They all refer to composite types?

vinnyataide16:05:45

seqs can be callable collections is a more broader concept

naomarik16:05:12

Perhaps other languages have let me lazily couple things together without effort, but finally came to a structure I like.

vinnyataide16:05:16

oh I mistook for arrays

urbanslug16:05:01

I read ahead and maybe found an answer.

urbanslug16:05:13

"you may have heard of Clojure’s sequence abstraction—all the persistent collections use it"

urbanslug16:05:19

Reading joy of clojure

urbanslug16:05:28

presistent just means lazy, right?

naomarik16:05:09

it means immutable urban

plexus16:05:33

persistent specifically refers to the fact that when you "update" a data structure, the old value is still accessible, i.e. "persists"

weyj416:05:54

According to joy of clojure, a sequence in a ‘sequential collection'

weyj416:05:11

i.e. it’s a subset of collection which, I suppose, is ordered

urbanslug16:05:12

Joy of clojure be a gem yo!

weyj416:05:16

and you can use first/rest ops on it

weyj416:05:32

so like I think sets are collections that are not sequential

urbanslug17:05:05

sets are mutable? hmm I wonder why they went with that.

weyj417:05:11

they’re not ordered

urbanslug17:05:21

Though as I read more I find the answer to a question I asked.

weyj417:05:26

assume it’s all immutable

plexus17:05:46

several collection types are not sequences, but you can get a sequence backed by that collection with (seq coll)

weyj417:05:48

try calling (first …) on a set

weyj417:05:58

doesn’t work, so it’s not a sequence

urbanslug17:05:00

"A sequential collection is one that holds a series of values without reordering them"

urbanslug17:05:08

Sets even in math have no ordering

urbanslug17:05:27

plexus: Thanks for that

plexus17:05:04

many functions will call (seq ...) internally on their argument, so you don't need to call seq yourself that often

plexus17:05:11

the most common reason you would use it yourself is to check if a collection is empty, because (seq []) returns nil

weyj417:05:28

good tip!

plexus17:05:51

yeah it's a common idiom, can be confusing the first time you see it, but that's how clojure people do it

weyj417:05:19

I’m just wrapping my head around programming to abstractions. The fact that

conj
is reversed for vectors and lists really bothered me for awhile

plexus17:05:07

I can imagine 🙂 took me a while to remember the argument order of cons vs conj

plexus17:05:13

but the abstractions thing is really nice, like the way that vectors, maps and sets are all associative

plexus17:05:29

so you can use get-in or update-in on any mixture of them and it just works

firesofmay18:05:28

weyj4: The way I remembered that was by remembering vectors are like arrays so adding to the end of the vector is cheaper while lists are linked lists so adding to the front of the list is cheaper. Once you remember that it won't be so confusing 🙂

weyj419:05:53

yeah once I started learning about the thought and use cases behind the various data structures it became easier to understand