Archived

This topic is now archived and is closed to further replies.

ChaosCommand

Am I a Bad programmer if I can't remember the majority of functions and code

Recommended Posts

It has been about 4 months since I REALLY started learning programming in c++. I have chekd out the C++ tutorials and Windows tutorials. But I just can''t seem to remember the stuff. I always start a project, but I always have to go back to tutorials or a book to see exactly how to do this stuff. Maybe I am a bad programmer that is just stupid when it comes to code that can''t get it, and should go into another field? Can someone tell me the answer to this: ------------------------------------- int main() { while(1) // While 1, what does it mean? { // HOW DO I BREAK OUT OF THIS // LOOP? If Possible? cout << "All Your Base Belong To Us" << endl; } return 0; }

Share this post


Link to post
Share on other sites
Hi

If I am not wrong, while(1) is an infinite loop, a loop that keeps runnung. If you want to break out of that loop you can put another condition on while, or use break;
O yeah, it is better to write a lot of programs if you want to remember someting. First just copy the code, play with it. And then make a program that differs from the tutorial, but uses the same concepts, without looking at the tutorial.

[edited by - White Crow on August 15, 2003 5:41:22 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by White Crow
Hi

If I am not wrong, while(1) is an infinite loop, a loop that keeps runnung. If you want to break out of that loop you can put another condition on while, or use break;
O yeah, it is better to write a lot of programs if you want to remember someting. First just copy the code, play with it. And then make a program that differs from the tutorial, but uses the same concepts, without looking at the tutorial.

[edited by - White Crow on August 15, 2003 5:41:22 AM]



Thanks, maybe I should be trying to make more programs, but it just gets annoying at the fact that I keep on having to write these tiny text programs, and can''t yet make a game or something that I am proud of yet. I was kinda hoping I would at least be able to program a simple tetris or pong or breakout type clone by now.

I guess only time will tell, with more practice.

Share this post


Link to post
Share on other sites
Don't worry about remembering everything .. try instead to understand *why* things are the way they are .. hopefully you should end up remembering the details by accident.

Also remember that you're using one of the most complex/powerful languages available - it's a steep learning curve but (imo) a rewarding one.

while(1) // While 1, what does it mean?
{ // HOW DO I BREAK OUT OF THIS
// LOOP? If Possible?
cout << "All Your Base Belong To Us" << endl;
}

Breakdown of what's going on here:

while( )
means loop while 'expression' returns true (evaluating expression after each run-through).

In C/C++, anything which isn't 0 is true .. 1 will always be true so the loop will run forever.

The thing 'looped' is the statement or code block which follows the while .. in your case it's everything (code block) within the curly braces:

{
cout << "whatever" << endl;
}

You can break out of an infinite loop using the 'break;' keyword.

while (1) {
cout << "looping!" << endl;
break;
}

Is an 'infinite loop' which will run just once

As a general rule, I would advise against using 'magic numbers' anywhere, even somewhere like while(1) ... it's common practice, but as you're finding, it's not very helpful/readable.

while(true) is what you really mean.

And lastly .. be *very* careful with infinite loops. They can be very annoying to debug. Try either looping for a large, but fixed, number of iterations or putting a hard-coded limits while debugging/testing.

for (int i=0; i<100000; i++) {
}

or

int i=0;
while(true && 100000>i++) {
}

or

int i=0;
while (true) {
if (i>100000) { break; } else { i++; }
}



[edited by - SimbobX on August 15, 2003 8:25:10 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by ChaosCommand
quote:
Original post by White Crow
Hi

If I am not wrong, while(1) is an infinite loop, a loop that keeps runnung. If you want to break out of that loop you can put another condition on while, or use break;
O yeah, it is better to write a lot of programs if you want to remember someting. First just copy the code, play with it. And then make a program that differs from the tutorial, but uses the same concepts, without looking at the tutorial.

[edited by - White Crow on August 15, 2003 5:41:22 AM]



Thanks, maybe I should be trying to make more programs, but it just gets annoying at the fact that I keep on having to write these tiny text programs, and can''t yet make a game or something that I am proud of yet. I was kinda hoping I would at least be able to program a simple tetris or pong or breakout type clone by now.

I guess only time will tell, with more practice.



You''re not the only one man..I know what you mean because i''ve only been doing c++ for a few months myself...Well personally i''m sure that whenever you''re using an API such as DirectX/OpenGL memorizing all the function calls isn''t really that useful simply because there''s plenty of references on them out there. When it comes to language concepts such as pointers, class structures etc it simply takes some time and some practice as you said. I even remember when i had trouble remembering the simple

int main()
{
return 0;
}

lol, but over time, since you understand its purpose and you know why you need it all the time, it sticks in your brain. So i''m sure in the end, what you find most useful from tutorials, books or articles will be what you remember off the top of your head (but trivial code always poke''s around my brain )


no theory`

Share this post


Link to post
Share on other sites
heh i thought it would be so easy to. i''ve been on and off looking at c and c++ for the last 4 years now. I''ve just recently started studying and buckling down and covering all the fields regarding programming since the beginning of summer. If i put my mind to it i could make something now but it would be a hack job of copy paste style code. I''m going to hold off a little while on programming a game and focus on making things such as a notepad for windows or a similar program.


while(1) = infinite loop. the condition is allways true. i like to use these with a "break;" statement. break cuts whatever loop it is in regardless of condition.

Share this post


Link to post
Share on other sites
quote:
Thanks, maybe I should be trying to make more programs, but it just gets annoying at the fact that I keep on having to write these tiny text programs, and can''t yet make a game or something that I am proud of yet. I was kinda hoping I would at least be able to program a simple tetris or pong or breakout type clone by now.


It takes a hell of a long time to learn to program a game, this is simply because it is one of the areas of programming that is so wide reaching and you need to have a lot of skills.

Really the only way to learn is to push youself, take a small text based app and then say to your self, right it randomly selects a sentence from a list, so how can I make it respond to a question i give it by selecting the right sentence as the answer. Never give up on your challenges and you will suceed.

Don''t worry about remembering everything, its soooo easy to forget little things and make a mistake, for example i forgot that doubles are actually just bigger versions of floats and I spent an entire day trying to fix a problem that didn''t exist because of it.

Good luck

You cannot see what does not want to be seen.

Share this post


Link to post
Share on other sites
Sounds like you may be starting too big if you''re looking at Windows tutorials. Try to make little programs that just loop and throw around numbers.

You can even step through them using the Visual C++ debugger and breakpoints to give you a good idea of the state of your program.


Why you shouldn''t use iostream.h - ever! | A Good free online C++ book

Share this post


Link to post
Share on other sites
quote:
Original post by simbobx
one of the most complex


Bah. You''ve not played with INTERCAL.

A computer language, as I see things, is just like any other language; there''s a grammer and a vocabulary (and when it comes to computer languages, I''d say that the grammer also includes language keywords). The vocabulary is usually vast.

So that''s what dictionaries are there for.

Concentrate on learning the important parts of the language - the grammer and keywords - rather than the vocab (or large collection of APIs). I still have MSDN open pretty much whenever I''m coding, and I''ve been doing it for 4 years; I expect I will always have it open, because why try committing it to memory when the information is at your fingertips anyway?

There''s really no problem in not knowing the types of parameters for WinMain() or the sequence of function calls required to draw a bitmap to the screen with GDI. All you have to know is how to find that information when you need it. The web, MSDN, books, a helpful friend... all require good technique for formulating a query.

Superpig
- saving pigs from untimely fates, and when he''s not doing that, runs The Binary Refinery.
Enginuity1 | Enginuity2 | Enginuity3 | Enginuity4

Share this post


Link to post
Share on other sites
Don''t worry, sooner or later you''ll refer to the docs less and less until you can do it all in your head. Trust me, I had to check up EVERYTHING when I first started up but now I practically code DirectX without the docs. It''ll all come by with practice.

---
Brent Gunning | My Site

Share this post


Link to post
Share on other sites
Thanks you guys, that is the kinda motivational push I am looking for.

I guess I am just being impatient, and would just like to know if this is what I would want to do. I looked at programming when i was 13 years old (now i''m almost 17) and at first, I thought it looked like something I would like to do. But I just didn''t really ever push myself. These past 2 months I have learned more than I have in the past 3 years just from trying so hard.


If anything, it is nice to know for me that I am not the only one having troubles with remembering this stuff.


I will keep trying though.

Thanks for the replies.

Share this post


Link to post
Share on other sites
If you haven''t tried a gfx library like SDL or Allegro you REALLY should. These libs provide high level functions that do all the DirectX dirty work for you (in Windows they are directx wrappers) With Allegro or SDL you can create a window and load and draw bmps in 10 lines of code or less.

This is a fast and ''easy'' way to get results. Then if you''re so inclined you can go on and learn the API (Directx or Opengl) or (like ALOT of people, me included) simply use the libs to implement more advanced stuff. Why reinvent the wheel? They are both fully mature and the result of the work of ALOT of really smart people.

Share this post


Link to post
Share on other sites
I have been doing hobby programming with C++ for over 7 years now. It has a very high learning curve, but is worth the effort. Don''t worry about not learning it within a few months. It will take years before you are ''comfortable'' it. Keep your MSDN Help Library and your books open and learn from them.
Writing a Windows program is another steep learning curve that requires a solid foundation in C++. If you want to learn how to do graphics in DirectX, then a minimal understanding of Windows programming is desirable--nothing fancy, just know how to create a window and process messages. DirectX isn''t bad to learn if you can afford a few expensive books, but it will take alot of time. So relax, you aren''t expected to learn how to program Tetris within 6 months.
I understand about being bored with silly little text programs, but write a text game of some sort, you''ll be suprised how quickly you learn when its something fun you are working on.

There are some languages out there, Java or Visual Basic that are ''easier''to learn, but C++ is the real deal and if you stick with it, you''ll grow to appreciate what it can do for you.

Share this post


Link to post
Share on other sites
I''m going to start releasing my series of tutorials in about a month or so. They will go over stuff like that, and more so. Don''t you worry.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I used to have the same problem. Then I started using this approach.

Read through the example, understand how it flows, take note of the components in the program and how they work together.

Then without using the tutorial, write it out. If you need to refer, go ahead. Add a few features of your own as you please as you proceed.

After several practice, you don''t even need the example.

Share this post


Link to post
Share on other sites
Consider making a text adventure game.
You can eliminate all the mucking about with graphics and windows API's completely and just concentrate on making a functioning game.

In my opinion, text adventures are among the best games ever made, even though they get little respect these days.

[edited by - SpaceRogue on August 16, 2003 9:22:27 AM]

Share this post


Link to post
Share on other sites
Hi,

I was in your situation when I first started programming, and like what everyone else said, it comes with practice, and there is nothing wrong with having to refer to tutorials and references. You wouldn''t how much or how little you know until you put it to use in a project.

In fact, why remember something if it''ll be there when u need it? Save your memory for stuff like exams.

Also, it helps to explore other related topics such as physics and maths instead of just programming. If you get frustrated, take a break from code and explore kinematics or linear algebra. At first none of the topics may seem to relate but they will converge sooner or later.

Its very hard to be a good prorgammer without knowing a bit of other things ie maths/physics. One example is in code optimization, analyzing the time complexity is maths.

Share this post


Link to post
Share on other sites
To directly answer the topic''s title: don''t worry too much about memorising standard library functions, but you will need to learn how control structures and language syntax works. There''s a difference between "learn" and "memorise"

Basically, you need to learn how to use constructs like "if", "while", "switch", how to make and call functions, how to declare variables etc. And the best way to learn is to not do too much at once, and learn (or at least, understand once) a language element before you move on.

The language itself isn''t really something you memorise, so trying to rote learn it isn''t going to help you. It''s, well, like learning to speak a language. The only thing you really have to memorise at all is the vocab (the standard libraries), but there''s nothing wrong with using a phrase book, so to speak. But a phrase book is the wrong place to learn grammar

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
The only reason I ever remember any of the function names/etc. is because I have had to step through them in debug mode so many times, and tweaked the parameters a million times..

Share this post


Link to post
Share on other sites
I''ve programmed since I was 9... C++ since I was about 16. I''m now 28. I still use reference books all the time. Sometimes I''ll be in a groove where I can just work without reference. Don''t worry about what you can remember. As long as you can *FIND* the information, you''re okay. Programmers usually have to jump from one language to another, sometimes not even knowing the language. What seems to be important to me is that you can quickly settle into a language, mine the necessary info and implement without prior knowledge.

Professionally, I''m never doing the same routine. It''s rare I''m NOT working out of a reference.

- Jay


[ Here, taste this ]

Share this post


Link to post
Share on other sites