29
Justice
17d

So strings in c++

Who the hell thought it was a good idea to name a fucking function strstr? What does this do? Takes a string and turns it into a string? Also strtok, strchr and the strn ones. What is the best way to shove a fucking keyboard through someone's ass and can I get it out through his mouth so I can shove it back in?

Comments
  • 5
    ++ just for the creative imagery.
  • 4
    Have you looked at the differed between the headers string, string.h and cstring yet?
  • 0
    @njpugh90 I'm not 100% but I thought cstring is same as string.h.

    http://cplusplus.com/reference/...
  • 4
    these function names make sense to me....
    string-in_a-string
    string-tokenize
    string-character (i.e. char-in-a-string)
  • 2
    Well they don't to me. I usually just write them from ground whenever I need them. I once had to parse equations(something like 2x+3x-5+6-x=5x+10x-6, no paranthesis fortunately). I was supposed to do it with string functions. I ended up doing it by looping through all the characters and analyzing it and it still got 100/100.

    And now I've got a test next week with string functions and we have to write the programs on paper. God please help me
  • 6
    In all fairness, these date from the early days of the C standard library, when at least one compiler/linker essentially ignored any characters in an identifier from the seventh.
  • 5
    Strings in C++... Surely just include <string> and use std::string instead? It's a lot nicer.

    The routines you're using originated in C.

    Though I agree, strstr I'd a bit confusing to guess it's purpose by its name alone.

    Edit: Just realised you need to use these specific functions for your test. Was assuming you were just trying to generally develop something to work with strings.
  • 3
    Just to add it out there, as a general rule, you shouldn't use strtok as it isn't thread safe.
    And you should always be using the versions that take the length as a parameter to reduce the possibility of buffer overflow attacks
  • 1
    You do know C has been creating in the 70s, right? Let's just say IDEs didn't exist, and text editors were lackluster. Also, terminals were probably limited to 80 characters.

    All those things make it a very sensible decision to have functions names as short as possible.

    And as @halfflat said, there might have been more practical reasons to limit the length of function names too.
  • 0
    Created in the 70s and not updated once? Or updated and those names still there? Hmm
  • 2
    @Justice It makes the language a bit warty but means you don't have to do much to old code to make it compile on a modern C compiler.

    New features do get added, like stdint.h and // style comments. I don't think anything generally gets renamed/removed.
  • 0
    @Justice and break everyone stuff for little reason?

    Most languages aren't going to break retro-compatibility, unless there is a really compelling reason to do it.

    Badly named functions that long-time users know, are documented and referenced everywhere is not a compelling reason.
Your Job Suck?
Get a Better Job
Add Comment