Like Tree67Likes

Global Varibles

This is a discussion on Global Varibles within the C++ Programming forums, part of the General Programming Boards category; Okay, buddy, you get to go to heaven now. Of course, you just proved why religion is bad. Anyway, sorry ...

  1. #91
    Registered User
    Join Date
    Feb 2010
    Posts
    93
    Okay, buddy, you get to go to heaven now.
    Of course, you just proved why religion is bad.
    Anyway, sorry for that analogy. It was insensitive.

    Back on topic, Singletons are bad here too:
    jalf.dk Blog Archive Singletons: Solving problems you didn’t know you never had since 1995

    That's enough, right?
    Someone with a big post count step in and end it already.
    stahta01 likes this.

  2. #92
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    934
    YES, finally, someone noticed.
    I'm not a corporation.
    No, but you ARE a programmer, and programming is a professional skill that people get paid to do. Most people start of doing it as a hobby, and then in turn end up doing it for a living, and as such, a hobby programmer who asks a question on these boards, will get a response which will help them in the long run, should they ever decide to do professional programming.

    If you are planning to never have your code leave the confines of your dungeon, then that is fine, do as you want. But if that is the case then why are you worried about coding conventions and style and professional coding? You got your answer, it didn't fit with the way your most recent project had been coded, you feel offended and refuse to acknowledge the fact that you are WRONG.

    Keep doing globals if you want, just don't trouble the world with your code then.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  3. #93
    Registered User
    Join Date
    Feb 2010
    Posts
    93
    why are you worried about coding conventions and style and professional coding?
    This is a legitimate question.
    I associate "professional code" with being primarily, "fast and efficient" and "not going to cause memory problems".

    I view C++ as a powerful tool.
    You guys view it as a career choice.

    My Levels of Importance:
    90% = Fast, Efficient, and Error Free (Professional by my definition)
    9.9% = Readable, Logical
    .1% = Being Textbook

    Your Levels:
    90% = Being Textbook (Professional by your definition)
    10% = Everything else

    Some of the 90% matches, some of it don't.
    Whatever.

    So I guess I should have phrased my question...
    Is using extern for globals going to cause memory or processing problems?
    Or maybe...
    Is there a way to increase the processing speed and reduce the footprint of globals by placing them somewhere other than in the Global.h?

    Oh well.
    It's too late now.

  4. #94
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by motocross1 View Post
    There are some great reads out there:
    I love globals, or Google Core Dump
    That is sort of an interesting article, but I am dubious about the significance of the premise (that globals are justified because they are easier to track inside a core dump). I also think he is being a little facetious. Maybe even, a lot facetious. Further: pretty sure the scenario he is referring to is unusually grotesque, but I very seldom examine core dumps, so I won't try to comment any further.

    I empathize with his reflections about cargo cult programming: so maybe, it would be better that you go ahead and use globals as much as you want, if you do not understand why not to. Acting on your own understanding is probably better than acting by imitation.

    Quote Originally Posted by motocross1 View Post
    That article is a critique of double checked locking and not singletons. The fact that singletons are not by default thread safe is meaningless in so far as all objects are by default not thread safe. And global variables are about as unthread safe as you can get, by default. Thread safety is something you have to implement; there are better and worse ways to do it. Double checked locking sounds absurd to me right away, and this article just goes in depth about why.

    Beyond that, motocross1, I think you missed some of the previous points, vis, singletons are not a good substitute for globals, and I don't think anyone here said they were.

    In other words: by making an issue of the singleton pattern, you are attacking a straw man.

    Straw man - Wikipedia, the free encyclopedia
    Last edited by MK27; 03-06-2012 at 06:51 PM.
    rags_to_riches likes this.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #95
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,968
    Quote Originally Posted by motocross1
    "Professional" means to be a clone who cannot think for themselves.
    Yep, I'm happily disqualified from that club.
    Ad hominem, and one that is pretty rich when you have been faced with reasoned argument, not answers recited without understanding from a textbook.

    Quote Originally Posted by motocross1
    GOTO is a stupid example - it IS hard to follow.
    Ah, but if you're programming in C rather than C++, goto has a valid use as a tool for a technique for error handling that can actually make things easier to follow. (In C++, I don't see much point when exceptions can be used instead.) There is also the valid use of breaking out of nested loops, though this is more debatable since sentinel values can be used instead.

    Do you find it ironic that you have accused other people of blindly following a "religion" when you may be following the "goto considered (always) harmful" religion?

    Quote Originally Posted by motocross1
    I view C++ as a powerful tool.
    You guys view it as a career choice.
    I view C++ as a powerful tool. It is not a career choice, because my career choice does not limit me to any one programming language. (In fact, the current main programming language I use at work is Python, not C++.)

    Quote Originally Posted by motocross1
    Your Levels:
    90% = Being Textbook (Professional by your definition)
    10% = Everything else
    You are being presumptuous here, and consequently, you are wrong.

    Quote Originally Posted by motocross1
    So I guess I should have phrased my question...
    Is using extern for globals going to cause memory or processing problems?
    Or maybe...
    Is there a way to increase the processing speed and reduce the footprint of globals by placing them somewhere other than in the Global.h?
    My answer to both would be no. In fact, if you have a header file for globals and you don't use extern for the global variables declared there, you will get problems since you will be defining them in the multiple translation units that include the header (assuming you don't declare them within an unnamed namespace, static or as static members).
    rags_to_riches likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #96
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,158
    Quote Originally Posted by motocross1 View Post
    This is a legitimate question.
    I associate "professional code" with being primarily, "fast and efficient" and "not going to cause memory problems".
    "Professional code" doesn't specify anything. At most, it means code written by professionals, and a professional is somebody who makes their living doing it. Nobody ever made the equation "professional == high quality, correct."

    I don't eschew global variables because I read it in some textbook. I eschew them because I understand why they are bad. Both theoretically, and from two decades of experience.

    Is there a way to increase the processing speed and reduce the footprint of globals by placing them somewhere other than in the Global.h?
    The fact that you even ask this question indicates you fundamentally don't really know what the compiler does and how the language works.

    Go look up the "Dunning-Kruger effect."
    rags_to_riches likes this.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  7. #97
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    839
    Quote Originally Posted by motocross1 View Post
    GOTO is a stupid example - it IS hard to follow.

    if( !User.isLoggedIn ) DoLogin();
    ...is the same as...
    if( !global_isLoggedIn ) DoLogin();
    Both are easy to track and understand.

    My code is very efficient, stable, readable, manageable, scalable, and "Professional".
    Just quit already.
    those are not even remotely close to the same as each other.

  8. #98
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Ignorance more frequently begets confidence than does knowledge - Charles Darwin

    One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - Bertrand Russell

    Code:
    .              ___   /\   ___
                 ,' `.`-'..`-',' `.
                (  |\ \      / /|  )
                 `.`|) : __ : (|','
                   \_  | -- |  _/
                  ( _`.|    |,'_ )
                   `.\ `.__,' /,'
          _ __ _     `..____..'      _ __ _
      ___(_(__)_\_____)/    \(______/_(__)_)____
     |    `|\|`|      \/)__(\/      |' |/|'     |
     |    _   _        `-_--___   _  _  _  _    |
     |   | \ / \   |\ | / \  |   |_ |_ |_ | \   |
     |   |_/ \_/   | \| \_/  |   |  |_ |_ |_/   |
     |      ___      _   ___  _   _             |
     |       |  |_| |_    |  |_) / \ |  |       |
     |       |  | | |_    |  | \ \_/ |_ |_      |
     |__________________________________________|

  9. #99
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    839
    i'll put in one last sincere comment here, as i honestly think this guy has only recently begun outright trolling.

    a few years ago, i was in what i a similar place. i went to college for chemical engineering. i have never been formally trained on programming, but i picked it up in high-school, and that odd combination of skills has really been my niche in the job market.

    in my first job out of college i wrote the software for a piece of semiconductor manufacturing equipment. it did a lot, didn't crash, and the control algorithm i invented worked amazingly well. i was proud as ........ of myself, as well i should have been. however, the code was horrid. i didn't have a great appreciation for good design, and, in fact, i was so ignorant i couldn't tell the difference.

    i was once having trouble solving a problem, and posted code here. one of the responses i got included the phrase "so many atrocities in here". i bristled and initially thought many here as overly-pedantic. however, i knew there had to be a reason, and ultimately i realized they were right.

    what you fail to appreciate in your post above is that being readable and logical isn't important for its own sake, but rather because it naturally leads you toward code that is efficient and error-free. in the same way that having a clear thesis in an essay provides a solid platform to easily launch your ideas from, a neat and clear design makes the rest of your job easier, and THAT is the most important thing. strive to find the elegant solution, and you'll not only have good code, but you'll make your job much easier in the future. it's not about eliminating errors, it's about preventing them in the first place. it's not about optimizing by tweaking your implementations, but choosing a design that is efficient by nature.

    once you can appreciate these things, you'll be a pro.
    Last edited by m37h0d; 03-07-2012 at 07:39 AM. Reason: garmmatical error

  10. #100
    Registered User
    Join Date
    Mar 2011
    Posts
    61
    Quote Originally Posted by motocross1 View Post
    Okay, buddy, you get to go to heaven now.
    Of course, you just proved why religion is bad.
    Your first statement shows that you have no conception of what religion even is, which puts you in no position to pass judgement on it. Not to mention that I was talking about a moral issue, and didn't mention religion once.

    I don't want to disrupt this thread any more, so that's all I'll say.

  11. #101
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    934
    Quote Originally Posted by motocross1 View Post
    I view C++ as a powerful tool.
    You guys view it as a career choice.

    My Levels of Importance:
    90% = Fast, Efficient, and Error Free (Professional by my definition)
    9.9% = Readable, Logical
    .1% = Being Textbook

    Your Levels:
    90% = Being Textbook (Professional by your definition)
    10% = Everything else

    Some of the 90% matches, some of it don't.
    Whatever.
    This isn't about textbooks.

    Using encapsulation in a proper and meaningful way, leads to error free code. (Or less-error-prone code i should say)

    Using globals rather than proper encapsulation leads to highly-error-prone code. The reason you are not experiencing any errors at the moment is because the code base you are working with is small. Despite what you think you know, your approach doesn't scale well, in fact it doesn't scale at all.

    As mk27 mentioned, you will look back on this thread in a couple of years and feel awed by your own ignorance. It's okay, i can wait.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  12. #102
    Registered User
    Join Date
    Feb 2010
    Posts
    93
    Ad hominem, the Dunning-Kruger effect, Charles Darwin, Bertrand Russell, overly-pedantic
    Some really intellectual comments, I love it.
    And the dragon artwork - very, very cool.

    And, yes, I guess I am mostly parroting what I've read in the past about GOTO.
    You got me on that one, wow, I'm like everyone else. Darn it, I'm a clone.

    "you fundamentally don't really know what the compiler does"
    Bingo. This is the one most perfect comment written.
    Except I want more than just to know fundamentals.
    There seems to be nothing written about how to write optimized code.
    Everything everywhere is about it being written to conform - not perform.
    Of course, that would be a seperate thread.

    the time has come
    to say goodbye
    and I'm sorry

    I'm sorry because without you
    I'll be blue

    the time has come
    when we must part
    and I'll mis you

    somehow I know
    that you will me too

    understand me won't you try
    let's just kiss and say goodbye

    Sam Cooke

  13. #103
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    839
    what a waste of time.

    grow up.

    go to college.
    MK27 likes this.

  14. #104
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,403
    plenty of good discussion has come out of this one methinks, despite, erm ... " trolls " ? is that like a word for new jeremy kyle / ophrah winfrey?? insert 'tv debate show irritation bringer' as appropriate to your country of origin. - consider it a 'global'
    Last edited by rogster001; 03-09-2012 at 03:40 PM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  15. #105
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    I should have killed this thread three pages ago.
    rags_to_riches likes this.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Page 7 of 7 FirstFirst 1234567
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. string varibles??
    By Labmouse in forum C++ Programming
    Replies: 2
    Last Post: 08-23-2007, 08:16 AM
  2. Declaring Varibles
    By lbrault in forum C++ Programming
    Replies: 6
    Last Post: 02-05-2003, 11:23 AM
  3. extern varibles
    By manwhoonlyeats in forum C Programming
    Replies: 5
    Last Post: 12-17-2002, 11:43 PM
  4. C Functions and varibles
    By mart_man00 in forum C Programming
    Replies: 13
    Last Post: 08-01-2002, 01:11 PM
  5. varibles
    By Klinerr1 in forum C++ Programming
    Replies: 8
    Last Post: 06-24-2002, 10:15 AM

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