Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Because it is not as useful as other languages?


> Because it is not as useful as other languages?

C++ doesn't have web frameworks, and is big and complicated. If you aren't doing web projects, you can safely stick with a subset(with guidance of course). You mention is not being useful - what is that Python can do that C++ can't? C++ is going to be a bit more verbose, yes, but verbosity is not the only variable. Also, use stl(and/or boost) and your code won't be that verbose. This isn't that bad.

    #include <set>
    #include <string>
    #include <iostream>

    int main(int argc, char **argv)
    {       
            // Declare and Initialize some variables
            std::string word;
            std::set<std::string> wordcount;
            // Read words and insert in rb-tree
            while (std::cin >> word) wordcount.insert(word);
            // Print the result
            std::cout << "Words: " << wordcount.size() << std::endl;
            return 0;
    }


It is verbose compared to python, which would do this in about 3 lines. It's also not that great an example because it begs the question why one moment a set of strings ('words' as variable name feels weird to me because I think in c of word boundaries, but whatever) is set<string> (please use 'namespace std') and next moment its char argv. These are obviously simple things to anyone with c++ knowledge, but teaching this to someone is just likely to put them off. There's no reason to use c/c++ today unless you're coding drivers or very performance critical things.

A set isn't necessarily implemented using a red-black tree, most likely its a binary tree of some kind, but why would anyone put that in a comment. It's a set, which just means there's only copy of any repeated 'words'.

I think the reason why c++ doesn't make a good language to teach youngsters is because stl is still a beast of a template library, still spits out garbage error messages and is painful to work with even by the most experienced of developers (25+ c/c++ here)

On the other hand, collections and data structures in python are simple, efficiently implemented and extremely succinct, if the value of a dictionary element contains 2 or 3 elements, or is another dictionary, or a map etc it's simple to do this in python, where as in stl pair<int, int> is great until you need three of them, then its auto_ptr or whatever and it starts to get unwieldy and the poor student trying to focus on the algorithm is now bogged down in the with the inelegance of a low level language.

Don't get me wrong, I love c and c++, but i'd rather teach some python or ruby because they can get stuff done and working and not struggle with tedious syntax.

len(set(sys.stdin.read().split(' ')))

C++ does have web frameworks too! Witty (wt)


> It is verbose compared to python, which would do this in about 3 lines.

That can be done as a perl one liner. The C++ program is pretty reasonable as in it matches to the algorithm.

1. Read words.

2. Add words to a set. Set only has unique elements.

3. Print set size which will give you the number of unique words.

> It's also not that great an example because it begs the question why one moment a set of strings ('words' as variable name feels weird to me because I think in c of word boundaries, but whatever) is set<string> (please use 'namespace std') and next moment its char argv.

Questions are good. Questions aid understanding. You are overestimating C++'s complexity and underestimating a 14 year old's abilities.

> There's no reason to use c/c++ today unless you're coding drivers or very performance critical things.

Personally, I think all programmers should have a working knowledge of C or C++. C is the best simulation of the machine. Assembly is closer, but writing assembly is a pain.

> A set isn't necessarily implemented using a red-black tree, most likely its a binary tree of some kind, but why would anyone put that in a comment.

Copied code from the web. Wasn't paying attention. That comment shouldn't be there. A set should be viewed as an ADT and the implementation shouldn't matter.

> I think the reason why c++ doesn't make a good language to teach youngsters is because stl is still a beast of a template library, still spits out garbage error messages and is painful to work with even by the most experienced of developers (25+ c/c++ here)

STL is a beast, yes, but you don't have to know the whole of it. Regarding error messages, I find clang's error messages better.

> Don't get me wrong, I love c and c++, but i'd rather teach some python or ruby because they can get stuff done and working and not struggle with tedious syntax.

I would teach Python as well. I was taking exception to the knee jerk reaction to C++.


I meant "not as useful" as "not as efficient". Of course you could do everything you could do in Python (or whatever) in C++, since Python is basically a subset of C++ (I assume Python is written in C/C++).

It just seems weird to make beginners start with a complicated tool when there are easier tools that can get the same results.


Useful in what sense? Are you _using_ an operating system? What language was that written in? So how useful is it?

NB: I'm taking your comments to apply equally to C as C++, given the prevalence of C in operating systems. If you really would not have said the same thing about C, I retract my comments.


If as a 14 year old your plan is to write an operating system, learning C might make some sense. It just seems like a very unlikely scenario to me.

Also I think a lot of tools for example in Linux are written in other languages.

Most likely scenario for using C as a 14 year old might be doing electronics projects, but I think Arduino is most commonly programmed in Java.


Arduino is C/C++. It's mostly a C++ abstraction built on top of the avr-libc library. The Arduino IDE is written in Java though.


I think you can program the Arduino in C/C++ (like every other Microcontroller), but I was under the impression that it actually has a Java Runtime and the usual way is to code Arduino programs in Java.


The Arduino is based around Atmel's 8 bit AVR architecture which really doesn't have what it takes to run a JVM. The ATmega328P which the Arduino Uno board uses has 32KB of code space and 2KB of SRAM which isn't really enough for something like Java. The normal way Arduino projects are built is by defining a "setup" function and a "loop" function which, when compiled, are actually just called by a hidden C++ file with a main function that essentially does this:

    int main(void) {
        setup();
        for (;;)
            loop();
    }
The actual file does a bit more and can be found in their git repository here: https://github.com/arduino/Arduino/blob/master/hardware/ardu...


Tell me that. C++ is a widely used industrial language.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: