Alexis King wrote on 04/10/2018 03:32 PM:
There is definitely a school of thought that buys into the idea of returning “the thing being operated on” rather than returning nothing for side-effectful functions. I think this is most characterized by so-called “fluent interfaces”[1], a way of encoding DSLs into object-oriented languages. As far as I can tell, this was style has been around for a very long time, but it was really forced into mainstream usage by the runaway success of jQuery in the mid to late aughts.


Yes, it was idiomatic in Smalltalk to return `self` for some things, and (together with the minimal required punctuation, the method names with interspersed arguments, and parsing disambiguation) this permitted the brave programmer to write neat-looking stream-of-words sequences of messages that jQuery could only dream of. :)

In Racket, with the `racket/class` object system, you'd probably use `send*` instead, which is boring, but clear.

BTW, Alexis is responding to the suggestion of "always return something useful, rather than void".  I think the case of `gzip` without a second argument, however, is different.  In that case, the code is generating a kind of handle or locator for the output of some (also side-effect-producing) operation.  Given that this generation behavior has been put into this procedure, and that it is common for a program want to do something else with that output or its handle/locator, then I think it makes sense to return the generated locator.  (`gzip` is not the best example, because it involves side effects in this other filesystem environment, along with locator naming conventions coming from elsewhere, which is why it can have the output argument unspecified.)

--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to