ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 09 Jan 2020 04:56:17 -0600Should I avoid using unicode in names of variables?https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/ Hello, Sage community!
Since Sage now supports Python 3, the possibility of using tildes and other unicode letters in names of variables is real. For example, I could define a constant `Gauß` instead of `Gauss` (with a "ß" instead of "ss"); or I could define a function called `Müller` (with two dots over the "u"). In Spanish and other languages, this is a more pressing matter. If I defined a function `design(howMany)`, in Spanish it would be `diseño(cuántos)`.
However, it seems quite strange to have tildes, betas, etc. in variable names. Is it a good programming behavior to avoid this kind of names?, or, should I use them sparely?
Thanks in advance!Sat, 04 Jan 2020 19:23:51 -0600https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/Answer by Iguananaut for <p>Hello, Sage community!</p>
<p>Since Sage now supports Python 3, the possibility of using tildes and other unicode letters in names of variables is real. For example, I could define a constant <code>Gauß</code> instead of <code>Gauss</code> (with a "ß" instead of "ss"); or I could define a function called <code>Müller</code> (with two dots over the "u"). In Spanish and other languages, this is a more pressing matter. If I defined a function <code>design(howMany)</code>, in Spanish it would be <code>diseño(cuántos)</code>.</p>
<p>However, it seems quite strange to have tildes, betas, etc. in variable names. Is it a good programming behavior to avoid this kind of names?, or, should I use them sparely?</p>
<p>Thanks in advance!</p>
https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?answer=49408#post-id-49408In Python 3 you can do some nice things like:
sage: π = pi
sage: sin(π)
0
sage: cos(π)
-1
and so on. For Python 3 builds of Sage it would be nice to have a few of these built-in. Per my comment on Nil's answer, special characters can be input fairly easily by using tab-completion.
Ticket: https://trac.sagemath.org/ticket/28966Tue, 07 Jan 2020 08:41:29 -0600https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?answer=49408#post-id-49408Comment by Iguananaut for <p>In Python 3 you can do some nice things like:</p>
<pre><code>sage: π = pi
sage: sin(π)
0
sage: cos(π)
-1
</code></pre>
<p>and so on. For Python 3 builds of Sage it would be nice to have a few of these built-in. Per my comment on Nil's answer, special characters can be input fairly easily by using tab-completion.</p>
<p>Ticket: <a href="https://trac.sagemath.org/ticket/28966">https://trac.sagemath.org/ticket/28966</a></p>
https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?comment=49466#post-id-49466IPython on Python 3, yes.Thu, 09 Jan 2020 04:56:17 -0600https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?comment=49466#post-id-49466Comment by John Palmieri for <p>In Python 3 you can do some nice things like:</p>
<pre><code>sage: π = pi
sage: sin(π)
0
sage: cos(π)
-1
</code></pre>
<p>and so on. For Python 3 builds of Sage it would be nice to have a few of these built-in. Per my comment on Nil's answer, special characters can be input fairly easily by using tab-completion.</p>
<p>Ticket: <a href="https://trac.sagemath.org/ticket/28966">https://trac.sagemath.org/ticket/28966</a></p>
https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?comment=49454#post-id-49454@iguananaut: you might want to edit your comment on Nils' answer which says that this is a feature of Python 3 rather than IPython.Wed, 08 Jan 2020 13:17:39 -0600https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?comment=49454#post-id-49454Comment by Iguananaut for <p>In Python 3 you can do some nice things like:</p>
<pre><code>sage: π = pi
sage: sin(π)
0
sage: cos(π)
-1
</code></pre>
<p>and so on. For Python 3 builds of Sage it would be nice to have a few of these built-in. Per my comment on Nil's answer, special characters can be input fairly easily by using tab-completion.</p>
<p>Ticket: <a href="https://trac.sagemath.org/ticket/28966">https://trac.sagemath.org/ticket/28966</a></p>
https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?comment=49448#post-id-49448@dsejas I agree, it might be good to have a module defining unicode aliases for different globals. It can be made to load on Python 3 only (which is now the default anyways).Wed, 08 Jan 2020 11:29:10 -0600https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?comment=49448#post-id-49448Comment by Iguananaut for <p>In Python 3 you can do some nice things like:</p>
<pre><code>sage: π = pi
sage: sin(π)
0
sage: cos(π)
-1
</code></pre>
<p>and so on. For Python 3 builds of Sage it would be nice to have a few of these built-in. Per my comment on Nil's answer, special characters can be input fairly easily by using tab-completion.</p>
<p>Ticket: <a href="https://trac.sagemath.org/ticket/28966">https://trac.sagemath.org/ticket/28966</a></p>
https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?comment=49447#post-id-49447I meant to add; I opened a ticket for this. I suggest following up there with suggestions: https://trac.sagemath.org/ticket/28966Wed, 08 Jan 2020 11:27:28 -0600https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?comment=49447#post-id-49447Comment by dsejas for <p>In Python 3 you can do some nice things like:</p>
<pre><code>sage: π = pi
sage: sin(π)
0
sage: cos(π)
-1
</code></pre>
<p>and so on. For Python 3 builds of Sage it would be nice to have a few of these built-in. Per my comment on Nil's answer, special characters can be input fairly easily by using tab-completion.</p>
<p>Ticket: <a href="https://trac.sagemath.org/ticket/28966">https://trac.sagemath.org/ticket/28966</a></p>
https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?comment=49444#post-id-49444It would be really nice to be able to have constants like $\pi$, $\gamma$ and $\phi$. For example, I would like to write `sin(π)` instead of `sin(pi)`, or `ϕ` instead of `golden_ratio`.
Can we do this a feature of Sage? Maybe a separate module could define this (I could do it, if the developers agree). Notice that the Julia language has a similar feature.Wed, 08 Jan 2020 09:32:46 -0600https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?comment=49444#post-id-49444Comment by Iguananaut for <p>In Python 3 you can do some nice things like:</p>
<pre><code>sage: π = pi
sage: sin(π)
0
sage: cos(π)
-1
</code></pre>
<p>and so on. For Python 3 builds of Sage it would be nice to have a few of these built-in. Per my comment on Nil's answer, special characters can be input fairly easily by using tab-completion.</p>
<p>Ticket: <a href="https://trac.sagemath.org/ticket/28966">https://trac.sagemath.org/ticket/28966</a></p>
https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?comment=49440#post-id-49440Of course--this is an IPython feature.Wed, 08 Jan 2020 09:13:59 -0600https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?comment=49440#post-id-49440Comment by John Palmieri for <p>In Python 3 you can do some nice things like:</p>
<pre><code>sage: π = pi
sage: sin(π)
0
sage: cos(π)
-1
</code></pre>
<p>and so on. For Python 3 builds of Sage it would be nice to have a few of these built-in. Per my comment on Nil's answer, special characters can be input fairly easily by using tab-completion.</p>
<p>Ticket: <a href="https://trac.sagemath.org/ticket/28966">https://trac.sagemath.org/ticket/28966</a></p>
https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?comment=49424#post-id-49424I just tried out the tab-completion on "\pi". It works for me in IPython but not in plain Python. (This is with Python 3.7.3, built via Sage 9.0.)Tue, 07 Jan 2020 12:52:23 -0600https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?comment=49424#post-id-49424Comment by Iguananaut for <p>In Python 3 you can do some nice things like:</p>
<pre><code>sage: π = pi
sage: sin(π)
0
sage: cos(π)
-1
</code></pre>
<p>and so on. For Python 3 builds of Sage it would be nice to have a few of these built-in. Per my comment on Nil's answer, special characters can be input fairly easily by using tab-completion.</p>
<p>Ticket: <a href="https://trac.sagemath.org/ticket/28966">https://trac.sagemath.org/ticket/28966</a></p>
https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?comment=49418#post-id-49418You would have to look into what unicode completion plugins exist for emacs (I'm sure there are several).Tue, 07 Jan 2020 10:54:30 -0600https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?comment=49418#post-id-49418Comment by Emmanuel Charpentier for <p>In Python 3 you can do some nice things like:</p>
<pre><code>sage: π = pi
sage: sin(π)
0
sage: cos(π)
-1
</code></pre>
<p>and so on. For Python 3 builds of Sage it would be nice to have a few of these built-in. Per my comment on Nil's answer, special characters can be input fairly easily by using tab-completion.</p>
<p>Ticket: <a href="https://trac.sagemath.org/ticket/28966">https://trac.sagemath.org/ticket/28966</a></p>
https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?comment=49416#post-id-49416That's true for the "sage console" you get via the "sage" command in a Unix terminal. And in "our" Jupyter notebook. Nice...
Not sure how to get something equivalent in my favorite interface (emacs + sage-shell-mode)...Tue, 07 Jan 2020 10:51:53 -0600https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?comment=49416#post-id-49416Answer by nbruin for <p>Hello, Sage community!</p>
<p>Since Sage now supports Python 3, the possibility of using tildes and other unicode letters in names of variables is real. For example, I could define a constant <code>Gauß</code> instead of <code>Gauss</code> (with a "ß" instead of "ss"); or I could define a function called <code>Müller</code> (with two dots over the "u"). In Spanish and other languages, this is a more pressing matter. If I defined a function <code>design(howMany)</code>, in Spanish it would be <code>diseño(cuántos)</code>.</p>
<p>However, it seems quite strange to have tildes, betas, etc. in variable names. Is it a good programming behavior to avoid this kind of names?, or, should I use them sparely?</p>
<p>Thanks in advance!</p>
https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?answer=49372#post-id-49372See python's [PEP-8](https://www.python.org/dev/peps/pep-0008/) for the policy for python's standard library (identifiers must be ASCII) and [PEP-3131](https://www.python.org/dev/peps/pep-3131/) for the proposal that led to unicode identifiers being possible. Sage library code has more-or-less been following PEP-8, so I expect non-ascii identifiers will not be allowed there. What you do in your own files is your own concern (go wild and name your eigenvalue $\lambda$).
Non-ascii unicode characters may be difficult to type (depending on keyboard layout) and they can be extremely confusing, because unicode contains different code-points that have (nearly) identical print-shapes. I'd be strongly in favour for keeping them out of library code.Sun, 05 Jan 2020 02:36:00 -0600https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?answer=49372#post-id-49372Comment by nbruin for <p>See python's <a href="https://www.python.org/dev/peps/pep-0008/">PEP-8</a> for the policy for python's standard library (identifiers must be ASCII) and <a href="https://www.python.org/dev/peps/pep-3131/">PEP-3131</a> for the proposal that led to unicode identifiers being possible. Sage library code has more-or-less been following PEP-8, so I expect non-ascii identifiers will not be allowed there. What you do in your own files is your own concern (go wild and name your eigenvalue $\lambda$).</p>
<p>Non-ascii unicode characters may be difficult to type (depending on keyboard layout) and they can be extremely confusing, because unicode contains different code-points that have (nearly) identical print-shapes. I'd be strongly in favour for keeping them out of library code.</p>
https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?comment=49420#post-id-49420I would not be pleased if I were to be forced to type `gro\ddot<tab>bner_basis`. Also, whatever tab completion exists in interactive shells is unlikely to be available in many code editors, so relying on tab completion would make for a very poor "transportable" sage experience. I think keyboards worldwide are just not very unicode capable. Given the prevalence of english as an international language, I suspect this won't change very quickly. Perhaps the situation will change when mandarin takes over.Tue, 07 Jan 2020 11:26:36 -0600https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?comment=49420#post-id-49420Comment by Iguananaut for <p>See python's <a href="https://www.python.org/dev/peps/pep-0008/">PEP-8</a> for the policy for python's standard library (identifiers must be ASCII) and <a href="https://www.python.org/dev/peps/pep-3131/">PEP-3131</a> for the proposal that led to unicode identifiers being possible. Sage library code has more-or-less been following PEP-8, so I expect non-ascii identifiers will not be allowed there. What you do in your own files is your own concern (go wild and name your eigenvalue $\lambda$).</p>
<p>Non-ascii unicode characters may be difficult to type (depending on keyboard layout) and they can be extremely confusing, because unicode contains different code-points that have (nearly) identical print-shapes. I'd be strongly in favour for keeping them out of library code.</p>
https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?comment=49407#post-id-49407Ah, I figured it out, you can type `o\acute<tab>`. Similarly `u\ddot<tab>` gives you `ü`, etc. So you can either do the full unicode character name, or you can use its latex name if it has one (e.g. `\ss` gives `ß`), but for latex commands that modify a character, you type the character *first* then the command, then tab. This is documented at https://ipython.readthedocs.io/en/stable/api/generated/IPython.core.completer.html#latex-and-unicode-completionTue, 07 Jan 2020 08:35:44 -0600https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?comment=49407#post-id-49407Comment by Iguananaut for <p>See python's <a href="https://www.python.org/dev/peps/pep-0008/">PEP-8</a> for the policy for python's standard library (identifiers must be ASCII) and <a href="https://www.python.org/dev/peps/pep-3131/">PEP-3131</a> for the proposal that led to unicode identifiers being possible. Sage library code has more-or-less been following PEP-8, so I expect non-ascii identifiers will not be allowed there. What you do in your own files is your own concern (go wild and name your eigenvalue $\lambda$).</p>
<p>Non-ascii unicode characters may be difficult to type (depending on keyboard layout) and they can be extremely confusing, because unicode contains different code-points that have (nearly) identical print-shapes. I'd be strongly in favour for keeping them out of library code.</p>
https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?comment=49406#post-id-49406I'm all for it--in fact I've been hoping that Sage will start to come with more unicode variables built-in (e.g. for pi). Also; neat trick available in Python 3 only that most people don't know: You can tab-complete unicode characters e.g. by typing `\pi<tab>`. Unfortunately it doesn't work well with some simple accented characters. For example to complete `ó` you have to type (afaict) `\LATIN SMALL LETTER O WITH ACUTE<tab>`. That should be fixed somehow...Tue, 07 Jan 2020 08:33:33 -0600https://ask.sagemath.org/question/49370/should-i-avoid-using-unicode-in-names-of-variables/?comment=49406#post-id-49406