SDF Chatter
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
DonjonMaister@programming.dev to Programmer Humor@lemmy.ml · 3 年前

The difference between an instance variable and a static variable.

programming.dev

message-square
10
link
fedilink
  • cross-posted to:
  • programmer_humor@programming.dev
34

The difference between an instance variable and a static variable.

programming.dev

DonjonMaister@programming.dev to Programmer Humor@lemmy.ml · 3 年前
message-square
10
link
fedilink
  • cross-posted to:
  • programmer_humor@programming.dev

cross-posted from: https://programming.dev/post/146762

alert-triangle
You must log in or # to comment.
  • tiredofsametab@kbin.social
    link
    fedilink
    arrow-up
    7
    ·
    3 年前

    Perl actually uses my and our to do scope.

    my @foo;

    our $bar;

  • jdr@lemmy.ml
    link
    fedilink
    arrow-up
    1
    ·
    3 年前

    Young man, could.you explain your shitpost?

    • fiah@discuss.tchncs.de
      link
      fedilink
      arrow-up
      1
      ·
      3 年前

      int variable => local scope => my int from the perspective of an instance

      static int variable => class scope => our int, for all instances of a class

      • Bear_with_a_hammer@lemmy.mlBanned
        link
        fedilink
        arrow-up
        1
        ·
        3 年前

        You know what’s funny? In PHP it’s backwards :D

        • fiah@discuss.tchncs.de
          link
          fedilink
          arrow-up
          1
          ·
          3 年前

          well of course it is!

    • Lux (she/her)@lemmy.blahaj.zone
      link
      fedilink
      arrow-up
      1
      ·
      3 年前

      I said, young man, what the fuck was that post?

  • azimir@lemmy.ml
    link
    fedilink
    arrow-up
    1
    ·
    3 年前

    This is a great one. I’m definitely using it in class this fall to explain static variables.

    • DonjonMaister@programming.devOP
      link
      fedilink
      arrow-up
      1
      ·
      3 年前

      Fun fact: I made this meme to explain my classmates static variables.

  • thebestaquaman@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    3 年前

    personally I prefer including the file

    prog_constants.h

    int program_state; // Keeps track of stuff

    in all translation units. That way I can easily keep track of what different parts of the program are doing at any time by modifying a single variable.

  • ndguardian@lemmy.studio
    link
    fedilink
    arrow-up
    1
    ·
    3 年前

    I hate how long it took me to get this, but I love it.

Programmer Humor@lemmy.ml

programmerhumor@lemmy.ml

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: !programmerhumor@lemmy.ml

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.
Visibility: Public
globe

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

  • 100 users / day
  • 732 users / week
  • 1.29K users / month
  • 2.37K users / 6 months
  • 444 local subscribers
  • 42.9K subscribers
  • 1.89K Posts
  • 40.3K Comments
  • Modlog
  • mods:
  • AgreeableLandscape@lemmy.mldeleted by creator
  • cat_programmer@lemmy.ml
  • BE: 0.19.18
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org