# Methods for maintaining backwards compatibility

**URL:** <https://discourse.julialang.org/t/methods-for-maintaining-backwards-compatibility/105227>\
**Category:** General Usage\
**Tags:** compatibility\
**Created:** [October 20, 2023, 11:14am UTC](https://discourse.julialang.org/t/methods-for-maintaining-backwards-compatibility/105227 "2023-10-20T11:14:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![user664303](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/user664303/32/37843_2.png) [@user664303](https://discourse.julialang.org/u/user664303)\
**Post date:** [October 20, 2023, 11:14am UTC](https://discourse.julialang.org/t/methods-for-maintaining-backwards-compatibility/105227/1 "2023-10-20T11:14:10Z")

</div>

I’ve just improved some of the code in a package of mine, and found (from my unit testing) that it throws an error in v1.6 of Julia. I’d like to maintain compatibility with Julia 1.6 since this is the most recent LTS release. I see 3 ways to achieve this:

1. Not make that particular change until there’s a new Julia LTS version - not ideal.
2. Create a new minor release which drops support for Julia 1.6, but keep patching the current minor release with bug fixes too. Also not ideal, since the code may diverge, increasing the work to port patches across both (and potentially more) releases.
3. Having a branch in the code based on the Julia version. According to [this thread](https://discourse.julialang.org/t/how-to-execute-code-depending-on-julia-version/75029), this can be done as follows:

> [@How to execute code depending on julia version](https://discourse.julialang.org/t/how-to-execute-code-depending-on-julia-version/75029/3):
>
> ```julia
> @static if VERSION ≥ v"1.7"
> # do something
> end
> 
> ```

Is this still the recommended way of achieving this?

Which of the 3 approaches do you use/recommend? Does option 3 become more complicated when the required features are in a package, not core Julia itself?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [October 20, 2023, 2:06pm UTC](https://discourse.julialang.org/t/methods-for-maintaining-backwards-compatibility/105227/2 "2023-10-20T14:06:53Z")

</div>

> [@user664303](#):
>
> Is [`@static if VERSION ≥ v"1.7"`] still the recommended way of achieving this?

Yes. In some cases you can use the [Compat.jl](https://github.com/JuliaLang/Compat.jl) package instead, which has these branches already written for you.

(Note that you usually don’t need the `@static` unless the code inside the branch has macros or similar that don’t exist in the newer version, which would prevent the code from being lowered in older versions.)
