Fork me on GitHub
#off-topic
<
2020-09-10
>
borkdude10:09:28

I made an #http-kit channel

jumar12:09:29

Does anyone have experience with https://zio.dev/ ? If so, could you share that and what you think about it?

leonoel18:09:41

ZIO is an effect system coupled to a dependency injector. Both ideas are great, but unifying them in a single abstraction is questionable IMO

leonoel18:09:58

I've not used it in anger but from what I've heard it's solid tech

jumar02:09:38

Great, thanks for sharing.

David Pham16:09:23

Hello, everyone :). I wonder how the knowledge and experience acquired writing and designing Clojure programs can be leveraged in other languages? I really appreciate the default idioms if Clojure and wondered which one where easily transported in other languages, such as python?

andy.fingerhut17:09:54

I have no experience using immutable data structures in production code in languages other than Clojure, but Python already has immutable tuples and frozen sets. There is no frozen dict, but I have written tiny-to-medium sized Python programs that used mutable dicts instead of creating custom classes for data before, in the Clojure style of 'just use maps' for collections.

andy.fingerhut17:09:50

Several languages have immutable persistent collection libraries for them, some also inspired by Phil Bagwell's work and others, and in some cases directly inspired by Clojure's implementations of them.

andy.fingerhut17:09:28

e.g. JavaScript immutable.js, Scala <something>, and I suspect probably dozens of others.

David Pham05:09:57

Thank a lot!

emccue18:09:41

In python, the dataclasses module has a decorator you can use with the frozen=True argument to make immutable objects with a copy method a'la java or scala immutable objects

emccue18:09:08

you can also use the pyrsistent library for persistent lists, maps, and sets

manutter5117:09:14

I used to have a day job in PHP and I tried to apply some Clojure principles where I could. You can, for example, have a class that has basically no data fields and all static methods, and that works like a Clojure namespace, assuming the methods use a lot of generic data types like arrays and hash maps. And you can avoid using inheritance and global variables.

manutter5117:09:01

The down side is if you’re on a team and they want to write plain vanilla PHP/Python/etc, and they look at your code and go bleh.

🎉 3
☝️ 3
jaide22:09:52

I know the feeling. I was learning FP through our JS codebase and the other devs didn’t like it because it wasn’t as easy even though it made a lot of systems way simpler, deterministic, and scalable. They sometimes would give it a try but as soon as any obstacle was encountered they would bow out to an OOP solution often introducing mutable state.

jaide22:09:00

It was hard to stress that it works best when our system uses FP as a default to reduce stateful complexity as much as possible instead of just using it at the edges when we could slow down to try and learn it.

jaide22:09:47

Another challenge was trying to express that it isn’t just about FP as a coding style, it was about having a common set of principles that guides our entire design process for interfaces and functionality.

jaide22:09:11

Oops I’m quite chatty today. Didn’t mean to hijack your convo, I guess your post took me back to the dark times.

jaide23:09:43

Though I’m curious, did you try demos, pairing and tutorials to win them over? Or did they just encounter it in code review?

manutter5111:09:51

I did lunch-n-learns, which were well-received at the time but produced few if any changes in the way everyone else was coding. Eventually I moved on to another employer and repeated the cycle until I finally got a full-time Clojure position.

jaide12:09:33

Nice! I tried some demos and pairing together. They tried to apply them but I don't think they entirely understood the point nor did they put any extra effort into learning. Eventually those devs left onto bigger and greater things, and the CTO stepped down where I took on some aspects of the role. From there I was able to hire clojure devs and we began using it in our tooling and backend. I did keep in touch with one former dev and it turns out he started using a curried FP library, less OOP, and now even adopted RxJS after resisting it when we first started working with it.

manutter5112:09:20

“…dragged kicking and screaming into the Century of the Fruitbat,” as Terry Pratchett used to say.

jaide13:09:43

Too true!

manutter5117:09:58

The main thing Clojure did for my PHP programming was teach me a new way of looking at problems and how to solve them.

Jeff Evans19:09:56

Can someone point me to how to actually search at https://clojurians-log.clojureverse.org/ ? I only seem to be able to click on specific channels, then dates

Lennart Buit19:09:28

you can google search on a specific site (general tip)

Jeff Evans19:09:51

yeah I just played with that, basically site: operator, kind of works

Jeff Evans19:09:54

thanks for the reminder

borkdude19:09:32

@U0183EZCD0D You can also use the Zulip archive. E.g. to search in the clojure-spec channel: https://clojurians.zulipchat.com/#narrow/stream/180378-slack-archive/topic/clojure-spec

👍 3
Jeff Evans20:09:57

thanks for the suggestion, @U04V15CAJ!

idiomancy22:09:47

So, I always trip over modeling this kind of problem and I'm wondering if anyone has any advice. What I'm trying to express is that y should be modified inversely to the magnitude of y. so like, ideally as y approaches 0, the change in y is reduced. but of course, when y is less than one, 1/y > y

idiomancy22:09:56

what is the operation I'm actually thinking of here?

idiomancy22:09:12

"delta y is inversely proportional to y"

andy.fingerhut22:09:30

If smaller y means smaller change, then "delta y is proportional to y" is closer to that meaning

phronmophobic22:09:19

you could do something like y = y * 0.8

andy.fingerhut22:09:50

new_y = old_y + constant * old_y is the only formula that strictly follows the interpretation of "delta y is proportional to y", at least according to the meaning of "proportional" that I know.

idiomancy22:09:57

err, right. I have this example kind of backwards, because im actually applying a counter velocity, so I want the size of that counter velocity to be greater the greater y is

