It's what you get for being lazy (non judging here, I'm guilty of it too) and not naming your variables accordingly. When you write the code you probably know what ndi, q, p, lnk, etc. are supposed to mean. But then you leave the code for some time and when you return you are lost. Just write out variable and function names so that your code reads like english - programming Obj-C for some time really helped me there :)
And with pointer-heavy code I tend to create aliases for offsets so I don't have to write out things like *(q->lnk+!dec) every time I reference that specific address.
Yes, maybe it will cost me wizard points with colleagues because they start to understand my code but my sanity is it worth to me ;)
(Also trailing/leading underscores are the devil!)
Sigh. Sadly, it has become fashionable to bring up Perl only to ridicule it even when there is absolutely no context or need.
Take a look at this implementation [1] of doubly linked list in Perl. Tell me how that is worse [2].
Now, I will go back to my corner to being productive using Perl or whatever language I need.
[1] https://metacpan.org/source/LEONT/List-DoubleLinked-0.003/li...
[2] Of course, I have no way of knowing if it is an exact or even close translation of your code, but it does implement doubly linked lists.
A lot of people ridicule C, I just laugh my head off.
Apologies, I assure you that I am not ridiculing it. The elegance of a language is not my concern. In fact, your comment has made me decide to put some effort into learning a bit more Perl, but I will have to find some time.
Good practise though.
typedef struct dll__ {
struct dll__ *lnk[2];
void *dat;
}ndi;
I've seen some examples on the web, but I haven't seen it done this way. I have a suspicion it might be slower than the traditional technique, but I'll have to check that. What is not evident from the code snippet is that I'm trying to make the code handle both fixed end and looped lists.
I would have ignored your comment were it not for you mentioning that you write javascript. I started learning it on and off a few weeks ago, and yesterday I installed spidermonkey as a standalone shell. What I have noticed is that a lot of the syntax that controls flow is very similar to C, which is notorious for being gibberish. I'm guessing the same will apply to js. I do not have a CS degree, but would you say that this is readable? This is a function for extraction of nodes in a double linked list that I am currently kicking into shape.
What the hell was I smoking when I wrote this? I can't even read it myself.Writing convoluted code is more to do with a certain state of mind. You should ask your coworkers where they obtain LSD, not where they got their degree. I haven't come across any acid for about a dozen years, I think it has gone out of fashion.
Of course if this was Perl it would be even worse.