| Random Tip #2 - Utilizing Whitespace | |
|
|
Author | Message |
---|
Wander C++ Expert
Posts : 72 Join date : 2010-08-10 Location : Florida
| Subject: Random Tip #2 - Utilizing Whitespace Wed Aug 11, 2010 3:15 pm | |
| In my personal experience, I have noticed that the code must stay organized throughout the process of coding it. As your code gets bigger, it becomes imperative to keep it as neat as possible. One of the ways that I keep my code organized is I use the whitespace that C++ gives to me. Spread your code out. Don't spread it out too much though. The reason C++ allows you to use whitespace (empty lines and spots where code isn't present) is so you CAN keep your code organized and you can read it. - Code:
-
#include <iostream>
using namespace std;
int add(int,int);
int add(int a, int b) { return a+b; }
int main() { int a, b, c; cout << "Please enter a number: " << endl; cin >> a;
cout << "Please enter another number: " << endl; cin >> b;
c = add(a,b);
cout << c << endl;
system("PAUSE"); return 0; } Notice how I separated the sections where different things are going on. Spacing everything out like this allows you to better read the code. I also spaced the operators one space away from the actual variables. Think about it this way. If you do this then your code takes up more lines and you can brag about how large your code is. -Wander I'll be posting more about C++ here on this forum. For my in-progress line of tutorials, visit my website: http://letslearncpp.forumstech.com/ For the corresponding video tutorial line; my YouTube channel is: LetsLearnCPP | |
|
| |
DarK_DemoN »[\...VIP.../]«™ AdminiStratoR
Posts : 584 Join date : 2010-07-20 Age : 31 Location : Hacking Kingdom, USA
| Subject: Re: Random Tip #2 - Utilizing Whitespace Wed Aug 11, 2010 4:44 pm | |
| lol, good point, larger=brag rights. lol | |
|
| |
Wander C++ Expert
Posts : 72 Join date : 2010-08-10 Location : Florida
| Subject: Re: Random Tip #2 - Utilizing Whitespace Wed Aug 11, 2010 4:46 pm | |
| heck yeah! XD I once wrote a program that was over 3000 lines of code hahahaha | |
|
| |
DarK_DemoN »[\...VIP.../]«™ AdminiStratoR
Posts : 584 Join date : 2010-07-20 Age : 31 Location : Hacking Kingdom, USA
| Subject: Re: Random Tip #2 - Utilizing Whitespace Wed Aug 11, 2010 4:56 pm | |
| holy crap! lol. seriously spaced out im guessing | |
|
| |
Wander C++ Expert
Posts : 72 Join date : 2010-08-10 Location : Florida
| Subject: Re: Random Tip #2 - Utilizing Whitespace Wed Aug 11, 2010 4:57 pm | |
| Nope. It was actually before I even thought about organizing my code. I was a jumbled mess. Lol | |
|
| |
DarK_DemoN »[\...VIP.../]«™ AdminiStratoR
Posts : 584 Join date : 2010-07-20 Age : 31 Location : Hacking Kingdom, USA
| Subject: Re: Random Tip #2 - Utilizing Whitespace Wed Aug 11, 2010 8:06 pm | |
| lol wow then thats a huge program. whats it do? | |
|
| |
Wander C++ Expert
Posts : 72 Join date : 2010-08-10 Location : Florida
| Subject: Re: Random Tip #2 - Utilizing Whitespace Wed Aug 11, 2010 8:10 pm | |
| It was a game. Lol! Me and a friend were working on it together. I had the idea to make it and I started making it. Got to about 1000 lines and then showed him the code and we teamed up. We added a GUI, keyboard controls, cheats, AI, and color schemes haha. | |
|
| |
DarK_DemoN »[\...VIP.../]«™ AdminiStratoR
Posts : 584 Join date : 2010-07-20 Age : 31 Location : Hacking Kingdom, USA
| Subject: Re: Random Tip #2 - Utilizing Whitespace Wed Aug 11, 2010 8:15 pm | |
| i want to do that lol. i havent even compiled my own src yet | |
|
| |
Wander C++ Expert
Posts : 72 Join date : 2010-08-10 Location : Florida
| Subject: Re: Random Tip #2 - Utilizing Whitespace Wed Aug 11, 2010 8:16 pm | |
| Get on it, boy! lol XD start learning. i have an open source section on my website where me and my friend post ideas. not many idea yet, but soon to be more | |
|
| |
DarK_DemoN »[\...VIP.../]«™ AdminiStratoR
Posts : 584 Join date : 2010-07-20 Age : 31 Location : Hacking Kingdom, USA
| Subject: Re: Random Tip #2 - Utilizing Whitespace Wed Aug 11, 2010 8:20 pm | |
| ill make sure i register at your site | |
|
| |
Wander C++ Expert
Posts : 72 Join date : 2010-08-10 Location : Florida
| Subject: Re: Random Tip #2 - Utilizing Whitespace Wed Aug 11, 2010 8:20 pm | |
| okay sweet | |
|
| |
Sponsored content
| Subject: Re: Random Tip #2 - Utilizing Whitespace | |
| |
|
| |
| Random Tip #2 - Utilizing Whitespace | |
|