My little Tick Tack Toe game...

Pages: 12
For example, I need to use a lot of globals.

If you want to make your code easier for others to understand... don't use a lot of globals.
Hi,

I haven't looked at your code, but there are some things I can comment on based on other replies, and on what you have said.

When adding members, add a suffix (m_) before their names (Unless they are totally obvious). Members that are marked "private" can have different suffix so that to help programmers search for public-type members much easier.


Here is a concept for you: All the class data members should be private: . Your code snippet had two private sections, because class members are private by default, unless marked otherwise. Personally, I think it is overkill to mark private members with p_ in the variable name. There are some that recommend against having
m_
for member variables.

With globals, consider that it should be possible to write all of your code with no globals at all. I am not saying that globals should be banned outright - there are valid situations for experienced coders to use them, but beginners really should avoid them. And the actual advice is the opposite of globals: keep the scope of your variables as tight as possible.

Another thing is that one should put their own code into it's own namespace.

With magic numbers, make them a const variable instead, and use that variable name in the code:

1
2
3
4
// constexpr is more strict than const, it's constness cannot be cast away
constexpr std::size_t DaysInWeek = 7;

std::array<double, DaysInWeek> WeeklyData = {1.0, 21.0, 2.3, 4.7, 6.3, 7.8, 9.2};


For data where you are unsure of how many items there may be, then use a std::vector , and not worry about the size of it at all.

In terms of transitioning from C to C++, I acknowledge that it can be a steep learning curve, but realise that it is a different paradigm. That is, it it is a completely different mind set. With C++, make use of the STL with it's containers and algorithms etcetera to do work for you. If you have copied or learnt from a site that has C code, then try to find a site that has actual C++ code. The other thing is to try and get a good grounding in actual C++ code before trying to tackle games.

As far as writing lots of code, then "splitting it into separate files later" , I would strongly recommend that you have separate files as early as possible. Leaving it for later is just going to make things harder. Try to avoid big and complicated, rather aim for lots of small simple and reusable tools.

Any way Good Luck !! :+)
I've learned a lot of things.

I'd like to thank you in depth, TheIdeasMan. I think I now have a better understanding on how to write a more standard and readable code.

I am currently learning template and attempting to create a container (just practice) to test my code skills. I basically have typical skills of an amateur, meaning that despire having strong pratical knowledge on some ascepts, I am also weak at some certain things, like code management. I might be also lacking theorical knowledge, and it appears that there are some problems with my code style that make my code not look standard and cause some difficulties for the readers. Is it really a bad thing? And if I want to post something, would you be willing to review it? I really want to perfect my code skills, I don't want to stay as an amateur forever and I need some directions from you programmers and aim to become a programmer expert. Will you really help me?
Last edited on
Will you really help me?


Sure I can help, but realise that knowledge / experience is a relative thing: I am just less amateur than you are :+), how much less is a subjective thing. All the other respondents to this Topic are way, way more experienced than me. So get help from all the people here.


I am currently learning template and attempting to create a container (just practice) to test my code skills.


There is two ways of looking at this:
1 Use the STL and get things done;
2 Write your own containers & algorithms etc.

I would do a bit of both, but would be inclined to do more of 1 to start with. If you go to University, they will get you to write your own sort and make your own linked list, binary tree and algorithms etcetera, so that you learn in detail how these things work. But you should really learn the C++ way of doing things.

Note that with 2, it's relatively easy to write your own simple container, but doing a proper templated version that mimics the STL takes hundreds of LOC. Volatile Pulse is doing just that right now. You can have a look here:

http://www.cplusplus.com/forum/general/180116/


I might be also lacking theorical knowledge, and it appears that there are some problems with my code style that make my code not look standard and cause some difficulties for the readers. Is it really a bad thing?


Yes. Always strive to have easy to understand, efficient code.

Also, purchase some books written by pillars of the Industry: Stroustrup, Herb Sutter, Scott Meyers, Andrei Alexandrescu to name a few. There are some links to good book list here:

http://www.codergears.com/QACenter/index.php?qa=resources


There are style guides, and recommend good practices here too. Note that the Google style guide is considered a piece of trash, the JSF Air Vehicle is apparently much better.

Some other sites:


http://www.gotw.ca/gotw/ Herb Sutter
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines Herb Sutter & Bjarne Stroustrup
http://en.cppreference.com/w/


Other things to learn about:

Design Patterns, C++ Idioms.

Good Luck !!
Topic archived. No new replies allowed.
Pages: 12