Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. How to Use Member Variables

How to Use Member Variables

Scheduled Pinned Locked Moved The Weird and The Wonderful
tutorial
23 Posts 12 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Anna Jayne Metcalfe

    He's right though. Although statics have their place, they are so frequently abused (a "lesser goto" seems a reasonable analogy) that instinctively associating their prescence in a codebase with a "smell" (particularly when said code was written by someone lacking experience) is perfectly natural. Beginner beware, as ever.

    Anna :rose: Tech Blog | Visual Lint "Why would anyone prefer to wield a weapon that takes both hands at once, when they could use a lighter (and obviously superior) weapon that allows you to wield multiple ones at a time, and thus supports multi-paradigm carnage?"

    N Offline
    N Offline
    Nagy Vilmos
    wrote on last edited by
    #21

    Thank-you AJ! I take the view that static should be avoided, but there are times were expedience allows them.


    Panic, Chaos, Destruction. My work here is done. or "Drink. Get drunk. Fall over." - P O'H

    A 1 Reply Last reply
    0
    • N Nagy Vilmos

      Thank-you AJ! I take the view that static should be avoided, but there are times were expedience allows them.


      Panic, Chaos, Destruction. My work here is done. or "Drink. Get drunk. Fall over." - P O'H

      A Offline
      A Offline
      Anna Jayne Metcalfe
      wrote on last edited by
      #22

      Anytime. :)

      Anna :rose: Tech Blog | Visual Lint "Why would anyone prefer to wield a weapon that takes both hands at once, when they could use a lighter (and obviously superior) weapon that allows you to wield multiple ones at a time, and thus supports multi-paradigm carnage?"

      1 Reply Last reply
      0
      • N Nagy Vilmos

        I've been looking at some code today written by a former slave. Now instead of using member variables in methods, dufus decided to pass them all around the shop as arguments to STATIC methods so we get crapola like this:

        class DoofusCode {
        private int first;
        private String second;

        // more stuff [tm]

        public void Method()
        {
        if (IsFirst(first))
        UpdateSecond(out second);
        }

        private static bool IsFirst(int first)
        {
        // more stuff [tm]
        return answer;
        }

        private static void IsFirst(out String second)
        {
        second = "Second";
        }
        }

        Go Optimisers! Go!


        Panic, Chaos, Destruction. My work here is done. or "Drink. Get drunk. Fall over." - P O'H

        S Offline
        S Offline
        S Senthil Kumar
        wrote on last edited by
        #23

        I think the "Create New Method" refactoring tool provided by VS automatically makes a method static if the code you selected to be in the body of the method did not use any non-static member variables. I have occasionally used this "pattern" if IsFirst contains behavior that is generally useful.

        Regards Senthil _____________________________ My Home Page |My Blog | My Articles | My Flickr | WinMacro

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups