pikusuru opened this issue on Oct 16, 2006 · 5 posts
pikusuru posted Mon, 16 October 2006 at 8:21 PM
This is probably a stupid question but I would like your advice. What's the best way to write this?
This:
<span style="background-color:rgb(255,255,255);">self.vertices.append(map(float,l.split(' ',1)[1].split()))</span>
or this:
vertex = l.split(' ',1)[1].split()
self.vertices.append(map(float,vertex))
or this:
vLine = l.split()
vertex = vLine[1:]
self.vertices.append(map(float,vertex))
They are all meant to take the a string 'v 1.0 2.0 3.0' and return a list [1.0,2.0,3.0] where each item in the list has been converted to a float.
The first obviously takes up less space but isn't as readable. Does it matter?
Thanks.
bushi posted Mon, 16 October 2006 at 10:02 PM
Of the three, I'd always go with the last style. I use to find it extremely frustrating to go back to a script months after writing it and have to spend a lot of time trying to figure out what I'd done earlier. Being more verbose and breaking steps up into individual lines helps that greatly. Also a nice comment block for each proc with an explanation of what it's suppose to be doing, what the inputs and outputs are and an overview of the intended algorithm are very useful when updating old code.
pikusuru posted Mon, 16 October 2006 at 10:20 PM
Thanks a lot. You're right looking at that first line after some time would be kind of weird.
tromnek posted Tue, 17 October 2006 at 6:52 AM
If you want your scripts to be Poser Pro Pack compatible, then you also need to call string methods using the 'string' module instead of the object way. So;
vline = l.split()
would become
vline = string.split(l)
Although, I understand that the 'string' module will (or has been) be depreciated and dropped in later python releases.
Maintaining Pro Pack compatibility can be a chore sometimes.
pikusuru posted Tue, 17 October 2006 at 9:20 AM
Thanks tromnek! My future self thanks you for saving him from head bruises.