Skip to main content

How can I become a good coder when i am using c++ or swift for my gaming or interactive projects

i will talk about coding standard which i follows in c++ or swift (ios)
for c++
  1. define a class name like thats - public myGame extends baseClass checkout class name in camel case
  2. use abstract classes whenever you go for inheritance that would help you and other coders that there are some method already declare in base class and he don’t need to be redeclared it and also your base class can access child class method through pointer .
  3. overriding in bad habit when its comes to deal with a big project instead of overriding create method with optional parameter which would help you to reduce code in your project.
  4. generic templates are best way to deal with common things like defining a template which combine string as well as float and int based on parameter type.
  5. including header file in .cpp is bad habbit try to include all header file in .hpp
  6. resuse classes are good but too much reusability is another bad habbit for example
button->mybutton->mymybutton->anotherbutton
instead of above you can do it like
button->mybutton
button->mymybutton
button->anotherButton
7. enum is best when dealing with multiple case for example
enum myDirection
{
left,
right,
up,
down.
}
if(key==myDirection.left)
{
“move left buddy”
}
8. try to use data structure when you need to add remove updated records specially linked list , doubly linked list or circular linked list.
9. inline function are fast but you need to be carefull function which is under 9 line are good for inline function.
10. use singleton where you need same operation to held in every part of application for example a http api call or getting windows height and width based on resolution or a global sound player which playing sound in every part of your application based on different action.
11. use static classes with you deal with operation which does not required a instance of class for example math.abs()
12.try to follow some standard pattern such as mvc or mvvm these pattern help you to separate your code for example mvc where Model deals with data realted stuff V realted to views and controller deals like a bridge between them. if you belongs to gaming ECS entity component system is widely used pattern for games.
13. put configuration related data in json so you don’t need to change code again and again for minor text changes.
14. dependency injection What is dependency injection? must check it once.
15 use const instead while dealing with const values in project.
16. don’t create big function that instead of it create small function with return type
17. comment your code whenever possible it would help other to understand your code and even you too sometime.
18.check out lambda
19.check out multithreading
20. spend time with data structure and searching algorithms.

Comments

Popular posts from this blog

Creating a word Scramble game where you can drag and drop the word and create a complete word. (drag and drop word Scramble game).

Creating a word game using  phaser game engine which is a javascript based gaming engine  where u can drag and drop world like Word Scramble Game and complete a given word. your index.html file look like below < html > < head > < script src = "src/phaser.min.js" ></ script > < script src = "src/wordGame.js" ></ script > < script src = "src/main.js" ></ script > </ head > < body > </ body > </ html > 1.    <script src="src/phaser.min.js"></script> required to run the  phaser game engine. 2. rest of the two files deals with game logics      <script src="src/wordGame.js"></script>       <script src="src/main.js"></script> you can download whole project from https://github.com/manishchauhan/wordgame/tree/master just copy and paste the project in your local server and run ...

starting with three.js and react with a very simple example

 1. three.js is undoubtedly the best library to create interactive content for the web in 3d. link https://threejs.org/ a working sample of three with react can be found below https://stackblitz.com/edit/react-7n5qf9?file=src%2FApp.js why choose threejs 1. lightweight  2.fast 3.big community  https://discourse.threejs.org/ 4. even you can use unity or unreal to publish html5 content but i don't think that would be acceptable in many cases. 5. open-source project. i created a running sample with React  https://stackblitz.com/edit/react-7n5qf9?file=src%2FApp.js

A simple binary search tree with generic approach tree can store any type of data. (DFS and BFS)

 1. a binary search tree in c++ using a generic approach with both BFS and DFS approach    working tree    https://www.onlinegdb.com/edit/HkuQLdA-w code=> some properties of binary search tree-> 1. binary search tree is not always a balanced tree.  2. Inorder, traversing gives you sorted data.  3.  best is o(log n) and worst is O(n).  4. left node data is always less than root data and right node data always be greater than root data.  5. red-black tree STL map is a balanced binary search tree. *******************************************************************************/ #include <stdio.h> #include<iostream> #include<queue> using namespace std; template < typename T > class Node {   //can store any type of data private:   //genric data or store any type of data   T data;   //reference of left pointer   Node *left = nullptr;   //reference of right pointer   Node *rig...