3 ms·
$ wc -c a.cpp t.cpp 399 a.cpp 380 t.cpp 779 total $ cat t.cpp #include <iostream> using namespace std; namespace utils { template<typenam
by claudius 12y ago
$ wc -c a.cpp t.cpp
399 a.cpp
380 t.cpp
779 total
$ cat t.cpp
#include <iostream>
using namespace std;
namespace utils {
template<typename T> T square(const T& n) { return n * n; }
}
int main() {
int input(0);
auto message("Please enter a positive number");
cout << message << ":\n";
cin >> input;
if (input>0) { cout << "Result: " << utils::square(input) << "\n"; }
else { cout << message << "\n"; }
return 0;
}
$ cat a.cpp
#include <iostream>
using namespace std
namespace utils
template<typename T>
auto square(const T& n)
return n * n
int main()
auto input = 0
auto message = "Please enter a positive number"
cout << message << ":" << endl
cin >> input
if input > 0
cout << "Result: " << utils::square(10) << endl
else
cout << message << endl
return 0
I am not entirely convinced that t.cpp has any more or less noise than a.cpp and where exactly there is any sort of gain from this – I had more trouble indenting the second piece of code properly for HN than the first.
- SupremumLimit 12y agoIf you squint in just the right way so as not to see any of the braces, semicolons and parentheses in the first example, then naturally we are going to disagree about the amount of noise :)
- claudius 12y agoMaybe my visual capabilities are just more limited than yours :) That said, I wouldn’t call things like ‘end of statement’ or ‘end of this block’ noise. They have very real effects and using ; and } over "\n" and "\t" seems a decent choice. Natural languages have ".", "," and ";" for a reason, too; although one could argue for paragraphs to be roughly (but only roughly!) block-equivalents and inherently whitespacy.