Ok, so, the original program I wanted to improve (netpong), it turned out that I couldn't (yet) figure out a way to merge the two aspects into a single function, since they hard-code different keymappings. Moving on, the next program I wanted to work on (shareaza) was FAR too complicated for me to get into (yet). I still think it's within my abilities, but I need to get a bit more familiar with the structure of the language again. It's been a while since I've worked with C++. Finally, I think I've found something more my present speed, which will let me get refamiliar with the language and also work on structure. In a group of C++ tutorials, I found a hangman program. A VERY VERY BAD hangman program. It functions, but it isn't the least bit object oriented (it has exactly one function other than main, and all it does is run a set of four if-then statements that would probably be better formulated as a single switch statement). It also doesn't even approach human-readable... most of its variables are single letters with no indication of what they do unless you read through the code and find them in action, and they're all declared in a clump. It looks like the programmer was probably taught this as a way of shortening the program, in that you only need one declaration of variables per variable type and the variable names themselves take up less space, but any speed increase due to that would be negligible and completely countered by the increased time needed to understand the program in order to maintain or update it. I'm going to see what I can do to get it fixed up, then I'll post both versions of the code and see what people think.
Tags:
no subject
no subject
However, they are declared in a group that includes a variable to hold the length of the word, first loop count variable, a variable to hold the number of guesses remaining, a variable to hold the number of spaces in the "word", a variable used to enter characters and commas into a string that is being used as an array to represent letters already chose, and a variable that is being used to hold a random number for a do-while loop that chooses the word. These variables are, respectively, named nothing more descriptive than: l,i,ng,n,k,x And that is just the integers. There's also a group of chars that are similarly helpful: char c,h,ch,ch1,ch2. c holds lines of the input file as it is being read in. h holds a user's choice of a word category. ch holds guesses, ch1 holds a choice of whether or not they would like to play again, and ch2 holds an initial menu choice. Frankly, the whole thing is written very poorly. I've seen (and written) more elegant code in BASIC.
no subject
no subject
http://www.bloodshed.net/c/hangman.zip
I'm going to work on it in two steps: First, I'm going to produce a cleaned up version that does the exact same stuff without the needless overhead, and in a more orderly fashion. Then, I'm going to see about extending it and making it more functional.
I know I'd probably be better off, in a sense, just starting over from scratch... but this is serving as a good lesson in working with someone else's code, and also helping me rebuild my skill with c++ "grammar" and "vocabulary", which has admittedly atrophied from even the small degree I once possessed.
no subject