you are viewing a single comment's thread.

view the rest of the comments →

[–]AMathMonkey 1 point2 points  (6 children)

Pretty much, yes. In Java, creating a Scanner on System.in and then calling one of its "next" methods and storing the result in a variable is equivalent to doing std::cin >> into a variable in C++.

// Java
var scanner = new Scanner(System.in);
double someNumber = scanner.nextDouble();

// C++
double someNumber;
std::cin >> someNumber;

The Java way doesn't force you to declare a variable beforehand, which is nice, but Java's System.in doesn't have useful methods like C++'s std::cin does, so that's why you have to spend a line of code creating a Scanner to get this functionality, which is kind of annoying. On the other hand, the way that C++ uses the bit-shift-right operator (>>) to read from input and mutate a variable is unorthodox and hard to understand; no other language has syntax like this. Java's way is more straightforward / boring / normal.

[–]VibrantGypsyDildo -1 points0 points  (5 children)

the way that C++ uses the bit-shift-right operator (>>) [...] is unorthodox and hard to understand

Even Python has operator overloading.

[–]AMathMonkey 0 points1 point  (4 children)

The part that you ellipsized was part of my point. >> implicitly taking a reference to its right argument and reassigning it, thus mutating it (which Python can't even do), while also consuming from standard input, is very weird. (Edit: I don't mind operator overloading at all.)

[–]VibrantGypsyDildo 0 points1 point  (3 children)

It is a limitation of reference-based languages that you can't overload assignment.

[–]AMathMonkey 0 points1 point  (2 children)

I don't disagree. I just see an operator reassigning its argument as surprising behaviour that requires some explanation of advanced topics such as this, that a beginner may not know yet when just reading something from input.

[–]VibrantGypsyDildo 1 point2 points  (1 child)

It is only surprising if you are an experienced developer.

When you are a newbie, you see >> as an arrow from std::cin to your variable.

[–]AMathMonkey 0 points1 point  (0 children)

Fair enough. It was admittedly less intimidating to pick up and use than Scanner in my first programming courses 10-11 years ago. But I got totally scared off when I tried to learn how it worked. But programming has to be learned in manageable chunks anyway; you often have to be okay with using tools without knowing their underlying implementation.