# Why so complex representation of a char?

**URL:** <https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052>\
**Category:** General Usage\
**Created:** [November 1, 2018, 1:08pm UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052 "2018-11-01T13:08:03Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![peters](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peters/32/5924_2.png) [@peters](https://discourse.julialang.org/u/peters)\
**Post date:** [November 1, 2018, 1:08pm UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/1 "2018-11-01T13:08:03Z")

</div>

I think the representation of a char in a terminal is overly complex in Julia. For instance,

```julia
julia> 'a'
'a': ASCII/Unicode U+0061 (category Ll: Letter, lowercase)

```

Is there any reason underlying the complex representation of characters?

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [November 1, 2018, 2:00pm UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/2 "2018-11-01T14:00:23Z")

</div>

I guess that’s mainly because Chars representing unicode are highly ambiguous in their graphical representation, so people doing more involved work with Chars will appreciate this.  
It should also help the non expert user to find tricky unicode bugs.  
The latter is a pretty good reason to make it the default, since quite a lot of people may not even know, that they could get char1 != char2, even if they look (almost) exactly the same.  
Maybe one could print the visible chars in the range 0:255 with less information as a compromise?

---

<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:** [November 1, 2018, 3:05pm UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/3 "2018-11-01T15:05:47Z")

</div>

> [@sdanisch](#):
>
> Maybe one could print the visible chars in the range 0:255 with less information as a compromise?

Why? Realize that the verbose format is only used for [“multiline” text/plain display](https://docs.julialang.org/en/v1/manual/types/#man-custom-pretty-printing-1). In other contexts it uses terse output:

```julia
julia> ['a', 'b']
2-element Array{Char,1}:
 'a'
 'b'

julia> println('a')
a

julia> repr('a')
"'a'"

julia> show('a')
'a'

```

What is the downside of showing more information about the character when you display a single character in the REPL or similar contexts?

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [November 1, 2018, 3:52pm UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/4 "2018-11-01T15:52:42Z")

</div>

**Question:** Are these the same letters or different ones: `A`, `Α`, `А`?

**Answer:** They are all different.

In the Julia REPL it’s clear:

```julia
julia> 'A'
'A': ASCII/Unicode U+0041 (category Lu: Letter, uppercase)

julia> 'Α'
'Α': Unicode U+0391 (category Lu: Letter, uppercase)

julia> 'А'
'А': Unicode U+0410 (category Lu: Letter, uppercase)

```

If you don’t care about the extra information, you can just ignore it.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [November 1, 2018, 3:54pm UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/5 "2018-11-01T15:54:17Z")

</div>

> [@sdanisch](#):
>
> Maybe one could print the visible chars in the range 0:255 with less information as a compromise?

To what end? What harm is the additional information doing?

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [November 1, 2018, 4:05pm UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/6 "2018-11-01T16:05:38Z")

</div>

@stevengj @StefanKarpinski, why do you ask me, I don’t really mind 😃

Just wanted to be productive and search for a simple solution, that may make @peters happy, as well 🙂

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [November 1, 2018, 4:13pm UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/7 "2018-11-01T16:13:22Z")

</div>

If everyone in the world got to change one thing about the language it would be a total mess.

---

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [November 1, 2018, 5:12pm UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/8 "2018-11-01T17:12:40Z")

</div>

If you are really annoyed for some reason, you can always do:

```julia
julia> import Base.show

julia> show(io::IO, mime::MIME"text/plain", a::Char) = print(io, a)
show (generic function with 296 methods)

julia> 'a'
a

```

---

<div class="post-metadata">

**Author:** ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)\
**Post date:** [November 1, 2018, 5:12pm UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/9 "2018-11-01T17:12:52Z")

</div>

If it is problem for you then you could change this behavior in your `.julia/config/startup.jl` initialization file.

This is what you could use:

```julia
julia> import Base.show

julia> Base.show(io::IO, ::MIME{Symbol("text/plain")}, c::AbstractChar) = show(io, c)

julia> 'a'
'a'

```

---

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [November 1, 2018, 5:13pm UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/10 "2018-11-01T17:13:04Z")

</div>

LOL 😃

---

<div class="post-metadata">

**Author:** ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)\
**Post date:** [November 1, 2018, 5:14pm UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/11 "2018-11-01T17:14:09Z")

</div>

You won! 😃

---

<div class="post-metadata">

**Author:** ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Post date:** [November 1, 2018, 5:34pm UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/12 "2018-11-01T17:34:09Z")

</div>

Isn’t there some `showcompact` or something? I think it used to be `showcompact` but I think it changed and I don’t remember how to do it now.

By the way, I really like the default printing behavior, explicit is good 👍.

---

<div class="post-metadata">

**Author:** ![Roger-luo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roger-luo/32/3399_2.png) [@Roger-luo](https://discourse.julialang.org/u/Roger-luo)\
**Post date:** [November 1, 2018, 5:38pm UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/13 "2018-11-01T17:38:12Z")

</div>

Why 0391 and 0410 is different? just curious.

---

<div class="post-metadata">

**Author:** ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)\
**Post date:** [November 1, 2018, 6:23pm UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/14 "2018-11-01T18:23:17Z")

</div>

It seems it would be useful to enhance info! 😃  
0391 is [GREEK CAPITAL LETTER ALPHA](https://www.fileformat.info/info/unicode/char/0391/index.htm)  
0410 is [CYRILLIC CAPITAL LETTER A](https://www.fileformat.info/info/unicode/char/0410/index.htm)

---

<div class="post-metadata">

**Author:** ![Roger-luo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roger-luo/32/3399_2.png) [@Roger-luo](https://discourse.julialang.org/u/Roger-luo)\
**Post date:** [November 1, 2018, 6:29pm UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/15 "2018-11-01T18:29:18Z")

</div>

lol…that’s funny

---

<div class="post-metadata">

**Author:** ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)\
**Post date:** [November 1, 2018, 6:55pm UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/16 "2018-11-01T18:55:23Z")

</div>

This is funny too: latin [ɛ](https://www.fileformat.info/info/unicode/char/025b/index.htm) and greek [ε](https://www.fileformat.info/info/unicode/char/03b5/index.htm) are different different but same! ( ping @Tero_Frondelius 🙂 )

```julia
julia> Meta.parse("\u025B") === Meta.parse("\u03B5")
true

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [November 1, 2018, 6:56pm UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/17 "2018-11-01T18:56:37Z")

</div>

[https://github.com/JuliaLang/julia/pull/19464](https://github.com/JuliaLang/julia/pull/19464)

---

<div class="post-metadata">

**Author:** ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)\
**Post date:** [November 1, 2018, 7:10pm UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/18 "2018-11-01T19:10:37Z")

</div>

Or _Julia identifiers are NFC-normalized_ (source: [Variables · The Julia Language](https://docs.julialang.org/en/v1/manual/variables/#Allowed-Variable-Names-1))

---

<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:** [November 1, 2018, 9:07pm UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/19 "2018-11-01T21:07:12Z")

</div>

> [@Liso](#):
>
> It seems it would be useful to enhance info!

Yes, it would have been nice to include the official name of each Unicode character, but that would involve shipping about 1M of data from the Unicode character database.

---

<div class="post-metadata">

**Author:** ![peters](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peters/32/5924_2.png) [@peters](https://discourse.julialang.org/u/peters)\
**Post date:** [November 2, 2018, 10:09am UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/20 "2018-11-02T10:09:21Z")

</div>

Thanks @sdanisch for trying me happy 🙂

[Next page](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052.md?page=2)
