GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 'import *' is not a recommended practice · Issue #114 · SolidCode/SolidPython

'import *' is not a recommended practice #114

New issue
Copy link
New issue
Copy link
Closed
Closed
'import *' is not a recommended practice#114
Copy link

Description

@rockstorm101
rockstorm101
opened on Aug 17, 2019
Issue body actions

Documentation tells the user to use from solid import *. Which a practice that is currently discouraged [1][2]. Am I missing some good reasoning for doing this? Otherwise, would you accept a PR in the lines of suggesting something like import solid as sp?

Activity

  1. etjones commented on Aug 18, 2019

    @etjones
    etjones
    on Aug 18, 2019
    Contributor
    More actions

    Yeah, in other Python code I write, I'd definitely frown on * imports. Here's my rationale for using the pattern in SP and why I'm not sold on switching the idiom out.

    If I were using SP in part of a bigger program with the geometry as a separate feature, I'd likely import solid as sp like you say. But pretty much all SP code I write (and, I suspect, that most people write) is just for a single purpose: geometry creation. If that's the case, namespacing all of your function calls seems to get in the way and decrease program clarity. Check out these two identical pieces of geometry:

    # From examples, at https://github.com/SolidCode/SolidPython/blob/master/solid/examples/basic_geometry.py
    from solid import *
    left_piece =  union()(
        translate([-15, 0, 0])(
            cube([10, 5, 3], center=True)
        ),
        translate([-10, 0, 0])(
            difference()(
                cylinder(r=5, h=15, center=True),
                cylinder(r=4, h=16, center=True)
            )
        )
    )

    And see this with the recommended python import style:

    # With namespaced import
    import solid as sp
    left_piece =  sp.union()(
        sp.translate([-15, 0, 0])(
            sp.cube([10, 5, 3], center=True)
        ),
        sp.translate([-10, 0, 0])(
            sp.difference()(
                sp.cylinder(r=5, h=15, center=True),
                sp.cylinder(r=4, h=16, center=True)
            )
        )
    )

    To my mind, the code in the first snippet is a lot clearer. Do you disagree?

  2. rockstorm101 commented on Aug 19, 2019

    @rockstorm101
    rockstorm101
    on Aug 19, 2019
    ContributorAuthor
    More actions

    I see and completely understand your point. If this is the reason for suggesting import * then I guess I'm fine with it. (And yes, I agree, it is clearer that way, and faster and easier to write)

    In all honesty I just started playing with this library so I'm not a long time user. However I've already found some downfalls to that practice such as having to name the function import_ instead of the more intuitive import. not being able to use __version__ to determine SolidPython version being used and specially the utils submodule defines several too common names that users might easily clash into by mistake (screw, nut, left, right, Green,...)

    Anyway, I see your point. I guess it is not such an easy trade-off.

  3. etjones
    closed this as completedon Aug 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.