Feature SS-3507
2 votes

Protect names of constants against re-definition and provide appropriate markup

Created by Martin Kraska on 2/22/2018 2:01 PM Last Updated by Martin Kraska on 2/23/2018 6:42 PM
%
 (hrs)
Logged: 0   (hrs)

 Description

Currently, you can re-define the pre-defined constants e, i and pi.

First funny thing is that these constants are handled differently: pi and e are displayed in bold, i isnt.

  • The fact that e or pi have been re-defined is visible by italic font and lack of bold weight.
  • Re-definition of i isnt reflected by italic font

i is used in display of complex results as a shortcut for sqrt(-1) regardless whether it has been re-defined or not.

The change to italic for user defined  names helps a bit in the case of e and pi but not in the case of i

My proposal is to strictly handle e, i and pi as immutable constants

  • mark them by non-italic font. I would not mind them being bold or blue in order to make it easier to distinguish.
  • If the user defines variables with the same name, these should be independent symbols marked by italic font.
  • Provide some shortcuts for these constants (like the already existing Ctrl-Shift-p for pi) or treat them as a unit by a leading semicolon

The benefit would be that we would NOT ANY MORE face issues related to constant's overwrite over again and again in the forum and could remove some of the current survival rules from the list (ideally there should be no survival rules due to lack of pitfalls).

 

PS: Guess how I re-defined numeric constant 2! Hint: nothing wrong with that, it's not a bug, just a nasty way to confuse the reader.

 

 

 

    Martin Kraska (Friday, February 23, 2018 6:42 PM) #

Here a bit clearer version of what the proposal means:

 

I agree that protection of imaginary unit and euler number should not prevent the user from using e and i as names of variables.

There are two challenges:

1. Clear visual distinction between protected constants and variables of the same name. The basic approach is to just use italic and non-italic black font. I prefer this because this would not require changes for complex result formatting and would be consistent to the general format rules in SMath (built-ins upright, user-defined italic)

2. Unambiguous and simple way to input either constant or variable using the keyboard. If you enter i or e, then this refers to the constants, as long nothing has been defined by the user. Once custom e or i are defined, then the selection could be done using the dynamic assistant. Alternatively, you might generally input the constants i as CTRL-SHIFT-I and e as CTRL-SHIFT-E just like CTRL-SHIFT-P gives pi.

Protecting pi is less important but would not harm and would add to consistant formatting.