4 ms·
I'm amazed it has taken so long to get rid of strtok(). This is one of the worst designed and most misused functions I have ever seen - just about every use of
by zabzonk 2y ago
I'm amazed it has taken so long to get rid of strtok(). This is one of the worst designed and most misused functions I have ever seen - just about every use of it I have ever come across has been wrong. Write your own mini-parser rather than use it.
- johnisgood 2y agoI'm amazed people who are skilled in C find it difficult to use, considering everything you have to know about it is available in man-pages (and pretty much everywhere online). If it is misused, that is a skill issue (yeah, sorry). I could misuse virtually anything in other languages, too... So, all in all, I don't understand what you are trying to say. There are cases where I would rather use strtok than to roll my own. Sometimes all you need is already available, e.g. strtok, or strsep, or strstr, or what have you. Consider that I misuse this and that in your favourite language. Is it a reflection of the programming language, or my limited "skills"? https://wiki.sei.cmu.edu/confluence/display/c/STR06-C.+Do+not+assume+that+strtok%28%29+leaves+the+parse+string+unchanged https://wiki.sei.cmu.edu/confluence/display/c/STR06-C.+Do+no... is worth a read, too.
- IshKebab 2y ago> If it is misused, that is a skill issue (yeah, sorry). No it isn't. It's very easy to misuse so even skilled people misuse it. > Consider that I misuse this and that in your favourite language. Is it a reflection of the programming language, or my limited "skills"? Depends on what this and that are. If they are things that are easy to misuse and many people do, then it's a reflection of the programming language. If they're well-designed and it's only you getting it wrong, then it's your limited skills.
- johnisgood 2y agoIf what you need is strtok, use it as documented. If you do not use it as documented, that is a skill issue. Do you even need strtok? If you do, RTFM. > If they are things that are easy to misuse and many people do, then it's a reflection of the programming language. If they're well-designed and it's only you getting it wrong, then it's your limited skills. Whatever "well-designed" means. At any rate, wonder where you got the "many people" from, who actually have read the manual. For some of my use-cases, strtok is designed well enough. If I need something else, then I will use something else, and so should you. No need to re-implement strtok (or any other functions) readily available. Plus, do you really think people who cannot use strtok properly can roll their own?
- IshKebab 2y agoThe fact that you don't get this is the real skill issue.
- johnisgood 2y agoSo you are resorting to ad hominems instead of answering me. I get it, strtok is difficult for you to use even after a hundreds of correct examples of its usage and having read the manual pages. Then do not use it. Stick to whatever you may for all I care. sighs
- IshKebab 2y agoI just don't know of a good way to help you understand the insane levels of hubris you have. Tell me this. Do you ever make mistakes? Do you always read the manual exhaustively and remember it perfectly?
- johnisgood 2y agoWhen I'm coding, I have at least 2 workspaces out of 10 dedicated to manual pages and documentation, so I don't need to always remember (sometimes incorrectly). I do make mistakes, but usage of strtok is not one of them.
- IshKebab 2y agoSo you do make mistakes. And despite having the documentation open you don't always read all of it, correct? Or are you trying to say you always read all of the documentation? You see where I'm going with this right? Either you never make mistakes and always read all the documentation (which is impossible), OR it's beneficial to avoid functions where mistakes and missed documentation are highly likely to result in misuse. That's just basic logic. Hopefully there are no skill issues understanding that?
- johnisgood 2y ago
- xedrac 2y agoThe trick is to just make everything hard to use, then it's not easy to misuse.
- zabzonk 2y agoI don't know why you are going on about "skills" - I never mentioned such things in my comment - something you have introduced, I think. I do agree though that however "skilled" you are strtok() (and other C strXXX functions) is difficult to use correctly.
- johnisgood 2y agoBecause of another commenter who did, BUT I do not think that this is true, not after having read the manual pages. Do you think people who misuse strtok can implement their own alternative? The Internet is full of proper uses of strtok, and I bet LLMs know it too, and would help you through the process if you so want. This applies to most functions e.g. strcpy vs. strncpy vs. strlcpy, just to name one. Honestly, if someone cannot use strtok (if they should really use it) after having read all the manual pages there is, I doubt they would be able to come up with their own, better version of it.