Re: [go-nuts] When would you use single quotes?

2019-02-07 Thread Volker Dobler

>
> The UTF8 encoding of that codepoint is three bytes.  So the rune will 
> still occupy 4 bytes, even if the last byte holds no data? 
>

A rune has nothing to do with UTF-8.
A rune stores the codepoint which is totally independent
of any encoding (like UTF-8, UTF-16, UTF-23, EBCDIC, whatnot).

A rune is an integer, the number of the codepoint.
An integer is stored in a certain number of bytes.
Asking  "So the rune will still occupy 4 bytes, even if the last
byte holds no data?" is like asking "So the number 12 will
still occupy 8 bits, even if the last 5 bits hold no data?".
Yes. An integer is stored in 8 bytes (64bit architecture)
and this is true even for "small" integers which would "fit"
into one byte.

A rune is an integer. It has nothing to do with UTF.

V.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] When would you use single quotes?

2019-02-07 Thread Jamie Caldwell
Thank you both for your answers.  It is much appreciated.

The UTF8 encoding of that codepoint is three bytes.  So the rune will still
occupy 4 bytes, even if the last byte holds no data? I'm sorry for the
school boy question!

Thank you.

On Thu, 7 Feb 2019, 10:52 Tamás Gulácsi  A rune is an int32, so it takes 4 bytes by definition.
> A string in a struct with position, length and backing array of bytes. The
> backing array here consumes 3 bytes, but tge position and length occupies
> space too, so the string of that rune occupies more than 3 bytes after all.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/-bvJLkhX_dY/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

On Thu, 7 Feb 2019, 10:52 Tamás Gulácsi  A rune is an int32, so it takes 4 bytes by definition.
> A string in a struct with position, length and backing array of bytes. The
> backing array here consumes 3 bytes, but tge position and length occupies
> space too, so the string of that rune occupies more than 3 bytes after all.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "golang-nuts" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/golang-nuts/-bvJLkhX_dY/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] When would you use single quotes?

2019-02-07 Thread Tamás Gulácsi
A rune is an int32, so it takes 4 bytes by definition.
A string in a struct with position, length and backing array of bytes. The 
backing array here consumes 3 bytes, but tge position and length occupies space 
too, so the string of that rune occupies more than 3 bytes after all.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] When would you use single quotes?

2019-02-07 Thread Jan Mercl
On Thu, Feb 7, 2019 at 11:25 AM Jamie Caldwell 
wrote:

> But why would you use one over the other? Why does Go support being able
to assign a codepoint using single quotes?

`type rune` vs type `string` not the same, but is bit like `type byte` vs
`type []byte`. The serve very different purposes. One cannot do the same
things with `byte` that can be done with `[]byte`.

> Also, why do they take more than three bytes each?

`rune` is an alias of `int32`, hence 4 bytes.

`string` is a two word struct, hence 2*size of pointer. 8 or 16 bytes.

-- 

-j

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] When would you use single quotes?

2019-02-07 Thread Jamie Caldwell
Thank you for getting back to me, but I don't think you have answered my
question.

I understand they are a rune and string respectively.  But *why* would you
use one over the other?  Why does Go support being able to assign a
codepoint using single quotes?

Also, why do they take more than three bytes each?

Thank you.

On Wed, 6 Feb 2019 at 23:30, Wagner Riffel  wrote:

> '⌘' is of type rune (aka int32), "⌘" and `⌘` are of type string, both
> takes more than 3 bytes.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] When would you use single quotes?

2019-02-06 Thread Wagner Riffel
'⌘' is of type rune (aka int32), "⌘" and `⌘` are of type string, both
takes more than 3 bytes.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.