# \#design-pattern

**URL:** https://discourse.julialang.org/tag/design-pattern/450.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Performance implications of computations in keyword arguments](https://discourse.julialang.org/t/performance-implications-of-computations-in-keyword-arguments/131977)

<div class="topic-metadata">

**Author:** [@loisel](https://discourse.julialang.org/u/loisel)\
**Replies:** 9\
**Last updated:** [September 1, 2025, 11:54am UTC](https://discourse.julialang.org/t/performance-implications-of-computations-in-keyword-arguments/131977 "2025-09-01T11:54:19Z")

</div>

Long story short, I’m putting my entire function into default values of keyword arguments, and I want to know if this is bad. I’m working on a Julia package to solve PDEs. The “driver code” of such solvers often has a z…

---

## [The best way(s) to encode binary type parameter choices](https://discourse.julialang.org/t/the-best-way-s-to-encode-binary-type-parameter-choices/127434)

<div class="topic-metadata">

**Author:** [@brainandforce](https://discourse.julialang.org/u/brainandforce)\
**Replies:** 9\
**Last updated:** [March 31, 2025, 8:06pm UTC](https://discourse.julialang.org/t/the-best-way-s-to-encode-binary-type-parameter-choices/127434 "2025-03-31T20:06:42Z")

</div>

Say I have a parametric type Foo{B} and I want to restrict B to two possible values. I can think of a couple of ways to do this: Have B take on a Boolean value and use an assertion in the inner constructor to verify th…

---

## [Copy on write?](https://discourse.julialang.org/t/copy-on-write/126021)

<div class="topic-metadata">

**Author:** [@iago-lito](https://discourse.julialang.org/u/iago-lito)\
**Replies:** 2\
**Last updated:** [February 18, 2025, 5:19pm UTC](https://discourse.julialang.org/t/copy-on-write/126021 "2025-02-18T17:19:17Z")

</div>

Hello Julia, I need copy-on-write behaviour to protect fields of the large values I’m handing out to my users from cluttering their memory with useless copies. Is there such thing as a julia Cow{T} akin to rust’s Cow\<T\>…

---

## [Second edition for Hands-on Design Patterns and Best Practices with Julia?](https://discourse.julialang.org/t/second-edition-for-hands-on-design-patterns-and-best-practices-with-julia/73940)

<div class="topic-metadata">

**Author:** [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Replies:** 5\
**Last updated:** [February 17, 2025, 11:58am UTC](https://discourse.julialang.org/t/second-edition-for-hands-on-design-patterns-and-best-practices-with-julia/73940 "2025-02-17T11:58:23Z")

</div>

Hi there! I’m the author of the book, and I’m considering updating it with a second edition. What would you like to add/update/remove? Your opinion counts! :pray: Any new topics or language features? Any suggestions …

---

## [Where to put export statements (Sub-Module Pattern) in distributed code?](https://discourse.julialang.org/t/where-to-put-export-statements-sub-module-pattern-in-distributed-code/125871)

<div class="topic-metadata">

**Author:** [@gwr](https://discourse.julialang.org/u/gwr)\
**Replies:** 2\
**Last updated:** [February 13, 2025, 7:26pm UTC](https://discourse.julialang.org/t/where-to-put-export-statements-sub-module-pattern-in-distributed-code/125871 "2025-02-13T19:26:42Z")

</div>

I am working through Tom Kwong’s book "Hands-On Design Patterns and Best Practices with Julia." In Chapter 7 on Maintainability Patterns, Tom talks about organizing code (sub-module pattern) and gives an example where a …

---

## [Zig Like Interfaces for Julia](https://discourse.julialang.org/t/zig-like-interfaces-for-julia/125085)

<div class="topic-metadata">

**Author:** [@cshen](https://discourse.julialang.org/u/cshen)\
**Replies:** 3\
**Last updated:** [February 3, 2025, 10:26pm UTC](https://discourse.julialang.org/t/zig-like-interfaces-for-julia/125085 "2025-02-03T22:26:24Z")

</div>

I’ve recently come across how Zig handles interfaces. The gist is that Zig doesn’t have syntax sugar for interfaces and instead opts for manually managing the vtable. I got curious and started playing with the idea, and…

---

## [Informal interfaces and abstract types](https://discourse.julialang.org/t/informal-interfaces-and-abstract-types/95993)

<div class="topic-metadata">

**Author:** [@nolb](https://discourse.julialang.org/u/nolb)\
**Replies:** 1\
**Last updated:** [May 11, 2023, 8:57am UTC](https://discourse.julialang.org/t/informal-interfaces-and-abstract-types/95993 "2023-05-11T08:57:06Z")

</div>

Hi everyone, I have a question regarding best practices for the design of informal interfaces. Let’s say that I want to implement a service that continuously reads in data from a source, processes the data, and publish…

---

## [Guideline on verbose in module (design pattern?)](https://discourse.julialang.org/t/guideline-on-verbose-in-module-design-pattern/72659)

<div class="topic-metadata">

**Author:** [@Thomas](https://discourse.julialang.org/u/Thomas)\
**Replies:** 0\
**Last updated:** [December 6, 2021, 3:45pm UTC](https://discourse.julialang.org/t/guideline-on-verbose-in-module-design-pattern/72659 "2021-12-06T15:45:39Z")

</div>

So far I use a kwarg verbose (0,1,2,inf) to allow diagnostic information during my computation: verbose && println("message here") A more systematic way to handle this is using the Logging module and @info, @warn, @err…

---

## [Keeping well-defined mathematical functions orthogonal to a project structs design](https://discourse.julialang.org/t/keeping-well-defined-mathematical-functions-orthogonal-to-a-project-structs-design/92601)

<div class="topic-metadata">

**Author:** [@dalbandea](https://discourse.julialang.org/u/dalbandea)\
**Replies:** 3\
**Last updated:** [January 6, 2023, 5:51pm UTC](https://discourse.julialang.org/t/keeping-well-defined-mathematical-functions-orthogonal-to-a-project-structs-design/92601 "2023-01-06T17:51:09Z")

</div>

I have a doubt regarding a design pattern. To expose it I’m going to refer to IterativeSolvers.jl’s Conjugate Gradient algorithm. For the end user, they supply the function cg(A, b; kwargs...), which solves the equation…

---

## [How to write idiomatic (non-OOP) Julia version of OOP design pattern?](https://discourse.julialang.org/t/how-to-write-idiomatic-non-oop-julia-version-of-oop-design-pattern/83548)

<div class="topic-metadata">

**Author:** [@merlin](https://discourse.julialang.org/u/merlin)\
**Replies:** 8\
**Last updated:** [July 13, 2022, 5:30am UTC](https://discourse.julialang.org/t/how-to-write-idiomatic-non-oop-julia-version-of-oop-design-pattern/83548 "2022-07-13T05:30:41Z")

</div>

I learned a lot about Object Oriented Programming from this blog article from 2020 about “Gang of Four” design patterns. I should say that I learned about OOP long ago via a Java book but as a data professional I have ne…

---

## [Is this design pattern of \`::Val{}\` dispatching evil?](https://discourse.julialang.org/t/is-this-design-pattern-of-val-dispatching-evil/54365)

<div class="topic-metadata">

**Author:** [@korsbo](https://discourse.julialang.org/u/korsbo)\
**Replies:** 10\
**Last updated:** [February 25, 2022, 10:25pm UTC](https://discourse.julialang.org/t/is-this-design-pattern-of-val-dispatching-evil/54365 "2022-02-25T22:25:02Z")

</div>

I’d like some feedback on a seemingly functional design involving recursion and a whole lot of ::Val{} overloads. I think that my time in the Julia community has conditioned me to shy away from such dispatching and proba…

---

## [Encapsulation and Interface-like implementations in Julia](https://discourse.julialang.org/t/encapsulation-and-interface-like-implementations-in-julia/74616)

<div class="topic-metadata">

**Author:** [@MAJegh](https://discourse.julialang.org/u/MAJegh)\
**Replies:** 2\
**Last updated:** [January 17, 2022, 8:56am UTC](https://discourse.julialang.org/t/encapsulation-and-interface-like-implementations-in-julia/74616 "2022-01-17T08:56:59Z")

</div>

My general question would be : Is there a way to organize code in Julia to improve maintainability/extensibility and make contributions to a project easier? any resources on the matter are welcome. More specifically, in…

---

## [Design patterns for parameterizing by functions](https://discourse.julialang.org/t/design-patterns-for-parameterizing-by-functions/70891)

<div class="topic-metadata">

**Author:** [@ruairidh](https://discourse.julialang.org/u/ruairidh)\
**Replies:** 2\
**Last updated:** [November 3, 2021, 10:42pm UTC](https://discourse.julialang.org/t/design-patterns-for-parameterizing-by-functions/70891 "2021-11-03T22:42:03Z")

</div>

I often write code that is parameterized by a small set of related ‘inner’ functions (f, g,…). The functions are related in the sense that they all do different computations but they share some parameters. I include a s…

---

## [Inserting new abstract type into existing hierarchy?](https://discourse.julialang.org/t/inserting-new-abstract-type-into-existing-hierarchy/62365)

<div class="topic-metadata">

**Author:** [@lamorton](https://discourse.julialang.org/u/lamorton)\
**Replies:** 7\
**Last updated:** [June 4, 2021, 2:05am UTC](https://discourse.julialang.org/t/inserting-new-abstract-type-into-existing-hierarchy/62365 "2021-06-04T02:05:24Z")

</div>

Suppose an existing package Barnyard defines abstract type Animal end abstract type Dog \<: Animal end Let’s say that in my package Zoo I define two new types: using Barnyard abstract type Zebra \<: Animal end abstract …

---

## [Implementing Singleton design pattern](https://discourse.julialang.org/t/implementing-singleton-design-pattern/61704)

<div class="topic-metadata">

**Author:** [@Niall](https://discourse.julialang.org/u/Niall)\
**Replies:** 8\
**Last updated:** [May 25, 2021, 6:04am UTC](https://discourse.julialang.org/t/implementing-singleton-design-pattern/61704 "2021-05-25T06:04:03Z")

</div>

Hi. I’m having trouble trying to implement the Singleton design pattern. In Java or C++, I would use a static pointer to the single instance, but Julia doesn’t have static data that I’m aware of. So I tried using an exte…

---

## [What's the best practice in Julia for research (often changed codes)?](https://discourse.julialang.org/t/whats-the-best-practice-in-julia-for-research-often-changed-codes/58892)

<div class="topic-metadata">

**Author:** [@iHany](https://discourse.julialang.org/u/iHany)\
**Replies:** 26\
**Last updated:** [April 20, 2021, 1:04am UTC](https://discourse.julialang.org/t/whats-the-best-practice-in-julia-for-research-often-changed-codes/58892 "2021-04-20T01:04:58Z")

</div>

Hi, I’ve used Julia about one year and I still struggle with how to use it. First of all, as a researcher, I often change my code including code structure and Julia types. When redefining types, Julia REPL needs to be …

---

## ["Zipped" loops in test sets: a bad design pattern?](https://discourse.julialang.org/t/zipped-loops-in-test-sets-a-bad-design-pattern/57685)

<div class="topic-metadata">

**Author:** [@Jollywatt](https://discourse.julialang.org/u/Jollywatt)\
**Replies:** 8\
**Last updated:** [March 22, 2021, 9:41pm UTC](https://discourse.julialang.org/t/zipped-loops-in-test-sets-a-bad-design-pattern/57685 "2021-03-22T21:41:47Z")

</div>

I’m (ab)using Julia’s testing interface to verify mathematical propositions for many randomly generated samples. I find myself using the following pattern a lot: @testset "definitions" begin for x in rand(N) ... @t…

---

## [Better design pattern for this type of development..?](https://discourse.julialang.org/t/better-design-pattern-for-this-type-of-development/44497)

<div class="topic-metadata">

**Author:** [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Replies:** 5\
**Last updated:** [August 7, 2020, 1:18pm UTC](https://discourse.julialang.org/t/better-design-pattern-for-this-type-of-development/44497 "2020-08-07T13:18:53Z")

</div>

I have a lot of Julia code that goes something like this: const data = DataFrame!(CSV.File("path/to/some/file.csv")) function foo(data) for row in eachrow(data) # do some stuff end return # some in…

---

## [New book: Hands-on Design Patterns and Best Practices with Julia](https://discourse.julialang.org/t/new-book-hands-on-design-patterns-and-best-practices-with-julia/33712)

<div class="topic-metadata">

**Author:** [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Replies:** 29\
**Last updated:** [April 1, 2020, 4:22am UTC](https://discourse.julialang.org/t/new-book-hands-on-design-patterns-and-best-practices-with-julia/33712 "2020-04-01T04:22:33Z")

</div>

Hi, everyone! :wave: I’m pleased announce that my first book Hands-on Design Patterns and Best Practices with Julia has been published. I want to thank everyone who helped me on Discourse / Slack before (too many to me…

---

## [Design patterns for generic code with reusable caches for intermediate values](https://discourse.julialang.org/t/design-patterns-for-generic-code-with-reusable-caches-for-intermediate-values/36627)

<div class="topic-metadata">

**Author:** [@jlperla](https://discourse.julialang.org/u/jlperla)\
**Replies:** 3\
**Last updated:** [March 29, 2020, 7:47am UTC](https://discourse.julialang.org/t/design-patterns-for-generic-code-with-reusable-caches-for-intermediate-values/36627 "2020-03-29T07:47:35Z")

</div>

We have an expensive algorithm with is run many, many times for different parameter values and want to design the interface for caching the memory preallocation. A few principles: We should have enough information to …

---

## [Design Pattern the Julian way?](https://discourse.julialang.org/t/design-pattern-the-julian-way/29002)

<div class="topic-metadata">

**Author:** [@atthom](https://discourse.julialang.org/u/atthom)\
**Replies:** 16\
**Last updated:** [September 24, 2019, 11:02am UTC](https://discourse.julialang.org/t/design-pattern-the-julian-way/29002 "2019-09-24T11:02:27Z")

</div>

Design Patterns are the firsts building blocks when developing an application. There are a few of them, most developers recognize or use them when building a medium/large application. They are listed here: Software des…

---

## [What is a good design pattern for developing parallel types, one designed for safety and the other for performance?](https://discourse.julialang.org/t/what-is-a-good-design-pattern-for-developing-parallel-types-one-designed-for-safety-and-the-other-for-performance/27464)

<div class="topic-metadata">

**Author:** [@philip](https://discourse.julialang.org/u/philip)\
**Replies:** 14\
**Last updated:** [August 13, 2019, 1:46pm UTC](https://discourse.julialang.org/t/what-is-a-good-design-pattern-for-developing-parallel-types-one-designed-for-safety-and-the-other-for-performance/27464 "2019-08-13T13:46:07Z")

</div>

Let’s say I plan to do something a billion times, like simulate draws from a probability distribution. I want to ensure that my code is correct by writing a bunch of checks into the type constructor. E.g. julia\> struct…

---

## [Examples of Well-Written Julia packages to emulate--in terms of generic functions, design, etc](https://discourse.julialang.org/t/examples-of-well-written-julia-packages-to-emulate-in-terms-of-generic-functions-design-etc/26903)

<div class="topic-metadata">

**Author:** [@00krishna](https://discourse.julialang.org/u/00krishna)\
**Replies:** 16\
**Last updated:** [July 29, 2019, 6:07am UTC](https://discourse.julialang.org/t/examples-of-well-written-julia-packages-to-emulate-in-terms-of-generic-functions-design-etc/26903 "2019-07-29T06:07:32Z")

</div>

I am trying to understand how to write programs in a more Julia, less object oriented way. I was reading the lectures by the QuantEcon folks on how to write generic functions and more generic code etc. The lectures are q…

---

## [Is there a Julian way to combine types generically or a design pattern that achieves the goal?](https://discourse.julialang.org/t/is-there-a-julian-way-to-combine-types-generically-or-a-design-pattern-that-achieves-the-goal/983)

<div class="topic-metadata">

**Author:** [@philip](https://discourse.julialang.org/u/philip)\
**Replies:** 16\
**Last updated:** [May 8, 2017, 2:50pm UTC](https://discourse.julialang.org/t/is-there-a-julian-way-to-combine-types-generically-or-a-design-pattern-that-achieves-the-goal/983 "2017-05-08T14:50:54Z")

</div>

The general idea is that I often have types that are composed of smaller “pieces” of the types. Not subtypes in the sense of a type tree, rather partial-types in the sense of records with only a fraction of the next type…

---

## [Metaprogramming design patterns](https://discourse.julialang.org/t/metaprogramming-design-patterns/2658)

<div class="topic-metadata">

**Author:** [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Replies:** 7\
**Last updated:** [March 14, 2017, 10:29pm UTC](https://discourse.julialang.org/t/metaprogramming-design-patterns/2658 "2017-03-14T22:29:39Z")

</div>

Feeling in a refactoring mood I decided to bravely tackle some performance bottlenecks that were present in Genie’s codebase. I decided to go for the low hanging fruits and squash The Evil eval. A quick search revealed …
