10 ms·
C++ Is the New Python
- eatonphil 5y agoI would _love_ to see a book on modern (like C++2021 modern) programming in C++ for Python developers.
- matthewaveryusa 5y agoThe closest you'll get to that is probably Scott Meyer's effective modern c++ which is for c++14. Scott has retired around in 2015 so don't expect an updated book.
- roxaaaane 5y agoActually there is a recently released book[1] by No Starch that gives a tour of modern C++ with details about implementations and librairies and even has a great chapter on unit testing. [1]:https://www.amazon.com/C-Crash-Course-Josh-Lospinoso/dp/1593278888 https://www.amazon.com/C-Crash-Course-Josh-Lospinoso/dp/1593...
- Wonnk13 5y ago+1 Lospinoso is the real deal
- tialaramex 5y agoOne problem for trying to just learn "modern C++" (so, C++ 20 and explicitly preferring the modern "right" way to do things, Kate Gregory talks about teaching C++ this way) is that C++ got this influential partly by having a lot of libraries. But for a library author, choosing C++20 over C++11 (or worse) means fewer users. So, sure, all the code from people learning "modern C++" is smart pointers and ranges, but to get work done you have to call this library that takes raw pointers and you're immediately out of your depth.
- vnorilo 5y agoraw pointers.. or homegrown strings, vectors and hash tables. C++ soldiers on because it can support such things and adapt to decades of changing hardware and philosophy. But the pain of using and composing libraries in C++ is not just about not having cargo or npm - it's the lack of consensus on data types for anything beyond C primitives.
- TillE 5y agoThis sounds like you're describing C++ from 20 years ago. Or maybe some ugly monstrosity like Qt. Everything uses/supports standard library containers or interfaces now.
- vnorilo 5y agoSome counterexamples that I've dealt in the recent years include LLVM, Abseil and Windows COM APIs.
- dekhn 5y agoThere's nothing ugly about Qt. In particular, the core system defines a way to add features to classes that were missing (MOC) and provides a full foundation of types up to network and other event-driven multi-threaded servers. Frankly I think it's one of the best examples of C++ I've seen.
- TillE 5y agoSmart pointers are a weird example because they're ancient. I'd say the majority of C++ libraries expect C++11, many C++14. Also it's still completely normal to use raw pointers or references when a function doesn't care about ownership.
- tialaramex 5y ago> Smart pointers are a weird example because they're ancient. I am an old man, and to me 2011 doesn't feel ancient, but fair. C++ 11 has unique_ptr and shared_ptr (if your library uses a previous generation of smart pointers you're in worse trouble than if it had raw pointers) and that's what you'd probably teach in class today. > Also it's still completely normal to use raw pointers or references when a function doesn't care about ownership. This is true. So you can't tell. And, with a different hat on it's also something that Kate Gregory has given talks about. As the new maintainer for several MLOC of C++ what can I conclude about this function that takes a raw pointer to a foo ? Maybe, it just wants to look at a foo, immediately and then has no further interest in it. Maybe, it will mutate the foo, immediately, and then loses interest. Maybe, it will hang on to this pointer and use it later, who knows when. Thus, now it "owns" the foo, I hope it will clean up after it ceases using it because I can't now. Maybe, I'm supposed to provide an "empty" foo and the contents of it afterwards are the primary result of the function. Those are pretty different, so it's disappointing that we don't learn which it is from the function signature.
- Zababa 5y agoI would love to see a book on modern C++ (11 and beyond) in general, for people used to other languages. I'd like to learn it at some point but it's honestly really intimidating.
- monkeybutton 5y agoWhat about a book or resources for someone who already knows C++? I haven't used it in 10 years and even then, where I worked at the time, using C++11 features was "off-limits". Just from a cursory glance, a lot seems to have changed since then?
- markus_zhang 5y agoI'm on the same line. I'd love to see a book focused on practical C++/11/17 with non trivial projects. Effective Modern C++ explains a lot of things, but concrete examples are a lot better. Some projects in mind: C++/SFML/SDL2 game programming using modern C++ Interpreter/compiler construction in modern C++ Explains how to implement things in modern C++ (e.g.unique_ptr) without modern C++ (maybe just use C)
- eatonphil 5y agoYes, just talking about the language isn't enough. Solving somewhat complex problems with standard data structures (maps, trees, hashtables, etc.) and doing it in the modern, efficient way is the kind of thing I'm really looking for. In Python it's easy (which isn't to say everything should use Python) because you don't have to do anything but use the builtin datastructures and solve your problem. Maybe modern C++ works the same way but if it does, I still need someone to show it since that isn't how it used to be (to my knowledge).
- markus_zhang 5y agoYeah the thing is I don't know if there is any _good_ small-medium modern C++ code base to read. Eventually I just gave up and use raw pointers. My theory is that since people don't care about JVM not returning memory to system, they should also not care a bout a few MBs of memory leak in my small game.
- munchbunny 5y agoAs someone who learned C++ when it was C++03 and followed the language as it went through 0x all the way to 20, I have no idea how you would be able to avoid crippling a newcomer with the sheer volume of permutations of symbols and language behaviors that a C++ developer might regularly encounter. As a consequence of the ecosystem of older libraries, I've never had the pleasure of fully stepping away from old C++-isms. There's always a naked pointer or a malloc floating around somewhere in code I have to be able to read. I still occasionally write C++ when I need to, but it's been a long time since I actually enjoyed doing it.
- rito_ 5y agoFor getting up to speed with modern C++, I highly suggest the courses and talks by Kate Gregory.
- trwired 5y agoSpeaking of "new Pythons", I recently started playing with D and got that impression. It's like the compiled, fast executing Python I have always wanted hidden in plain sight.
- otherme123 5y agoI think you might like Nim lang.
- lanstin 5y agoGo Lang is C designed after Python existed.
- spullara 5y agoGo Lang is a lot closer to Java 1.2 than it is to C.
- lanstin 5y agoIt is not object oriented. Interfaces and struct methods with composition and not inheritance is much more C than Java (no not overriding methods) kind of the C or compiled version of duck typing. Reading thru OpenSSL code is not that different from reading thru Go code. Typed but not a artificial hierarchy of types.
- 37ef_ced3 5y agoI strongly disagree. Go is an improved C that includes garbage collection (as is needed to make bug-free concurrent programming easier).
- deleted 5y ago[deleted]
- Zababa 5y agoIt's just "Go". The way I usually describe it is "the sweet spot between C, C++, Python and Java", which, considering who worked on it and where they worked, seems to be closer to reality than just C.
- sonicggg 5y agoMaking a comeback? When did it ever go away? The author talks about high frequency trading and finance applications, but it does not seem he has ever worked in the field. Production HFT is written in C++.
- NotSwift 5y agoWhat's interesting is that some of it happens to be written in Haskell.
- gotoeleven 5y agoYes it's easy to find orders sent by haskell because they're unfilled and marked 'canceled'.
- avmich 5y agoAnd Java. I suspect that would be harder to believe to some.
- NotSwift 5y agoMay I politely disagree. A lot of software in financial institutions is written in Java (maybe this is a cultural bias because I happen to live in Western Europe). The fact that some of the HFT software is (or was) written in Haskell is pretty amazing because when you first look at it, it does not appear to be a good language for being very fast.
- agumonkey 5y agosolving approach >> tool
- Zababa 5y agoThat's what I don't understand, C++ has always been one of the most popular programming languages.
- atatatat 5y ago
- NotSwift 5y agoAFAIK speed is only a real issue in the financial sector for very few applications. For most of them the database is the bottle-neck not the programs. Also, security is generally important in this sector. Both C++ and Python do not have a good track record when it comes to security. C++ has a lot of guns to shoot yourself in the foot. Python is essentially un-typed which means that errors only show up on runtime. Where I live most financial software is still being developed in Java.
- riazrizvi 5y agoSpeed is an issue in many domains, for example graphics applications and games, embedded systems and scientific computing.
- aprdm 5y agoYes and Python is fast enough for many of those. It’s very rare that the speed of Python is an actual bottle neck that cannot be worked around and must be replaced in lieu of its effectiveness
- Zababa 5y agoNo it's not? At least not raw Python. Python calling C, C++ or Fortan could be fast enough but not raw Python.
- 5y ago
- diego_moita 5y agoThe site talks so much about C++ in finance that makes it look more like the new COBOL. Besides, for high-frequency transactions I think there are better alternatives (e.g.:Rust). Edit: this is a subjective impression, not a statement of a fact. Please feel free to disagree.
- Zababa 5y agoPlease try to elaborate a bit more than the usual "Rust is a better C++". Do you know of any people in the industry using Rust? Do you know of any successful transition from C++ to Rust? What were the easy part? What were the pain points?
- lynndotpy 5y agoFor me, Python's killer feature is the interactivity. If I can't figure out how to do something in Bash, or if I need to do some math, I just start the Python interpreter
- lostmsu 5y agoC++ has Cling (terrible name): https://blog.llvm.org/posts/2020-11-30-interactive-cpp-with-cling/ https://blog.llvm.org/posts/2020-11-30-interactive-cpp-with-...
- teamspirit 5y agoIt's how I do everything now. I need the instant gratification so I pull up ptpython and just start writing line by line. The other way is to use something like fswatch and have the file I'm working on (a small snippet or one function of the larger code base) instantly run after I type :w. I do this with go and node.
- flohofwoe 5y agoThe difference between C++ and Python is that the Python standard library is actually useful to get practical work done (the famous "batteries included" philosophy). The C++ standard library can't quite decide if it wants "academical purity", or solve real world problems, and the result is a remarkably useless mishmash of random ideas.
- CodeGlitch 5y agoI find if you combine the standard library with boost, it does become pretty useful... Although some of the libraries in boost are beyond my understanding eg CallableTraits. I agree that the python standard library is really useful.
- je42 5y agoboost has quite a few useful libs.. unfortunately, some of the libs put performance first over ease-of-use. which can be a drag. and then there is compiling boost which is usually a thing where i need to set aside a day or two to get it working on a new platform / project.
- lostinparadise 5y agoWhat parts of the C++ standard library do you find useless/random?
- tialaramex 5y agoMaintenance matters. The C++ standard library provides some data structures you shouldn't use. OK, not some, C++ stdlib provides almost exclusively data structures you shouldn't use. But hey, the C++ language itself has some data structures you shouldn't use too (arrays especially). However, Python's standard library is stuck with urllib, although these days they have the courtesy to tell any poor fool looking at the documentation that Requests exists, if you do use the standard library you get very primitive HTTPS handling, and so many wrong defaults. Because these standard libraries have so many users, Hyrum's law means that you have to work very hard to fix anything.
- 5y ago
- thesuperbigfrog 5y agoRust is the new, improved C++. Rust is being added to the Linux kernel and is making inroads in domains where C and C++ have historically been used. It can match (and sometimes exceed) the performance of C and C++ but with better memory safety and sound concurrency. C++ won't go away anytime soon, but it's practically disingenuous to call C++ "the new Python".
- mountainriver 5y agoYeah Rust will mostly kill c++ overtime. I know people keep talking about modern c++ and the language has certainly improved, but it’s nowhere near the productivity of Rust. With how slow the c++ community moves and how much debt they have I think it’s game over in most arenas
- benttoothpaste 5y agoExactly the same thing was being said about Java (the first of the C++ killers) back in 1990s. And yet C++ is still around. It is not that easy to kill it seems.
- mountainriver 5y agoJava did replace a lot of c++ and Rust will replace a lot more for low latency applications
- thesuperbigfrog 5y agoJava did replace C++ in many domains, but not all simply because the JVM requires more overhead than C++. The trade-off was more overhead, but faster development and fewer errors due to not needing to manage memory or other low-level details. Java is easier to write than C++ and is more portable than C++, but needs more time to get fast and more memory to work with. By way of comparison, Rust offers all of the speed of C++ and similar low overhead with practically none of the footguns that C++ is known for.
- 5y ago
- SavantIdiot 5y agoFunny, coming from machine learning, C++ is taking over from Python there as well. Why? I think it is because Python isn't really a deployment language for this domain (development, yes). Also, C++ lets you bend C in ways that are more Pythonlike (from STL classes to templates to zany overloads). The downside: C++ that has been massaged for years by multiple academics can end up being far more dense and difficult to understand than Python over the same period. For example, look at TFLiteMicro github, it is a snarl of custom idioms in C++. Compared to TensorFlow, it is IMHO a mess and a symptom of unchecked C++ style.
- simonw 5y ago"C++ is the New Python"... in the finance world. Note that this is an article from efinancialcareers.com - and this article is about how it's popular for high speed trading systems.
- cs702 5y agoLonger term, I'd say Julia is more likely to compete with Python than C++: * Julia is now at the point that it can be used for interactive development and experimentation without time-to-compile issues; * the Julia ecosystem is coming along nicely; and * Julia has always provided near-C performance in production.
- CodeGlitch 5y agoInteresting. Numpy within python does give near native speeds for number crunching though does it not? Copying around arrays does feel like an area where python suffers, however.
- dekhn 5y agoTBH, the only reason I switched from C to Python was because I didn't know how to implement std::vector<type> and std::hash_map<type, type> in C at the time (1995), and GNU C++ didn't support templates.
- nineplay 5y agoI'd thought that one of the biggest advantages of python is that 'non' programmers can use it. All the math majors and data scientists love it and aren't interested in learning C++ . As much as I love C++ I wouldn't trust anyone to write it after a Udemy course and "Learn C++ in 30 days".
- sharikous 5y agoAll those "language market shares" are not very indicative of the multifaceted language landscape. C++ is certainly not becoming the language of wannabe research data scientists that made Python grow so much, but of course there are fields where it is growing and there are fields where adoption is decreasing. I doubt that HFT used Python before a C++ wave swept it, since speed has always been a concern, so I am skeptical of the article. As to the "Rust is the C++ killer" crowd... show me a really big project using mainly Rust now, as there are uncountable using C++, a network simulator, a desktop application, a physical simulation engine, an operating system, a compiler, anything really big. You perhaps will find one or two, compared to thousands for C++. The best that you can hope is to see Rust seriously compete with Rust 15 years from now. And then overtaking it, perhaps. Best case scenario.
- smoldesu 5y agoC++ and Rust are not competing languages. In many instances, they actually compliment each other pretty well. Rust offers native interop for C++ code, but the cost of running it is that it's labelled "unsafe" and doesn't offer any of the memory safety that truly "safe" Rust code offers (duh). With that being said though, most of the infrastructure that C++ left behind is perfectly usable in Rust. With that in mind, the "15 year plan" for Rust is to work alongside C++, giving developers a safer, oftentimes easier option for writing performant code. Rust isn't the anything killer, Rust is Rust. That's why it's so special; it's really in a league of it's own.
- davesque 5y ago> show me a really big project using mainly Rust now, as there are uncountable using C++ For starters, the Rust compiler is self hosted and is written in Rust. Many important parts of Firefox are written in Rust. The Linux kernel just added support for Rust. A moment's Googling could turn up plenty of other examples.
- Popegaf 5y agoThough they may seem more similar in syntax now that python is introducing faux static typing, C++ is definitely not "the new python" imo. The tooling around C++ is still a maze of its own, it doesn't have a proper packaging system, STL errors are still an unreadable mess in gcc (clang does a better job), and you probably won't be using the new syntax in mid-sized and larger companies. If I have to whip something up quickly, python nearly looks like the pseudo-code your would write on your paper napkin, while C++ will make you battle with pointers, references, and static typing first. For a larger project, you're better off with Rust, Go, or pretty much anything else.