esbo's data sharing example

This is a discussion on esbo's data sharing example within the C Programming forums, part of the General Programming Boards category; Originally Posted by laserlight You are right. Neo1 is wrong to say that all functions must return some value. Indeed, ...

  1. #31
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by laserlight View Post
    You are right. Neo1 is wrong to say that all functions must return some value. Indeed, Neo1 gave a counterexample in the same post: functions with a return type of void do not return a value. On the other hand, Neo1 also pointed out that your functions are supposed to return a value since you did not specify that their return type was void. Since you do not intend them to return values, you should declare them with a return type of void.


    I thought you might say that. Well, I am not making the claim so I do not need to either

    So, what claim would you like to make concerning global variables?
    Global variables are easy to use.

  2. #32
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,632
    Global variables are easy to use.
    Provide a mathematical proof that global variables are easy to use.
    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

  3. #33
    The larch
    Join Date
    May 2006
    Posts
    3,573
    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.

    No you can just rename the file.
    You mean, in Windows Explorer?

    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.
    I would have thought that the more vital the data is, there more things you might want to try before you give up.

    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.

    I only had one array to save so that what I did.
    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.

    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?

    Code:
    It's a simple matter to modify the code for differnt hand size if required.
    OK, you are countering all arguments that it is trivial for you.

    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).

    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.
    Of course you can't program having any potential and bizarre requirement change in mind.
    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.

    You only need to give it the functinality it needs to work.
    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 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.

    Code:
     datasave(var1,var3); would also give a problem because you are using the function incorrectly.
    If that compiles in C, then you have just pinpointed another problem in your code. The proper signature should be
    Code:
    void datasave(void);
    and the compiler would stop bad things from happening.

    People use to think the world was flat.
    Think about it.
    There were people teaching that at the time.
    Has it occurred to you that may-be it's you who is teaching that world is flat.

    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 05:04 PM.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  4. #34
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by laserlight View Post
    .
    >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.

  5. #35
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,666
    People use to think the world was flat.
    Think about it.
    There were people teaching that at the time.
    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.

    That doesn't mean that every instance of conventional thinking is within the domain of problems that mathematics solves and will solve.

  6. #36
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by laserlight View Post
    Provide a mathematical proof that global variables are easy to use.
    You dont have to worry about the scope of the variable so you can use it anywhere in the
    program. With local cariables you have the extra concern of the scope thus global variables
    are easier to use.

  7. #37
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    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.

  8. #38
    The larch
    Join Date
    May 2006
    Posts
    3,573
    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.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  9. #39
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794

    >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.

    Code:
    It's a simple matter to modify the code for differnt hand size if required.
    >OK, you are countering all arguments that it is trivial for you.

    >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).

    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.
    >Of course you can't program having any potential and bizarre requirement change in mind.
    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.

    Code:
     datasave(var1,var3); would also give a problem because you are using the function incorrectly.
    If that compiles in C, then you have just pinpointed another problem in your code. The proper signature should be
    Code:
    void datasave(void);
    >and the compiler would stop bad things from happening.

    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.

  10. #40
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by MWAAAHAAA View Post
    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.
    If anyone is a troll it is you.
    You have nothing constructive to say.

  11. #41
    The larch
    Join Date
    May 2006
    Posts
    3,573
    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.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  12. #42
    Registered User
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    217
    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.

  13. #43
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by esbo
    >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.
    Well here's a crazy idea, but what if you prompt the user to enter a different filename and try saving it again?

  14. #44
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Quote Originally Posted by esbo View Post
    Heard??? Heard?
    Why are you yelling at me?
    Did you actually see any proof of this?
    Well... hmm. Actually, no. That seems really odd. You would think that they would have proof somewhere.
    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.
    Thanks esbo!

    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.html
    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.
    hmm... maybe. I don't think I've thought about it quite that way before. I'm not really that good at math.

    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.

  15. #45
    Fountain of knowledge.
    Join Date
    May 2006
    Posts
    794
    Quote Originally Posted by cpjust View Post
    Well here's a crazy idea, but what if you prompt the user to enter a different filename and try saving it again?
    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:-

    Code:
     
    	
            datasave();
    	
    	fclose(ptr2);
    	fclose(ptr3);
    
    /* printf("\ndone\n"); */
    
    
    }/*main */
    So the only thing is does not do is close two other unimportant files, maybe it should try
    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.

Page 3 of 4 FirstFirst 1234 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. COM data sharing
    By George2 in forum Windows Programming
    Replies: 1
    Last Post: 09-02-2007, 02:48 PM
  3. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  4. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  5. Replies: 1
    Last Post: 07-31-2002, 11:35 AM

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