Fork me on GitHub
#beginners
<
2022-07-12
>
byrongibby10:07:45

Hi. Is there a way of splitting defmulti and defmethod definitions into different namespaces and requiring only the defmulti namespace in the client code? It seems when I try to do this that the defmethod namespace isn't loaded in the client code and I get No method in multimethod 'foo' for dispatch value: bar. I am looking to separate the API and implementation namespaces, but this doesn't seem possible?

byrongibby10:07:08

The answer on SO seems to suggest it is possible, but the comments to the answer rebut this, so I am confused. https://stackoverflow.com/questions/39585510/using-clojure-multimethods-defined-across-multiple-namespaces

Ben Sless10:07:46

You can do that, but you'll still need to require the NS with the implementation you need

Hermann11:07:20

To expand on that: Code is only executed, when it's loaded. So when you require a specific namespace, the namespace's code gets evaluated. You require the file containing the defmulti -> You have that multimethod available, but none of its implementations. For each implementation you want, you need to require the file containing the respective defmethod. Evaluating a defmethod for some dispatch value already specified will override the previous definition, a fact you can use to change behaviour for specific cases of ustream packages. One caveat: In the REPL, reloading a file containing a defmulti will not replace the dispatching. You'll have to reload/reset the REPL to do that.

byrongibby11:07:42

Thank you very much that clears it up for me. Much appreciated.

byrongibby11:07:01

Updated SO with your comments

lepistane11:07:09

Hi I am using aleph to play around with it little bit. I have a processing that's sending live messages to frontend. The thing that bothers me is that when frontend disconnects/closes connection, backend continues to serve those messages to that connection. Is there a chance for me to detect client disconnect in aleph? I was mostly using this as a reference https://matthewdowney.github.io/aleph-websocket-client-not-jetty.html

popeye13:07:54

