Hacker News new | ask | show | jobs
by thom 2226 days ago
Not to say this is bad or incorrect, but this is very unidiomatic Clojure. I would question the amount of global state, and the broad use of loops inside threads. This can’t be fun to try and test!

Perhaps better would be to make pure functions to take current telemetry as an argument and return actions as outputs, perhaps all at once or more likely individually for each control. You could then capture all of this inside core.async go-loops to manage the control flow and timeouts, but you could also probably build something simple with one or more agents wrapping the current state and updating a set of commands to be executed later. Another argument for core.async would be to make it easier to funnel all commands into a single channel because I’m not entirely convinced a WebDriver is multithreaded, but perhaps the library manages that for you.

Anyway, cool stuff!

2 comments

Each time someone complains a working program is not "idiomatic" in what ever language I die a little inside.

That makes it sound you approach this from a haughty presumptuous, uncharitable angle.

It sounds like you exclude the possibility that the author did not try it "your way" first, for example, but found a simpler way to implement it.

"That's not the most obvious to do it IMO" or "I would have preferred to do it like this..." are much better ways to approach this. Programs should be beautiful and understandable, but "idiomatic" sounds it excludes lots of simple beautiful solutions to a problem out of pure dogma.

Clojure is a mostly pure functional language, it is very uncommon to have almost all logic reach out to global variables to do work. It’s also rare to see multithreaded code that eschews most of the mechanisms built into the language for multithreading. These two things together (pure functional programming and strong concurrency primitives) are arguably the fundamental motivations behind the language. You value simplicity: Clojure can help make this code simpler. If there’s a succinct way to say that without the word idiomatic, one with fewer negative connotations, I will try to use that in the future.
And those are valid critique. I'm sorry - my prior response was harsh now I'm reading it again.

We all like to critizice things that offend our sense of aesthetics. But criticism always hurts the author. It's ok if it hurts if it is valid critique. And the only way to get understood is to be explicit.

I'm a Clojure fan but I'm not sure a modeling and simulation problem such as this is the best use case for it. Sure, you can do it, but it probably wouldn't be my first choice. Last I checked, Aerospace software is still dominated by C/C++ and Ada (still alive because it found itself a niche), and there's good reasons for it. The satellite simulators I worked on had to be able to execute actual flight code from the vehicle, so you needed to get fairly low level.

Nowadays I write web applications like everyone else on the planet and use Java, JS and/or Clojure (when I can get away with it).

But cool little project, nonetheless.

I would have to google but I’m fairly sure Rich Hickey has expressly state’s this sort of project as a motivation for Clojure. Perhaps not with such real-time demands or For integrating with hardware, but certainly from the exploration and theory side.