| 1. |
Solve : Gone for a day or two? |
|
Answer» Of COURSE, when I get involved with a project, it ends up consuming all my time. I'm working on a large C++ program now to give me practice with Object-Oriented Programming and to practice making code on a large scale. (Well, large for now; I know I'll make longer programs later in life) Good luck with your project Dilbert. Thanks. *urf* 2:20 AM... 812 lines of code... still not to the main function yet... sooo tired... ZzZzZzZzGood luck Dilbert.What game are you making? I was making a C chess game. I got up to 1467 lines of code before it got too complicated and disorganised it was beyond my ability. Lines in themself don't tell much either.. each person has his own preferences on how much white space to use, etc.I'm making a command-line interface game. I'll explain it in more detail once I've GOTTEN every last detail down, but it revolves around my house. Each room is a separate class, or object. Normally, I'd have each object in the room inherit from the room, with its own properties, in a "has-a" relationship. However, due to the nature of the game, the member functions are various commands that can be executed. That is the purpose behind int main(): To accept commands, parse them based on what room is in use, and pass control to another parser which parses on a room-by-room basis. In a sense, I outsourced int main() for the most part. The class member functions take up the majority of the work. But I'm still writing them. Then, there's the minor setback I found this morning, which was the result of coding at midnight. When the project is tentatively complete, I'll post the game and ask for playtesters to look for bugs. That should be... interesting. I personally like to think my code is foolproof after all this coding, but I know that I have to have made mistakes. As for my whitespace preferences, it's rather simple: I leave blank lines between functions and classes. Classes are also broken with whitespace per section, i.e. constructors and destructors are separate from the list of POSSIBLE commands, etc. I also will devote some space, if necessary, to comments. I'd say about 80% of my lines are actually used for code. EDIT: Oh, and to make sure I can read it: I liberally indent. 3 spaces for anything inside an opening brace (I've nested as far as 9), with each closing brace lined up with its partner.Hehe. I like to use lots of whitespace, often having blank lines within functions to seperate different sections. It seems to make my code easier to understand for me. Also what I meant was things such as {} taking up whole lines on their own. Indenting with spaces? Why not use tab. My C++ editor actually does most of the tabs for me automatically.Well, I use a monospace font, so space is just as easy. Also, I edit in Notepad2, which, when in C/C++ Source mode, when you press Enter will automatically indent to wherever the previous line started. Oh, and I'll also do this: void myFunction() { //Some stuff } So it can look something like this (I do use extra comments if it gets this bad, which is rare): void myFunction() { if(!myVariable) { for(int i = 0; i < 4; i++) { //Stuff } } else { //Other Stuff } } EDIT: D'oh! I found another midnight ERROR: I started trying to initialize member variables in the class declarations! Bad bad bad! Shame on me! (That won't COMPILE.) If I keep catching these as I go, I might have at least a silver-star program. (My key: Bronze-Star programs have only minor syntax errors, silver-star programs compile the first time, but may or may not have runtime errors or bugs, while gold-star programs have no errors from the first time it is compiled and run, forever. In other words, a "hello world" program. )Poor, poor Dilbert. "when you press Enter will automatically indent to wherever the previous line started" oh wow! not Get Microsoft Visual C++ Express Edition - automatic indentation is the way to go. And, suprisingly for Microsoft, it's a free download. for(int i = 0; i < 4, i++) missing a semi-colon? I think the code looks neater like this void myFunction() { if(!myVariable) for(int i = 0; i < 4; i++) //assuming only one line here else //assuming only one line here } Of course if you need to add extra lines later, you need to add the {} again, but if you're completely sure only one line is required, this way is clearer for me.Yeah, but for this project, where I have "//Stuff", it's usually a few couts, along with variables set and possibly other ifs or loops. It can get rather confusing without the braces even if it is one line. Yes, I screwed up on the post and made a comma. I do intend to look over my program before I compile for that stuff, but I'm not making that kind of slip very often in the actual code. Quote Poor, poor Dilbert. "when you press Enter will automatically indent to wherever the previous line started" oh wow! not I'll get VC++ Express. But I'll want to finish this particular project the way I'm doing it now... then use the auto-indent in the future. See, I have Bloodshed's Dev-C++, but the auto-indent is very screwed up. So... I got a little discouraged and used Notepad2, which has syntax highlighting and the like. (I particularly like the fact that when the cursor is next to a brace or parenthesis, it highlights it and its mate in bold red, so I know whether I skipped a } or a ). ) |
|