# PSA: New keywords for defining types

**URL:** <https://discourse.julialang.org/t/psa-new-keywords-for-defining-types/2029>\
**Category:** Internals & Design\
**Created:** [February 10, 2017, 6:28pm UTC](https://discourse.julialang.org/t/psa-new-keywords-for-defining-types/2029 "2017-02-10T18:28:12Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![dancasimiro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dancasimiro/32/92_2.png) [@dancasimiro](https://discourse.julialang.org/u/dancasimiro)\
**Post date:** [March 4, 2017, 6:58pm UTC](https://discourse.julialang.org/t/psa-new-keywords-for-defining-types/2029/21 "2017-03-04T18:58:12Z")

</div>

How do I adapt my code to this change so that it works with Julia v0.5 and Julia v0.6? Does Compat have support for this change?

I tried the following in a [branch](https://github.com/dancasimiro/WAV.jl/tree/v0.6-changes), but it [fails](https://travis-ci.org/dancasimiro/WAV.jl/builds/200984493) to compile.

```julia
@compat struct WAVFormat
    compression_code::UInt16
    nchannels::UInt16
    sample_rate::UInt32
    bytes_per_second::UInt32 # average bytes per second
    block_align::UInt16
    nbits::UInt16
    ext::WAVFormatExtension
end

```

Thanks

---

<div class="post-metadata">

**Author:** ![bicycle1885](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bicycle1885/32/107_2.png) [@bicycle1885](https://discourse.julialang.org/u/bicycle1885)\
**Post date:** [March 4, 2017, 7:08pm UTC](https://discourse.julialang.org/t/psa-new-keywords-for-defining-types/2029/22 "2017-03-04T19:08:21Z")

</div>

`type` and `immutable` still work in Julia 0.6 without deprecated warnings. So I think the best way to write compatible code with Julia 0.5 and 0.6 is to keep using `type` and `immutable` for a while and change them to `mutable struct` and `struct` when you drop Julia 0.5 support in the future.

---

<div class="post-metadata">

**Author:** ![andyferris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andyferris/32/235_2.png) [@andyferris](https://discourse.julialang.org/u/andyferris)\
**Post date:** [March 6, 2017, 4:57am UTC](https://discourse.julialang.org/t/psa-new-keywords-for-defining-types/2029/23 "2017-03-06T04:57:45Z")

</div>

I’m loving all the changes except I’m still a bit hung-up on `const` or not-`const` in the new typealiases:

```julia
Vector{T} = Array{T,1}
const BitVector = BitArray{1}

```

For whatever reason, the disagreement here grates me…

---

<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:** [March 6, 2017, 5:00am UTC](https://discourse.julialang.org/t/psa-new-keywords-for-defining-types/2029/24 "2017-03-06T05:00:51Z")

</div>

You should be able to add the `const` in the former case just for visual consistency, even though it’s implied.

---

<div class="post-metadata">

**Author:** ![andyferris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andyferris/32/235_2.png) [@andyferris](https://discourse.julialang.org/u/andyferris)\
**Post date:** [March 6, 2017, 5:40am UTC](https://discourse.julialang.org/t/psa-new-keywords-for-defining-types/2029/25 "2017-03-06T05:40:39Z")

</div>

Thanks Tony. Yes, I do understand that 🙂

I’m just a little unsure the long-term plan is here? This type of inconsistency seems fine while we wait for something else to deprecate or change behavior. Do we plan to allow the latter statement without the `const`? (This would seem to change the nature of toplevel bindings). And if not, what is the advantage of allowing the former? Or are we happy with this the way it is? Maybe it’s just me! 🙂

---

<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:** [March 6, 2017, 5:43am UTC](https://discourse.julialang.org/t/psa-new-keywords-for-defining-types/2029/26 "2017-03-06T05:43:13Z")

</div>

It’s not just you, it bugs me a little too. I think some people might like to see the need for `const` go away completely, but I’m not sure on what horizon that might be feasible. Having `const` be the default could be a pretty major change.

---

<div class="post-metadata">

**Author:** ![andyferris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andyferris/32/235_2.png) [@andyferris](https://discourse.julialang.org/u/andyferris)\
**Post date:** [March 6, 2017, 5:46am UTC](https://discourse.julialang.org/t/psa-new-keywords-for-defining-types/2029/27 "2017-03-06T05:46:21Z")

</div>

Right, it seems just a little weird in the current situation where we have one particular form of one particular type of statement have implied `const` and everything else is non-`const` by default.

(I would have expected `const` in both cases, with the advantage of getting more of the community to understand the simplicity of `UnionAll`. If we want to make toplevel statements `const` by default this seems rather orthogonal).

---

<div class="post-metadata">

**Author:** ![andyferris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andyferris/32/235_2.png) [@andyferris](https://discourse.julialang.org/u/andyferris)\
**Post date:** [March 6, 2017, 5:48am UTC](https://discourse.julialang.org/t/psa-new-keywords-for-defining-types/2029/28 "2017-03-06T05:48:49Z")

</div>

(though I’m actually supportive of making `const` by default, at least inside most modules. What would be epic/awesome is compiler dependency edges for `const`s that might change, e.g. at the REPL)

---

<div class="post-metadata">

**Author:** ![fengyang.wang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fengyang.wang/32/104_2.png) [@fengyang.wang](https://discourse.julialang.org/u/fengyang.wang)\
**Post date:** [March 16, 2017, 5:39am UTC](https://discourse.julialang.org/t/psa-new-keywords-for-defining-types/2029/29 "2017-03-16T05:39:07Z")

</div>

I think it is reasonable to special case the REPL here. I would guess that for most REPL work, having many methods be recompiled when consts change could be annoying.

[Previous page](https://discourse.julialang.org/t/psa-new-keywords-for-defining-types/2029.md?page=1)
