Thread: Global Varibles

  1. #46
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Quote Originally Posted by motocross1 View Post
    It's all of the threads and popup/child windows that leave me wondering how do globals (or handle my data) more professionally.
    I send the required data using the CREATESTRUCT when creating the child window or have the child retrieve the data as required using GetParent() [depending on the requirements of the window and data model complexity].
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  2. #47
    Registered User
    Join Date
    Feb 2010
    Posts
    98
    > Global variables make it more difficult to verify #2.
    > Beyond small programs, global variables make #3 difficult to achieve
    This is so wrong that it IS religion.
    There should not be "anything" difficult, let alone "more difficult".
    If anything about your program is difficult, I would say YOU need to look for ways to improve YOUR design.

    This is the truth. The difference between 2 threads tapping the same data through a pointer or method to a class and 2 threads using global_anyData is that global is direct. The risk of errors and difficulty of tracking errors increase with indirection.

    Global is global is global.
    Do you people NOT get that?

    Why can't any of you hardliners explain why it is that you think global is magically not global if you stick it into a class? Using the same data globally whether directly or indirectly is still using global data.
    Yes, I'll admit, using global data can get ugly.
    But putting lipstick on a pig does not make him pretty.

    All such data requires being "grouped" and requires quality comments.
    All such data requires safeguards prior to the actual usage, like checking if null, etc.

    But I'll say it again...
    Global is global is global.

    Is your code really more readable?
    Is your code really more maintainable?
    Yes, it really is. I wouldn't write it any other way.

    The independent reviewer is a scrupulously honest and cynical bastard, with tremendous experience with large software systems, and also has a reputation for recommending that the customer reject about half of the systems that he assesses.
    He sounds like my twin, so we would be best friends.

    novacain,
    Thanks for staying on topic.
    I currently do the same with my top level windows.
    I also pack some processing into a few WM_USER+#'s to limit outside functions.

    Everyone else,
    It is my hope that down deep you know I am right.
    Meaning, the goal is 1-efficientcy, 2-stability, 3-readablity.
    The rest is bragging rights.
    For me, I can brag that I really do have a very nice, well organized GDI app.
    That's all that matters.
    Thanks, and enjoy your week.

  3. #48
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Is anybody else okay with this sort of trolling here? Because I'm not. It took me four pages of comments before I realized it, so hey, he's good. Also, I'm ........ed and don't feel much like contributing today. I'm out.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #49
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    Quote Originally Posted by motocross1
    This is so wrong that it IS religion.
    There should not be "anything" difficult, let alone "more difficult".
    If anything about your program is difficult, I would say YOU need to look for ways to improve YOUR design.
    Sorry, but your claims simply go against the experience of many programmers who work on larger programs in teams. You don't see it because you are working with a program for which you can get away with it. ("It's my project, my code, my app, it's just for me - not a corporate project group of programmers.")

    Quote Originally Posted by motocross1
    Why can't any of you hardliners explain why it is that you think global is magically not global if you stick it into a class?
    I do not think that global state is magically not global if you stick it into a class

    Quote Originally Posted by motocross1
    Yes, it really is. I wouldn't write it any other way.
    Until your code has been reviewed by other programmers, that is just a claim, possibly even delusion. I know I suffer from such delusions of perfection, otherwise I would not deign to show my code to others The difference is that I have the decency to respond positively to reviews and improve my code.

    Quote Originally Posted by motocross1
    Meaning, the goal is 1-efficientcy, 2-stability, 3-readablity.
    No objection to that. The thing is, when you say things like:
    • There ARE times to use static data.
    • There ARE times to use global data.
    • For the record, I agree the fewer the better - I strive for none.

    I agree. Yet, the overall outlook you give here is that you don't quite practice what you preach, and consequently you have a lower bar for globals than desirable, despite claiming to "strive for none". If you did strive for no globals while recognising that in some cases global state may be appropriate, you would not have started this thread in the first place, since you would have determined that "in my current project, it makes sense to use them" and then just used them where they really make sense.

    Calling the ideas of cohesion versus coupling and such "high-minded concepts", attacking strawman arguments concerning the use of classes: these don't help your case at all. They make you appear like you started this thread merely to pick a fight with professionals rather than learn from them.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #50
    Registered User
    Join Date
    Feb 2010
    Posts
    98
    For all of the insults.
    I AM freakin awesome, period.
    Here's my app (no way I'll post the code):Attachment 11541

  6. #51
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,739
    What are those, simulation statistics? Or do you use realworld data?
    Devoted my life to programming...

  7. #52
    Registered User
    Join Date
    Feb 2010
    Posts
    98
    Real world data - that's today's market.
    It's your last chance to buy STRI at those prices.

  8. #53
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    i don't get it. what's so awesome about those charts?

    as to the topic: if you're manipulating globals, a singleton with accessors will give you much better control over how and when they are changed, and will allow you to use them more easily and safely in a greater variety of contexts, for example: multi-threading.

  9. #54
    Registered User
    Join Date
    Feb 2010
    Posts
    98
    I'm actually stuffing a few globals into a new singleton right now.
    I found another C++ standards that I like:
    C++ Programming Practice Guideline
    Of course, I will still keep a few globals by choice.

    "what's so awesome about those charts?"
    The features: zoom, trendlines, different timeframes, live prices, price alerts, etc.

  10. #55
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    Dude, please don't "like" something I say if you don't understand it; you might accidentally convince me that you are worth helping further.

    Thankfully, taking this thread into "Look how awesome I am even though I'm not listening to you!?" territory saves me from my confusion.

    [Edit]
    Oh, and you weren't insulted until a couple of us realized that you only wanted someone to confirm your preconceived notions.

    Strangely, that's exactly why some people seek out religious groups.
    [/Edit]

    Soma

  11. #56
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    just so you know, neither features nor speed translate into great code. that's judging a book by it's cover.

    good code is like good prose; being factually correct on a wide variety of topics is not the same thing as delivering a message in a consistent, clear, and coherent manner. having code that does many things and doesn't crash is not the same as having good code.

  12. #57
    Registered User
    Join Date
    Feb 2010
    Posts
    98
    phantomotap,
    I "like" what you posted because you obviously understand the difficulties in Windows GDI.
    But I "love" it because you said:
    "That's the biggest problem with global state; you can decorate it all you like, but you can't solve all the problems unless you literally never use it."

    As for:
    "you only wanted someone to confirm your preconceived notions"
    No, I wanted to know the best way do globals (other than not use them).
    That's it.

    Surprisingly, brewbuck nailed it when he said "prefix them with g_ or Global or something like that". But what the right hand giveth, the left hand taken away: He then said, "so you can easily search for them and measure just how much the code sucks".

    He is the perfect example of the larger problem here (which is actually inescapable)...

    There are 3 groups of people who come to this forum:
    1) Students
    2) Professionals who help the Students
    3) Me - Someone needing information, not advice

    Sure, Students need to know the "corporate team project" way of writing code.
    They come here dumb as a brick and will one day be a Professional, so they need to hear preaching and brainwashing - the more the better.
    The problem is that the Professionals deal with so many hordes of Students that they start preaching to anyone who starts a thread.

    I KNEW the word "global" would set-off a frenzy.
    I tried to curtail it, but then, I TOO got sucked into the debate.
    Oh well, I'm sorry I stepped on some toes.
    But did I really?

    I think it's okay if people disagree with convention.
    There's no reason to treat them like they are dumb as a brick, not even if they ARE a Student.
    Hey, here's an idea, let people screw-up their own projects if they think it is best.

    But when everyone berates you and tells you that you suck, then you gotta say:
    "I AM THE BEST - I AM FREAKIN AWESOME - I WILL NOT LISTEN TO ANYONE"

    That's it, unless someone wants to say something nice.
    Seriously.

  13. #58
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Please let this thread die.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  14. #59
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by brewbuck View Post
    Is anybody else okay with this sort of trolling here?
    I don't think that is quite fair, because I think a troll is someone who intentionally provokes an endless argument by intentionally ignoring/misconstruing everything that has been said and intentionally repeating the same thing over and over again, with the intention of baiting others and de-railing legitimate discussion. If the OP is a troll, he's pretty good at it, lol, because I still believe he believes what he says.

    The pragmatic realist in me says, stop responding, because in reality, many (or most) adults, when confronted with evidence of the fact that they are wrong about something they perceive as potentially contentious, will not back down; no matter how strong the evidence, they will reject it in favour of more and more ridiculous justifications for their otherwise rationally untenable belief. In fact, people will ruin themselves and others in this way, so que sera sera.

    But the foolish optimist in me says, a person confronted with evidence of the fact that they are wrong about something important to them has a great opportunity, psychologically, to do something that might be new to them: recognize you're wrong, that you've made a big mistake, and that you, way way way more than anyone else involved, stands to benefit by recognizing this and taking it to heart, not just with regard to this issue but with regard to life in general. If you are that kind of person.

    Sigh. I don't hold my breath. It hurts too much.

    Quote Originally Posted by motocross1 View Post
    For all of the insults.
    I AM freakin awesome, period.
    No, you made an app with some graphs and buttons in it. What you are is freaking PARANOID.


    There are 3 groups of people who come to this forum:
    1) Students
    2) Professionals who help the Students
    3) Me - Someone needing information, not advice
    Okay, so pretty much everyone in the first two groups has bent over backward trying to help you understand, you can now dismiss this as "advice" and not "information". At this point, I presume the only thing that would count as "information", ironically, would be if we really could send God over to sort your head out.

    I said it before and I'll say it again, lol:

    Quote Originally Posted by MK27
    You are free to do what you like, but here's a promise: if you stick with programming seriously, at some point in the future you will remember this little debate and wonder what the beejezus you were trying to defend.
    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

  15. #60
    Registered User
    Join Date
    Feb 2010
    Posts
    98
    I'm a believer now, I've seen the light. Glory halleluha!!!
    I "Like" it all. Like, Like, Like.

    Are you happy now?
    How about ending the thread, jerk?

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, 12:23 PM
  3. extern varibles
    By manwhoonlyeats in forum C Programming
    Replies: 5
    Last Post: 12-18-2002, 12:43 AM
  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