sympy.github.com icon indicating copy to clipboard operation
sympy.github.com copied to clipboard

Don't use import *

Open jfpuget opened this issue 3 years ago • 9 comments

The startup code loaded by default for the SymPy shell has an import * statement. This is very very bad practice and should not be used

jfpuget avatar May 16 '22 08:05 jfpuget

Why is it bad practice in the particular context of the sympy interactive shell to use a star import?

oscarbenjamin avatar May 16 '22 10:05 oscarbenjamin

Right, I always thought the import * should not be used in Python source files, but it can be used in interactive shells (that is what is was meant for).

certik avatar May 16 '22 11:05 certik

import * is just fine for interactive use. What would you suggest we use instead? If we were to replace it with an explicit import the import would be huge. sympy contains over 900 names.

asmeurer avatar May 16 '22 14:05 asmeurer

sympy contains over 900 names.

I guess you could argue that maybe it isn't necessary to import all 900 of them.

oscarbenjamin avatar May 16 '22 16:05 oscarbenjamin

If import * is just fine in your shell then I can break it with one line. Just run this as first command

from math import * # import * is just fine

Then, this example from right pane no longer works:

sin(x).series(x, 0, 7) # one of the examples on the right pane

In general, import * is bad practice (I hope there is no disagreement here). If people see you use it, then they are likely to use it later on when writing python programs. And there it could be real bad.

jfpuget avatar May 17 '22 16:05 jfpuget

I think that it was design flaw that sympy made exceptions for CamelCase for sin, cos even if they were really classes. The choice that they made everything look like math library like some 'magic' before, rather starts to confuse the users, and make conflicts for contributors, and not sure if it is helpful for learning curve.

sylee957 avatar Jan 19 '23 06:01 sylee957

The real design flaw is the fact that there isn't a single sin function that can work with all types. Hence we have math.sin, 'cmath.sin', numpy.sin, sympy.sin etc. If there was a single dispatch sin function (like in Julia) then there would be no confusion about which to use.

oscarbenjamin avatar Jan 19 '23 12:01 oscarbenjamin

hey i can solve it please assign this issue to me

Anshika91 avatar Jan 21 '23 11:01 Anshika91

I don't think that we want to change anything here. The online shell is designed for conveniently using sympy interactively.

oscarbenjamin avatar Jan 21 '23 12:01 oscarbenjamin