2 not so important questions!
First of all, are pointers really that important? I can and have, hesitantly used them but for some reason I''m just really uncomfortable with using them. Is using global variables really that bad?
And second of all, after a few days constant programming my arse really hurts! Seriously how do people do it?
quote: Original post by flukus
First of all, are pointers really that important? I can and have, hesitantly used them but for some reason I''m just really uncomfortable with using them. Is using global variables really that bad?
Yes, pointers are very important. Yes, global variables are bad, I speak from experience (most of my learning of ''good coding practices'' has come from finding out just how hard it is without them). When your projects surpass a certain size it just becomes far to hard to track down bugs or make any changes to your program.
quote: Original post by flukus
And second of all, after a few days constant programming my arse really hurts! Seriously how do people do it?
Expensive (well, you don''t have to spend that much) chair. Get a decent one that isn''t rock solid. For instance my chair has gel arm rests (like the mousepads, only firmer). This makes leaning on the armrests far more confortable.
That''s three questions
Pointers are very important. Learn to use them, and don''t be afraid of them.
Global variables are very bad, in most cases. It''s usually not bad having one or two global variables, but I''ve worked on projects with hundreds of them, and it''s impossible to keep track of them all (and non-reentrant functions suck when it comes to debugging - you can never tell the side-effects of a function which modifies global variables).
And I can''t recommend a good chair enough. Also, make sure your chair is right for your floor type (sounds silly, but quite important). For example, I moved my desk from a carpeted room to a room where the floor was polished wood. The chair had wheels designed for carpet, but when on the wood, it was too "light" and I was rolling all over the place. Once I replaced the wheels with proper ones for the floor, it was much better
Pointers are very important. Learn to use them, and don''t be afraid of them.
Global variables are very bad, in most cases. It''s usually not bad having one or two global variables, but I''ve worked on projects with hundreds of them, and it''s impossible to keep track of them all (and non-reentrant functions suck when it comes to debugging - you can never tell the side-effects of a function which modifies global variables).
And I can''t recommend a good chair enough. Also, make sure your chair is right for your floor type (sounds silly, but quite important). For example, I moved my desk from a carpeted room to a room where the floor was polished wood. The chair had wheels designed for carpet, but when on the wood, it was too "light" and I was rolling all over the place. Once I replaced the wheels with proper ones for the floor, it was much better
If I had my way, I''d have all of you shot! codeka.com - Just click it.
i have long ago abandoned OOP in favour of globals (burn the witch!)
my engine has 3 arrays, one for flags, one for ints and one for floats. it's one big (efficient) state machine.
i had some horrible problems early on but with a little dicipline, my only problems recently are mistypes.
i still use pointers to pass structures to functions etc.
but what about the benefits of OOP like inheritence etc? take my linked list pseudo-class as an example. i have a Node structure of 2 node pointers (previous and next) and several functions to manipulate and sort them. any time i want a linked list structure, i make the first member a Node and cast the pointers.
it works like a charm and because all of the functions are simple and non-OOP, the script only has to worry about the function pointer and the number of paramaters to push (all paramaters are ints, floats or pointers: all 4-bytes).
there is a LOT of stress relief in not worrying about namespaces or functions being called implicitly and messing up other things, not to mention the easier debugging when every single step is carried out visibly and explicitly in an unambigoous order. i recommend it to anyone who can be bothered to not make silly mistakes.
********
A Problem Worthy of Attack
Proves It's Worth by Fighting Back
[edited by - walkingcarcass on August 2, 2002 6:43:10 AM]
my engine has 3 arrays, one for flags, one for ints and one for floats. it's one big (efficient) state machine.
i had some horrible problems early on but with a little dicipline, my only problems recently are mistypes.
i still use pointers to pass structures to functions etc.
but what about the benefits of OOP like inheritence etc? take my linked list pseudo-class as an example. i have a Node structure of 2 node pointers (previous and next) and several functions to manipulate and sort them. any time i want a linked list structure, i make the first member a Node and cast the pointers.
it works like a charm and because all of the functions are simple and non-OOP, the script only has to worry about the function pointer and the number of paramaters to push (all paramaters are ints, floats or pointers: all 4-bytes).
there is a LOT of stress relief in not worrying about namespaces or functions being called implicitly and messing up other things, not to mention the easier debugging when every single step is carried out visibly and explicitly in an unambigoous order. i recommend it to anyone who can be bothered to not make silly mistakes.
********
A Problem Worthy of Attack
Proves It's Worth by Fighting Back
[edited by - walkingcarcass on August 2, 2002 6:43:10 AM]
spraff.net: don't laugh, I'm still just starting...
quote: Original post by walkingcarcass
i recommend it to anyone who can be bothered to not make silly mistakes.
Ha! That''s hilarious!
If I had my way, I''d have all of you shot! codeka.com - Just click it.
walkingcarcass, how large is your engine? For very short, simple programs, I oftern forego OOP. However, once you start writing large applications, OOP begins to show its wonder. This holds especially true when you join a team of programmers to write truely huge programs.
For example: An app I wrote a few months ago for my employer weighed in at around 8400 lines of C/C++. I didn''t really use any OOP, as I barely knew the basics of it at the time. Since then, almost every program I write is fully encapsulated into classes. I dread the moments where I have to go back and do more work on the original, non-OPP app, as it is a huge convoluted mess, spread across dozens of files with hundreds of global variables. 8400 lines of code is not even that large of a program. Large commercial apps can easily run into the hundreds of thousands. That''s a lot of globals.
So, my point is: OOP is practically a must for huge programs, but not necessarily needed for small apps/engines.
Back to the original question: Pointers are very useful, but are very powerful and should be handled with care (an errant memory write to an unknown region of memory could easily crash a computer).
-Mike
For example: An app I wrote a few months ago for my employer weighed in at around 8400 lines of C/C++. I didn''t really use any OOP, as I barely knew the basics of it at the time. Since then, almost every program I write is fully encapsulated into classes. I dread the moments where I have to go back and do more work on the original, non-OPP app, as it is a huge convoluted mess, spread across dozens of files with hundreds of global variables. 8400 lines of code is not even that large of a program. Large commercial apps can easily run into the hundreds of thousands. That''s a lot of globals.
So, my point is: OOP is practically a must for huge programs, but not necessarily needed for small apps/engines.
Back to the original question: Pointers are very useful, but are very powerful and should be handled with care (an errant memory write to an unknown region of memory could easily crash a computer).
-Mike
How large would the average commercial game be?
I think it''s the concept of pointers that turns me off the most. If were on opposite sides of the room and I want you to pass me the remote I would expect you to throw the remote to me (or at me). With pointers it''s like you handing me a bit of paper telling me how to stand up and get it myself.
And seeing as I have the mind (and body) of a lazy person the latter seems like alot more thearitical.
I clearly put to much thought into this post.
I think it''s the concept of pointers that turns me off the most. If were on opposite sides of the room and I want you to pass me the remote I would expect you to throw the remote to me (or at me). With pointers it''s like you handing me a bit of paper telling me how to stand up and get it myself.
And seeing as I have the mind (and body) of a lazy person the latter seems like alot more thearitical.
I clearly put to much thought into this post.
Pointers are really great because they can be used to create different types of structures such as linked lists, binary search trees, resizeable arrays ,etc..
Here is an example of a situation for a linked list in a game.
Suppose you are creating a game like Command and Conquer and you want to store all of the soldiers on each side. You could create a very large array for each different type of soldier and make it a global variable. However, by the time u had done this for each type of soldier, there would be a lot of arrays. Also, u would be limited in the number of soldiers you could create.
However, using a linked list, for example, you could start out with 0 soldiers. Then you can add them each one by one. The structure is much more memory efficient.
There are many other uses for pointers and to be a serious coder, IMHO it is important to use them.
Here is an example of a situation for a linked list in a game.
Suppose you are creating a game like Command and Conquer and you want to store all of the soldiers on each side. You could create a very large array for each different type of soldier and make it a global variable. However, by the time u had done this for each type of soldier, there would be a lot of arrays. Also, u would be limited in the number of soldiers you could create.
However, using a linked list, for example, you could start out with 0 soldiers. Then you can add them each one by one. The structure is much more memory efficient.
There are many other uses for pointers and to be a serious coder, IMHO it is important to use them.
Feel free to email me at NYYanks432@hotmail.com if you have any questions
In my recent applet game "asteroids" (www.geocities.com/nonnus29/asteroids/asteroids.htm) I used a complete oop approach (well, yeah, its java, but this was the first time I really did an oop game with interfaces and all....) and it was really cool looking at my nice trim little classes and my nice trim little main loop. Its really a nice tight little program. Thats why java is my anti-drug.
quote: Original post by flukus
I think it''s the concept of pointers that turns me off the most. If were on opposite sides of the room and I want you to pass me the remote I would expect you to throw the remote to me (or at me). With pointers it''s like you handing me a bit of paper telling me how to stand up and get it myself.
That''s a bad example You''d pass a remote around "by value" anyway, since it''s small (like a built-in type, heh).
If you want an analogy like that, think about cars. If you buy a car, the sales assitant doesn''t go out to the lot, pick up the car, and hand it to you. He just gives you the keys!
That''s still not a good example because it doesn''t show you the actual benefits of pointers. I can''t recommend a good C/C++ book enough. There''s plenty out there, and they should all have a great explanation of pointers - much better than anyone''s going to be able to write in a few paragraphs here...
If I had my way, I''d have all of you shot! codeka.com - Just click it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement