r/AskComputerScience • u/Ricky771 • Aug 26 '19
Future of C/C++?
I am a student majoring CS and I heard a lot of comments that C/C++ is useless in the real field on internet or from someone who I know personally. (although school teaches C C++ Java Python and this courses are mandatory)
I am the heavy user(?) of C/C++ , and I liked it because of the features that can manage memory directly and fast and ability to control over low level system.
I also searched what kind of thing in the "field" is built by C/C++ and I found a lot of them.
For example, TensorFlow, Node.js, Firefox(mostly C), OpenCV, and many others which are famous AND huge project.
So, I am really confused. Why I fell in love with C/C++ is that actually I am really interested in what happened exactly backside of applications, how actually network communications established, processes are managed and so on. But many many people, especially on the internet keeps saying that JavaScript or Python is the best and C/C++ is suck.
Give me your idea on the claim that C/C++ is on its decline.
9
u/earlyryn Aug 26 '19
I've heard the oposite from people who teach people high load computing in mail and cloud company, so your friend should get his facts checked
2
u/Ricky771 Aug 26 '19
what exactly those people said??
5
u/Sqeaky Aug 26 '19
I can't speak for those people, but there is a common pattern in business that leverages multiple languages where they ate strongest.
Let's lump Ruby, Python, Php, and Js together and C, C++, Go, Java, and Rust. The group is fast to develop in and slow to run. The second group can be slow to develop in and fast to run.
Many people and business build their first iteration in Ruby (Twitter), Php (Facebook), or some other scripting language where the type system is loose and gets out of the way so development can proceed quickly. Then when hardware gets expensive, the product is done re-inventing itself, and obviously slow parts show themselves then the system can be rewritten in a faster language.
Twitter resisted this and just tried to fix ruby, going so far as to create their own hyper optimized version of the language. In the end this helped a little but they didn't stop serving fail whales until they just gave in and started writing c modules for their hot paths which fixed their issues rapidly.
This strategy allows business to iterate rapidly and throw away code for bad ideas at low cost, but eventually high performance and lower hardware cost once they have a proven strategy and product. This strategy comes at the cost of at least one guaranteed rewrite but tries to maximize short term chances of success at each stage.
1
u/earlyryn Aug 26 '19
for the highest load services they use c++ and recently started adopting go, big in CES companies like mail. ru and badoo, they stating it on their talks on youtube, also there are online courses on highload.
11
Aug 26 '19
Each language is good for certain things.
Anything that needs high performance will be written in C++, C, or some other language that compiles to machine language like Rust or D.
I note that Python is written in C, and Javascript is AFAIK too.
3
u/Ricky771 Aug 26 '19
oh been never heard of that JS is written in C. I should go for search that. thx for your reply :)
6
u/Mukhasim Aug 26 '19
Google's Javascript engine is C++, Mozilla's is a mix of C and C++. (There's no such thing is C/C++ but people occasionally do write some parts of a program in C and other parts in C++.)
1
u/kylebustard Aug 26 '19
Mozilla’s Firefox also uses Rust. How much of Firefox is written in Rust?
2
u/Mukhasim Aug 27 '19
I'm glad you're excited about Rust! As far as I can tell, though, it's not really used in Mozilla's JS engine yet, just elsewhere in the browser. The SpiderMonkey web page says: "SpiderMonkey is Mozilla's JavaScript engine written in C and C++." I do see a small amount of Rust code in the "js" tree though, so maybe they'll start using more Rust code in the future? I also found some discussion on Reddit of experimental JS code being developed in Rust.
1
u/kylebustard Aug 27 '19
Thanks for the clarification abt Firefox.
I think the experimental JS code you mentioned is the Deno project. Deno is a JS runtime written in Rust.
2
u/delventhalz Aug 26 '19
Yeah, I wouldn't be surprised if a newer language like Rust with similar performance characteristics eats C++'s lunch eventually. But that day is still a ways off.
1
3
u/CastigatRidendoMores Aug 26 '19
Echoing what others have said, C and C++ each have staying power as being ideal for performance-critical applications. Lots of stuff is built in each language that will need to be maintained and cannot be ported over to almost any other language. There is a good alternative to C now - Rust. For a long while at least, C will continue to be dominant due to momentum. Even if you will want to develop in Rust someday, gaining mastery in C will help you learn that language as well due to a high conceptual overlap.
I will say that while classic web development is basically never done in C or C++, some applications written in those languages are now being ported to web assembly, so it is (kind of) picking up in that sector. Two recent examples include Diablo and Google Earth. That isn’t central to web development but it will be a growing specialization related to it.
2
3
u/uber_kerbonaut Aug 26 '19
I think Google is 10 years into the future of software development, so I'll tell you what the future looks like.
Mandatory smart pointers
Strict compilation settings
Lousy common data structures like std::map banned in most situations.
include constricted down to a single pattern, so there's not 10 ways to do it.
And a lot of C++ abandonment in favor of Go and Rust.
1
u/lord_segfault Aug 26 '19
Lousy common data structures like std::map banned in most situations.
Could you elaborate on that? Why do you consider std::map a "lousy" data structure that shouldn't be used?
3
u/MCPtz Aug 26 '19 edited Aug 26 '19
https://www.fluentcpp.com/2018/12/11/overview-of-std-map-insertion-emplacement-methods-in-cpp17/
TL;DR Go ahead and try out the C++17 emplacement / insertion methods. They offer a tangible improvement in terms of expressiveness and code safety.
Here's a specific example they provide:
// C++03 style std::map<int, std::string> m; m[1] = "Ann"; // C++03 style std::map<int, std::string> m; m.insert(std::make_pair(1, "Ann"));Convenience aside, what is more important, operator[] differs from insert() in how it handles a situation when an element with the given key already exists in the map. While operator[] simply overwrites the corresponding value, insert() doesn’t.
Also (need to read article to get context):
Clang-tidy uses a mixed approach with a general preference for emplacement with the exception of std::unique_ptr and std::shared_ptr where emplacement could lead to memory leaks:
// might leak if allocation fails due to insufficient memory for an object A std::map<int, std::unique_ptr<A>> m; m.emplace(1, std::make_unique<A>("Ann",63));Anyways read the article for full information.
With all the different ways to use the std::map, it's little surprise that it's unsafe and inconsistent.
1
u/UncleMeat11 Aug 26 '19
std::map is very slow for what it is doing. It also has a really nasty API that is full of footguns. Developers frequently do 2 or 3 lookups when only one is needed and operator[] creating a default entry is a classic cause of bugs.
2
u/t4YWqYUUgDDpShW2 Aug 26 '19 edited Aug 26 '19
Tensorflow and node.js are great examples. Tensorflow was built to be used in python. Most users use it in python, despite it needing to be written in C++ in many parts for sufficient performance. Likewise with node.js. Much of it is written in C and C++, but the purpose is JS. Almost all users of tensorflow and node.js don't use C or C++ when they use tensorflow or node.
Languages exist in ecosystems, which are essential to the choice of which language to use for this project or that. Sure python isn't fast enough for ML, but that doesn't matter because it has libraries that use faster languages for you. For common enough tasks, you will get their benefit whether you use them or not, because of great ecosystems.
Doing the rest of the task at a low level of abstraction is an extra cost that might only net you a small gain. Small gains due to the diminishing returns of doing the less time sensitive parts quickly, or small net gains due to the higher dev costs of having to deal with low level concerns like memory as well as business logic.
C and C++ are crucial to the work you'll probably do, but you may never have a reason to program in them yourself. It really depends on the industry. They'll stay incredibly important, but the number of jobs out there where you can work in them may decrease.
2
u/_370HSSV_ Aug 26 '19
C++ is used in unreal, lots of apps use c++ that want performace. Lots of embbeded shit uses c. They ain't going anywhere.
2
Aug 26 '19
Alright, I am not going to say the same thing everyone else has already said about C/C++. Neither are going anywhere, that much is clear.
However, that does not mean these people are automatically idiots; every language is merely a tool, and certain tools are better for certain tasks. In the same way I would not write a website in pure C++, no one should (yes it has technically been done) write a full operating system in JavaScript. That's improper tooling.
In my opinion, it is a programmer's job to know what tool is best for their task, and to figure out how best to integrate it. If that means you need to use Python, then use that. If it means writing an entire network stack in C, then I wish you the best of luck.
1
u/chefboirkd Aug 26 '19
Many of the libraries used to power frameworks and performance critical operations are written in C++.
1
u/MCPtz Aug 26 '19
High performance generally points to C or C++. I've interviewed (initial tech screens) with a handful of companies in that area just this year.
Embedded systems, with generally very limited memory use assembly and/or C xor C++. It's possible to change your compiler settings so that, for example, gcc compiles C++ into relatively small binaries. This would be known as running C++ on the "bare-metal", that is without an operating system such as Linux.
Also embedded Linux can run python, Java, C++, etc, but Java has a "feature" in that it uses as much memory as given to it, and thus if a system has limited RAM and no swap, Linux will start killing processes that try to use more memory than is physically available.
If your important program is on the java virtual machine, it might get killed for using too much memory, or your background compression algorithm (e.g. bzip2) might not be able to execute due to too little RAM, and so your rolled over log files remained uncompressed, filling your limited file system.
C++, or something similar, would be a good higher level language in those limited environments.
There are downsides to C++, in that you can do unsafe things that will crash your software or system. Or that there are ten different ways to do the same thing, meaning each software engineer might do it different ways, some of them being unsafe.
1
u/xxkid123 Aug 26 '19
New grad, my daily programming work is 70% coding in c++, 30% python test automation. I think C will stick around virtually forever thanks to it being the de facto open source language, but I think C++ may see its way out in the next couple decades. In my opinion, C++ isn't a pleasant language to work in and you choose it because it's the only compiled down, high performance language that supports object oriented and other modern features. As soon as another language can completely replace C++ you'll see it phased out pretty quickly.
My CS program also started with C++ and moved to C. It's an excellent way to learn fundamentals of CS and programming at a deep level. You're better prepared to write lower level code when you learn about Operating Systems and Data Structures, which gives you a better understanding of how memory is utilized. Chances are you'll probably teach yourself python through your degree (because it's super useful and easy to pick up), and your later classes will probably teach you Java and other languages. You should definitely be trying to pick up a second language because your technical interviews will be in a language of your choice, and you're really holding yourself back if you're trying to code in C++ on a whiteboard.
81
u/salamanderoil Aug 26 '19
Just so you know, there is no such language as 'C/C++'. There is C, and there is C++. Don't fall into trap of mentally lumping them together – although C++ is more or less a superset of C, in practice, they are very different languages.
As to your question, neither C nor C++ is going away anytime soon. Anyone who tells you otherwise doesn't know what they are talking about, and can be safely ignored.
In industry, C is big in embedded systems, operating systems, and various other spaces where low-level hardware access is needed, without any overhead. C++ is big in commercial applications development (especially in applications where performance is critical), finance (high-frequency trading, for example), games development, and for creating computationally-intensive libraries, such as OpenCV and TensorFlow (as you rightly pointed out).
People who claim that C and C++ are useless are either completely uninformed, or are so heavily into web development or similar that they forget that other domains exist. Just ignore them. If you learn one or both of C or C++ well, it will open up all kinds of interesting career doors for you that those other people will never have access to.