# AbstractMyType or just MyType for abstract types?

**URL:** <https://discourse.julialang.org/t/abstractmytype-or-just-mytype-for-abstract-types/5247>\
**Category:** General Usage\
**Created:** [August 6, 2017, 11:33am UTC](https://discourse.julialang.org/t/abstractmytype-or-just-mytype-for-abstract-types/5247 "2017-08-06T11:33:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![smldis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/smldis/32/1735_2.png) [@smldis](https://discourse.julialang.org/u/smldis)\
**Post date:** [August 6, 2017, 11:33am UTC](https://discourse.julialang.org/t/abstractmytype-or-just-mytype-for-abstract-types/5247/1 "2017-08-06T11:33:48Z")

</div>

Hello,  
For the naming of an abstract type (MyType), should I use AbstractMyType or just MyType for abstract types?

Base is using the former, some packages are using the latter. I remember someone telling that once it was not possible to have MyType as abstract type name and MyType() as constructor or callable type.

A side note, if abstract types would be highlighted somehow in the editors some of the disadvantages would disappear.

Is there someone with a clear perspective on this subject?

---

<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:** [August 6, 2017, 11:59am UTC](https://discourse.julialang.org/t/abstractmytype-or-just-mytype-for-abstract-types/5247/2 "2017-08-06T11:59:18Z")

</div>

I don’t think there is a rule, and it will depend on your case. I think if you work mostly with the concrete types then having a `AbstractMyType` is good and vice-versa.

> [@smldis](#):
>
> Base is using the former,

Not always, e.g. `Associative` is an abstract type.

Also of note is the rename `FloatingPoint` → `AbstractFloat`, which may give you some hints with your decisions:

> <https://github.com/JuliaLang/julia/issues/8142>
>
> We've seen empirical evidence that new users sometimes use abstract numeric type…s like \`FloatingPoint\` or \`Complex\` in lieu of concrete types like \`Float64\` and \`Complex128\`. The result is that users end up with slow code or even wrong code due to operations over variables with types like \`Array{Complex,2}\` or \`Vector{FloatingPoint}\`. (For example: \[this comment\](https://github.com/JuliaLang/julia/issues/4796#issuecomment-28459235) in #4796)
> 
> The unintentional use of abstract numeric types seems especially prevalent with \`FloatingPoint\` or \`Complex\` which share common prefixes with concrete types. Other abstract numeric types like \`Signed\` or \`Real\` do not seem prone to accidental misuse to the same extent.
> 
> Suggestions for new names? I'd propose something like \`FloatingPointAbstract\` or \`AbstractFloatingPoint\` to emphasize the abstract nature of the type. And perhaps something like \`ComplexCartesian\` instead of \`Complex\` to emphasize the canonical (real, imaginary) representation and to distinguish it from polar forms or other more esoteric representations.

> [@smldis](#):
>
> I remember someone telling that once it was not possible to have MyType as abstract type name and MyType() as constructor or callable type.

> <https://github.com/JuliaLang/julia/issues/14919>
>
> I'm updating ApproxFun and this caught me by surprise:
> 
> \`\`\` julia
> abstract Foo
> j…ulia\> (f::Foo)(x)=x
> ERROR: cannot add methods to an abstract type
> in eval(::Module, ::Any) at ./boot.jl:267
> \`\`\`
> 
> Is this intentional? Is there a way to get around this other than define for each subtype:
> 
> \`\`\` julia
> julia\> immutable CFoo \<: Foo end
> julia\> (f::CFoo)(x)=x
> \`\`\`

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [August 8, 2017, 5:27am UTC](https://discourse.julialang.org/t/abstractmytype-or-just-mytype-for-abstract-types/5247/3 "2017-08-08T05:27:48Z")

</div>

I am also questioning myself about this convention sometimes. Currently I am adopting the `Abstract` prefix to make this abstraction very explicit throughout the codebase and to help with auto-completion on my text editor.

However, as @mauro3 mentioned, if you are manipulating these abstract types all the time as your primary package types, then removing the prefix may save you some typing.

It is a matter of taste 🙂
