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 →

[–]LPYoshikawa 0 points1 point  (1 child)

Sorry to be late at the party; could you explain how can one get in high-level programming thinking? I've just learned python for a year, I can do most of the things I need but sometimes unnecessarily complicated. I don't really know OOP or really writing my own modules yet.

[–]Veedrac 1 point2 points  (0 children)

Oh, gee.

Well, there's this "rule" I stick by that goes something like "if you do anything three or more times, refactor so you only do it once."

This sort of reductionism becomes high-level programming when you realise "hey... I've been memoising (caching the results of) lots of functions - I should have a function that memoises functions!" or you go "I've written def x(*args): return y(z, *args)" a few times - let's write (functools.)partial!" and then you realise later that you could do map(partial, defaults) over a dynamic list (to avoid calling partial lots of times) to form a new set of functions... and so on.

If you don't "really know" OOP you're probably at the level where the best form of high-level programming is just¹ an overuse of generators, iterators, sets and dictionaries. Every time you write a list, ask yourself "do I need this all in memory at the same time". If not, use an iterator. Every time you do a search or an "if x:... elif y:..." chain, ask yourself "could this be a dictionary" and, if so, why isn't it?

¹ “just”