Тёмный

CppCon 2015: Herb Sutter "Writing Good C++14... By Default" 

CppCon
Подписаться 149 тыс.
Просмотров 189 тыс.
50% 1

www.cppcon.org
-
Presentation Slides, PDFs, Source Code and other presenter materials are available at: github.com/isocpp/CppCoreGuid...
--
Modern C++ is clean, safe, and fast. It continues to deliver better and simpler features than were previously available. How can we help most C++ programmers get the improved features by default, so that our code is better by upgrading to take full advantage of modern C++?
This talk continues from Bjarne Stroustrup’s Monday keynote to describe how the open C++ core guidelines project is the cornerstone of a broader effort to promote modern C++. Using the same cross-platform effort Stroustrup described, this talk shows how to enable programmers write production-quality C++ code that is, among other benefits, type-safe and memory-safe by default - free of most classes of type errors, bounds errors, and leak/dangling errors - and still exemplary, efficient, and fully modern C++.
Background reading: Bjarne Stroustrup’s 2005 “SELL” paper, “A rationale for semantically enhanced library languages," is important background for this talk.
--
Videos Filmed & Edited by Bash Films: www.BashFilms.com
*-----*
Register Now For CppCon 2022: cppcon.org/registration/
*-----*

Опубликовано:

 

23 сен 2015

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 111   
@amaarquadri
@amaarquadri 2 года назад
You know that something is amazing when it seems so natural and obvious that in hindsight you wonder why something like it wasn't done a decade earlier!
@MrSparc
@MrSparc 8 лет назад
Thanks CppCon for share this videos early on! Look the number of views in few hours! Please continue posting other talks for all of us that unfortunately can't assist this great event with the C++ family. CppCon you're rock!!!
@AlessandroStamatto
@AlessandroStamatto 8 лет назад
Fantastic presentation! Amazing work, getting memory safety without too much annotation is fantastic.
@MaherBaba
@MaherBaba 8 лет назад
I could watch these all day
@JCStelu
@JCStelu 8 лет назад
Herb explains things so much better than Bjarne. Everything is nice and clear, even for a beginner like me. Thanks Herb! :-)
@JCStelu
@JCStelu 7 лет назад
Benjamin Rood I couldn't say, since I am yet to listen to many of the C++ guys, but he sure is a great one! :-)
@mathieusoum6994
@mathieusoum6994 8 лет назад
[Completing previous comment] As Herb said : "You take a copy of a shared pointer before you turn it into a raw pointer and pass it on a call tree". His point is that the tools he is presenting helps you to remember to do that.
@maxx666mayhem
@maxx666mayhem 8 лет назад
Awesome presentation, very educational.. Thanks for sharing...
@MatthisKruse
@MatthisKruse 8 лет назад
This is great! I can't wait for C++14! :D
@MrAbrazildo
@MrAbrazildo 13 дней назад
2:00, I know this is just a silly example. But it's nice to point some things. I use to separate the midia (big data) of a circle, from "its logic", which is likely to fit on caches. So it becomes an "OO inspired by DOD" approach. As for for range loop, despite being a C++11 thing, I only passed to use it from C++14. It was required to specify the type. So on those years I used a macro of my own, which deduced the type, at the cost of using pointer syntax. I think "auto all the things" is gold. 3:31, good, because there are old things with bad reputation, that actually are pretty useful - macro, old enum, someone could say unions. So, don't make mistakes Carbon folks are already doing!
@kimicochiang
@kimicochiang 11 месяцев назад
I love this video so much.Really appreciated.
@enhex
@enhex 8 лет назад
+Vasiliy Galkin I think it's because gsp is a global variable so f() or any other fuction f() may call can access gsp directly and modify it (f.e. call gsp.reset()), so gsp' could be invalid. Using sp means you increase the ref count so even if f() or any function f() calls modifies gsp, the ref count won't go down to 0 and delete the pointer's object. It confused me too because Herb wasn't clear about the fact that gsp can be accessed and modified from the functions, even tho he said that (was thinking about what can change the pointer and not the owner).
@LukaszStafiniak
@LukaszStafiniak 8 лет назад
Woohoo! Variants!
@qumetademo
@qumetademo 8 лет назад
Good job
@mathieusoum6994
@mathieusoum6994 8 лет назад
I am not an expert (at all), but I think the second method works because you create a copy of the smart point global_sp into the local sp. This should increment the number of existing references (pointers) to *global_sp (that's what smart pointers are for). With such a copy, it is now impossible for f() to completely invalidate global_sp using only sp.get() because there will be at least 1 more reference to *global_sp due to the copy before the call. RU-vid response comments are too short >
@jeffdovalovsky7259
@jeffdovalovsky7259 4 года назад
Does a crossword-puzzle or scrabble board use a 2-dimensional string?
@Orgyilkos
@Orgyilkos 7 лет назад
I wonder if these static analysis tools work when the memory validations happen separated in the code. For example if a function created a pointer to that vector... Oh forget it, since I started writing this he started to cover this point. :D
@VileLasagna
@VileLasagna 8 лет назад
It kinda disturbs me that Herb pronounces things like "shared_ptr" as "shared putter" rather than "shared pointer"
@yemiez
@yemiez 8 лет назад
+Vile Lasagna Same x_x
@HobokerDev
@HobokerDev 8 лет назад
+Vile Lasagna I think he said "pointer" once.
@ruadeil_zabelin
@ruadeil_zabelin 7 лет назад
In another video he also talked about stuhduh instead of std
@isakbuhl-mortensen1967
@isakbuhl-mortensen1967 7 лет назад
He does that in this one too ^ ^
@SamVsCode
@SamVsCode 7 лет назад
He wanted to rhyme sutter with putter
@ecinZtark
@ecinZtark 7 лет назад
I don't really know C++. How can I learn how to do it how he mentions it @ 2:00 without having to go through the code on the left hand side.? In other words, learn C++14 from C [or scratch], not from C++03. I come from a C background as implied. I'd like to develop good habits from day one!
@ChefSalad
@ChefSalad 2 года назад
The one thing about this newer style of C++ that I really hate is the keyword "auto". I always find it harder to figure out what's going on without the types being laid out explicitly.
@InXLsisDeo
@InXLsisDeo Год назад
If you use a modern IDE, it always tell you what's the type is just by having the mouse on the variable name.
@robbie_
@robbie_ 6 лет назад
reinterpret_cast is OK if you're interfacing with a C-style library (like OpenGL for example)? I use them there.
@MagnificentImbecil
@MagnificentImbecil Год назад
reinterpret_cast is often wrongly used to convert "pointer to T" to "pointer to U" when T and U are "unrelated types" (e.g. char and unsigned char) and static_cast does not seem enough, but in fact static_cast really is enough: const U *pointer_to_const_U = static_cast (static_cast (pointer_to_const_T)); I believe reinterpret_cast remains useful for converting pointers to integrals (e.g. of type std::uintptr_t or std::size_t) and... anything else, anyone ? (-:
@VasiliyGalkin
@VasiliyGalkin 8 лет назад
I've written it wrong, f(global_sp) should be replaced by f(global_sp.get()), and f(sp) --> f(sp.get()). Yet, my question remains open.
@CdTCzech
@CdTCzech 8 лет назад
-1 because: Visual Studio is free tool if you are open source developer. Look at Community edition. Herb Sutter works for Microsoft so, yeah, he is firstly implementing everything for Visual Studio I guess and than it comes to clang or gcc. And at last but not least as Zarviroff Serge said - it doesn't matter - it's about C++ and you not IDE or operating system.
@jvsnyc
@jvsnyc 3 года назад
Lots of points for correctly using the term "dangling pointer". Too many otherwise good sources seem to confuse the meaning.
@VasiliyGalkin
@VasiliyGalkin 8 лет назад
I didn't get the example about shared_ptr (slide precisely at 1:00:00). What Herb claims: void f(int* p) { /* might invalidate p */ }; shared_ptr global_sp = ...; int main() { f(global_sp); // bad, and tool confirms it auto sp = global_sp; f(sp); // OK, checker tool also has no complaints. return 0; } I can't get it why second case is a good scenario. When we assign global_sp to sp, they both still point to the same data. Given that, f(sp) will invalidate both.
@mapron1
@mapron1 4 года назад
No, f(sp) could potentially invalidate global pointer, no it's data. If we change global_sp to new pointer value, any local copy of it is unaffected. So local sp pointing to original global_sp location, no problem at all.
@RyanHaining
@RyanHaining 8 лет назад
The examples around 1:20:55 don't compile because you can't bind a non-const int& to the return of std::min
@MagnificentImbecil
@MagnificentImbecil Год назад
We all know very well what he meant -- a reference to const --, so we can mentally substitute. This is 90-minute talk with a thousand details. Some typos sneak in. But the meaning is clear.
@BloodHaZaRd666
@BloodHaZaRd666 5 лет назад
does someone know how to reproduce the errors for example 1 using code analysis @46:30 , what rule to set ?
@SrIgort
@SrIgort 2 года назад
Good question, of someone discover please tell us
@treyquattro
@treyquattro 7 лет назад
why isn't thing.bytes() thing.byteCount() or thing.numberOfBytes()? If you say in the explanation "number of bytes" but it still says bytes() which I would have presumed returned a byte array then you've done something wrong.
@rizonplaygd5004
@rizonplaygd5004 6 лет назад
You are a university student I presume?
@inyangainyanga1733
@inyangainyanga1733 8 лет назад
Exactly, both will be invalidated, because they both point to the same thing. Reference counter is not going to prevent that. I wonder how nobody complained about that. What you need in this case is another copy: auto sp = std::make_shared<int>( *gsp );
@sy8111
@sy8111 8 лет назад
Good fun
@TheRevolucas
@TheRevolucas 7 лет назад
I don't get it, one guy on panel exclaims std::max is wrong and now they saying std::min is wrong.
@Danielle_1234
@Danielle_1234 7 лет назад
It was about trying to convert a temporary value (also called: r-value. A variable without a name.) to a reference (also called: l-value reference). C++ doesn't support that. Why doesn't C++ support it? Because the temporary (r-value) is by default const. eg func("Hello world");
@keepmefromdecay
@keepmefromdecay 4 года назад
So is there a similar tool for linux ?
@MagnificentImbecil
@MagnificentImbecil Год назад
Yes, certainly. In Linux, one can use Virtual Machine to run Windows with the wonderful Windows applications such as Visual C++. He. He, he, he.
@EnthusiasticCoder
@EnthusiasticCoder 8 лет назад
How does copying a shared_ptr protected from side effects from callees when both the orignal and copy shared ptr's point to the same underlying memory? [1:01:00] Dead confused.... Any replies?
@EnthusiasticCoder
@EnthusiasticCoder 8 лет назад
+MaidePlays So its upping the count by 1 to keep things alive. Is this a threading issue?
@EnthusiasticCoder
@EnthusiasticCoder 8 лет назад
+MaidePlays I dont remember the code.
@EnthusiasticCoder
@EnthusiasticCoder 8 лет назад
***** Ok i remember the code. So what's the fix that Herb suggests for this dangling pointer problem? Surely any new shared ptrs put in will also point to the same ptr?
@EnthusiasticCoder
@EnthusiasticCoder 8 лет назад
***** A copy of the shared Ptr I remember.
@EnthusiasticCoder
@EnthusiasticCoder 8 лет назад
Ok - I tried your sample code and as you say it works. Thanks!
@sienkobilenko
@sienkobilenko 8 лет назад
Why only VS? Why don't tall about free IDE and what about user of Linux ?)
@__hannibaalbarca__
@__hannibaalbarca__ Год назад
Why old programmers were so smart : 1. Working with unsafe language 2. No Social Media 3. No CS all of them were mathematician. So …
@VictorChavesVVBC
@VictorChavesVVBC 8 лет назад
But C++14 is already out...
@origamibulldoser1618
@origamibulldoser1618 8 лет назад
Complaining about heavy annotation in a language that still relies on header files...
@gim913
@gim913 8 лет назад
1:09:17 he said eminem, half-life 3 confirmed
@llothar68
@llothar68 8 лет назад
I tried to use smart pointers in a smaller new project. I'm sorry but i can't get myself behind it. It uglifies the code where readability is the most important part. Lambdas and r"sql( )sql" strings are the best. I only want a better stdlib and multiple return values from functions. Unfortunately modern C++ is also using much more memory and performance. So i upgraded from C with classes to C with lambdas.
@AtheistSid
@AtheistSid 8 лет назад
+Lothar Scholz multiple return values? Return a struct with multiple members?
@llothar68
@llothar68 8 лет назад
Karl Hatteland But struct splitting to put the values into variables or pass two result values into another function as 2 seperate arguments is not possible without built in compiler support. Yes it is all Syntax Candy and there is a way around it, i know, but then i could also use C and Brainfuck.
@twostickman
@twostickman 8 лет назад
return a tuple, and use std::tie to assign to variables in the calling scope
@Baekstrom
@Baekstrom 5 лет назад
en.cppreference.com/w/cpp/language/structured_binding
@childhood1888
@childhood1888 2 года назад
55:55
@childhood1888
@childhood1888 2 года назад
32:48
@ifilmhackersdotcom
@ifilmhackersdotcom Год назад
The community (incl Chandler Carruth, Kate Gregory and even Sutter) came to realize that Modern C++ and in particular move semantics were like lipstick on a pig. It is unusually complex for beginners, it requires much more CS theory knowledge (xvalue/prvalue etc) that should be handled by the compiler like in more contemporary languages as Rust and Carbon. It feels out of place. Many heavyweights are jumping boat, creating new languages due to the realization that Modern C++ hit a dead end.
@shimondoodkin
@shimondoodkin 8 лет назад
better name: a better default profile for type safety in c++14
@inyangainyanga1733
@inyangainyanga1733 8 лет назад
No, you don't create a copy, you just create another object that points to the same thing (same memory address). A real copy would do the job.
@canmetan670
@canmetan670 7 лет назад
Every time I see an " *auto* " part of my soul dies a little.
@mzaxnav4153
@mzaxnav4153 7 лет назад
(-_-) why? auto is so useful... oh u are talking about auto keyword in C++98.. yeah, that indeed eats part of one's soul.
@treyquattro
@treyquattro 7 лет назад
it's like "var": I don't really know what's going on here so I'll just leave it for the runtime/type checker to figure out. Also it promotes laziness.
@NyiBBang
@NyiBBang 7 лет назад
Wait what ? auto has nothing to do with runtime ...
@kamilkoczurek484
@kamilkoczurek484 6 лет назад
Have you thought that… well, maybe code is a bit cleaner if you use auto instead of std::vector::const_iterator? Writing short and readable code isn't a sign of laziness, it's a sign of being a good developer.
@jonesconrad1
@jonesconrad1 6 лет назад
auto is compile time not runtime. It's not about laziness, it allows much easier refactoring amongst other things. How many libraries I've used where people do something like (int i =0; i < xx.size(); i++) { be_lazy(); } where size() returns a size_t, the compiler then throws a signed / unsigned mismatch warning, can easily be avoided with auto, it's still obvious what you are doing, and if the xx type gets swapped for something where size() returns a signed type, using auto means still no warning. It also prevents copies/conversions of objects where the declared type is mismatched to the assigned value type.
@paulfunigga
@paulfunigga 8 лет назад
Why are they making it so difficult to use? It's insane, good thing I switched to Java...
@iitalics
@iitalics 8 лет назад
+Paul Orekhov It's safe and VERY fast (much unlike Java...)
@paulfunigga
@paulfunigga 8 лет назад
+Milo Turner that is complete bullshit.
@paulfunigga
@paulfunigga 8 лет назад
***** I would, I just don't understand why they have to make C++ so complex, the only thing I like about it is the STL, that's it.
@iitalics
@iitalics 8 лет назад
+Mariano c++ is hardly just object oriented. when they add variants it will be just as functional your average fpl
@iitalics
@iitalics 8 лет назад
***** because of C++'s history of backwards compatibility, it occupies a niche filled but few other languages. C++ is already widely adapted; rather than being replaced, it is being evolved (whether you like it or not). Most new features aim to replace older, worse features. These features are retained as to not break the large amount of software built on C++; C++ does not have the luxury of quickly deprecating features. Talks like these aim to show how to fully utilize the newer features so that in the future the worse features may be "phased out"
@caydnlofton
@caydnlofton 8 лет назад
Anyone else feel like they are trying to make a "C++ for dummies" language out of it? I mean, if you are writing in C++ you should have a full understanding of your pointer arithmetic and memory allocation/deletion. C++ doesn't need to be more simple, its already a great OOP language to use and very fast :)
@drazpa489
@drazpa489 8 лет назад
Not feeling like that at all, to be honest. Also, I'm rarely inclined to people dummies for their mistakes, even though I'd be in a pretty good position to do that. After all, nobody can click on my RU-vid-nick to look up a list of the last 20 bugs I fixed in my private code before committing it to some repository, to see if he, in hindsight, could call *me* a dummy. Also, I think I have different opinions on what constitutes "smarties". Devising or adapting an algorithm to solve an actual problem is an exercise that actually requires intelligence. Typing those ideas into some text editor is the least "smart" part of the whole activity. Finding a formal error in memory allocation/deletion doesn't require intelligence and the talk proofs that because they were able to create tools to do that. Wasting the focus and capacity of an intelligent mind on that would be a real dumb thing to do. C++ should not be a language that requires smart people who want to get actual hard problems solved (like mathematical problems) to do dumb exercises like reading to thousands of lines to look for memory allocation errors. Because that would make C++ a bad tool. I am happy to see that C++ is becoming a better tool through the great work of people like Sutter and Stroustrup, a tool that allows smart people to get work done effectively, without having to waste their time by gaining hours of experience in questions like "How do I map this list of several hundreds of compiler errors pointing to header-files, I've not even written, to find the single slip I made when using some template?". The tools should help them to use their time more efficiently.
@somecoder3054
@somecoder3054 7 лет назад
Caydn Lofton exactly what I was thinking. lots of hand holding going on here. not trying to be a spoil sport, it just looks to me to be some bunch of standardising and simplification that might make harder to explain or requiring loads of commenting. as long as they don't actively remove older C++ standards and pointer arithmetic in the future, it's cool but once they start to over it all, that's when it might get ugly, especially for game programmers.
@caydnlofton
@caydnlofton 7 лет назад
Some Coder Its the age old question: freedom or safety? Freedom to build and design in whatever way is best, even if it takes longer to make sure the code is safe, or safety knowing that a language is there to save you even though it also limits you from exploring
@somecoder3054
@somecoder3054 7 лет назад
Caydn Lofton if the limitations are kept at a minimum with the language allowing for both safe and risky options, then we can all have cake. Give people the options for both and low level interaction. I think that's what most people want anyway
@caydnlofton
@caydnlofton 7 лет назад
Some Coder Have you heard of C#? :p haha C++ 11 is already very high level programming. But thats just my opinion
Далее
CppCon 2019: Jason Turner “The Best Parts of C++"
58:36
LISA - ROCKSTAR (Official Music Video)
02:48
Просмотров 25 млн
CppCon 2015: Bjarne Stroustrup “Writing Good C++14”
1:40:46
The Tragedy of systemd
47:18
Просмотров 1,1 млн