• TimeSquirrel@kbin.melroy.org
    link
    fedilink
    arrow-up
    5
    ·
    1 hour ago

    Lemme tell you something, DO NOT learn BASIC as your first language. As a hobbyist, I avoided C/C++ for 25 years because I just didn’t get pointers and memory manipulation, and messed around with other languages like JS and PHP instead (also BASIC’s GOTO and GOSUB kinda ruined me as a programmer for a few years). But once it finally clicked a couple years ago, I now want to write EVERYTHING in C/C++.

    I think plain C at least should be everybody’s first language. It literally reprograms your brain to think exactly like how a computer internally functions. I never got that with other languages, because they were so far removed from the actual machine.

    • ☆ Yσɠƚԋσʂ ☆@lemmy.mlOP
      link
      fedilink
      arrow-up
      2
      ·
      17 minutes ago

      I actually think that everybody should learn a functional language like Scheme first because it teaches you to think about state explicitly. It’s very easy for somebody who learned a functional language to pick up an imperative one, but it’s very hard for people to go the other way around.

  • SelfProgrammed@lemmy.today
    link
    fedilink
    English
    arrow-up
    23
    ·
    3 hours ago

    Here’s a secret I wish someone told me in high school: literally everything is pass by value, it’s just that sometimes the value is an address. It demystified pointers for me.

    • ddplf@szmer.info
      link
      fedilink
      arrow-up
      4
      arrow-down
      1
      ·
      edit-2
      2 hours ago

      It’s the opposite, everything is passed by reference but primitives are also addresses and therefore passed by value

      You can’t pass objects or functions as value

    • underisk@lemmy.ml
      link
      fedilink
      arrow-up
      2
      ·
      2 hours ago

      They taught you about pointers in high school? The only course available to me that even touched on programming just covered how to use C to do conditionals, read keyboard input, and print text to a terminal. The bulk of the course was learning MS Office.

    • asudox
      link
      fedilink
      arrow-up
      8
      arrow-down
      1
      ·
      3 hours ago

      That got me confused with rust references and why the dereference operator even exists as well.

      • Ephera@lemmy.ml
        link
        fedilink
        English
        arrow-up
        2
        ·
        32 minutes ago

        I mean, Rust has the additional thing that a reference is a pointer + a borrow, so it’s not quite as similar to a pass-by-value.

        And as for the dereference operator, occasionally you can use it to turn a reference into an owned value, often by making a copy of the value (but in that case, you can usually also use .to_owned()).

        A case where I don’t think there’s an alternative to the dereference operator, is if you’ve got a mutable reference and you want to replace the value that’s underneath: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=04621490e1d0fd6fe1af7f2e843547fb
        At the very least, if you remove the asterisk, the compiler will tell you very precisely that you need to add it back.

        • asudox
          link
          fedilink
          arrow-up
          1
          ·
          10 minutes ago

          yeah. references aren’t the same as pointers in c++ but similar, so it’s something along those lines.