By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,654 Members | 936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,654 IT Pros & Developers. It's quick & easy.

Writing better program?

P: n/a
I am working on another game project and it is comming along. It is an
improvment over a previous version I wrote. I am trying to write
better programs and often wonder how to get better at programming. I
tend to learn what is useful and gets the job done. I am always
curious if there is some techique I don't know. I read books and study
as well as write programs. My goal is to some day be able to get a job
programming. I have a degree but not in programming. I have quite a
bit of experience in writing programms and some on-line cources. I am
trying to wite programs people might actualy want. I don't think it is
possible I could or any one could write profetional software by them
selvs.

I am trying to find those of you out there who have programming jobs to
look at what I am doing and criticize my work. I do a great deal of
work myself but there are limits to my experience. I realy could use
ideas to make my projects better. I would like to know how my work
stacks up.

Nov 3 '06 #1
Share this Question
Share on Google+
22 Replies


P: n/a
Hi JoeC,

Do you have a website? If you post your programs online and make them
available to download, then people can see what you have to offer.

Also, what sort of technology are you using? Are you writing C++/Java
programs? Do you use .NET?

I wish you luck in finding a programming job!

Nov 3 '06 #2

P: n/a

Steve Chamberlain wrote:
Hi JoeC,

Do you have a website? If you post your programs online and make them
available to download, then people can see what you have to offer.

Also, what sort of technology are you using? Are you writing C++/Java
programs? Do you use .NET?

I wish you luck in finding a programming job!
http://www.planetsourcecode.com/vb/s...1=Quick+Search

Nov 3 '06 #3

P: n/a
LR
JoeC wrote:
Steve Chamberlain wrote:
>>Hi JoeC,

Do you have a website? If you post your programs online and make them
available to download, then people can see what you have to offer.

Also, what sort of technology are you using? Are you writing C++/Java
programs? Do you use .NET?

I wish you luck in finding a programming job!


http://www.planetsourcecode.com/vb/s...1=Quick+Search
I generally think that using namespace std; is a bad idea.
Putting using namespace std; in a header is a very bad idea.

buf should probably be some kind of smart pointer, and be careful about
where you make it, and how you use it.

Your code is scattered with magic numbers. This should be avoided. And
remember that in C++, a char is really an integral type.

When I run, all the moves cause the code to crash.

You ought to think about adding a function that adds two coords
together. Like:

Coord operator+(const Coord &c1, const Coord &c2);

Coord should have a default ctor. Particularly as you're using the
default value for a coord in board::move.

And maybe also, coord should have ctor that looks like this:
coord::coord(const int &xx, const int &yy) : x(xx), y(yy) {}

Also, you might want to think about something like this:
bool board::validCoordForSpaces(const Coord &c) const {
const bool result = (0 <= c.x && c.x < size) && (0 <= c.y && c.y <
size);
return result;
}

But I tend to think that class board might already do too much. For
example, it's not clear to my why you have data members e,n,s,w in
board. Think about how your ctor for board is written, and perhaps
consider adding an enum like this:
enum Direction { NORTH, SOUTH, EAST, WEST }
and a map like:
std::map<Direction, coordkeys;
then you can:
keys[NORTH] = coord(0,-1);

