Fork me on GitHub
#other-languages
<
2021-04-24
>
raspasov00:04:26

Mutability will literally prevent you from doing good work in the long run, unless you have a constant + consistent mitigation strategy. Good luck enforcing that discipline. You’re much better off starting with the right tool for the job.

Stuart00:04:10

I think this is a good point, as soon as you require developer discipline, you've lost

Stuart00:04:45

As deadlines, pressure etc affect the work, things like mutability, tests, quality etc will go out of the window

ksd00:04:17

I was wondering if there were experienced Clojurists that had experience with Go, and specifically with the Reader and Writer interfaces. I find them pretty interesting and they seem to be especially well suited to streaming data. The thing I find unfortunate is that they deal exclusively with bytes. For instance, encoding something to JSON and streaming it into an HTTP request looks like this:

reader, writer := io.Pipe()
gzipWriter := gzip.NewWriter(writer)

go func() {
  json.NewEncoder(gzipWriter).Encode(myThing)
  gzipWriter.Close()
  writer.Close()
}()

req, _ := http.NewRequest("POST", someURL, reader)
client := http.Client{}
(req)
reader.Close()
In essence, the JSON encoding writes into the gzip writer which writes into the write end of the pipe, and writes into the pipe block until data is being read from the read end of the pipe, with data being transferred directly from the write to the read. We put the writing in a separate thread to avoid blocking the main thread. The HTTP client reads from the pipe when performing the request. When the encoding to JSON is done, we close the write end of the pipe which tells the reader that there is no more data, probably through an EOF. I’ve been using Go at work for a little over a year and have unfortunately not been able to use Clojure for much, other than writing little tools for myself and a compiler from a very small subset of Clojure to Go, written for a class. I was wondering if something like Clojure transducers could take the place or be used with something like the Reader/Writer interfaces from Go. Maybe they could be a protocol or family of protocols? This is still pretty hazy in my mind.

emccue00:04:29

@ruyvalle Sounds roughly like InputStream and OutputStream

ksd00:04:05

looking at InputStream now, that does look very similar, thanks!