Access Modifiers

This is a discussion on Access Modifiers within the C# Programming forums, part of the General Programming Boards category; So something that most (if not all) of us have seen and noticed is the different styles of access modifiers ...

  1. #1
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738

    Access Modifiers

    So something that most (if not all) of us have seen and noticed is the different styles of access modifiers in C++, Java, and C#.

    In C++ you do things like this:

    Code:
    class X
    {
    public:
        int i, j, k;
        string str;
        double d1, d2, d3;
    private:
       int a, b, c;
       float d, e, f;
    protected:
       char m, n, o, p;
    }
    Whereas in Java or C# it would look something along these lines:

    Code:
    class X
    {
        public int i, j, k;
        public string str;
        public double d1, d2, d3;
        private a, b, c;
        private float d, e, f;
        protected char m, n, o, p;
    }
    Although this isn't the best example, I couldn't think of a better one off the fly.

    Anyways, why do you think the programming community has shifted to a position where you have do declare everything as being "public", "private", etc. on each line instead of just declaring a section as "public" by using "public:" as you do in C++? Do you get what I am saying?

    In C++ you say "public:" and from that point foreword everything is public until you either end the class or you declare some other access modifier such as private or protected.

    In C#, however, you have to write "public" on every declaration that you want to be public...and it seems tedious and cumbersome. Why has the programming community shifted to doing it that way?
    My Website

    "Circular logic is good because it is."

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    I actually prefer the C# way over the C++ way. It looks better, gets better structured and is regular. Perhaps it's just my pedantic way of coding .
    Last edited by Magos; 05-21-2008 at 09:24 AM.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738
    The reason I prefer the C++ way is because a lot of classes I make have a lot of variables in them (I'm sure yours do too), and it gets annoying typing "public" or "private" so many times.
    My Website

    "Circular logic is good because it is."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 02:49 PM
  2. ww hosting and SSH access
    By spoon_ in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 04-07-2005, 08:49 AM
  3. Replies: 3
    Last Post: 09-22-2003, 09:48 PM
  4. Direct disk access in DOS
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 02-26-2002, 01:52 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21