7 ms·
Tacit programming
- ngcazz 3y agoLove point-free. It's definitely a muscle you need to keep in shape, and although it's definitely not for everybody, if you design your API with this in mind it can be a lot of fun to program in this style. I think TidalCycles is a nice example of such an API (for the most part)
- surprisetalk 3y agoThere are some great episodes about tacit programming on The ArrayCast, a podcast about APL/J/K. [1] https://www.arraycast.com https://www.arraycast.com
- siraben 3y agoWhy not translate your code to pointfree style automatically? Using[0], you can go from quad a b c = let d = b * b - 4 * a * c in ((-b + sqrt d) / 2 * a, (-b - sqrt d) / 2 * a) to ghci> import Control.Monad ghci> quad = ap (ap . ((.) .) . ap (ap . (liftM2 (,) .) . flip (flip . ((*) .) . flip flip 2 . ((/) .) . (. sqrt) . (+) . negate)) (flip (flip . ((*) .) . flip flip 2 . ((/) .) . (. sqrt) . (-) . negate))) (flip ((.) . (-) . join (*)) . (*) . (4 *)) ghci> quad 1 3 (-4) (1.0,-4.0) [0] https://pointfree.io/ https://pointfree.io/
- yau8edq12i 3y agoApart from "just because we can" or "it's fun", why on earth would someone prefer the second style?
- euiq 3y agoIt's a joke.
- rebeccaskinner 3y agoIn this example I can’t imagine anyone preferring the second style, but there are cases where it’s nicer. For example compare the tacit: foo = h . g . f With the more verbose: foo x = let a = f x b = g a c = h b in c If a, b, and c have useful names that help you understand the code then the second function might be preferable- but in a lot of cases all the intermediate variables are just adding noise and making it harder to see what’s happening at a glance. The tacit example makes it very clear at a quick glance exactly what’s happening. My personal rule of thumb is that if you are passing combinators in as arguments to other combinators then you should probably stop, but straightforward chaining is usually okay.
- pasquinelli 3y agotacit programming means you don't use argument names to direct your data to the desired output. what's interesting to me about that is the unexplored possibilities of how data could be directed without names.
- meindnoch 3y agoClearly superior.
- nextos 3y agoThis led to the algebra of programming school: https://www.cs.ox.ac.uk/people/jeremy.gibbons/publications/squiggol-history.pdf https://www.cs.ox.ac.uk/people/jeremy.gibbons/publications/s... For context, see this discussion: https://stackoverflow.com/questions/5671271/what-are-advantages-and-disadvantages-of-point-free-style-in-functional-progra https://stackoverflow.com/questions/5671271/what-are-advanta...
- nextos 3y agoAlso, related HN thread: https://news.ycombinator.com/item?id=24056901 https://news.ycombinator.com/item?id=24056901
- lgas 3y agoMy favorite resource on Tacit programming is Point Free or Die: https://www.youtube.com/watch?v=seVSlKazsNk https://www.youtube.com/watch?v=seVSlKazsNk
- TuringTest 3y agoI love the concept of point-free programming - write your function by simply concatenating the transformations you want. I just hate reading the resulting code written by others. What information is expected to come in, and exactly what data passes from one step to the next, and in what position? Data type signatures only go so far. Point-free means you have all that wiring in your head, without assistance from the notation.
- anonzzzies 3y agoI like reading and writing point-free code, I just really hate debugging it. The debuggers/IDEs are (usually? are there exceptions) not really geared up for it and so the debugging experience is basically one of just having 1 call. This goes for more lambda style calling mechanisms of course. I end up pulling it apart, but that's only because of bad debug/ide support in my case. I can read/write it fine; in most cases it just works and then I like it better than the (verbose) alternatives.
- euiq 3y agoRecent versions of F# can stop on individual function applications in an expression like x |> f a |> g b … (search for "pipeline debugging" on < https://devblogs.microsoft.com/dotnet/whats-new-in-fsharp-6/ https://devblogs.microsoft.com/dotnet/whats-new-in-fsharp-6/>). In my experience, these are more common than strict point-free style anyway.
- astrobe_ 3y agoJust like there is "decision fatigue" [1] I believe there is "naming fatigue", and naming are one of the three great problems of computing, as everyone knows. I'd say that at least point-free prevents naming fatigue, but for the result to be nice to the reader, the naming and factorization is much more important than with explicit code, which has sort of much more "safeties". On the specific question you ask, let's hear the creator of one of the major stack oriented languages, Forth, by its inventor when he had about 30 years of professional practice. He talks about code comments, which is the local solution that comes immediately to mind when thinking about the issues you pointed out: So people who draw stack diagrams or pictures of things on the stack should immediately realize that they are doing something wrong. Even the little parameter pictures that are so popular. You know if you are defining a word and then you put in a comment showing what the stack effects are and it indicates F and x and y F ( x - y ) I used to appreciate this back in the days when I let my stacks get too complicated, but no more. We don't need this kind of information. It should be obvious from the source code or be documented somewhere else. Well, comment-less code isn't popular either, but we're not here to design the next Python anyway. By the way, Chuck Moore evolved his language until he determined that the remaining problems were "in the hardware". He did his own CAD tools with his language to design stack-oriented CPUs with some success, as some of them ended up in spacecrafts (notably Philae in 2014 [3]). In my experience, when you want to keep the data flow as simple as possible (in Forth: keep "stack juggling" to a minimum), there's very often only one good order for parameters. That works very well for the writer, for whom the understanding of the problem helps with memorizing signatures and semantics. As a reader (of other's code), I have much less experience, but I guess that understanding the same things requires the readers to invest more time up front, in addition to the "accidental obfuscations" (poorly written code, unusual programming habits and conventions...). [1] https://en.wikipedia.org/wiki/Decision_fatigue https://en.wikipedia.org/wiki/Decision_fatigue [2] https://www.ultratechnology.com/1xforth.htm https://www.ultratechnology.com/1xforth.htm [3] https://en.wikipedia.org/wiki/RTX2010 https://en.wikipedia.org/wiki/RTX2010
- notemaker 3y agoI've never found this style readable unless with pipes (bash / elixir), where I love it. With any other syntax, I find it just adds mental overhead. Maybe because you have to read it backwards?
- technojamin 3y agoPipes in both of the languages you specified do function application, not composition, so they’re very much point-ful (you see the arguments you pass/get passed).
- euiq 3y agoI assume they're talking about code like x |> f a |> g b … … where everything after the first |> is essentially in point-free style.
- diggan 3y agoClojure (and I'm sure other lisps and programming languages) have a nice solution to this, the `->` macro ("threading") You'd do something like: (save (transform (fetch))) ;; calls fetch, then transform, then save (-> (fetch) (transform) (save)) Not that the non-threading version was hard to read, but once the function names start to be a bit longer and involve arguments, the threading version tends to be a lot easier to read.
- mihaic 3y agoAbsolutely every single time when I use functional programming, I store my intermediary calls in a variable, specifically because naming that variable forces me to explain what that intermediary result should be. If the intermediary result makes no sense, and only the function composition makes sense, I'll create a new well named function that does the chaining, even if it's single use. This is literally the only way I've seen multi-year projects be maintainable, and anything else eventually breaks down into uninteligible code. Writing code for other developers in the long-run is empathy for yourself, since you'll eventually forget all the context you once had.
- mirekrusin 3y agoTacit programming shines when you have combinators over some closed, well defined domain - ie. parser combinators, runtime assertion combinators, iterator combinators etc.
- auggierose 3y agoYeah, point-free sounds cool, until you actually try it out. Even in their example they are not point-free: compose(foo, bar, baz) Here compose is applied to three "points" (which happen to be functions).
- epgui 3y agoThat example is as point free as it gets. Just because the syntax doesn’t look like Haskell doesn’t really change that.
- auggierose 3y agoYou are applying functions to arguments, aren't you? So "point-free" means you cannot apply a function to arguments on the left hand side of a definition, but you are allowed to do so on the right hand side? If that's point-free, it is also point-less.
- pasquinelli 3y ago
- i_am_a_peasant 3y agoSeems like a maintenance nightmare tbh. You have to jump at a billion functions definitions before you can hope to understand what a program is doing. I could see myself transforming a functional program into a procedual one as I try to understand it just so I can have all information just in front of me and not have to keep things in my head. Like I get that a functional style helps with the mathematical correctness side of things. But I'm just one of those people who still hold "code is meant for humans" first.
- epgui 3y ago> You have to jump at a billion functions definitions before you can hope to understand what a program is doing On the contrary, if you assume that your functions are good abstractions then you shouldn’t need to know their implementation details in order to compose them. You can tell what it does by looking at just what you have in front of you. If that’s not the case, then you’re not looking at a good example of this concept. And we all know we can find bad examples of any idea or paradigm— what is useful is the good examples.
- AnimalMuppet 3y ago> > You have to jump at a billion functions definitions before you can hope to understand what a program is doing > On the contrary, if you assume that your functions are good abstractions then you shouldn’t need to know their implementation details in order to compose them. You can tell what it does by looking at just what you have in front of you. In maintenance, you often cannot assume that your functions are good abstractions. One of them is doing something wrong, or at least something that needs changed. Which one? You have to go into the implementation details in order to find where you have to begin to work. That's not "bad examples" of FP. That's just how software maintenance is. And maintenance is going to happen to FP programs too...
- rebeccaskinner 3y ago> One of them is doing something wrong, or at least something that needs changed. Which one? While this is as true in FP as it is anywhere, my experience is that it’s rarely true of the kind of small pure functions that tend to be composed like this. When someone is using a chain of functions like this, they usually are good abstractions that don’t change, and are short enough to be trivially correct.
- bbor 3y agoWow, seems pretty obvious what this was written for (even if they didn’t know it): building commands/prompts for LLM ensembles. It’s just too perfect —- the LLMs could easily implement their own combinators. Would be a huge step towards self-improving systems…
- dang 3y agoRelated. Others? Tacit Programming - https://news.ycombinator.com/item?id=28413195 https://news.ycombinator.com/item?id=28413195 - Sept 2021 (1 comment) What’s the Point of Pointfree Programming? - https://news.ycombinator.com/item?id=25509468 https://news.ycombinator.com/item?id=25509468 - Dec 2020 (1 comment) When Does Point-Free Notation Make Code More Readable? - https://news.ycombinator.com/item?id=15365214 https://news.ycombinator.com/item?id=15365214 - Sept 2017 (73 comments) Programming in the Point-Free Style - https://news.ycombinator.com/item?id=14077863 https://news.ycombinator.com/item?id=14077863 - April 2017 (101 comments) Point-Free style: What is it good for? - https://news.ycombinator.com/item?id=1175946 https://news.ycombinator.com/item?id=1175946 - March 2010 (22 comments)
- DougBTX 3y agoThe broader idea of “pass a value between functions without naming it in the caller” crops up in a few other places outside FP. In Rust there is the “builder pattern”[0] where the builder isn’t mentioned directly: ByValueBuilder::new() .with_favorite_number(42) .with_favorite_programming_language("Rust") .build() In OO land they are called “fluent interfaces”[1], commonly used when building SQL queries while only mentioning the final query at the end: query = translations .Where(t => t.Key.Contains("a")) .OrderBy(t => t.Value.Length) .Select(t => t.Value.ToUpper()); Especially in the query builder example, since it is essentially building up an AST, the type of the top-level object can change in each call, but since it isn’t named it also doesn’t need to be typed, so there’s no issue with variable shadowing etc. [0] https://blog.logrocket.com/build-rust-api-builder-pattern/ https://blog.logrocket.com/build-rust-api-builder-pattern/ [1] https://en.m.wikipedia.org/wiki/Fluent_interface https://en.m.wikipedia.org/wiki/Fluent_interface
- mike_hock 3y agoThe framing of the builder pattern as primarily a Rust feature, and fluent interfaces as primarily an OO feature, is a bit odd. A prime example of non-builder fluent interfaces are containers in Rust. Both builders and fluent interfaces exist pretty much in all languages that can support chaining methods on some sort of object. This includes OO languages as well as totally-not-OO languages like Rust that just stop short of calling their classes "classes."
- layer8 3y agoThe builder pattern [0] is orthogonal to fluent interfaces. It has merely become customary for builders to have a fluent interface. The defining feature of the builder pattern is that you don’t set configurable properties on an object itself, but that you use a separate object (the builder) to set the properties on, and then have it build the final object (on which the respective properties are then usually immutable). It’s immaterial whether the builder object has a fluent interface or not. The important thing is that the builder interface is separated from the resulting object’s interface. [0] https://en.wikipedia.org/wiki/Builder_pattern https://en.wikipedia.org/wiki/Builder_pattern Both builders and fluent interfaces have little to do with point-free style. X.foo().bar().baz() is not any more point-free than baz(bar(foo(x))).
- teleforce 3y agoThe first time I've read about tacit programming is in one of the blog posts on oilshell [1]. Really like the idea and apparently one of my favorite features of UNIX is the pipe facility, and it's actually a form of tacit programming. This makes a lot of sense since the OS itself is already full of ready made functions that can be exposed through the API [2]. It's also interesting to note that most of the modern programming languages for examples Python, Ruby, Perl, and JavaScript are missing or have awkward support of this feature. [1] Pipelines Support Vectorized, Point-Free, and Imperative Style: https://www.oilshell.org/blog/2017/01/15.html https://www.oilshell.org/blog/2017/01/15.html [2] The Linux Programming Interface: https://man7.org/tlpi/ https://man7.org/tlpi/
- BenGoldberg 3y agoYou consider Perl's map and grep to be awkward?
- jlouis 3y agoThis technique is highly useful in moderation, provided you are working in a language where the syntax/semantics affords it. It can certainly be overdone to the point where the code becomes harder to decipher for a human reader. A key step is that programming languages which use the style builds a vocabulary of commonly used operations and make these into general knowledge for programmers using the language. Thus, succinctness is obtained and you can compress hundreds of lines into a few. Flip side is a steeper learning curve, which has to be balanced against.
- adityaathalye 3y agoTinkering with APL (Dyalog) gave me one of my most mind-bending programming moments. dismal ← 10⊥(⌈/10⊥⍣¯1⊢) This is the complete solution to addition in the framework of Dismal Arithmetic [1]. The pivotal idea there was the inverse of a function, and "trains". Until that moment of insight, I was fiddling about with dfns, which looks janky in comparison. dismal ← {10(⊤⍣¯1)⍵}∘{⌈/⍵}∘{10(⊥⍣¯1)⍵}⊢ ⍣¯1 is APL for "inverse". Aaron Hsu helped me understand [2] what was going on. I feel like this kind of conceptual power is tacit programming at is finest. It blows my mind that this alien gobbledygook code still makes sense to me after not touching APL for years now. And I've only toyed around with the language. [1] I was playing with the problem to compare Clojure and APL, just because. https://www.evalapply.org/posts/dismal-arithmetic-dyalog-apl-clojure/ https://www.evalapply.org/posts/dismal-arithmetic-dyalog-apl... [2] https://www.sacrideo.us/decoding-inverses/ https://www.sacrideo.us/decoding-inverses/ (edit: fix typos, verbiage)
- prezjordan 3y agoI can't seem to figure out what you mean by inverse. Is the inversion of addition subtraction? Neither post seems to explain what it is (or maybe it assumes knowledge of ⊥ and ⊤?)
- lokedhs 3y agoGiven a function F that accepts an argument x and returns y, its inverse is another function which, when passed y will return x. For dyadic functions, the incerse argument is always the right side one. So negation is its own inverse. So the inverse of 2+ is indeed subtraction of 2.
- adityaathalye 3y agoAnd if anyone wants an absolute masterclass in tacit programming, have a look at Aaron's Co-dfns compiler. The README has extensive reference material. https://github.com/Co-dfns/Co-dfns/ https://github.com/Co-dfns/Co-dfns/
- thelastparadise 3y ago> dismal ← 10⊥(⌈/10⊥⍣¯1⊢) And what does that look like in C?
- mrob 3y agoHow is omitting the names in any way beneficial? It all ends up as memory addresses in the end. Surely the important point is the sequential data flow. I often use point-free style myself (pipelines), but I'd never pretend it's good practice. Pipelines are a quick-and-dirty hack for when you're too lazy to use a better programming paradigm. They're "write only", in that it's quicker to write one from scratch than to understand an existing one. "Tacit programming" as a concept sounds like typical mathematicians' obscurantism, like their love of single-character variable names and implicit operations.
- jan_Inkepa 3y agoThe wiki page leaves out the source of the the 'point-free' nomenclature - category theory ( e.g. https://en.wikipedia.org/wiki/Pointless_topology https://en.wikipedia.org/wiki/Pointless_topology ). The original game was talking about sets (or other similar objects) without talking about 'set membership'/'elements', whence 'point-free'; you want to only talk about functions between sets (or morphisms between objects), and build everything up from those. Is 'tacit' an old term or a newer rebranding? (edit: https://en.wikipedia.org/wiki/Whitehead%27s_point-free_geometry https://en.wikipedia.org/wiki/Whitehead%27s_point-free_geome... might be earlier than the category stuff, but not sure if it used the 'point-free' nomenclature, nor if it has a direct lineage to the later category theory stuff )
- mlochbaum 3y agoThe name "tacit" comes from the APL family as far as I know. It certainly fits with Iverson's style, as he was fond of seeking out just the right word to describe something regardless of obscurity ("ravel", "copula", etc.). I think the name would have come about after the development of function trains in 1988, and I found a paper "Tacit definition" about Iverson's J from 1991: https://dl.acm.org/doi/10.1145/114054.114077 https://dl.acm.org/doi/10.1145/114054.114077 (digitized at https://www.jsoftware.com/papers/TacitDefn.htm https://www.jsoftware.com/papers/TacitDefn.htm). Not knowing when "point-free" started to be applied to programming, I can't say which is first. I doubt J's developers were aware of "point-free" in any case.
- jan_Inkepa 3y agoGreat, good to know where it comes from - thanks. :) I'd guess given that I associate point-free with Haskell, which came much later, that the APL nomenclature (of which I was ignorant) came first.
- mlochbaum 3y agoI was inspired to write up a little section on Iverson's approach to naming (including his probable coinage of "bubble sort"): https://aplwiki.com/wiki/Ken_Iverson#Naming_things https://aplwiki.com/wiki/Ken_Iverson#Naming_things
- macmac 3y agoThe Blackbird combinator in Clojure: (defn blackbird [f g] (fn [x y] (f (g x y)))) or (def blackbird (comp comp comp))
- bgribble 3y agoThe graphical dataflow languages that are popular for music and audio programming (thinking Pure Data, Max/MSP, Reaktor etc) do this in a way that makes the value of "namelessness" a bit more clear. When you connect the output of one unit to the input of another unit, there's no need to name that linkage, but it's still perfectly clear what's flowing over it. I really enjoy trying to think through programming problems in a dataflow style like this. It often turns the problem inside out in an interesting way. I did about half of this year's Advent of Code problems in such a system and it was a blast.
- Etheryte 3y agoHave you tried visual programming, e.g. Labview and the like?
- ssfrr 3y agothe languages listed (Pure Data, Max/MSP, Reaktor) are all visual languages where you connect up boxes with wires, similar to labview. I usually associate the term "Dataflow language" to refer to these types of languages, but I'm not actually sure if there are also text-based dataflow languages. Maybe Faust (which is also audio DSP focused)
- ssnri 3y agoOh, I’m huge on doing the opposite of this. When I write JS (not TS), I prefer as much as possible to use destructuring in every function definition. Named keyword arguments. Try to change the name of something as little as possible even as it gets passed around. It’s more powerful than a type system in some ways. Not always doable, but just try it sometime; it’s fun. I call it nominative programming.
- valty 3y agoI feel like JS needs auto-currying. function greet(greeting, name) { return `${greeting} ${name}` } const greetWithGreetingHello = greet('hello') greetWithGreetingHello('sally') And this should work with named arguments too. function greet({greeting, name}) { ... } const greetWithGreetingHello = greet({greeting: 'hello'}) greetWithGreetingHello({name: 'sally'}) With named params, curried functions can be read more naturally too. greetWithGreetingHelloAndWith({name: 'sally'}). "and with name sally"
- ssnri 3y agothe key idea for me was realizing that variables are really 3 things: value, type, and identifier. A javascript object is like an S-expression if you squint. The subtree nesting is messier.
- veqq 3y agoI'm responding to an unrelated old comment of yours about questioning all assumptions. In Forth, Chuck Moore said local vars are dangerous. Rather, everything should be a global. (However multithreaded Forth implementations do require locals.)
- AndyKluger 3y agoIf this interests anyone who hasn't played with it yet, I highly recommend trying out Factor. For me, it makes programming fun again. Some good practice problems can be found on Advent of Code, Codewars, and the Perl Weekly Challenge.
- ccorcos 3y agoJavaScript is great for point-free programming! Make sure you check out Ramda.js https://ramdajs.com/ https://ramdajs.com/ It’s fun in the sense that solving a puzzle is fun, but I avoid it for anything I need to maintain long-term. But it’s good practice for understanding combinators which is useful for some kinds of problems.
- avindroth 3y agoTacit programming + llm control library (like LangChain) has a lot of untapped potential. Tacit programming shines when the control structures are simple (and functions/variables can be anonymized), and these patterns occur frequently in programming on top of llms.