Skip to main content
Commonmark migration
Source Link

##Overview

Overview

##Code Review

Code Review

##Overview

##Code Review

Overview

Code Review

added 860 characters in body
Source Link
Loki Astari
  • 97.7k
  • 5
  • 126
  • 341

The value NULL is no longer considered good practice. This is because it is a macro and is usually a number (not sure on the exact definition). But as a result it can be assigned to things it should not be able to assigned to and thus hide errors.

In modern C++ we use nullptr to represent the value 'null'. It has a specific type std::nullptr_t. This type is automatically convertible to another pointer type but will not auto convert into a numeric type and thus can not accidentally be passed to methods that take int as parameter.


The value NULL is no longer considered good practice. This is because it is a macro and is usually a number (not sure on the exact definition). But as a result it can be assigned to things it should not be able to assigned to and thus hide errors.

In modern C++ we use nullptr to represent the value 'null'. It has a specific type std::nullptr_t. This type is automatically convertible to another pointer type but will not auto convert into a numeric type and thus can not accidentally be passed to methods that take int as parameter.


added 860 characters in body
Source Link
Loki Astari
  • 97.7k
  • 5
  • 126
  • 341

If we look at the node constructor:

Node(string s)
{
    word = s;
    occurences = 1;
    right = left = NULL;
} //Node's constructor initialises node's values

Example of a bad comment above!

But if we look at what is actually happening here. The member word is default constructed, then in the body you are calling the assignment operator to update word with the value of s. Effectively your code is equivalent to:

Node(string s)
    : word()        // Note word is defaulted constructed here.
{
    word = s;       // Now we call the assignment operator.
    // STUFF
}

The better way to do it is using the initializer list:

Node(string s)
    : occurences(1)
    , word(s)
    , right(nullptr)
    , left(nullptr)
    , height(0)
{}

If we look at the node constructor:

Node(string s)
{
    word = s;
    occurences = 1;
    right = left = NULL;
} //Node's constructor initialises node's values

Example of a bad comment above!

But if we look at what is actually happening here. The member word is default constructed, then in the body you are calling the assignment operator to update word with the value of s. Effectively your code is equivalent to:

Node(string s)
    : word()        // Note word is defaulted constructed here.
{
    word = s;       // Now we call the assignment operator.
    // STUFF
}

The better way to do it is using the initializer list:

Node(string s)
    : occurences(1)
    , word(s)
    , right(nullptr)
    , left(nullptr)
    , height(0)
{}
deleted 2 characters in body
Source Link
Loki Astari
  • 97.7k
  • 5
  • 126
  • 341
Loading
Source Link
Loki Astari
  • 97.7k
  • 5
  • 126
  • 341
Loading