Function uses like this

Hey guys so I've been wondering why don't people do this all the time:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>

template<class T>

void print(T out)
{
    std::cout << out;
}

int main()
{
    print("Hello");
    int x = 5;
    print(x);

    return 0;
}

I mean replace a bunch of things with functions of your own so you can use simpler keywords (e.g. print instead of std::cout << ).

Why don't people do this?
Last edited on
I would guess there are multiple reasons.

In the example your giving, print x looks like a "basic" command, and other languages may use the same format so I'm guessing it's so the programmer can use a command he's used to instead of a command that's slightly longer to type. To me print x also seems slightly easier to read.

Now myself I wouldn't do it to simply use a command from another language, but if it saves keystrokes then I'm all for it.

The reason to use a function is to type a function once and use it over and over saving keystrokes and to tidy up the code. In this case it seems like overkill but if your programming and can type 30 words a min, and you save yourself 15K keystrokes a day using shortcuts, then you increase your productivity 20-30%.
Thanks for the great answer!

I also do this when I'm testing out my program:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <cstdlib>
void clear()
{
    system("cls");
}
int main()
{
    std::cout << "Hello World!";
    clear();
    std::cin.ignore();
    return 0;
}


Thanks again for your answer.
Topic archived. No new replies allowed.