Skip to content

Rethink "connected" attribute #372

Closed

Description

@WasabiFan

When we originally designed the ev3dev-lang libraries, we based them all on a concept where devices would expose a connected property to indicate whether they had successfully found a device matching the parameters from the constructor. This has led to a lot of code that looks like this:

m = ev3.Motor(ev3.OUTPUT_A)
assert m.connected

...and lots of confused users as a result (especially when they don't know to include that assertion).

Do we want to change this behavior? I think it would make sense at this point to throw an exception from the constructor. This would be just for this library and wouldn't necessarily require a change to others.

Activity

  1. ddemidov commented on Sep 23, 2017

    @ddemidov
    Member

    I guess there is no point in creating a Motor class instance that is not actually linked to a physical motor, so 👍

  2. dwalton76 commented on Sep 23, 2017

    @dwalton76
    Collaborator

    Seems worth raising an Exception in this scenario

  3. ensonic commented on Sep 25, 2017

    @ensonic
    Contributor

    +1, right now you get exception when you try to use it anyway (e.g. when you set m.polarity right after constructing it).

  4. dwalton76 commented on Oct 8, 2017

    @dwalton76
    Collaborator

    See PR #402

  5. bidaian commented on Oct 11, 2017

    @bidaian

    Throwing the exception is ok. But, should we get rid of the connected attribute too? Isn't there a valid use case for it?

  6. WasabiFan commented on Oct 11, 2017

    @WasabiFan
    MemberAuthor

    Yep, one of the changes in #402 is to remove the attribute entirely. In fact, that's the title of the PR.

  7. bidaian commented on Oct 11, 2017

    @bidaian

    Yep, one of the changes in #402 is to remove the attribute entirely. In fact, that's the title of the PR.

    I noticed the title :). My question is, if it would make sense to just throw the exception but not get rid of the attribute, because it might come in handy at some point (for things that could actually go on/offline after instantiation) and because it was exposed, so it's removal would break things (for example this or this from the projects gallery).

  8. WasabiFan commented on Oct 11, 2017

    @WasabiFan
    MemberAuthor

    Yes, it will be a breaking change. I can't imagine a case where a device would come on/offline in a way that we'd notice proactively (i.e., every read of connected would need to perform I/O to check if things are still connected). If there are devices that have such a need, those classes can implement this attribute as needed.

    Existing scripts will work as-is. I'm working on an "upgrading guide" (#399) which walks you through the details, but the short version is that we plan to rename the module to be ev3dev2. So, if you continue to import ev3dev, you'll get the existing version of the library, but you can choose to update your import statements and only then will you be forced to adapt to breaking changes. So, those examples will work, however we'll need to make sure we have clear documentation that explains this behavior.

  9. bidaian commented on Oct 11, 2017

    @bidaian

    Existing scripts will work as-is. I'm working on an "upgrading guide" (#399) which walks you through the details, but the short version is that we plan to rename the module to be ev3dev2. So, if you continue to import ev3dev, you'll get the existing version of the library

    Well done. No concerns then. Thanks for clearing that up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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