Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

In addition to what cmh and Loki have said, here are a few pet peeves of mine:

  1. Ban C-style casts from your code-base. They are dangerous (they are an everything-goes cast which severely undermines the type system) and too innocuous. Casts should stand out.

    Ban C-style casts from your code-base. They are dangerous (they are an everything-goes cast which severely undermines the type system) and too innocuous. Casts should stand out.

    So instead of (char) foo, use static_cast<char>(foo); yes, it’s long and ugly. That’s intentional to make the cast stand out.

  2. Break the logic into smaller non-repeating blocks. With Loki’s amendments this is obsolete but in general look how similar your encrypt and decrypt functions are. You should strive to reduce this redundancy. If I remember my Vigenère correctly these functions are symmetrical and can be implemented by the same logic.

    You are also converting quite a lot between chars and numbers by adding or subtracting 'A'. Encapsulate this into a pair of functions, it makes the code cleaner.

So instead of (char) foo, use static_cast<char>(foo); yes, it’s long and ugly. That’s intentional to make the cast stand out.

  1. Break the logic into smaller non-repeating blocks. With Loki’s amendments this is obsolete but in general look how similar your encrypt and decrypt functions are. You should strive to reduce this redundancy. If I remember my Vigenère correctly these functions are symmetrical and can be implemented by the same logic.

You are also converting quite a lot between chars and numbers by adding or subtracting 'A'. Encapsulate this into a pair of functions, it makes the code cleaner.

In addition to what cmh and Loki have said, here are a few pet peeves of mine:

  1. Ban C-style casts from your code-base. They are dangerous (they are an everything-goes cast which severely undermines the type system) and too innocuous. Casts should stand out.

So instead of (char) foo, use static_cast<char>(foo); yes, it’s long and ugly. That’s intentional to make the cast stand out.

  1. Break the logic into smaller non-repeating blocks. With Loki’s amendments this is obsolete but in general look how similar your encrypt and decrypt functions are. You should strive to reduce this redundancy. If I remember my Vigenère correctly these functions are symmetrical and can be implemented by the same logic.

You are also converting quite a lot between chars and numbers by adding or subtracting 'A'. Encapsulate this into a pair of functions, it makes the code cleaner.

In addition to what cmh and Loki have said, here are a few pet peeves of mine:

  1. Ban C-style casts from your code-base. They are dangerous (they are an everything-goes cast which severely undermines the type system) and too innocuous. Casts should stand out.

    So instead of (char) foo, use static_cast<char>(foo); yes, it’s long and ugly. That’s intentional to make the cast stand out.

  2. Break the logic into smaller non-repeating blocks. With Loki’s amendments this is obsolete but in general look how similar your encrypt and decrypt functions are. You should strive to reduce this redundancy. If I remember my Vigenère correctly these functions are symmetrical and can be implemented by the same logic.

    You are also converting quite a lot between chars and numbers by adding or subtracting 'A'. Encapsulate this into a pair of functions, it makes the code cleaner.

Source Link
Konrad Rudolph
  • 6.7k
  • 23
  • 35

In addition to what cmh and Loki have said, here are a few pet peeves of mine:

  1. Ban C-style casts from your code-base. They are dangerous (they are an everything-goes cast which severely undermines the type system) and too innocuous. Casts should stand out.

So instead of (char) foo, use static_cast<char>(foo); yes, it’s long and ugly. That’s intentional to make the cast stand out.

  1. Break the logic into smaller non-repeating blocks. With Loki’s amendments this is obsolete but in general look how similar your encrypt and decrypt functions are. You should strive to reduce this redundancy. If I remember my Vigenère correctly these functions are symmetrical and can be implemented by the same logic.

You are also converting quite a lot between chars and numbers by adding or subtracting 'A'. Encapsulate this into a pair of functions, it makes the code cleaner.

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /