Beehaw
  • Communities
  • Create Post
  • search
    Search
  • Login
  • Sign Up
 Maven (famous)   ( @Maven@lemmy.zip )  to Programmer Humor@programming.dev · 1 year ago

A Guessing Game

lemmy.zip

message-square
25
link
fedilink
  • cross-posted to:
  • programmerhumor@lemmy.ml
706

A Guessing Game

lemmy.zip

 Maven (famous)   ( @Maven@lemmy.zip )  to Programmer Humor@programming.dev · 1 year ago
message-square
25
link
fedilink
  • cross-posted to:
  • programmerhumor@lemmy.ml
alert-triangle
You must log in or # to comment.
  •  lemmytellyousomething   ( @lemmytellyousomething@lemmy.dbzer0.com ) 
    link
    fedilink
    arrow-up
    69
    ·
    1 year 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.

    •  uis   ( @uis@lemm.ee ) 
      link
      fedilink
      arrow-up
      8
      ·
      edit-2
      1 year ago

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

      •  lemmytellyousomething   ( @lemmytellyousomething@lemmy.dbzer0.com ) 
        link
        fedilink
        arrow-up
        8
        ·
        1 year 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   ( @zagaberoo@beehaw.org ) 
          link
          fedilink
          arrow-up
          5
          ·
          1 year 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   ( @barsoap@lemm.ee ) 
          link
          fedilink
          arrow-up
          5
          ·
          edit-2
          1 year 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   ( @uis@lemm.ee ) 
            link
            fedilink
            arrow-up
            2
            ·
            1 year 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   ( @barsoap@lemm.ee ) 
              link
              fedilink
              arrow-up
              1
              ·
              1 year 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   ( @uis@lemm.ee ) 
                link
                fedilink
                arrow-up
                1
                ·
                1 year 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.

        •  uis   ( @uis@lemm.ee ) 
          link
          fedilink
          arrow-up
          2
          ·
          edit-2
          1 year ago

          man strncpy

          •  Test_Tickles   ( @Test_Tickles@lemmynsfw.com ) Banned
            link
            fedilink
            English
            arrow-up
            1
            ·
            edit-2
            1 year ago

            Removed by mod

      •  xigoi   ( @xigoi@lemmy.sdf.org ) 
        link
        fedilink
        English
        arrow-up
        2
        ·
        1 year 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?

  •  Gobbel2000   ( @Gobbel2000@programming.dev ) 
    link
    fedilink
    arrow-up
    59
    ·
    1 year ago

    man -k to the rescue: mbsrtowcs, strxfrm and wcstold are C functions.

    •  uis   ( @uis@lemm.ee ) 
      link
      fedilink
      arrow-up
      14
      ·
      1 year ago

      Oh no. You tell them forbidden knowledge of reading manual.

    •  within_epsilon   ( @within_epsilon@beehaw.org ) 
      link
      fedilink
      arrow-up
      5
      ·
      1 year ago

      The function wcstol appears to be missing. Cross platform C is difficult.

  •  dogsoahC   ( @dogsoahC@lemm.ee ) 
    link
    fedilink
    arrow-up
    34
    ·
    1 year ago

    Easy. The ones with vowels are C library functions.

  •  MajorHavoc   ( @MajorHavoc@programming.dev ) 
    link
    fedilink
    arrow-up
    30
    ·
    1 year ago

    I thought I would be better at this game than I am.

  •  BeigeAgenda   ( @BeigeAgenda@lemmy.ca ) 
    link
    fedilink
    arrow-up
    17
    ·
    1 year ago

    Are there any of them that are both?

  •  Comment105   ( @Comment105@lemm.ee ) 
    link
    fedilink
    arrow-up
    8
    ·
    1 year ago

    Rhowch, mwyn, and wnffre are Welsh. The rest is nonsense.

    •  anti   ( @anti@lemm.ee ) 
      link
      fedilink
      arrow-up
      2
      ·
      1 year ago

      Cwtch is the most obviously Welsh word there.

      •  Comment105   ( @Comment105@lemm.ee ) 
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        Obviously.

  •  hddsx   ( @hddsx@lemmy.ca ) 
    link
    fedilink
    arrow-up
    7
    ·
    1 year ago

    wcs?

    •  lugal   ( @lugal@lemmy.ml ) 
      link
      fedilink
      arrow-up
      4
      ·
      1 year ago

      Welsh?

      •  hddsx   ( @hddsx@lemmy.ca ) 
        link
        fedilink
        arrow-up
        6
        ·
        1 year ago

        Ugh apparently my asterisks turned into italics.

        All the words with wcs should be functions. Not sure about the rest of them

        •  lugal   ( @lugal@lemmy.ml ) 
          link
          fedilink
          arrow-up
          7
          ·
          1 year ago

          I still vote for Welsh

        •  odium   ( @odium@programming.dev ) 
          link
          fedilink
          arrow-up
          4
          ·
          1 year ago

          Does \ to escape work? *testing*

  •  nexussapphire   ( @nexussapphire@lemm.ee ) 
    link
    fedilink
    English
    arrow-up
    4
    ·
    1 year ago

    I’m bad at naming things too🖐️

Programmer Humor@programming.dev

programmer_humor@programming.dev

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programmer_humor@programming.dev

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 1.05K users / day
  • 1.75K users / week
  • 4.42K users / month
  • 8.42K users / 6 months
  • 447 local subscribers
  • 27.8K subscribers
  • 1.14K Posts
  • 18.6K Comments
  • Modlog
  • mods:
  •  Feyter   ( @Feyter@programming.dev ) 
  •  adr1an   ( @anzo@programming.dev ) 
  •  BurningTurtle   ( @BurningTurtle@programming.dev ) 
  •  Pierre-Yves Lapersonne   ( @pylapp@programming.dev ) 
  • BE: 0.19.13
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code