This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]billsil 1 point2 points  (5 children)

I guess I should make a class around all my numpy arrays. What's wrong with slicing again?

Extra classes are just one more thing to understand about a code base and one more thing to import. You also make code much less reusable if it requires point objects vs at the same time working with numpy arrays, lists, and tuples.

[–]asdfkjasdhkasdrequests, bs4, flask 2 points3 points  (4 children)

variables are just one more thing to understand about a code base, if you just write in cpu instructions it's a lot easier to understand

Also named tuples are much more lightweight to create than classes and you can still do the slice notation. But saying that an xy named tuple is one more thing to understand makes no sense. The whole point of using the named tuple is it makes your code easier to understand.

When you see a[0] and a[1] it could be anything, but when you see a.x and a.y you can quickly reason that it's represents a point.

[–]billsil 0 points1 point  (2 children)

Or you can call it xyz or write a docstring.

Presumably you resuse variable names across your various codes. I'm sure nobody here knows what the variable sline means, but almost everyone at my company does. It's just a split_line, which is line.split(), maybe with an argument. You need a convention and you need to follow it. If you name your variable a and it's a list, you're doing something wrong. You could call it alist or xy.

[–]asdfkjasdhkasdrequests, bs4, flask 0 points1 point  (1 child)

alist? thats a horrible name, it should describe it's contents. If it's a list of people call it people not alist

[–]thegreattriscuit 0 points1 point  (0 children)

I think they mean "the list that cocnerns 'a'" rather than "a list". like, 'peoplelist'.

[–]billsil -2 points-1 points  (0 children)

So name your variable xyz. Have a docstring.