comprehensions are the pythonic way to construct
list and dictionaries with short code.
for loops resemble C++ and so they can seem more eligible
to people with more experience in C++. Including me 3 years ago!
If the for loop is more eligible to you I will not argue any further.

comprehensions cause a compiled C function to execute at runtime with
memory preallocation
The complete for loop is interpreted at runtime with memory allocated on
the go.
Test show comprehensions to be 2 times faster than equivalent for loops.


Cheers
Manos Nikolaidis

Software Team
Shadow Robot Company. 251 Liverpool Road, London U.K. N1 1LX
Tel: +44 (0) 20 7700 2487 E: manos@shadowrobot.com



On 28 March 2014 10:16, toliver <notifications@github.com> wrote:

> In sr_hand/scripts/sr_hand/shadowhand_ros.py:
>
> > @@ -476,3 +494,52 @@ def activate_etherCAT_hand(self):
> >
> >          return False
> >
> > +    def joint_states_callback(self, joint_state):
> > +        """
> > +        The callback function for the topic joint_states.
> > +        It will store the received joint velocity and effort information in two dictionaries
> > +        Velocity will be converted to degrees/s.
> > +        Effort units are kept as they are (currently ADC units, as no calibration is performed on the strain gauges)
> > +
> > +        @param joint_state: the message containing the joints data.
> > +        """
> > +        tmp_vel = {}
> > +        tmp_effort = {}
> > +        for joint_name, position, velocity, effort in zip(joint_state.name, joint_state.position, joint_state.velocity, joint_state.effort):
> > +            tmp_vel[joint_name] = math.degrees(velocity)
> > +            tmp_effort[joint_name] = effort
>
> Interesting view.
>
> I agree that position is not needed at all (a copy paste error), but my
> preferred form would still be
>
> self.hand_velocity = {}
> self.hand_effort = {}
> for joint_name, velocity, effort in zip(joint_state.name,
> joint_state.velocity, joint_state.effort):
> self.hand_velocity[joint_name] = math.degrees(velocity)
> self.hand_effort[joint_name] = effort
>
> as I find this far more legible.
>
> By the way, why would this be slower? (there's only one zip operation and
> one loop in this form, instead of two)
>
> --
> Reply to this email directly or view it on GitHub<https://github.com/shadow-robot/sr-ros-interface/pull/117/files#r11060408>
> .
>

-- 

------------------------------
*Shadow Robot Company Ltd.*
251 Liverpool Road, N1 1LX, UK
Registered Number 3308007 (England & Wales)

RoNeX - Building Robots with ROS Made Easy 
http://www.shadowrobot.com/products/ronex/
------------------------------