7 ms·
From design patterns to category theory
- defined 9y ago> I'll write these articles in an authoritative voice, because a text that constantly moderates and qualifies its assertions easily becomes unreadable. Don't consider the tone an indication that I'm certain that I'm right. Kudos for including this disclaimer. The article can be trim and readable, while the disclaimer acts to dissuade well-meaning reviewers (like - ahem - me), who sometimes value precision and accuracy more than the big picture, from nitpicking it to death.
- vog 9y agoIn other words: strong opinions, loosely held. Shouldn't this be the default expectation, for every article we read, anyway? Such a disclaimer makes only sense if the article was written by some very famous author who must reasonably fear that their advice is taken too dogmatically. Speaking of that, I've never seen people like Martin Fowler make such a disclaimer.
- c3534l 9y agoDepends on the audience, really. You have to already know a fair bit before you can critically evaluate the speaker.
- mikekchar 9y agoTo be fair, Martin Fowler's entire blog is a "bliki" because he intends to (and does) change his entries often. He's even ripped out entire swathes of his writing when he thinks he's wrong (occasionally frustrating when you think he's wrong about being wrong ;-) ). I assume he doesn't make such a disclaimer because he thinks everyone already realises it -- but I have to agree that it would be nice if he (and other people as well) did. A lot of times people seem to think that reading something from a well known author is equivalent to permission to turn their brains off :-( Instead of, "Oh, that's amazing! Let's try it", they think, "Oh, that's amazing! We don't have to try it".
- conistonwater 9y ago> It seems to me that some design patterns are essentially ad-hoc, informally specified, specialised instances of basic category theory concepts. There is a flaw in this type of thinking which I think is not addressed here, but should be. (I took the quote from the summary, but I think it's fair.) The usual issue with ad-hoc informally specified things is that the ad-hocness and the informality leaves something out, making sure that if you understand the informal thing, but not the formal, you end up understanding only some part of the whole thing that you could understand if you tried. So in the context of design patterns, that means there should exist situations where the extra abstraction, the non-ad-hoc non-specialized understanding, allows you to write code that is better than otherwise, and (more importantly) that you would not have otherwise written. This would show explicitly the gap between the ad-hoc ideas and the formal ideas instead of leaving you to guess. Whereas the way this post tries to explain it, as I understand it, is that it shows you things (design patterns) that you would have otherwise written, and shows how it can be talked about in more general terms. But the things that you wouldn't have written are missing. E.g., in some monad tutorials at some point one of the exercises is the nondeterministic choice monad, which is totally something you might not have written yourself, which makes it a way of showing why monads are a useful concept. If the only monad you had was IO, it'd be a much more useless idea (it would merely be a different, not even necessarily better, way of writing things that you already knew).
- empath75 9y ago> There is a flaw in this type of thinking which I think is not addressed here, but should be. (I took the quote from the summary, but I think it's fair.) The usual issue with ad-hoc informally specified things is that the ad-hocness and the informality leaves something out, making sure that if you understand the informal thing, but not the formal, you end up understanding only some part of the whole thing that you could understand if you tried. I’m fairly sure that’s the entire premise of his series.
- closed 9y agoWow, this really struck home the idea of useful forms of generality for me. Definitely reminded me of an interesting section in Polya's book Induction and Analogy in Mathematics that discusses different forms of generality, and when it's useful (in the context of a problem to figure out).
- 100ideas 9y ago"Physics, Topology, Logic and Computation: A Rosetta Stone (2009) [pdf]" https://news.ycombinator.com/item?id=12317525 https://news.ycombinator.com/item?id=12317525
- westoncb 9y agoI found another interesting approach to formalizing design patterns a few years ago: https://dl.acm.org/citation.cfm?id=2207827 https://dl.acm.org/citation.cfm?id=2207827 —rather than expressing them as particular instances of more general things (as you'd do using category theory), he breaks them into a small set of more fundamental things which can be re-combined into familiar design patterns. I find it pretty interesting that it's possible to do both of these things... I'd also bet category theory isn't the only generalization and 'elemental design patterns' isn't the only decomposition. Also, while the formalization might be interesting, I wish I could be sold on its value... I'd definitely be interested in seeing some 'train of thought' examples of how someone used category theory (for instance) to reason about some architectural issues for something like... a game engine or web framework or CAD tool—something where the domain isn't going to make it an easy fit for category theory on its own.
- proc0 9y agoI will check that link out, but I'm willing to bet CT actually captures the entirety of design patterns plus any subset that you might make out of them. CT is the most abstract math and is really good for studying structures and patterns of computation itself.
- TuringTest 9y ago> rather than expressing them as particular instances of more general things (as you'd do using category theory), he breaks them into a small set of more fundamental things which can be re-combined into familiar design patterns. I haven't read that book, but it sounds similar to how Peter van Roy deconstructs programming paradigms: [1] https://www.info.ucl.ac.be/~pvr/VanRoyChapter.pdf https://www.info.ucl.ac.be/~pvr/VanRoyChapter.pdf [2] https://en.wikipedia.org/wiki/File:Programming_paradigms.svg https://en.wikipedia.org/wiki/File:Programming_paradigms.svg
- runeks 9y ago> … rather than expressing them as particular instances of more general things (as you'd do using category theory), he breaks them into a small set of more fundamental things which can be re-combined into familiar design patterns. How do these two approaches differ from each other? As far as I can see, they’re exactly the same thing. From the linked article: > Smith introduces a foundational layer of patterns terminology: a collection of core patterns that can't be decomposed further. This is exactly the purpose of category theory. Rather than have group theory, set theory, propositional logic, etc., category theory unites all of these into something that cannot be decomposed further (identity and composition).
- uptownfunk 9y agoHas anyone come across design patterns w.r.t data science (e.g., importing / transforming data / creating a modelling record / doing a grid search / scoring a new data set / outputting results?) I see these things running in scripts generally, but wondering if there are any applications of design patterns to a data science workflow.
- terminalcommand 9y agoFull disclosure: I have not dabbled with data science, nor I'm an experienced programmer. But many of the CS pioneers dealt with the issue of reading input, processing it, and giving a meaningful output. Recently I've stumbled upon Jackson's Principles of Program Design and it has really helped me in writing a parser. IMHO general understanding of structuring a program goes a long way than arbitrary design patterns. I now am a propenent of modular programming. For me it resembles functional programming and TDD. Basically it states your program should be made up of numerous self-contained modules that can be independently tested. For data science workflow it could be an import package, further divided in modules such as general helpers and implementations for different file types; a computation package etc.
- ambicapter 9y agoIts always hard for me to decide how those modules are going to end up communicating though. Should there be a lingua franca to all your modules? Or do they all have specialized APIs?
- terminalcommand 9y agoProgramming to interfaces help in this matter. e.g. if I have a data interface, I could use the same type on any format I liked. If it is the same interface, methods are the same too. For encapsulation and message passing, coroutines work wonders. You could use a generator in Python, or a goroutine in Golang. And then you could treat different modules of your program, as if they were a standalone independent part.
- pizza 9y ago
- proc0 9y agoBetter to use discovered languages as they say, but also better to learn the actual abstractions of computation itself, which CT does a great job at, instead of arbitrary patterns that are based on human intuition.
- filmor 9y agoCategory Theory is also a set of arbitrary patterns based on human intuition. Just with the added property of being formalised and consistent :)
- proc0 9y agoWhat about the Curry-Howard-Lambek correspondence? This is directly relate to why math works so well on the real world. CT and pure FP languages seem to tap into this fundamental workings of our mind and possibly the universe (CT is used in quantum mechanics). In contrast things like OOP are modeled based on intuitive patterns that solve specific problems, and which are often based on metaphors or abstract analogies, but not a fundamental abstraction of nature. In other words CT seems to capture the patterns of computation itself.
- DonbunEf7 9y agoI fear that we do not understand patterns well enough to categorify them so easily.
- sigsergv 9y agoDesign patterns are not formalized enough, we cannot apply category theory axioms to them.
- aauthespian 9y agoCheck out this http://www.aauthespian.news/2017/09/new-music-m2-who-are-you-prod-by-eddie.html http://www.aauthespian.news/2017/09/new-music-m2-who-are-you...
- sandGorgon 9y agoThe problem with category theory and monads, etc are that they are inaccessible for some of the popular tools. E.g. javascript, python, ruby . It invariably happens that learning these patterns needs you to learn haskell, lisp or erlang. Which is where accessibility breaks down. If there was a conceptual framework that bridges these higher order designs to accessible languages .. even if partially so, that would be killer. P.S. I love what dg for python has done - http://pyos.github.io/dg/ http://pyos.github.io/dg/ >Annoy advocates of the category theory! >With Haskell's syntax but none of its type system, dg is the best way to make fans of static typing shut up already
- edem 9y agoHow can you call lisp an inaccessible language? It has less syntax than anything else. It is as simple as a language gets.
- kryptiskt 9y agoBrainfuck has even simpler syntax and is even more inaccessible. There's way more to languages than syntax.
- edem 9y agoBrainfuck it unintuitive, but Lisp is. You can learn the lambda calculus in 10 minutes. You can'c tompare the two.
- 201709User 9y agoIt's better to have 50 keywords than 1000 nested brackets.
- empthought 9y agoPersonally I don't see the advantage of )}]]})} over ))))))).
- 9y ago
- fmap 9y agoI'm looking forward to reading this series! Based on the overview, I would call it "From design patterns to algebra", though. There's (in most cases) no reason to involve categories in a discussion of monoids/semigroups and isomorphisms.
- madhadron 9y agoThat would be my choice of title, too. I considered writing exactly such a thing a few years ago, but realized that I am almost certainly the wrong person to do so, since I use the algebras but not the design patterns that approximate them.
- avodonosov 9y agothrough blockchains?
- heroku 9y agohow long do we wait until the series is complete, a year?
- wisam 9y agoWell, he just posted the second entry in the series. Let's hope he keeps posting that frequently. http://blog.ploeh.dk/2017/10/05/monoids-semigroups-and-friends/ http://blog.ploeh.dk/2017/10/05/monoids-semigroups-and-frien...
- CodingChef 9y agoDoes anybody have a recommendation for a book on category theory?
- sjakobi 9y agohttps://github.com/hmemcpy/milewski-ctfp-pdf https://github.com/hmemcpy/milewski-ctfp-pdf appears to have quite a few fans.
- _zachs 9y agoThanks for writing this! Looking forward to reading the articles as they come out.
- aaimnr 9y agoMark Seemann, TFA's autor wrote a highly praised book Dependency Injection in.NET and then slowly gravitated towards F# and Haskell. He presents lot of perspectives on FP often in the context of OO alternatives making it easier to appreciate FP advantages not just in theory, but in the context of practical application problems. I've found his Pluralsight course on Functional Architecture pretty interesting.