Thread: About using global vars

  1. #31
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Quote Originally Posted by esbo View Post
    Are you serious? "The name, documentation, and general project design should make it clear what each variable does. ".
    The variable does what it does, the documention etc is what is 'supposed' to do.

    What if there is no documentation?

    Most variable are not documented.
    The only thing which will tell you what a function does is the code.
    There may be errors in the design at all levels.
    Most variables are not documented because you can tell what they do given their name and the function they are in. If that isn't enough, then a comment is required. If the variable is part of the external API of the component, then more documentation is needed.

    If you want to find out what something is supposed to do, you look at the documentation, the name, and the context.

    If you are trying to find a bug, then you are correct that the documentation usually won't show it (unless the bug is in the design).
    Quote Originally Posted by esbo View Post
    There may not be a debugger aavailable.
    What a 'trace' is is unclearly defined, there may well not be one which does what you
    just described, if indeed at all of if I even understand what you mean. (unclear).
    Tracing is when a debugger steps through your code line by line as your program runs. It is an extremely common feature.

    Certainly there are environments where you cannot use a debugger, and you are forced to examine code manually. Even then it is often most useful to follow code flow, rather than what variable is changing.

    This benefit of semi-isolating when a variable changes is small compared to the other benifits of local variables (mentioned in the other thread). Indeed in most cases having function local variables is itself a way of isolating when a variable changes, as then you know that the variable can only change within the function it is declared in, and the functions called by it.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  2. #32
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Quote Originally Posted by esbo View Post
    It is really not a problem for me at all.
    It might be for everyone else but that's their problem not mine.
    I can easilly write code to fit into a big project.
    If there are any scoping problems they will be easy enough to sort out.
    It's not something I would want to waste time on beforehand.
    If it's everyone else problem and not yours then perhalps you have not worked on enough of such projects. In which case you should follow the design pattern, before you run into the problem that it solves on your own.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  3. #33
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    I prefer to write code rather than talking about it.
    That way once it is written at least everyone knows exactly what they are talking about, rather
    than some ill defined definitions.

    Lecturers like to talk about it first because otherwise you would have no homework

  4. #34
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    huh?

    If you write code without formal design, then you wind up with crappy design. At least for big projects.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  5. #35
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by King Mir View Post
    huh?

    If you write code without formal design, then you wind up with crappy design. At least for big projects.

    Ever noticed how most big formally designed projects end up having to be scrapped

  6. #36
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Quote Originally Posted by esbo View Post
    Ever noticed how most big formally designed projects end up having to be scrapped
    There are plenty of successful large software projects out there. I'd wager all of them had a formal design phase.

    But what does that have to do with global variables?
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  7. #37
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    But what does that have to do with global variables?
    My attempt to explain how abstraction often makes globals unnecessary, and how they can actually break a program by introducing side effects has obviously failed entirely as opposed to just esbo's special case.

  8. #38
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by esbo
    I can easilly write code to fit into a big project.
    Define "big project".

    Quote Originally Posted by esbo
    I prefer to write code rather than talking about it.
    Me too.

    Quote Originally Posted by esbo
    That way once it is written at least everyone knows exactly what they are talking about, rather
    than some ill defined definitions.
    Unfortunately, real world projects do not work that way. Even if you do not go with a full formal design up front, you still need to talk first and get the requirements right, otherwise you could all end up knowing exactly what you are talking about, except that what you are talking about is nothing like what the customer wanted.
    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

  9. #39
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by whiteflags View Post
    My attempt to explain how abstraction often makes globals unnecessary, and how they can actually break a program by introducing side effects has obviously failed entirely as opposed to just esbo's special case.
    You realy can't talk in general terms about programs as they are all different.
    Programs tend to have a fair bit of global data but then ever program is different.
    The only thing which can break a program is the person(s) who write it.
    Anyway it's all rather too vague, nobody knows what anyone else is talkin about because
    we are talking about the undefined.
    We can waffle on endlessly about the underfined but it is all rather pointless, unless we are
    talking about something specific nothing has any real meaning.
    It's all just too vague.
    Last edited by esbo; 12-14-2008 at 11:29 PM.

  10. #40
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by esbo
    You realy can't take in general terms about programs as they are all different.
    That's rubbish. Programs are different, but they have common characteristics in their requirements, design, development and maintenance (though these may differ depending on the exact area of computing).
    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

  11. #41
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by esbo View Post
    You realy can't talk in general terms about programs as they are all different.
    Programs tend to have a fair bit of global data but then ever program is different.
    The only thing which can break a program is the person(s) who write it.
    Anyway it's all rather too vague, nobody knows what anyone else is talkin about because
    we are talking about the undefined.
    We can waffle on endlessly about the underfined but it is all rather pointless, unless we are
    talking about something specific nothing has any real meaning.
    It's all just too vague.
    The extent of thought you've spent on a subject you so deeply care about is astonishing.

  12. #42
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    > I prefer to write code rather than talking about it.
    > That way once it is written at least everyone knows exactly what they are talking about, rather
    than some ill defined definitions.

    > We can waffle on endlessly about the underfined but it is all rather pointless, unless we are
    talking about something specific nothing has any real meaning.
    > It's all just too vague.

    You claim to have worked on projects before, and not using local variables is your style. Could you post or otherwise show a non-trivial example of a project that uses the techniques you are describing?

  13. #43
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Quote Originally Posted by esbo View Post
    You realy can't talk in general terms about programs as they are all different.
    Programs tend to have a fair bit of global data but then ever program is different.
    The only thing which can break a program is the person(s) who write it.
    Anyway it's all rather too vague, nobody knows what anyone else is talkin about because
    we are talking about the undefined.
    We can waffle on endlessly about the underfined but it is all rather pointless, unless we are
    talking about something specific nothing has any real meaning.
    It's all just too vague.
    This seems a shrewd way to opt out of a discussion. First you make your point, then somebody else makes theirs, then you say that the subject is to broad an unconcrete to meaningfully talk about it in the first place.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  14. #44
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by King Mir View Post
    This seems a shrewd way to opt out of a discussion. First you make your point, then somebody else makes theirs, then you say that the subject is to broad an unconcrete to meaningfully talk about it in the first place.
    Because it is.
    You can't prove global variables are bad.
    If you can do it, do it, untill then stop making claims you cannot substanciate.
    All you can give a lot of waffle basically.
    I have a program with over a 100 globals and about 20 locals, it works fine.
    It would have been much harder to write using al local variabes, although possible, why should I waste time doing that?

  15. #45
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by robwhit View Post
    > I prefer to write code rather than talking about it.
    > That way once it is written at least everyone knows exactly what they are talking about, rather
    than some ill defined definitions.

    > We can waffle on endlessly about the underfined but it is all rather pointless, unless we are
    talking about something specific nothing has any real meaning.
    > It's all just too vague.

    You claim to have worked on projects before, and not using local variables is your style. Could you post or otherwise show a non-trivial example of a project that uses the techniques you are describing?
    Not really.
    I don't want my code stolen
    What would it prove if I did?
    I have a prog with over 100 global and about 30 local.
    If I posted what would it prove?
    I could post the code and the data it works on to prove that it works, then what are
    you going to do?
    Tell me it does not work????
    Tell me I won't be able to modify or add to it?
    Well I could post all the previous versions of it with less functionality which also work.

    So what exactly are you going to say is bad about it????

    Or maybe say it is only 1200 lines long and that I would have probllems if it was a million lines long?
    The reason it is not a milion line long is because it is well written
    Last edited by esbo; 12-16-2008 at 12:54 AM. Reason: I can't remember

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. basic question about global variables
    By radeberger in forum C++ Programming
    Replies: 0
    Last Post: 04-06-2009, 12:54 AM
  2. Best way to avoid using global variables
    By Canadian0469 in forum C++ Programming
    Replies: 7
    Last Post: 12-18-2008, 12:02 PM
  3. Maintaining Global Vars Between Libraries
    By Canadian0469 in forum C Programming
    Replies: 9
    Last Post: 11-27-2007, 12:29 PM
  4. Global objects and exceptions
    By drrngrvy in forum C++ Programming
    Replies: 1
    Last Post: 09-29-2006, 07:37 AM
  5. Global Vars
    By ihsir in forum C++ Programming
    Replies: 4
    Last Post: 04-18-2002, 10:40 AM

Tags for this Thread