xigoi

C++ Language Criticism

Everything that applies to C also applies to C++. This article contains only things that don't apply to C.

The C++ FQA has a lot of great points, so go read it too.

Overall philosophy

I believe that a programming language should be designed to make simple things simple and complex things as simple as possible. C++ is designed to make simple things complex and complex things even more complex. For example, a program to read space-separated numbers from STDIN, sort them and again output them space-separated:

Python 3
nums = [int(inp) for inp in input().split()]
print(*sorted(nums))
Try it online!
Nim
import std/[strutils, sequtils, algorithm]

let nums = stdin.readLine.splitWhitespace.mapIt(it.parseInt)
echo nums.sorted.mapIt($it).join(" ")
Try it online!
Haskell
import Data.List

main = interact $ (++ "\n") . unwords . map show
                . sort
                . map (read :: String -> Int) . words
Try it online!
C++
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
  std::vector<int> nums;
  std::string inp;
  while (std::getline(std::cin, inp, ' ')) {
    nums.emplace_back(std::stoi(inp));
  }
  std::sort(nums.begin(), nums.end());
  std::string sep = "";
  for (int num : nums) {
    std::cout << sep << num;
    sep = " ";
  }
  std::cout << std::endl;
}
Try it online!

Features

Syntax

C++ took the horrible syntax of C and somehow managed to make it even worse.

Standard library

Tooling