• lemmytellyousomething@lemmy.dbzer0.com
    link
    fedilink
    arrow-up
    111
    arrow-down
    1
    ·
    edit-2
    2 months ago

    Why are they even named like this?

    When I read code, I want to be able to read it…

    Is this from a time when space was expensive and you wanted to reduce the space of the source files on the devs PC???

    For me (with a native language != english), this made it a lot harder to get into programming in the first place.

    • lukstru@lemmy.world
      link
      fedilink
      arrow-up
      84
      ·
      2 months ago

      I recently held a science slam about this topic! It’s a mix of the first computer scientists being mathematicians, who love their abbreviations, and limited screen size, memory and file size. It’s a trend in computing that has been well justified in the past, but has been making it harder for people to work together. And the need to use abbreviations has completely gone with the age of auto completion and language servers.

      • papabobolious@feddit.nu
        link
        fedilink
        arrow-up
        1
        ·
        2 months ago

        It’s been really holding me back in learning coding. I felt pretty comfortable at first learning javascript, but as I got further the code was increasingly hard to look back to and understand, to the point I had to spend a lot of time understanding my own code.

        Does it truely matter after the code has been compiled if it has more full words or not?

        • lukstru@lemmy.world
          link
          fedilink
          arrow-up
          2
          ·
          2 months ago

          It matters as soon as a requirement change comes in and you have to change something. Writing a dirty ass incomprehensible, but working piece of code is ok, as long as no one touches it again.

          But as soon as code has to be reworked, worked on together by multiple people, or you just want to understand what you did 2 weeks earlier, code readability becomes important.

          I like Uncle Bobs Clean Code (with a grain of salt) for a general idea of what such an approach to make code readable could look like. However, it is controversial and if overdone, can achieve the opposite. I like it as a starting point though.

    • trolololol@lemmy.world
      link
      fedilink
      arrow-up
      40
      ·
      edit-2
      2 months ago

      It’s from a time keyboards were so hard that you needed to do push ups on your finger tips if you wanted to endure a 9 to 5 programming job.

    • orangeboats@lemmy.world
      link
      fedilink
      arrow-up
      35
      ·
      2 months ago

      I recall reading somewhere the earlier compilers had a hard limit on the length of function names, due to memory constraints.

    • sandalbucket@lemmy.world
      link
      fedilink
      arrow-up
      22
      arrow-down
      4
      ·
      2 months ago

      Did you know that in the first version of php, each function name would be hashed to lookup the code to run it? And the hashing algorithm was: the first letter. So all the functions started with a different letter.

        • FooBarrington@lemmy.world
          link
          fedilink
          arrow-up
          17
          ·
          2 months ago

          It’s not. PHP used to use the function length as hash buckets, so by having evenly distributed lengths the execution time was faster. No idea where GP came up with that.

          • racemaniac@lemmy.dbzer0.com
            link
            fedilink
            arrow-up
            1
            ·
            2 months ago

            GP specifically talked about the first version of PHP, sounds like it was just a dummy implementation as they were working on PHP, that then later got replaced with a proper implementation :)

    • uis@lemm.ee
      link
      fedilink
      arrow-up
      9
      arrow-down
      7
      ·
      edit-2
      2 months ago

      strncpy becomes stringnumbercopy. You can see why short version is used.

      • lemmytellyousomething@lemmy.dbzer0.com
        link
        fedilink
        arrow-up
        14
        ·
        edit-2
        2 months ago

        And with a bit of namespacing and/or object orientation and usage of dots, it becomes perfectly readable.

        There are also camel case and underscores in other languages…

        BTW: How on earth should a newcomer know that the letter “n” in that word stands for number without having to google it? The newcomer could even assume that it’s a letter of the word string… And even, if you know that it stands for number, it’s still hard for me to understand what it means in this context… I actually had to google it… But that’s probably some C++ convention I don’t know about, because I don’t program in C++…

        • zagaberoo@beehaw.org
          link
          fedilink
          arrow-up
          5
          ·
          2 months ago

          C is a little older than namespacing and object orientation. C++ wasn’t even a glimmer in Bjarne’s eye when these conventions were laid down.

          And yes, having to google it is part of the design. Originally C programmers would have had to read actual manuals about this stuff. Once you learn the names you don’t really forget so it works well enough even now for ubiquitous standard library functions.

          And yet, C was an ergonomic revelation to programmers of the time. Now it’s the arcane grandpa that most youngsters don’t put up with.

        • barsoap@lemm.ee
          link
          fedilink
          arrow-up
          6
          arrow-down
          3
          ·
          edit-2
          2 months ago

          How on earth should a newcomer know that the letter “n” in that word stands for number without having to google it?

          By looking at the difference between strcpy and strncpy. Preferably, though, you should simply learn C before writing C.

          The gist of is is that strcpy takes a null-terminated string and copies it somewhere, while strncpy takes a zero-terminated string and copies it somewhere but will not write more than n bytes. strncpy literally has exactly one more parameter than strcpy, that being n, hence the name. If n is smaller than the string length (as in: distance to first null byte) then you’re bound to have garbage in your destination, and to check for that you have to dereference the pointer strncpy returns and check if it’s actually null. Yay C error handling.

          In retrospect null-terminated strings were a mistake, but so were many other things, at some point you just have to accept that there’s hysterical raisins everywhere.

          • uis@lemm.ee
            link
            fedilink
            arrow-up
            2
            ·
            edit-2
            2 months ago

            If n is smaller than the string length (as in: distance to first null byte) then you’re bound to have garbage in your return destination

            Wha? N is just maximum length of string to copy. Data after dst+n is unchanged.

            In retrospect null-terminated strings were a mistake, but so were many other things, at some point you just have to accept that there’s hysterical raisins everywhere.

            All hail length-prefixed strings!

            • barsoap@lemm.ee
              link
              fedilink
              arrow-up
              2
              ·
              edit-2
              2 months ago

              Data after dst+n is unchanged.

              Sure but that means the part before that is garbage because you have a null terminated string without terminator.

              Or at least that’s how I see it. If your intention isn’t to start and end with a null-terminated string you should be using memcpy. Let us not talk about situations where CHAR_BIT != 8 that’s not POSIX anyway.

              Even better, just avoid doing string manipulation in C.

              • uis@lemm.ee
                link
                fedilink
                arrow-up
                1
                ·
                2 months ago

                Let us not talk about situations where CHAR_BIT != 8 that’s not POSIX anyway.

                Yeah, let’s not talk about 20-bit one’s complement ints.

      • xigoi@lemmy.sdf.org
        link
        fedilink
        English
        arrow-up
        2
        ·
        2 months ago

        Why not just add function overloading to the language and have a function named copy that takes a string and an optional character count?