# 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:** 9\
**Page:** 3

<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 14, 2018, 1:34am UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/42 "2018-11-14T01:34:22Z")

</div>

> [@stevengj](#):
>
> What is the downside of showing more information about the character when you display a single character in the REPL or similar contexts?

You are mentioning the following question, right? If so, I did not propose to lose any information about the UTF-8 details. Instead, what I proposed is just to drop some superfluous words e.g. “Category” from:  
‘a’: ASCII/Unicode U+0061 (category Ll: Letter, lowercase)

I think I can raise a question in the same way you asked. What is the upside of printing the superfluous word over and over, whenever users type characters directly in REPL? No need for any immediate change. Let’s see how many users support the idea of more concise representation for a character.

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [November 14, 2018, 5:36am UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/43 "2018-11-14T05:36:12Z")

</div>

Whether to leave out the word `category` or not seems like a trivial issue.

It really doesn’t matter whether we have that word or not, and I’m not sure it’s really worth debating either.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [November 14, 2018, 5:44am UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/44 "2018-11-14T05:44:14Z")

</div>

> [@peters](#):
>
> What is the upside of printing the superfluous word over and over, whenever users type characters directly in REPL?

Looking at this from the perspective of someone not already familiar with Unicode, if you don’t know how ASCII works and that Unicode has letter categories, how would you ever find out what those mysterious `U+xxxx` and `Ll` mean? It’s not at all clear to me that `U+xxxx` in your proposed representation is not a part of ASCII: `‘a’: ASCII U+0061 (Ll: Letter, lowercase)`. Sure it’s more information for someone familiar with Unicode, but I think the increased clarity is better when someone’s not familiar with the topic.

---

<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:** [November 14, 2018, 6:33am UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/45 "2018-11-14T06:33:21Z")

</div>

> [@peters](#):
>
> What is the upside of printing the superfluous word over and over, whenever users type characters directly in REPL?

When characters are used in isolation, it is reasonable to assume that detailed information is desired. Note that when they are used in collections or to form strings, only the character is printed. Eg

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

julia> collect("foo")
3-element Array{Char,1}:
 'f'
 'o'
 'o'

julia> "foo"
"foo"

```

---

<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 14, 2018, 6:47am UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/46 "2018-11-14T06:47:53Z")

</div>

> [@peters](#):
>
> You are mentioning the following question, right? If so, I did not propose to lose any information about the UTF-8 details. Instead, what I proposed is just to drop some superfluous words e.g. “Category” from:  
> ‘a’: ASCII/Unicode U+0061 (category Ll: Letter, lowercase)

I did not see any problem with complex representation before! 😉

> [@peters](#):
>
> I think I can raise a question in the same way you asked. What is the upside of printing the superfluous word over and over, whenever users type characters directly in REPL?

It is not just when user **type** character to REPL:

```julia
julia> a_or_b() = rand(Bool) ? 'a' : 'b';

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

```

> [@Sukera](#):
>
> Looking at this from the perspective of someone not already familiar with Unicode, if you don’t know how ASCII works and that Unicode has letter categories, how would you ever find out what those mysterious `U+xxxx` and `Ll` mean?

If you are not familiar with Unicode why would you need info about category?

And if you need to know additional information about character why not use some special function(s)?

One could for example use @tkf’s nice [hack](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/25):

```julia
julia> import PyCall

julia> unicodename(a::Char) = PyCall.pyimport("unicodedata")[:name](string(a));

```

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [November 14, 2018, 7:31am UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/47 "2018-11-14T07:31:24Z")

</div>

> [@peters](#):
>
> Ok. It sounds you guys are ok with printing the 50 characters for one character 🙂

Yeah, there’s always quite a bit of meta information in these outputs, so it’s not a big deal to me.

But it does seem like something that could be configurable. I’ve seen some requests to mimic Matlab’s `format` command when printing numbers:

```julia
>> format short
>> a
a =
    0.0853

>> format long
>> a
a =
   0.085307484729089

```

which seems neat. Having an option like that, also for `Char`s, could be quite handy.

---

<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 15, 2018, 4:27am UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/48 "2018-11-15T04:27:58Z")

</div>

Yes nothing serious, but I was surprised at all the inputs I received on my small suggestion.

---

<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 15, 2018, 4:43am UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/49 "2018-11-15T04:43:28Z")

</div>

@Liso. Thanks for being with me. Yes, I like the Python approach.  
Julia doesn’t have to bother its users (particularly beginners like me) with all the details. In most cases, users may not need all the details and when they really need the details, they can just call a function to spit out all the details. Explicit is better than implicit but also concise is better than verbose.

---

<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 15, 2018, 7:30am UTC](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/50 "2018-11-15T07:30:33Z")

</div>

_Explicit is better than implicit_ - I read that it is better to ask for some behavior (for example additional info about char 😉 ) explicitly and not get it implicitly.

But as I wrote - complex representation is not something that bother me much… (and I also wrote [simple (?) possibility](https://discourse.julialang.org/t/why-so-complex-representation-of-a-char/17052/9) how to avoid complex info if somebody need it)

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