TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Google's C++ Class

272 pointsby hamid914about 7 years ago

12 comments

cglouchabout 7 years ago
Does anyone have any recommendations for learning to write modern, idiomatic C++? I used C++ in college for data structures and algorithms, so I have some familiarity with the basics. But we were mostly restricted to using C++98, and I'm not sure what the best practices look like these days with the changes introduced in 11, 14, and 17.
评论 #16526429 未加载
评论 #16527343 未加载
评论 #16526696 未加载
评论 #16526481 未加载
评论 #16526783 未加载
评论 #16526663 未加载
评论 #16527849 未加载
jghabout 7 years ago
I really like the idea of google open sourcing stuff but it seems like they always do it in the worst way possible.. Maybe I'm looking at the wrong projects. For example WebRTC is buried in Chromium (so is QUIC iirc) and to build either of those things it's a lot of freaking work because you have to figure out Google's build system with the documentation doing its best to prevent you from figuring it out.
评论 #16526899 未加载
评论 #16527485 未加载
mmelabout 7 years ago
Is there a list of all classes available under developers.google.com ? I could not find one from the front page. Edit: found it, <a href="https:&#x2F;&#x2F;developers.google.com&#x2F;products&#x2F;#a" rel="nofollow">https:&#x2F;&#x2F;developers.google.com&#x2F;products&#x2F;#a</a>
westoncbabout 7 years ago
I was hoping this was a class in the object-oriented language sense, and that somehow you&#x27;d use this class to instantiate a C++ in your program. Oh well—one can always dream.
评论 #16526521 未加载
freedombenabout 7 years ago
Really cool that Google is open sourcing this (as well as some of their other classes, like the machine learning one).<p>Back in the day when I was learning to code, one had to trudge through a tome of esotericism after spending hours setting up your compiler. The snow was waist deep and uphill both ways. Seriously tho, this is great. My kids are now learning to code and the availability of great resources makes a huge difference.
robbritabout 7 years ago
I&#x27;m surprised that they don&#x27;t go too much into good practice and style; these are heavily enforced in Google&#x27;s code-bases. I would expect to see things like references and smart pointers, raw pointers are typically avoided as much as possible to avoid all the fun problems that come along with them.
评论 #16526864 未加载
russellbeattieabout 7 years ago
Looking at the Getting Started section... Is this really the best way to write text out to the console in C++, or is it just traditional?<p><pre><code> cout &lt;&lt; &quot;Hello World!&quot; &lt;&lt; endl; </code></pre> It seems like something a bit simpler, readable and predictable would be better for beginners and&#x2F;or experienced devs alike. I look at that and wonder where did cout come from? Is &lt;&lt; a heredoc or some sort of pipe indirection, or am I bit-shifting? And is endl a keyword? Does it always follow cout? Is this like a Pascal endif? Oh, it&#x27;s basically just a newline. What&#x27;s wrong with just &quot;\n&quot;? I think C++ devs purposefully make their language as obtuse as possible.<p>Maybe NOT starting with streamio and operator overloading might be a more modern way to start teaching the language?
评论 #16528017 未加载
评论 #16527709 未加载
评论 #16527897 未加载
评论 #16538625 未加载
kodrabout 7 years ago
I&#x27;m surprised that in their unit tests category, they are using CPPUnit instead of Google Unit (gunit). Any ideas why?
rosegeabout 7 years ago
I guess Google is in favour of spaces over tabs by the look of that
评论 #16526625 未加载
评论 #16526691 未加载
hupsterlupsterabout 7 years ago
Please for god&#x27;s sake, let this language die. There has been nothing this bad in the entire history of programming languages and now Google wants to impose more undefined behaviors on our professional lives. Anyone starting out with learning should go through <a href="https:&#x2F;&#x2F;www.rust-lang.org" rel="nofollow">https:&#x2F;&#x2F;www.rust-lang.org</a> path and anyone who&#x27;s wise enough to understand pros and cons of such language will automatically choose rustlang over them in 2018.<p>Even in comparison with C, it falls short. C was a beautifully designed language.<p>The features of the C language were added with purpose. They were intended to solve a real problem and solve that problem they did. Simple arithmetic with promotion. Automatic register allocation with a portable (between compilers) ABI. A simple-but-handy preprocessor. And so on. C is also a lean language: a single person can feasibly write a C compiler in a relatively short time (tinycc is a C99-compliant C compiler written in just 65kLOC of C!). C set out to achieve a clear goal and it achieved its goal. Thanks to the cleanness of C lots of quality compilers came on the market quickly and even decent OSS solutions were available early on.<p>In contrast, C++ never had a clear goal. The features of C++ were added almost at random. Stroustrup&#x27;s original idea was essentially &quot;C is cool and OOP is cool so let&#x27;s bolt OOP onto C&quot;. Retrospectively, OOP was massively overhyped and is the wrong tool for the job for most of the people most of the time. Half of the GoF design patterns just emulate idioms from functional programming. Real OOP languages like Smalltalk and IO express many useful things that C++ cannot. The feature that C needed most was perhaps parametric polymorphism (aka generics in Java and C#, first seen in ML in the late 1970s) but instead of that C++ got templates that weren&#x27;t designed to solve any particular problem but rather to kind of solve several completely unrelated problems (e.g. generics and metaprogramming). Someone actually discovered by accident that C++ templates are Turing complete and they wrote and published a program that computed prime numbers at compile time. Wow. A remarkable observation that led to decades of template abuse where people used templates to solve problems much better solved by other pre-existing solutions such Lisp macros and ML polymorphism. Worse, this abuse led to even more language features being piled on top, like template partial specialization.<p>The massive incidental complexity in C++ made it almost impossible to write a working compiler. For example, it remains extremely difficult to write a parser for the C++ language. The syntax also has horrible aspects like List&lt;Set&lt;int&gt;&gt; being interpreted as logical shift right. None of the original C++ compilers were reliable. During my PhD in 2000-2004 I was still stumbling upon dozens of bugs in C++ compilers from GNU, Intel and SGI. Only after two decades did we start to see solid C++ compilers (by which time C++ was in decline in industry due to Java and C#).<p>C++ is said to be fast but the reality is that C++ is essentially only fast when you write C-like code and even then it is only fast for certain kinds of programs. Due to the &quot;you don&#x27;t pay for what you don&#x27;t use&quot; attitude, C++ is generally inefficient. RAII injects lots of unnecessary function calls at the end of scope, sometimes even expensive virtual calls. These calls often require data that would otherwise be dead so the data are kept alive, increasing register pressure and spilling and decreasing performance. The C++ exception mechanism is very inefficient (~6x slower than OCaml) because it unwinds the stack frame by frame calling destructors rather than long jumping. Allocation with new and delete is slow compared to a modern garbage collector so people are encouraged to use STL collections but these pre-allocate huge blocks of memory in comparison so you&#x27;ve lost the memory-efficiency of C and then you are advised to write your own STL allocator which is no better than using C in the first place. One of the main long-standing advantages of C over modern languages is the unpredictable latency incurred by garbage collectors. C++ offers the worst of both worlds by not having a garbage collector (making it impossible to leverage useful concepts like purely functional data structures properly) but it encourages all destructors to avalanche so you get unbounded pause times (worse than any production GC). Although templates are abused for metaprogramming they are very poor at it and C++ has no real support for metaprogramming. For example, you cannot write an efficient portable regular expression library in C++ because there is no way to do run-time code generation and compilation as you can in Java, C# and languages dating back to Lisp (1960). So while Java and C# have had regular expressions in their standard libraries for well over 10 years, C++ only just got them and they are slow.<p>C++ is so complicated that even world experts make rookie mistakes with it. Herb Sutter works for Microsoft and sits on the C++ standards committee where he influences the future of C++. In a lecture he gave his favorite 10-line C++ program, a thread-safe object cache. Someone pointed out that it leaks memory.<p>My personal feeling is that the new Rust programming language is what C++ should have been. It has useful known features like generics, discriminated unions and pattern matching and useful new features like memory safety without garbage collection.
评论 #16528458 未加载
评论 #16532351 未加载
评论 #16542894 未加载
ericfrederichabout 7 years ago
Chapter 1: Use Golang
评论 #16529636 未加载
评论 #16526855 未加载
oh_sighabout 7 years ago
I used to touch some cc files at Google. I must say they are really horrible. Basically everything relies on bizarre internal frameworks glued together with opaque macros. Some of the least legible c++ code bases I&#x27;ve worked on.
评论 #16526284 未加载
评论 #16526306 未加载
评论 #16526236 未加载