andy.fingerhut22:09:38

where constant can be a negative number in my formula.

phronmophobic22:09:19

y = y * k, where k is some constant which is how friction works

idiomancy22:09:48

err, wait, my mental model is definitely screwed up, so I'll just explain the thing. the thing is a spring. I want the damping of the spring to be less when the spring is in an extended position

andy.fingerhut22:09:22

Is damping in any way related to 'force'?

idiomancy22:09:24

so a regular spring dampening would be y * -k * deltaTime

idiomancy22:09:46

where y is the displacement, or current degree of extension of the spring

idiomancy22:09:59

negative k because its a force applied in the opposite direction

andy.fingerhut22:09:24

The ideal spring law I learned in physics was that many springs exert a force that is a constant times the distance that the spring is away from its rest position, which is 0 at its rest position, positive in one direction, and negative in the other, so the force is always directed back towards rest position.

idiomancy22:09:56

right, which is hooke's law, which is the formula I just wrote

andy.fingerhut22:09:35

except Hooke's law relates force and position, and has no deltaTime in it. But I am guessing that you are doing some kind of discrete time simulation that approximates continuous time?

idiomancy22:09:24

yeah but hooke's law doesn't have to deal with a nondeterministic timestep in between applications of the formula lol

idiomancy22:09:38

this is correcting for the fact that I'm in a discrete nondeterministic environment and I calculate this factor in discrete steps. I need the dampening to increase as the spring approaches its rest position, because otherwise the spring overcorrects and picks up too much acceleration and never comes to rest

andy.fingerhut22:09:57

Many discrete time simulations of physical systems maintain position and velocity of objects at all times of interest, calculate forces, add up the net force on each object, then do "new_velocity = old_velocity + F / object_mass", then take the velocity vector times delta_t to get an offset that the object moves during delta_t

idiomancy22:09:30

right, yeah. thats another reasonable way to do that

andy.fingerhut22:09:57

I might have that new_velocity formula off a bit there .... been a while.

andy.fingerhut22:09:41

F/m is acceleration, and perhaps that needs to be multipled by delta_t, also, to put it in units of velocity.

idiomancy22:09:18

well, anyway I appreciate the input. the deltaTime business isnt where the confusion here lies. thats just a constant that gets applied to any force that occurs in a frame

andy.fingerhut22:09:13

When you say nondeterministic time step, are you saying that you aren't simply making delta_t a constant in your simulation, but that it is expected to change from one discrete step to the next, for some reason?

phronmophobic22:09:14

in theory, you get to pick the deltaTime for each step of the simulation, but if you're trying to display the simulation in realtime, your deltaTime may vary to match your frame rate

andy.fingerhut22:09:18

Oh, if by dampening you mean friction, then yeah, that is one of the forces involved, completely independent of the spring restoring force, and many objects have an approximate friction force that is "- c * velocity_vector", where c is called the dynamic coefficient of friction, IIRC

✔️ 3
andy.fingerhut22:09:46

So you would want to calculate both of those forces at each time step, and add them, before calculating the new velocity.

andy.fingerhut22:09:52

but note that the friction force is not proportional to the current offset from the rest position, it is proportional to the current velocity vector.

andy.fingerhut22:09:20

So the friction force is actually greatest when the object is moving fastest, which in an oscillating spring is going to be when the offset from rest position is 0, i.e. the object zips by the rest position faster than at any other time during its movement, in a single 'sweep'

idiomancy23:09:17

Basically what it comes down to is that I want a function that takes some input x and produces a y between 0 and 1, where y is larger the closer x is to 0

idiomancy23:09:41

so... that sounds kind of like cosine

idiomancy23:09:23

its cosine-ish

idiomancy23:09:28

if my input range was between 0 and pi, then that would be true for cosine

andy.fingerhut23:09:19

There are an unlimited number of such functions, if you don't need the damping effect to behave like friction.

👍 3
idiomancy23:09:30

yeah this actually might be exactly what I need

chucklehead23:09:07

can you not just do the absolute value of the cosine?

andy.fingerhut23:09:34

That would decrease up to pi, then increase again, which may not be what he's looking for

andy.fingerhut23:09:58

if one knew the maximum distance from the rest point, you could scale that distance so it was in the range [-pi, pi] and use cosine

idiomancy23:09:31

I think e ^ (-x^2) is perfect, actually

idiomancy23:09:56

I can just multiply x by another constant to customize for the shape I'm after

andy.fingerhut23:09:28

The base can be anything, e.g. 50 ^ (-x^2), which is just another way of scaling the shape of the curve.

andy.fingerhut23:09:45

But e is pretty cool.

idiomancy23:09:03

oh its not a special property of e ? lol, shows you what I know

andy.fingerhut23:09:41

Any positive real number raised to the power 0 equals 1, so any positive number works there

idiomancy23:09:29

man thats awesome. Im really, really happy to have (I'll just sub in k) k^(-x^2) pattern available. I feel like I run into this problem a lot

andy.fingerhut23:09:19

Are you trying to achieve spring-like oscillating motion?

idiomancy23:09:26

yeah, a mass that, when disturbed, oscillates back and forth, where that oscillation decays at some rate I control

idiomancy23:09:16

but with the additional constraint that I can only work by setting the forces acting on them, not their positions directly

andy.fingerhut23:09:11

Because if the simulation uses a step like next_y = (e^(-cur_y^2)) * cur_y, where y is the offset from the rest position, and you repeat that, it will not ever oscillate around the 'rest position'. If it starts out with cur_y = 10, say, then the next values of y will just get smaller and smaller, but always positive, and slow down the closer it gets to 0.