Provide a mathematical proof that global variables are easy to use.Global variables are easy to use.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
OK, so you are a hopeless case.
You post a thread bragging about how extensible and superior quality your code is. I give you a lengthy analyses. You disagree to everything and admit that your code indeed only works for this particular, very specific use case and there are no reusable parts for similar projects and that small changes cannot be made without major rewrites.
You mean, in Windows Explorer?No you can just rename the file.
I would have thought that the more vital the data is, there more things you might want to try before you give up.What if the moon was made of green cheese?
The vital data is what cannot be saved there is nothing you can do other than exit.
If I made a lengthy Word document and for some reason Word failed to save it, I wouldn't be happy if the program just chose to exit.
OK, but you haven't answered what you would do if your boss came to you and said there needs to be two arrays or if you simply changed your mind.I only had one array to save so that what I did.
Being ready for such cases is all that extensibility is all about. I find it very practical to program with a little margin for extra requirements / requirement changes, and in this case I would simply add the other array and call the same functions with different arguments. As far as the file-routines are concerned, only a coulple of lines would be added. How many lines of code would you have to change?
OK, you are countering all arguments that it is trivial for you.Code:It's a simple matter to modify the code for differnt hand size if required.
Please post your updated routine if hand size is chosen arbitrarily by the user at run-time, perhaps even changed during program run. I might then post the same change (I didn't plan this change, because that would require using dynamic allocation over static).
Of course you can't program having any potential and bizarre requirement change in mind.Code:There are numerous other modifications that could be specified, such as a certain two cards must be in the straight, but to think of every condiseration before writing a piece of code is a complete waste of time.
But if you studied my example, you might find that for me that requirement would be easy to implement because my implementation already finds the cards that belong to the flush.
Why did I write it so, even if current requirements didn't demand it?
Because
a) the function produces this information naturally as a by-product without any extra cost,
b) it would have been stupid to throw away data that obviously could have versatile uses - for example for comparing two player's hands, if this function was to be reused in a multiplayer project.
And that precisely means non-reusability and non-extensibility. Especially since you do it in a way that burns all bridges for reuse - hard-coding, globals, magic values etc, etc.You only need to give it the functinality it needs to work.
I don't mind if you program privately in any way you like, but if you start bragging about the quality of your code - seeing that you are almost unable to produce a single line of code without exhibiting some bad practice - you get what you deserve.
You act like somebody who has only managed to learn to crawl - trying to convince people that crawling is the superior method of movement.
If that compiles in C, then you have just pinpointed another problem in your code. The proper signature should beCode:datasave(var1,var3); would also give a problem because you are using the function incorrectly.
and the compiler would stop bad things from happening.Code:void datasave(void);
Has it occurred to you that may-be it's you who is teaching that world is flat.People use to think the world was flat.
Think about it.
There were people teaching that at the time.
As to flatness of Earth, it was mostly a church dogma (at a time). People who knew had to keep silent while the vast majority was uneducated and just didn't care. (Just like non-programmers wouldn't have an opinion about global variables.)
The shape and even the size of the Earth was quite well known in the Antiquity, if I'm not mistaken.
Last edited by anon; 01-08-2008 at 06:04 PM.
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
>hmm... but you cannot, since anon specified that "you need a file with a different name".
So simple create the file the click on it the select rename - job done.
>Normally, I would applaud such a statement. Indeed, a function should do one thing and do it well. Likewise, one should write just enough code to meet the requirements. On the other hand, what you have done is to cripple the flexibility of the code from the start.
>I think that hardcoding the filename as "data.doc" is fine. It was an example, so you do not need to be so flexible as you do not have to meet such requirements. However, by the use of global variables, your functions are now tightly coupled to the dataptr and pname variables. Sure, this does not necessarily hurt extensibility, but it does hurt reuse.
>You can argue that these functions will never be reused in this example program. That may be true, but unlike hardcoding a filename, this example is an example of poor design: there is no space for possible reuse, despite the fact that allowing for such reuse also accomplishes the goal of writing just enough code to meet the requirements. Why fix the code to use those two variables alone when it could be written to vary, and yet use those two variables?
It's not poor design it did the job. If it did not work then yes that would be poor
design however that is not the case.
>Actually, we can blame other people's mistake on your function: you stated that your function returns a type of int. Oh, you didn't? Well, you did, since its return type was not stated explicitly, so it defaulted to a return type of int (assuming this is still standard, and not just some undefined behaviour). It is your mistake, fair and square
It is not a mistake the function does not return anything, where it that int it returned?
I can't seem to find it.
The example does what it says on the can. It save data and reloads it which was what
the original poster wanted I believe.
It was actually very difficult to get the program to work as there were some strange
data alignment problems with it. When you read the data back in some variables would
be right and other wrong, it took a while to fix it. I think thats why I had all those
extra header files in trying different things. Trouble is I forget how I resolved it.
It does not look like I did anything in particular but I must have changed something.
We know the Earth is a sphere because if you walked outside, you would notice a vanishing point where the sky meets the earth: had the world been a flat plane, we would be able to see the edges, like any other surface, such as a table. Unlike the concept of a global variable, the Earth is tangible and can be measured, or measured in relation to other parts of space or time. I am not aware of any mathematical proof for the Earth being round apart from the fact that we can measure the Earth's circumference or volume as a sphere.People use to think the world was flat.
Think about it.
There were people teaching that at the time.
That doesn't mean that every instance of conventional thinking is within the domain of problems that mathematics solves and will solve.
I can not believe you are actually entertaining this troll... Look at his answers for crying out loud, he is just messing around with you guys, this post was created as flamebait in the first place. Either ban him, ignore him, sue him for spamming, lock his posts, or whatever, but answering his questions does not serve ANY purpose. The way you're behaving now makes everyone here look childish.
Moderators, please do something about it.
Do you consider statistics as valid math?
How many lines of code would you have to change to introduce another array and save it to a different file?
How many lines of code would you generally have to change to reuse parts of the code of a fairly large progject in another project if all or most of your functions depend on each other via global variables and everything is hard-coded for a particular scenario?
How many bugs would changes or attempts at reuse introduce if all your functions work by having curious side-effects? Etc.
--------
Globals generally seem easier to novice programmers, as well as most other bad practices (spaghetti code, magic values), because they let one write small programs without much thought to structure. A thought occurs and you write the code.
With experience however, you should be able to recognize solutions concerning better structure etc more easily. (Unless, of course, you are satisfied with what you know and decide you can stop developing.) Although I am a hobbyist, it does not require me any effort to determine what would reasonably be the arguments and return value of a function that saves an array to a file, and I'm pretty sure most programmers feel the same.
So, you use globals effortlessly and can't reuse functions in different projects or even in the same program with different data (at least not without a tedious copy'n'paste job). I wouldn't use global data, would write the same functionality just as effortlessly with parameters and return value, and be able to reuse the code (within reason).
As an example of your bad structure, you are mixing completely different jobs in your functions. datasave() cannot possibly know whether it is called in a context where exiting is a valid error response.
Or the straight function, that instead of returning a result prints the result. That is, the function makes an unjustified decision what it should be used for.
The thing with this design and globals is that small changes are not localized to a single or a few places but may be required all over the place.
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
>OK, so you are a hopeless case.
>You post a thread bragging about how extensible and superior quality your code is. I give you a lengthy analyses. You disagree to everything and admit that your code indeed only works for this particular, very specific use case and there are no reusable parts for similar projects and that small changes cannot be made without major rewrites.
The program does what it set out to do and passed with fling colours.
>You mean, in Windows Explorer?
Yes, why are you using Linux?
>I would have thought that the more vital the data is, there more things you might want to try before you give up.
There is nothing you can do. There is a fatal error.
>If I made a lengthy Word document and for some reason Word failed to save it, I wouldn't be happy if the program just chose to exit.
Neither would I but these things happen from time.
It low level I/O has failed there is not really much else you can do.
>OK, but you haven't answered what you would do if your boss came to you and said there needs to be two arrays or if you simply changed your mind.
Depends I could just rename the file and variable and function if I wanted a quick fix
or pass some values to the function or whatever.
>Being ready for such cases is all that extensibility is all about. I find it very practical to program with a little margin for extra requirements / requirement changes, and in this case I would simply add the other array and call the same functions with different arguments. As far as the file-routines are concerned, only a coulple of lines would be added. How many lines of code would you have to change?
Well the function is only a few lines. You could get it all on one line I expect.
>OK, you are countering all arguments that it is trivial for you.Code:It's a simple matter to modify the code for differnt hand size if required.
>Please post your updated routine if hand size is chosen arbitrarily by the user at run-time, perhaps even changed during program run. I might then post the same change (I didn't plan this change, because that would require using dynamic allocation over static).
>Of course you can't program having any potential and bizarre requirement change in mind.Code:There are numerous other modifications that could be specified, such as a certain two cards must be in the straight, but to think of every condiseration before writing a piece of code is a complete waste of time.
But if you studied my example, you might find that for me that requirement would be easy to implement because my implementation already finds the cards that belong to the flush.
>Why did I write it so, even if current requirements didn't demand it?
>Because
a) the function produces this information naturally as a by-product without any extra cost,
b) it would have been stupid to throw away data that obviously could have versatile uses - for example for comparing two player's hands, if this function was to be reused in a multiplayer project.
>And that precisely means non-reusability and non-extensibility. Especially since you do it in a way that burns all bridges for reuse - hard-coding, globals, magic values etc, etc.
I use bits of my code all the time without a problem.
>I don't mind if you program privately in any way you like, but if you start bragging about the quality of your code - seeing that you are almost unable to produce a single line of code without exhibiting some bad practice - you get what you deserve.
Code is code, the oly concern here is that it solves the problem presented, which it did
I believe.
>You act like somebody who has only managed to learn to crawl - trying to convince people that crawling is the superior method of movement.
No I just address the issue at hand.
Well it is funny you should say that as I strugged with this p........ poor editor trying to
reply to you post.
No doubt the people who wrote vBulletin software had extensibility in mind at the time.
Yes it will be easy to modiify in the future but it is a pain to use in the present.
If that compiles in C, then you have just pinpointed another problem in your code. The proper signature should beCode:datasave(var1,var3); would also give a problem because you are using the function incorrectly.
>and the compiler would stop bad things from happening.Code:void datasave(void);
Nothing 'bad' happens coe has been running well for some time now without problem.
Which is more than I can say for, Windows XP, Internet explorer, Outloook express, Firefox.......etc.........etc...etc.......all extensible no doubt.
>Has it occurred to you that may-be it's you who is teaching that world is flat.
Not a chance.
>As to flatness of Earth, it was mostly a church dogma (at a time). People who knew had to keep silent while the vast majority was uneducated and just didn't care. (Just like non-programmers wouldn't have an opinion about global variables.)
The shape and even the size of the Earth was quite well known in the Antiquity, if I'm not mistaken.
I hear next version of C++ will include flat earth classes.
There is obviously no point to say anything constructive because it is going in circles.
You are right in all points. Tada!
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
Hmm this topic is confusing. Not exactly sure what's going on but i think using sockets locally is the best way for two programs to share data.
Well here's a crazy idea, but what if you prompt the user to enter a different filename and try saving it again?Originally Posted by esbo
Why are you yelling at me?Well... hmm. Actually, no. That seems really odd. You would think that they would have proof somewhere.Did you actually see any proof of this?Thanks esbo!Where is there proof?
I would prefer a mathetical proof if possible, but if all you can find is some windbag waffling on using big ill defined words he has made up then I will take a look at it.
I couldn't find any with no big words though...
Here are some that are some of the reasons given to me:
http://en.wikipedia.org/wiki/Global_variable
http://www.infis.univ.trieste.it/C/N...tion3_6_3.htmlhmm... maybe. I don't think I've thought about it quite that way before. I'm not really that good at math.You see the thing is I have no problems programming as I so so where are all these problems
which I am supposed to be having.
I have experience none whatsoever. Maybe you have had problems?
Maybe the person who taught you how to program had a lot of programs?
Maybe he was just a rubbish programmer and will have problems however he programs
it is just that it will take twice as long to wriite the program.
And come to think of it, I'm always having problems with extensibility in my programs. If it's not one thing, it's another. If it's not that, it's code in spot C. There's so many things that manage to go wrong. Isn't there an easier way?
I think you may be on to something.
It is from a program which does a job, it processes some files, aggregates some of the
data and saves it to a predetermined file. When it has finished it saves the results into
the file.
To out things into context here is the end of the program:-
So the only thing is does not do is close two other unimportant files, maybe it should tryCode:datasave(); fclose(ptr2); fclose(ptr3); /* printf("\ndone\n"); */ }/*main */
however all that is irrelevant, the program works and it will only fail if there is a major
problem with my computer, such as disk failure, in which case I am up the creek anyway.
Changing the filename at this stage won't help. It would just be unnecessary work which
would increase the complexity of the program and possibly introduce new bugs.
I keep things as simple as possible, it is the sensible thing to do.
The error checking is only really there to help debug the program while developing it,
once it is finished it is not important, it will work, and if it does not it will be obvious why.