Hello, bored reading and a bunch of questions.
Hello to all.
First post, that's right, so it's time for a short presentation. (When I say short I really mean a long one, I do that allot).
I'm 14, from Portugal and started programming C++ about one and a half year ago. Before that, I was stuck with HTML, CSS and basic JavaScript programming, so I decided it was finally time to move onto something more 'non-web-related'. I would never be able to have classes. First because I've never really learn't anything about anything that isn't tutored at school outside of it.
I decided to google for something and I found this site which I must say that, although it is not perfect, it sure taught me allot! So thanks to all of Regular Forum users and tutorial writers and all those people in charge of this domain!
Now, some info on what i've done 'till here.
Back a year ago when I was still reading tutorials I had this 'great idea' of the 'prefect game'. I decided I would work on it and so I did, I started off with my 'archaic-like' programming and made a quite nice engine that outputted to console. No wait, scratch that, what I really meant was that: 'I made a really crappy engine that caused lot's of errors and got me tired of programming until I gave it up'. yes, looking back I think that's the correct description.
Time passed and I never touched Dev-CPP again (back in the time when I thought Dev-CPP was a compiler and I thought that what they did was magic to turn code into executables) until the day a friend of mine asked me how 'the Game' was. Then I decided I would make a GUI, replacing all the old 'colourful console codes' with API one's. I evolved throughb phases, programmed one week, didn't program the next one and so on.
I got lot's of nice functions for everything since registry manipulation to Window painting functions and C-like Strings functions. (Yes, although I consider myself a C++ programmer I rarely use String, Is tick with pure ol' char *||[].
I got tired again after all, I have a life, a school life...gave up the project, the Engine was way to buggy. I decided to port lot's of code and make another game, a project 'Company Tycoon'...well, it's dumped now, at least suspended.
We're getting closer to present day, at the moment we're taking of December 2007 when I was focused on learning deeper concepts of programming, I started involving projects like OpenTTD and ReactOS and decided to dump my 'old programming style'. Well, I didn't Ğdecideğ, it just happened. I dumped my 'all code in headers', 'slower is better' and 'hey, who needs Linked Lists? Arrays do the job!' pathetic theories...
I started learning WSocket programming and made a chat application. Simple and in the console. Multiple clients connect to server.
Let's just say I got a moving project, haven't stopped programming since then and have a Chat Application working with a good GUI that allows to chat, multiple commands like name changing, name memorizing, list commands and lots of future features I have already planned to code (and thought of how to code them). But most important, I implemented a way to send files (OK, it isn't that amazing, but let's think I'm 14, i've been working alone without posting code anywhere and I managed to get all my friends to use this because it sends files up to 2000% (in extreme situations) faster than Skype or MSN and because they simply like the idea of using and testing some made by someone they know).
BTW, at the moment I'm working on things like Admins, I mean User Privileges, I call it Client Privilege Protocol.
Well, that was it, I don't know if you read it but if you did you've got a hell of a patience! I myself wouldn't be able to read something about a 14 yrld portuguese kid.
Now to my questions, I believe they are really basic and probably many won't answer them but here they come.
JUMP HERE IF YOU DON'T CARE ABOUT MY PRESENTATION
- Which one do you think is better? (I know, regular question, just want your opinion)
Code:
void SomeFunction(SomeType x) {
if(x) {
//Some Code...
}
else {
return; //Error. Escape
}
}
Code:
void SomeFunction(SomeType x) {
if(!x) return; //Error. Escape
//Some Code...
}
Code:
void SomeFunction(SomeType x) {
//Go One through code
Function1();
Function2();
//Now we need to use x
if (!x) return; //Error. Escape
}
- Do you agree with loops like:
Code:
bool bExit=false; while(!bExit) { //work
bExit=true; //Exit the loop}
or do you think the best choice is:
Code:
while(true) { //work
break;//Exit the loop}
- Ok, this is gonna get complex. Let's imagine function 1:
Code:
int g_aValue;
void Function1(void) {
while (true) {
FunctionX();//Do Some work
FunctionY(); //Some more Work
g_aValue=FunctionZ(); //Affect g_aValue
if(GottaExitCauseWorkIsDone()) break;
}
}
Now let's imagine that is a long loop and that we need to use g_aValue elsewhere in parallel using threads let's say to print text so we'd have that:
Code:
int g_aValue;
void Function1(void) {
FunctionX();//Do Some work
FunctionY(); //Some more Work
g_aValue=FunctionZ(); //Affect g_aValue
}
void Function2(void) {
cout<<g_aValue; //Access g_aValue and print it
}
Would Function2 slow down Function1 by accessing its memory address? If yes, what would you recommend to me to keep Function1 the faster as possible?
- What do you think is the fastest way to compare to strings (I mean C Strings) so that they are exactly equal? (I have my own code, wanna check yours if you may)
- For WSockets programmer's. Imagine I have a function that sends a piece of data through a socket and that immediately after that sends another piece of data. What has happened to me was that these two pieces of data merged in the same (I think it's because one Send does not Equal to one Recv)
- Do you agree with dynamic arrays (I mean arrays that are defined according to the value of another array or size)?
- I have experienced some problems with what I call 'memory saving'. Memory Saving and Time Saving are everything to me, so I did a risky business which put me a great ammount of bugs in the Chat (and I figured out that my 'perfect game' had these problems) so, here comes the code. I had this code in my Chat Application (cutting down other variables and leaving the essentials):
Code:
struct Client
{
char *Name;
char *CurrQueueAct;
Client::Client();
};
Client::Client()
{
Name = new char;
CurrQueueAct= new char;
}
Well, I thought it seemed ok and it didn't have a defined size so it would be great! WRONG, I don't know what I did but I got to a point where CurrQueueAct would overlap Name and this happened with other variables too. My point is: Is this wrong? if it is, what is it?
Well, I am really sory for boring you so much, so I'll leave my other questions for later. I just wanted to say that I have my theories for all these questions but want to know if I am right.
Thank you.