# Make Base Types const?

**URL:** <https://discourse.julialang.org/t/make-base-types-const/4537>\
**Category:** Internals & Design\
**Created:** [June 29, 2017, 9:17am UTC](https://discourse.julialang.org/t/make-base-types-const/4537 "2017-06-29T09:17:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cortner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cortner/32/204_2.png) [@cortner](https://discourse.julialang.org/u/cortner)\
**Post date:** [June 29, 2017, 9:17am UTC](https://discourse.julialang.org/t/make-base-types-const/4537/1 "2017-06-29T09:17:45Z")

</div>

I’ve spent quite a bit of time hunting down a bug that was caused by redefining a Base type. E.g.:

```julia
Int = find(something) # I am finding interior nodes in a grid

# a function defined somewhere else in the notebook
function do_something()
   A = Int[]
   push!(A, 5)
end

do_somthing()
# ERROR: MethodError: no method matching push!(::Int64, ::Int64)

```

It took me a while to find this. Obviously I should have chosen better naming. But in a notebook neither syntax highlighting warned me, nor an actual Julia warning.

What surprised me is

- `const T = Int64; T = 5` throws an error
- `Int = 3` or `Float64 = sqrt` is ok.

```julia

Should these "standard types" for lack of a better name be `const`?
```

---

<div class="post-metadata">

**Author:** ![martinholters](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/martinholters/32/3690_2.png) [@martinholters](https://discourse.julialang.org/u/martinholters)\
**Post date:** [June 29, 2017, 11:29am UTC](https://discourse.julialang.org/t/make-base-types-const/4537/2 "2017-06-29T11:29:41Z")

</div>

They are const, just in another module:

```julia-repl
julia> eval(Core, :(Int = 5))
ERROR: invalid redefinition of constant Int
Stacktrace:
 [1] eval(::Module, ::Any) at ./boot.jl:235

```

If you use `Int` before you assign to it, at least you get a warning:

```julia-repl
julia> Int
Int64

julia> Int = 5
WARNING: imported binding for Int overwritten in module Main
5

```

If you could not assign to a type (or something else) exported from `Base`, every new export from `Base` would potentially be breaking, so that’s not really an option.

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [June 29, 2017, 11:34am UTC](https://discourse.julialang.org/t/make-base-types-const/4537/3 "2017-06-29T11:34:27Z")

</div>

Lint.jl picks this up:

```julia
julia> using Lint                                                                                                                     
                                                                                                                                      
julia> lintstr("Int = 4")                                                                                                             
1-element Array{Lint.LintMessage,1}:                                                                                                  
 none:1 I392 Int: local variable might cause confusion with a synonymous export from Base                                             

```

---

<div class="post-metadata">

**Author:** ![cortner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cortner/32/204_2.png) [@cortner](https://discourse.julialang.org/u/cortner)\
**Post date:** [June 29, 2017, 11:46am UTC](https://discourse.julialang.org/t/make-base-types-const/4537/4 "2017-06-29T11:46:06Z")

</div>

```julia
function fun()
    a = Int[]
    push!(a, 5)
end 
fun()
Int = 1

```

First time executes ok, second time it throws an error. So technically I did use `Int` before redefining it. Or am I misunderstanding?

Anyhow, if this is not an option, then maybe I’ll just open an Issue in `IJulia` to improve syntax highlighting.

---

<div class="post-metadata">

**Author:** ![cortner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cortner/32/204_2.png) [@cortner](https://discourse.julialang.org/u/cortner)\
**Post date:** [June 29, 2017, 11:46am UTC](https://discourse.julialang.org/t/make-base-types-const/4537/5 "2017-06-29T11:46:28Z")

</div>

Is there a nice way to use `Lint` with notebooks?

---

<div class="post-metadata">

**Author:** ![tkelman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkelman/32/692_2.png) [@tkelman](https://discourse.julialang.org/u/tkelman)\
**Post date:** [June 29, 2017, 12:31pm UTC](https://discourse.julialang.org/t/make-base-types-const/4537/6 "2017-06-29T12:31:54Z")

</div>

Might be some way of integrating Lint with NBInclude.