(Of course, there is some debate as to NORTH or North would be
preferable, you'll have to choose what you think is best.)


Think about this code snippet and your board::move method.

const int arraySize = 10;
int a[arraySize];
if( a[103] == 0 ) { SomeErrorMessage("Oops can't check that index."); }
If you offer a reference to code that you've written in the hopes that
people will look at it, it would be best for that code to compile.
Also, I still have the opinion that you are biting off more then you can
reasonably chew at this point. I think you'd do better to try some
simpler programs and build up to your game.

Good luck.

LR
Nov 4 '06 #4

P: n/a
>
I generally think that using namespace std; is a bad idea.
Putting using namespace std; in a header is a very bad idea.

buf should probably be some kind of smart pointer, and be careful about
where you make it, and how you use it.

Your code is scattered with magic numbers. This should be avoided. And
remember that in C++, a char is really an integral type.
What is a magic number and how do I avoid them? I have used char in
past programs where I thout approate.
>
When I run, all the moves cause the code to crash.
They run fine for me. I did have a problem when I was experimenting
with some display variables.
>
You ought to think about adding a function that adds two coords
together. Like:

Coord operator+(const Coord &c1, const Coord &c2);
not sure why but it may be a good idea.
>
Coord should have a default ctor. Particularly as you're using the
default value for a coord in board::move.
Not sure which game your looking at my maze game? Yes, I know that one
is very buggy. Once I got it running, I figured that while it still
often runs it was poorly designed byond repair without a complete
rewrite.
>
And maybe also, coord should have ctor that looks like this:
coord::coord(const int &xx, const int &yy) : x(xx), y(yy) {}
coord(const int xx, const int yy){x = xx; y = yy;}
This is what I can up with for my current project, but I can make a
change.
>
Also, you might want to think about something like this:
bool board::validCoordForSpaces(const Coord &c) const {
const bool result = (0 <= c.x && c.x < size) && (0 <= c.y && c.y <
size);
return result;
}
That would be a good idea I am saving this it will be very useful in
future work.
>
But I tend to think that class board might already do too much. For
example, it's not clear to my why you have data members e,n,s,w in
board. Think about how your ctor for board is written, and perhaps
consider adding an enum like this:
enum Direction { NORTH, SOUTH, EAST, WEST }
and a map like:
std::map<Direction, coordkeys;
then you can:
keys[NORTH] = coord(0,-1);

(Of course, there is some debate as to NORTH or North would be
preferable, you'll have to choose what you think is best.)
Actually this code has been recycled many times by me. I found it very
useful and lifted it from a perl program. I find that a bit confusing
to use

case VK_UP:
if(selectedUnit != -1){bn[selectedUnit]->mover('n');}
...........................
void unit::mover(char ch){
loc.y = loc.y + keys[ch].x;
loc.x = loc.x + keys[ch].y;
moved++;
}
>

Think about this code snippet and your board::move method.

const int arraySize = 10;
int a[arraySize];
if( a[103] == 0 ) { SomeErrorMessage("Oops can't check that index."); }
>

If you offer a reference to code that you've written in the hopes that
people will look at it, it would be best for that code to compile.
My code did compile for me. I do rember writing this code that was a
real challenge to get to compile and run without crashing.
>

Also, I still have the opinion that you are biting off more then you can
reasonably chew at this point. I think you'd do better to try some
simpler programs and build up to your game.
This game was a challenge but I learned from it. I have simple board
game which I am trying to improve. That game would require a full
re-write to improve. I would like to get back to it some time but find
my current work more intersting.

You can goback and see my old perl work:
http://www.planetsourcecode.com/vb/s...1=Quick+Search

I realy enjoy the comments I get from people who take the time and look
at what I have writtem. My dream job would be able to design and
create strategy games. I am not very satisifed with the kind of
war/strategy games out there. I have come up with ideas for some game
I would like to write. The ideas I have are far byond my ability to
create. I am in the military and have seen how an army actualy
functions in war. For example, I have learned about all the behind the
scenes stuff that goes into combat. The logistics intelligence
comunications the management of information these aspects are just as
important that firepower and manuver. I have a few other ideas as
well.

For me the games I play are loosing the game and the power of the
computer is not being used for simulation but for overdone graphics.
Civ 4 is a great example of a great game being lost in the graphics and
the game lost.

If I can't write games, I will if my skill programming can get me a
job. I am always pushing what I can do trying to write better code. I
do have a few books that are actually helpful in my projects but most
of what I write I come up with. I am always looking to improve my
techniques of improving my code. How can I make that into a function,
how can I seperate that out it to its own objects. Breaking my current
simple and basic ideas down into parts that work well together. The
project I am working on is an improvment on similliar gam e I have many
challenges and I don't yet even have a clue how I would implement a
computer player.

Good luck.

LR
Nov 4 '06 #5

P: n/a
JoeC wrote:
>>I generally think that using namespace std; is a bad idea.
Putting using namespace std; in a header is a very bad idea.

buf should probably be some kind of smart pointer, and be careful about
where you make it, and how you use it.

Your code is scattered with magic numbers. This should be avoided. And
remember that in C++, a char is really an integral type.


What is a magic number and how do I avoid them? I have used char in
past programs where I thout approate.
42.

Define a constant like const unsigned someDescriptiveName = 42;

and use the constant value in place of the number in your code.

--
Ian Collins.
Nov 4 '06 #6

P: n/a

Ian Collins wrote:
JoeC wrote:
>I generally think that using namespace std; is a bad idea.
Putting using namespace std; in a header is a very bad idea.

buf should probably be some kind of smart pointer, and be careful about
where you make it, and how you use it.

Your code is scattered with magic numbers. This should be avoided. And
remember that in C++, a char is really an integral type.

What is a magic number and how do I avoid them? I have used char in
past programs where I thout approate.
42.

Define a constant like const unsigned someDescriptiveName = 42;

and use the constant value in place of the number in your code.

--
Ian Collins.
I try to do that more in my current programs.

Nov 4 '06 #7

P: n/a
Hi Joe,

Have you also considered packaging an executable with your code? When I
check out demos I always like to run the program first, then check out
the code if I am interested in how a certain part of the program was
implemented.

The reason I ask is that I use Borland Developer Studio tools (not MS
Visual Studio) on a daily basis and while I can use your makefile, I
don't really have the time to set it up in my compiler, build it, run
it etc. So I would consider maybe including an executable.

Steve.

Nov 8 '06 #8

P: n/a

JoeC wrote:
I am working on another game project and it is comming along. It is an
improvment over a previous version I wrote. I am trying to write
better programs and often wonder how to get better at programming. I
tend to learn what is useful and gets the job done. I am always
curious if there is some techique I don't know.
You seem to be a positive guy...
I read books and study
as well as write programs.
Judging by the code you write, the books you have read may be dated.
You sourcecode is certainly not production standard.
My goal is to some day be able to get a job
programming. I have a degree but not in programming. I have quite a
bit of experience in writing programms and some on-line courses.
If you want a job, you will need to learn to write code that is
maintainable. Your interfaces need to convey your intent. Others should
not be able to do the wrong thing with each class that you write.
Consider using RAII, consider const correctness, the magic numbers
mentioned elsewhere needs to be replaced. Consider designing for change
(ABC's or interfaces ring a bell). The ability to develop things so
that they can scale to meet future requirements are important. Things
should not only work, but be able to adapt. OTOH, things should first
and foremost work, yes. With little difficulty this can be achieved
whilst simultaneously designing for change. Look for "programming
towards a contract" or the other buzzword - "Test Driven Design".
I am trying to find those of you out there who have programming jobs to
look at what I am doing and criticize my work. I do a great deal of
work myself but there are limits to my experience. I realy could use
ideas to make my projects better. I would like to know how my work
stacks up.
Go to the website http://www.gotw.ca and read up on some of those free
articles - great place to learn, BTW. Also, read "More Effective C++"
by Scott Meyers. Many people advocate the book "Accelerated C++" by
Andrew Koening. I have (to my detriment, I suppose) not personally
studied it though.

To summarize, on the whole - apart from your code not being what I
would call modern production standard C++, it looks as though you have
enough logic to be able to learn to program in that way. You are not
there yet, though (IMHO).

Regards,

Werner

Nov 8 '06 #9

P: n/a

Steve Chamberlain wrote:
Hi Joe,

Have you also considered packaging an executable with your code? When I
check out demos I always like to run the program first, then check out
the code if I am interested in how a certain part of the program was
implemented.

The reason I ask is that I use Borland Developer Studio tools (not MS
Visual Studio) on a daily basis and while I can use your makefile, I
don't really have the time to set it up in my compiler, build it, run
it etc. So I would consider maybe including an executable.

Steve.
I do include the exe file but the site remove it for security reasons.
If you would like I can send you the exe of what ever program you want.
I use the dev C++ free compiler and it is easy to compile code. I have
been slowly adding to my game and I am happy to where I am going. I
would like advice on how I am writing the program. How can I do things
better. What I have written is improvments based on the advice I have
gotten. I am to where I can move units based on movment factors and by
side. I am proud of what I have done so far.

Nov 8 '06 #10

P: n/a

werasm wrote:
JoeC wrote:
I am working on another game project and it is comming along. It is an
improvment over a previous version I wrote. I am trying to write
better programs and often wonder how to get better at programming. I
tend to learn what is useful and gets the job done. I am always
curious if there is some techique I don't know.

You seem to be a positive guy...
That is a key to success.
>
I read books and study
as well as write programs.

Judging by the code you write, the books you have read may be dated.
You sourcecode is certainly not production standard.
I know that but most of the books I have teach syntax but not much in
the way of design. That is fustrating and I know my programs could be
much better. Most of code is a result of my isolation and I am
fighting to get attention and looks from people who know better than I
do. I also realize that there is a learning curve and I will not be an
expert over night but I want to make progress. I do have another job
which I have done for years and have proficiency and it is hard to
document experience for others to follow.
>
My goal is to some day be able to get a job
programming. I have a degree but not in programming. I have quite a
bit of experience in writing programms and some on-line courses.

If you want a job, you will need to learn to write code that is
maintainable. Your interfaces need to convey your intent. Others should
not be able to do the wrong thing with each class that you write.
Consider using RAII, consider const correctness, the magic numbers
mentioned elsewhere needs to be replaced. Consider designing for change
(ABC's or interfaces ring a bell). The ability to develop things so
that they can scale to meet future requirements are important. Things
should not only work, but be able to adapt. OTOH, things should first
and foremost work, yes. With little difficulty this can be achieved
whilst simultaneously designing for change. Look for "programming
towards a contract" or the other buzzword - "Test Driven Design".
I do what I do learn also as a desire to create. I want X there for I
should create it. Still you are right, I have to go in the right
direction. They are competing activites for my time create large
projects that do somthing worth wile or create small programs to learn
a concept. I have not seen too much advice on better concepts but I
will look into the links you sent me. One of the reasons why I do the
project I do partly for ego because I can acheave it but also take that
theory and advice I get and turn it into a better program. This
current program is far better an more powerful than anything I have
written. Still I have a ways to go and there are things I need to
change to make better for example I have identical convert function in
two objects I need to remove that make it sperate accessed by both
objects. Also I have a move concept embedded in one of my functions I
should seperate out because it is an independent concpet.

I like criticizm theory and showing where it could make my program
better. I also look into how I can re-use my objects from one program
in others. Being only one person I have a limit on the projects I can
do. I also don't have the experience in programming in groups. If I
had to deal with the code of others, it would teach me how to write for
others.

I know I have to work on my commenting and naming of functions and
variables, I am working on that and trying to do a better job.
I am trying to find those of you out there who have programming jobs to
look at what I am doing and criticize my work. I do a great deal of
work myself but there are limits to my experience. I realy could use
ideas to make my projects better. I would like to know how my work
stacks up.

Go to the website http://www.gotw.ca and read up on some of those free
articles - great place to learn, BTW. Also, read "More Effective C++"
by Scott Meyers. Many people advocate the book "Accelerated C++" by
Andrew Koening. I have (to my detriment, I suppose) not personally
studied it though.

To summarize, on the whole - apart from your code not being what I
would call modern production standard C++, it looks as though you have
enough logic to be able to learn to program in that way. You are not
there yet, though (IMHO).

Regards,

Werner
Thanks, I do put in the effort and I am proud of what I do considering
am completly self taught from a few book. I am encouraged by the
responces I get. I look to those who are successful not failures
becasuse failure is easy success is hard. I do enjoy what I create.

Nov 8 '06 #11

P: n/a

JoeC wrote:
Thanks, I do put in the effort and I am proud of what I do considering
am completly self taught from a few book.
Most of my knowledge of C++ and programming happen to be self-taught
too. I have an elec. eng. background, but now I do programming for a
living.
I am encouraged by the
responces I get. I look to those who are successful not failures
because failure is easy success is hard. I do enjoy what I create.
I suppose (although I'm not good at failing), the key to success is how
one deals with failures. Failure is inevitable, but how you deal with
it is what counts (and leads to eventual success). Writing programs to
stimulate your creativity is good. Don't isolate yourself though, look
at what others do and question why they do what they do. Good luck.

Regards,

Werner.

Nov 9 '06 #12

P: n/a
werasm makes some very good points. Designing maintainability and
scalability are very valuable skills that many employers will welcome
with both hands. Also try to get a feel for the whole life cycle
process.

I also find that a good working relationship with testers/test
department can be worth its weight in gold! Whilst you are still
learning continue to ask other people to review your work, as a
developer you tend to get too close to your work and it is very
difficult to spot errors. Like werasm says, get used to problems in
your software, it WILL happen!

I know that advice is not very code specific, but there is a lot more
to development than just coding! Keep in mind that programming is not a
hard and fast science and that one way of doing things is not
necessarily better than another.

Nov 9 '06 #13

P: n/a
Couple of extra thoughts, maybe already mentioned previously:

1) I think you should clarify what your functions and variables do by
giving them more descriptive names. It's just my personal preference,
but instead of something like "pl" I would use a name like "player".
Consider what will happen if when you are part of a development team
you get sick and someone has to work on your code whilst you are away,
if it reads more like English (or your language of choice!) then you
can make progress much quicker.

2) Particularly for games, you should aim to separate your game world
from your graphics engine. I saw that your board class has knowledge of
the player (I didn't analyse too deeply). If you can run your game
engine without the graphics engine, then you can separate the two.
Maybe you will make Dungeon Adventure in 3D in future, how useful would
it be if your game engine didn't need to be touched, so you could focus
on the graphics side :-)

Nov 9 '06 #14

P: n/a

Steve Chamberlain wrote:
Couple of extra thoughts, maybe already mentioned previously:

1) I think you should clarify what your functions and variables do by
giving them more descriptive names. It's just my personal preference,
but instead of something like "pl" I would use a name like "player".
Consider what will happen if when you are part of a development team
you get sick and someone has to work on your code whilst you are away,
if it reads more like English (or your language of choice!) then you
can make progress much quicker.

2) Particularly for games, you should aim to separate your game world
from your graphics engine. I saw that your board class has knowledge of
the player (I didn't analyse too deeply). If you can run your game
engine without the graphics engine, then you can separate the two.
Maybe you will make Dungeon Adventure in 3D in future, how useful would
it be if your game engine didn't need to be touched, so you could focus
on the graphics side :-)
M dungeron adventoure is pretty old and I have learnd from that game.
Seperating graphics from the game is a major goal of my improvments. I
think myt newest partial game does a much better job. I am very happy
with how the game runs right now. I have a bunch of stuff written to
make it work but I am looking for better ways of writing the code and I
want to have somthing that runs.

I do see the value of not using magic numbers and I will try to cut
down on them. For example I use -1 to mean no unit selected that
shoult be const noneSelected = -1. It just seems like more typing on
my part. I have been using longer names and I find that I use cut and
paset to put the names in where I need them. I tend to lp for my loop
values. I have been trying to use better names just longer nameg for
me get cumbersome.

Finally when it comes to graphics, I am really sick of the over
graphicized games. It seems that everyone is trying to make games look
better but I seldom find games that are what I am looking for. I
minimize the work on geraphics because I want o focus on my program
writing and I like the nature of being able to display things on a
screen with graphics.

My programs are very simple they don't do much but even th ese simple
programs are very dificult to write and create. Like all designers, I
have games in my head and I need to devlope the skills I need to make
those games a reality. I have quite a bit of experience in the army
and I see how war happens from a global view. The importance of
logistics, intelligence, resource managment. I would like to find a
way to put those and other aspects in a fun and intersting way. I also
have other ideas in which I would like to create. Most of what I would
like to create is along the lines of civilization but very different
play mechinism.

Again, I know that I severly lack the skill I need to realy do anything
useful but I keep working and keep posting messages like this and take
the advice I get and implement them in the programming projects I
create. I also spoke to somone who said math and statics classes are
very important for getting jobs because everyone wants to be a namager.
I want to create code and improve my skill.

Check out this game:
http://www.planetsourcecode.com/vb/s...1=Quick+Search

simple map game is my latest post. It is much better and is the result
of much learning. I is not yet complete but is an improvment of my
prot-wargame. I am having people look at the first game an I get
suggestions on how to write and improve the next version. The next
version so far is way better even in the parital form. The real
challenge is figuring out how I can do the map and map manager better.
Still I am realy open to sugestions from either program.

Nov 9 '06 #15

P: n/a

I'm in a similar position. I an a Network Engineer with some Computer
Engineering and Comp Sci classes under my belt. I'm working on
designing programs that are easier to port from one system to another
and am working on understanding and designing modern day real time
engines. I have been working a lot with games and have made some good
strides in the last year toward understanding some of the more advanced
concepts. I'm enjoying the thread because I'm getting some good ideas.
One set of books I would HIGHLY recommend for the topic you are
programing in. Game Programming Gems. There are plenty of C++ and STL
concepts including when to follow standards and when to break them.

Since I'm not in school any more and none of the people I talk to
understand computers much less programming I find that groups and books
are my best source for information.

Nov 9 '06 #16

P: n/a

AzizMandar wrote:
I'm in a similar position. I an a Network Engineer with some Computer
Engineering and Comp Sci classes under my belt. I'm working on
designing programs that are easier to port from one system to another
and am working on understanding and designing modern day real time
engines. I have been working a lot with games and have made some good
strides in the last year toward understanding some of the more advanced
concepts. I'm enjoying the thread because I'm getting some good ideas.
One set of books I would HIGHLY recommend for the topic you are
programing in. Game Programming Gems. There are plenty of C++ and STL
concepts including when to follow standards and when to break them.

Since I'm not in school any more and none of the people I talk to
understand computers much less programming I find that groups and books
are my best source for information.
I find these discussion very intersting and that is why I start them.
I can usually figure out how to write x syntax but writing better code
is more dificult. And I am looking for all the advice I can get and to
have my work reviewed. I am always doing somthing to improve my code
while trying not to break it doing somthing stupid so that it no loger
works.

Nov 9 '06 #17

P: n/a
The one big suggestion I would give would be to wrap out all your
graphics. Not just the redraw and the main window but the message
boxes as well. The biggest thing that I notice is how saturated with
MFC includes and proprietary code your program is. Unfortunately this
seems to be the way a lot of people write code in examples and
tutorials. It is a valid style but it does make all of your code 100%
unportable. You may have not desire to port your program to MAC or
LINUX but think about the following:

You finally finish your game and it is wonderful and you feel you are
ready to use some full screen graphics modes with 3D Graphics and your
error messages going to Logs or the user message window instead of the
annoying message boxes. Or even better, you can configure in game and
on the fly how the messages are displayed. You would have to edit
almost every file you have. If you wrap out your error handling and
messages you can change the whole code without effecting the look and
change the look without effecting the code

Again what you have works and I see people do it all the time. But
when it comes to production code these days the more flexible engines
are what the companies want. Keep the I/O, Data, and core program
separate. That way when nVidia and ATI come out with new cool features
the company only has to have you change some graphics and when Intel
comes out with the 87 core Super Split Infinity Threaded Hyper
processor you don't have to trash the whole project to make it work.

Nov 9 '06 #18

P: n/a

JoeC wrote:
I do see the value of not using magic numbers and I will try to cut
down on them. For example I use -1 to mean no unit selected that
shoult be const noneSelected = -1. It just seems like more typing on
my part. I have been using longer names and I find that I use cut and
paset to put the names in where I need them. I tend to lp for my loop
values. I have been trying to use better names just longer nameg for
me get cumbersome.
Cut-and-pasting is bad. When things need to change fast, they tend to
fall apart if cut-and-paste stile programming were used. Get into the
habit of avoiding cut and pasting at all costs - serious (even forget
the key sequence, if need be). As far as const go, this is a little
rule I follow myself. If the value needs to be part of my public
interface, or if it needs to be used in the class definition, then I
use an anonymous enumerated type:

example:

class X
{
//...
enum {Sz = 20 };
char array_[Sz];
};

If on the other hand, the value is not required as part of the
definition, I use enumerators in my source file within anonymous
namespace (or static consts). The value of static consts can be
specified at the definition (during initialisation).

[snip]

Most of the above is more about graphics, and less about C++
specifically, I therefore cannot comment, other than what has already
been said.

Kind Regards,

Werner

Nov 10 '06 #19

P: n/a

AzizMandar wrote:
The one big suggestion I would give would be to wrap out all your
graphics. Not just the redraw and the main window but the message
boxes as well. The biggest thing that I notice is how saturated with
MFC includes and proprietary code your program is. Unfortunately this
seems to be the way a lot of people write code in examples and
tutorials. It is a valid style but it does make all of your code 100%
unportable. You may have not desire to port your program to MAC or
LINUX but think about the following:

You finally finish your game and it is wonderful and you feel you are
ready to use some full screen graphics modes with 3D Graphics and your
error messages going to Logs or the user message window instead of the
annoying message boxes. Or even better, you can configure in game and
on the fly how the messages are displayed. You would have to edit
almost every file you have. If you wrap out your error handling and
messages you can change the whole code without effecting the look and
change the look without effecting the code

Again what you have works and I see people do it all the time. But
when it comes to production code these days the more flexible engines
are what the companies want. Keep the I/O, Data, and core program
separate. That way when nVidia and ATI come out with new cool features
the company only has to have you change some graphics and when Intel
comes out with the 87 core Super Split Infinity Threaded Hyper
processor you don't have to trash the whole project to make it work.
You are referring to my code?

I did use win32, I know there are other ways to do this kind of GUI
work openGL and DirectX. Because I havn't used other programming
engines other than win32, I have no idea how to write a program for
diferent graphic engines. I am still at the stage of trying to create
a playable game. I realy am focused on the creation of good objects
that are well designed and re-useable. I know my graphics are bound to
the unit objects and I realy don't have the skill to totally seperate
them. To realy make a playable game I would have to create AI for a
computer player and I have no idea how to do that, I will have to do
basic research to even make the dumbest computer player. My two
challenges right now is finding a good way to create units. Later I
want the ability to buy units or buy units during play and second,
making an impoved board scheme for the game. I created a board with
terrain and made it all work but I want to do it better.

Nov 10 '06 #20

P: n/a

werasm wrote:
JoeC wrote:
I do see the value of not using magic numbers and I will try to cut
down on them. For example I use -1 to mean no unit selected that
shoult be const noneSelected = -1. It just seems like more typing on
my part. I have been using longer names and I find that I use cut and
paset to put the names in where I need them. I tend to lp for my loop
values. I have been trying to use better names just longer nameg for
me get cumbersome.

Cut-and-pasting is bad. When things need to change fast, they tend to
fall apart if cut-and-paste stile programming were used. Get into the
habit of avoiding cut and pasting at all costs - serious (even forget
the key sequence, if need be).
Yeh, I know that cut and paste is bad but I was trying to make the
point of how somthing simple could be done better. One of the reasons
why I try to avoid longer names is a basic typing errors. Worse if I
use names that are too close and put the wrong name in. It happens in
other things I do.

As far as const go, this is a little
rule I follow myself. If the value needs to be part of my public
interface, or if it needs to be used in the class definition, then I
use an anonymous enumerated type:

example:

class X
{
//...
enum {Sz = 20 };
char array_[Sz];
};
I don't realy use enum lists much, I think I used them one or two
times. I have seen them in books and how to do it but have never realy
been shown the value for writing better programs. In my current work I
can't see where they would improve my code.
If on the other hand, the value is not required as part of the
definition, I use enumerators in my source file within anonymous
namespace (or static consts). The value of static consts can be
specified at the definition (during initialisation).
You lost me here. I have used static const where I need to but mostly
I am trying to take small steps to improve my code. Programming is
just a bunch of small steps.
>
[snip]

Most of the above is more about graphics, and less about C++
specifically, I therefore cannot comment, other than what has already
been said.
Thanks, I my graphics are not the focus of what I am doing but they
serve their purpose.

Nov 10 '06 #21

P: n/a

JoeC wrote:
Yeh, I know that cut and paste is bad but I was trying to make the
point of how somthing simple could be done better. One of the reasons
why I try to avoid longer names is a basic typing errors. Worse if I
use names that are too close and put the wrong name in. It happens in
other things I do.
With regards to naming conventions, a rule I used to follow was as
short as possible to be descriptive. I later realized that what is
considered as being descriptive is very subjective. If you know the
domain, that could be very short, but not clear for someone maintaining
your code. I now use the philosophy - as clear and concise as possible.
Spelling errors are the least of my concern. If you can spell
phonetically and the concept is brought over, it is better than using a
short non-descriptive name.
As far as const go, this is a little
rule I follow myself. If the value needs to be part of my public
interface, or if it needs to be used in the class definition, then I
use an anonymous enumerated type:

example:

class X
{
//...
enum {Sz = 20 };
char array_[Sz];
};

I don't realy use enum lists much, I think I used them one or two
times. I have seen them in books and how to do it but have never realy
been shown the value for writing better programs. In my current work I
can't see where they would improve my code.
The benefits of enum are for me:

1) You don't need to provide a declaration and definition (like with
statics). If you want to save typing, use enums :-).

2) The minimal type is automatically selected for you. If your range is
less than 128, it is stored within a byte if less than 32768, it may
be stored within a short, etc...

If on the other hand, the value is not required as part of the
definition, I use enumerators in my source file within anonymous
namespace (or static consts).
Here I was referring to the class definition:

class XClass //Definition starts here!
{

/*
If a value is not required here (as part of the
interface of the class, so to speak, then don't
define the constant here, as when it changes,
all dependents require unecessary recompilation.
Recompilation times to become an issue in large
projects...
*/

};//Definition ends here!

Thanks, I my graphics are not the focus of what I am doing but they
serve their purpose.
Ok, but I can't comment on that - just the C++.

Kind regards,

Werner

Nov 13 '06 #22

P: n/a
The benefits of enum are for me:

1) You don't need to provide a declaration and definition (like with
statics). If you want to save typing, use enums :-).

2) The minimal type is automatically selected for you. If your range is
less than 128, it is stored within a byte if less than 32768, it may
be stored within a short, etc...
I will look into practicing enum lists so I can learn how to use them
and see if they are helpful for for my project.

Nov 13 '06 #23

This discussion thread is closed

Replies have been disabled for this discussion.