DEV Community

[Comment from a deleted post]
Collapse
 
bugrahasbek profile image
Buğra Hasbek

Hi Ali,

I have a few comments, hope it helps:

  1. Prefer initialization to assignment. Keywords: assignment vs initialization
// bad practice 
int first;
first=34;

// good practice
int first = 34;
Enter fullscreen mode Exit fullscreen mode
  1. Prefer cmath::abs to writing your own absolute number function. Related question:

    I am currently writing some glsl like vector math classes in C++, and I just implemented an abs() function like this:

    template<class T>
    static inline T abs(T _a)
    {
        return _a < 0 ? -_a : _a;
    }
    

    I compared its speed to the default C++ abs from math.h like…

  2. Use floating numbers for division, unless you intentionally want to lose the decimal part.

  3. It is a good idea to write functions and call these functions from main. I understand that you are writing simple programs but writing functions prepares you for the more complex stuff you will face later on.

Don't lose your motivation and try to learn new things everyday. Have a good one!

Collapse
 
code_with_ali profile image
AlixaProDev

Thank you so much. It really helps me a lot. Thanks again for the contributions you are making to the community.