Skip to content
This repository was archived by the owner on Aug 15, 2019. It is now read-only.

Keep initialisation in API consumers #7

@PeterJCLaw

Description

@PeterJCLaw

In a number of places I've seen comments that there's a desire to move the API from:

from robot import Robot
bot_instance = Robot()

to something approximately like

from robot import bot_instance

I'd like to put a vote in for not doing this, as well as understand why this is seen as beneficial.

My experience is that libraries which try to be "helpful" by doing various initialisation for you under the covers tend to end up being difficult to use as soon as you want to do something interesting with them (including test them).

I think it's also the case that if we're teaching people to code by using this library as an example, we should keep this example as close to the other sorts of library they're likely to encounter.

There might be an argument for having a global robot instance as well as locally instantiable ones, with a pattern a bit like Python's re library:

import robot
robot.move_forward()

# you can also do
from robot import Robot
bot = Robot("custom", "stuff")
bot.move_forward()

# or maybe
bot = robot.initialise("custom", "stuff")
bot.move_forward()
# though this one is held back by lack of a decent name for the `initialise` function

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