# Global variables const by default?

**URL:** <https://discourse.julialang.org/t/global-variables-const-by-default/33138>\
**Category:** Internals & Design\
**Tags:** proposal\
**Created:** [January 9, 2020, 8:15am UTC](https://discourse.julialang.org/t/global-variables-const-by-default/33138 "2020-01-09T08:15:28Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![RaulDurand](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rauldurand/32/2044_2.png) [@RaulDurand](https://discourse.julialang.org/u/RaulDurand)\
**Post date:** [May 27, 2021, 11:53am UTC](https://discourse.julialang.org/t/global-variables-const-by-default/33138/21 "2021-05-27T11:53:04Z")

</div>

If we could mark the type of a variable in global scope we wouldn’t need to think about making globals constants.  
E.g.  
myvar::Int64 = 1  
in global scope.  
Actually, I miss this feature even inside functions.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 27, 2021, 11:56am UTC](https://discourse.julialang.org/t/global-variables-const-by-default/33138/22 "2021-05-27T11:56:13Z")

</div>

> [@RaulDurand](#):
>
> Actually, I miss this feature even inside functions.

😕

```julia
function f()
    x::Int64 = 0
    x = "foo" # error
end

```

---

<div class="post-metadata">

**Author:** ![RaulDurand](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rauldurand/32/2044_2.png) [@RaulDurand](https://discourse.julialang.org/u/RaulDurand)\
**Post date:** [May 27, 2021, 2:12pm UTC](https://discourse.julialang.org/t/global-variables-const-by-default/33138/23 "2021-05-27T14:12:46Z")

</div>

Ohh, great!

Do you know why we cannot do the same in global scope?

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [May 27, 2021, 2:22pm UTC](https://discourse.julialang.org/t/global-variables-const-by-default/33138/24 "2021-05-27T14:22:10Z")

</div>

That `Traceur.jl` could over the poster code 🙂 .

Actually having a linter available as an interactive tool for discourse posts would be cool. (actually not a bad idea having a linter server which can be indicated, where one could copy/paste MWE and get hints of possible problems).

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 28, 2021, 2:23pm UTC](https://discourse.julialang.org/t/global-variables-const-by-default/33138/25 "2021-05-28T14:23:41Z")

</div>

No intrinsic reason, it’s just not implemented yet. Cf

[https://github.com/JuliaLang/julia/issues/964](https://github.com/JuliaLang/julia/issues/964)

[Previous page](https://discourse.julialang.org/t/global-variables-const-by-default/33138.md?page=1)
