Here are examples of what my code cards look like: https://imgur.com/a/LxS18YK
Personally, I prefer to make syntax cards only for parts of a framework/language that seem especially important or that I expect to be using relatively frequently.
Syntax is largely arbitrary, with little or no “why” behind the way that it is (think of Java’s ‘s.trim()’ vs Python’s ‘s.strip()’, which do almost the same thing). Hotkeys are even worse (I have some Emacs cards with answers like “C-M-e”. They are of questionable utility). This makes it harder to create well-connected and coherent syntax cards than it is for mathematical concepts (even though the latter are more abstract). Don’t get me wrong, I have >1,000 programming cards. I just try to be judicious about what I make them for (Core Python language features: good cards; obscure library I only used for 1 hour 4 years ago: bad cards!).
I’ve only made a multi-line programming card once or twice, and hated it, so I feel your pain :).
I’ve been toying with a new experiment, using an analogy to spoken language and writing systems: learning Chinese characters one-at-a-time is painful with Anki. But learning them as part of short sentences or sentence fragments works quite well.
So I’ve been wondering: what if we neither use my isolated approach to Python syntax, nor your multi-line cards, but something in between? And we try to do it in such a way that the same library function gets used in more than one short example?
I dunno, just an idea I’ve been turning over.
PS: For a decorator function, I’d probably make a card that asks “how would you write a custom decorator in Python (basic idea)?” and explain the gist verbally (“Define a function that takes a function as input and returns another function”). Maybe with a screenshot of a code snippet one side with the relevant parts circled in red. I call these cards that reduce an idea to a single-sentence definition “basic idea” cards, and I use them all the time (sometimes in conjunction with other cards that ask about further details).