> I don't like
> from psychopy import *
> It encourages beginners not to think about what is being imported or what
> imported names they might be overlapping with.
Agreed. in retrospect I like listing everything explicitly much better.
> I agree that sound is common enough that we might assume most experiments
> need it, so we could add that to builder's load-by-default list.
>
> Not sure about importing microphone for all experiments. I feel like that's
> still likely to be used relatively rarely, no?
I have no real idea about microphone, although people are asking about
usage (unlike say google speech or encryption). (As an aside, it seems
like microphone should really be part of sound, not a separate module.
This issue might be reason enough to do it. The previous thinking was,
yeah, it probably should be in sound but its not worth the effort to
change it now.)
Two, more-general thoughts here. a) Besides style, is there any real
cost of importing things that are not used much? How often do people
use sin, cos, tan, log, log10, pi, average, sqrt, std, deg2rad,
rad2deg, linspace, asarray? Isn't that the same issue?
b) Knowing that everything will be available means that Builder /
experiment objects do not have to keep track, which would simplify
their internal code.
> Should we be trying to
> 'train' people only to import what they need, rather than always importing
> everything? Or should we not care about such things?
Well, PsychoPy is your creation. Here's how I see it. Enabling easy
construction of high-quality experiments seems like the primary,
defining goal of the package. This is why people will try it out and
stick with it. Training or teaching good coding practices by example
is a noble but secondary goal. If it came along for free, that would
be great. But to learn python, I don't think people are going to start
and end with psychopy. And there's a real cost of supporting that as a
high priority goal, in terms of code complexity; supporting that fully
will mean that functional things will not get implemented, or not as
quickly. So as a compromise, I think a realistic goal is to generate
code that is readable and comprehensible, even if there are some rough
edges. Tradeoffs are acceptable, and heck, they even might lend
themselves to teaching (e.g., "Here's some auto-generated code that
works -- how would you optimize it?").
Currently, there are many ways that Builder-generated code is not what
you would write yourself. This is surely because of the considerable
added work required to further streamline / optimize (especially in
builder.py and experiment.py). The numpy imports are one example.
Another is that if you use the same routine 3 at three places in the
flow in an experiment (e.g., for practice and two sessions of real
trials), you get redundant code, like:
# Initialize components for Routine "trial"
trialClock = core.Clock()
# Initialize components for Routine "trial"
trialClock = core.Clock()
# Initialize components for Routine "trial"
trialClock = core.Clock()
To avoid this, we could go through and add checks and so on... ugh.
There are many other ways that the generated code is not going to be
tight. You get a trialClock whether or not your routine needs a clock.
Do we add a check for that? When might that check not be smart enough?
If you compile an .psyexp that consists of one routine having a single
code component with nothing in it, you get 100 lines of python that
queries for a subject number and then does nothing. You know, I'm okay
with that.
The Coder examples might be the place to strive for exemplary code.
Possibly there could be an included example or two of how to do the
same thing directly in code that will run exactly the same as one of
the Builder demos.
--Jeremy
> "psychopy-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
psychopy-dev...@googlegroups.com.