I have the data as `

[{0 {:a asdfasdf, :b 123, :t 0}} {1 {:a sdsdd, :key 124, :t 1}}]
how to get the result as ?
[{:a asdfasdf, :b 123, :t 0} {:a sdsdd, :key 124, :t 1}]

byrongibby13:07:33

(mapv #(first (vals %)) [{0 {:a "asdfasdf", :b 123, :t 0}} {1 {:a "sdsdd", :key 124, :t 1}}])

lepistane13:07:14

(flatten (map vals a)) where a is your input

byrongibby13:07:05

(into [] (flatten (map vals a))) if you need the result to be a vector

blogscot13:07:04

(let [input [{0 {:a "asdfasdf", :b 123, :t 0}}
             {1 {:a "sdsdd", :key 124, :t 1}}]]
  (mapv #(apply second %) input))
;; => [{:a "asdfasdf", :b 123, :t 0} {:a "sdsdd", :key 124, :t 1}]

pavlosmelissinos13:07:28

[{1 {:a sdsdd, :key 124, :t 1}} {0 {:a asdfasdf, :b 123, :t 0}}]

[{0 {:a foo, :b 122, :t 0}} {0 {:a asdfasdf, :b 123, :t 0}}]
@U01J3DB39R6 how about these? What should be the result in each of the above? Does the ordering of the keys play any role? Also can you tell us what you're tried already and how it fails?

popeye13:07:31

(flatten (map vals a)) this was enough for my requirement , Thanks for the response @U9KLJ8N0Z @U45SLGVHV @U0D6971L3 @UEQPKG7HQ 🙂

👍 3
Pedja Zolinsky13:07:43

Hi there, I am mostly a java programmer who recently got a job offer from Company A and Company B. Company A is a java shop, company B uses clojure, something which I have no experience in. Both are Fortune 500 companies. Whichever company I go with I plan on staying there for several years. Company B pays much more and the team seems very passionate about Clojure in general, which makes me more interested in learning it and working with them. However, I am seeing that on linked in there are only ~700 jobs for Clojure and over 34k jobs for Java. I'm afraid of shooting myself in the foot by taking the risk and going for the Clojure job and pidgeonholing myself. It seems as if it may be more difficult down the line to go back to a Java gig or any other mainstream language because Clojure is so niche. But I'm also hearing from former java devs that they will never go back to java after discovering Clojure. I feel as if it's a big statement for Rich to say he would've stopped developing if he had to keep using Java. Does this imply that you can get more done with less in Clojure and that there might even be more work life balance in a Clojure role? Any advice would be much appreciated

lepistane13:07:52

There is no right answer here. Choose one and make it work. Winners to make right choices they make choices right. Go go!

👍 1
2
Ben Wadsworth13:07:27

Experience in one programming language does not preclude you from getting a job in another language in the future. If anything I’d say the variety of experience you might get going from Java <-> Clojure as an example would be a benefit in the future.

👍 1
Bart Kleijngeld13:07:30

If you are passionate about programming itself, learning a new language, especially one that's very different, can be very exciting and educative. From a professional point of view: yes, there's a lot more Java jobs out there, so in a way it's probably safer. Although you're bound to find a Clojure job as well, but probably there's less junior-level jobs there especially. If money is important to you: Clojure jobs pay a lot more on average. So yes, it depends. Either way, I would advise you to check out other languages 🙂. Trying out a dynamic language like Clojure (or Python, Elixir, Ruby) will teach you a lot, and who knows how your preferences will evolve. And of course, I can recommend Clojure 😉.

Darrell13:07:20

As an aside, this might be better suited to #jobs-discuss. However, I agree with @U45SLGVHV and would add that, with 34,000 Java jobs, trying a Clojure job out isn’t as big a risk as it might seem considering you could always go back to doing Java.

kennytilton14:07:48

I would go to bartending school before I would do Java for a living. Hth! 🍻

7
vanelsas15:07:42

Perhaps you should think about what you are passionate about. And see which of these jobs serves that best.

respatialized15:07:59

I personally would not take a job with lower pay and less interesting work just so I could gain expertise in a language that's already got quite a saturated job market because of (in my opinion) very conjectural prospects of future job security.

respatialized16:07:38

Two more non-Clojure specific observations: • To me, "job security" is a proxy for something like "risk-adjusted long term earning potential". It may be the case that Clojure is a risk compared with more "stable" languages - but putting yourself in a lower salary band for a job you intend to stay in for several years is also a risk to your future earnings potential. My appetite for near term risk may be a bit higher than yours, so you have to weigh your own situation and priorities to figure out the tradeoff for yourself. • Similarly, a programming language is just a single word on your résumé to a potential employer until you're actually having a conversation. The real question is: what can you do with that language? Are the jobs you're taking going to provide you with bigger problems to solve? That's just as much of a factor to consider in thinking about different jobs / companies as the name of the language. This is what the real substance of your cover letter and interview is going to consist of, so it makes sense to think deliberately about it.

CarnunMP17:07:46

> However, I am seeing that on linked in there are only ~700 jobs for Clojure and over 34k jobs for Java. I'm afraid of shooting myself in the foot by taking the risk and going for the Clojure job and pidgeonholing myself. It seems as if it may be more difficult down the line to go back to a Java gig or any other mainstream language because Clojure is so niche. My 2¢: But how many people are competing for those 34k Java jobs? Which is to say, those numbers alone don't really tell you anything about the Clojure vs Java job markets—except of course that one is bigger. But which one is more fun? Which language is more exciting/interesting to you? Which one has the better community? Which one do you actually have a better chance finding a job in, all things considered? 😄 For my part, I got my current job, and the one before that, largely because of Clojure. The first job because apparently junior Clojure(Script) devs are a rare enough breed that the CEO had an alert set up on AngelList, and the second because of a cold DM on Tw**ter from my current boss/partner in crime. Because of overlapping niche interests. So... if you're into tattoos, and like the idea of being with someone who's into tattoos, you should probably get some tattoos: https://twitter.com/visakanv/status/1269973823907983361?s=20&amp;t=4i9tvCUewqW6BkhPYyRaTQ

seancorfield17:07:30

(unrelated to the thread in general but related to that last comment: my wife's family constantly told her that her tattoo would make it hard to find a "good husband" but that's actually how we met -- online, in a Usenet group for tattoos etc -- and we've been happily married for 23 years at this point... so, yeah, I'm with @U018D6NKRA4 on that and I think taking the Clojure job would be a great opportunity to learn new skills and potentially give you access to more interesting work)

🎉 4
❤️ 1
👌 1
seancorfield17:07:56

And, yes, definitely a thread for #jobs-discuss but since it's in a thread we'll let it stand here for now... 🙂

CarnunMP17:07:38

(Incidentally, this thing about Clojure jobs paying more on average... has anyone ever bothered controlling for seniority I wonder? 😅 )

3
Bart Kleijngeld17:07:54

@U018D6NKRA4 I tried to account for that by mentioning I get the impression there's relatively few (I've never seen one) junior positions. But yes, you're absolutely right that would give a better perspective.

👍 2
Drew Verlee13:07:40

I suggest you find out way more information then you have given us here about these companies. • Are they creating a good thing in a good way? Ask very specific quetions about their goals and there process. Ask them to tell you about a time they faced a challenge and how they overcame it. • What is there turn over rate? If it's a pure software company and their most valuable assets, dev's aren't being retained, then it's a red flag. • How well can you communicate with the direct team you will be working with. Do you agree with the methodology and practices of the team? Do they have any hard rules? Everyone must login by 8am. Everything needs to be a jira ticket. everything must be logged in onenote/notion,etc... • What does there compensation package look like? Are they offering stock? How is it realized?

upvote 1
sheluchin17:07:19

Is the parent folder of a namespace referred to as its package, as in Python?

Alex Miller (Clojure team)17:07:13

no, there are no "packages" in Clojure

Alex Miller (Clojure team)17:07:48

just namespaces, which have names that map to a hierarchical directory structure

sheluchin17:07:29

There's no special name for the parent folder?

sheluchin17:07:48

Perfect. Thank you.