CppCon 2018: Jason Turner “Applied Best Practices”

Поділитися
Вставка
  • Опубліковано 24 лис 2024

КОМЕНТАРІ • 36

  • @treyquattro
    @treyquattro 4 роки тому +41

    Jason is really a great communicator, and C++ expert. I must catch one of these talks live soon.

  • @pocsbe
    @pocsbe 5 років тому +57

    "What feature to remove from C++ if you could? Implicit conversions!" Finally! Good to see I'm not alone with this observation.

    • @Falcrist
      @Falcrist 3 роки тому +3

      I usually work down in the embedded C world, and even *_WE_* would love see languages enforce strong typing. For example, typedef enum should NEVER have been allowed to implicitly convert to a uint8_t. That's bad news all day long.
      I know GCC has something like that as a compiler flag, though I'm not sure when it'll be available in most MCU libraries.

    • @joestevenson5568
      @joestevenson5568 7 місяців тому

      I mean there's so many good choices though?
      Implicit pass by value and Implicit mutability are also bad defaults.

  • @TheLeontheking
    @TheLeontheking 5 років тому +25

    love how he engages with the audience!

  • @minciNashu
    @minciNashu 6 років тому +16

    17:00 if readability is an issue, instead of trailing return types, you can break before function name. It's a style available in clang-format also. eg
    [[nodiscard]] constexpr int
    myGettter() const noexcept;

    • @theRECONN
      @theRECONN 6 років тому

      But still I would put return type before the name just to stick to the legacy code and when the return type is long say like std::pair then making it trailing return type is much more readable to me

    • @lperkins2
      @lperkins2 6 років тому +2

      @Ziggi Mon Exactly. I truly hate splitting function declarations onto multiple lines. The biggest problem I have working in C* is figuring out where implementations live. Being able to grep for a function by name and return type is absolutely critical.

    • @lperkins2
      @lperkins2 6 років тому

      @John Smith I can see the advantage to that. Assuming the split-line is only used at the implementation, and assuming the code is sanely indented, the only place the function name will appear at the start of a line is at the implementation. I don't know why I hadn't thought of using the start-of-text regex before, but I think that will help. The only remaining issue would be if the same function name is used in different namespaces, returning different types. Not something I'd expect in a well behaved project, but something I've encountered more often than I'd like. Also, won't that fail in c++ inside namespaces where the function declarations are indented?
      When you're trying to learn a new code base, being able to find a list of functions that return a particular type is handy. Searching for typename on a line not ending with ; usually gives you a pretty good shortlist. If the codebase puts the { at the end of the line instead of on its own line, you can also look for that, and get an even better shortlist.

    • @lperkins2
      @lperkins2 6 років тому

      @John Smith Wow, I dropped from 8-column tabs to 4 about 10 years ago. Lots of the time these days I'm running at 2-column tabs. If you're only using a single namespace per file, not indenting the namespace block probably doesn't make much difference. If the return type is the only thing on the line, that would probably work. Lots of the time I see the other tag-soup stuff included on the same line as the return type. I suppose you could look for return_type$ . In C, where functions are often prefixed by something to reduce the symbol collisions (projectname_function1 et cetera), I often grep for (return_type projectname_).
      It's not the end of the world to put grep into multiline mode; I just never thought about the advantage to splitting the function name to its own line. I suspect I'll still default to keeping it on one line out of habit, but I'll probably be less annoyed the next time the project of the day uses that style.
      As for why I run into this often enough to care, I usually have to familiarize myself with a new codebase about every other week. Being able to track return types quickly and easily makes a big difference in how long it takes to get the 1000' view of the whole project.

  • @OperationDarkside
    @OperationDarkside 6 років тому +12

    Very entertaining. It's really interesting/annoying, that not everything is constexpr yet. A constexpr vector would be really nice.
    If my employer would use C++, I would advise to book you. Even if it's just for fun.

    • @Scorbutics
      @Scorbutics 6 років тому +2

      If you've not already seen it, take a look to the Louis Dionne talk about "Compile-time programming and reflection in C++20 and beyond"

  • @philmarsh3859
    @philmarsh3859 4 роки тому +6

    "portability is the best practice" Amen. I just wish more developers heeded this. The best code is portable. Period.

    • @skeleton_craftGaming
      @skeleton_craftGaming 7 місяців тому

      Yes, portable Windows applications are tight, I agree with what he's saying in general, but if you're writing code for a specific platform, there is no reason to not use the tools that are provided by that specific platform... [And there is some cases where that is unavoidable]

  • @Trass3r
    @Trass3r 6 років тому +6

    Let's hope the implicit constexpr proposal makes it through.

  • @rich_in_paradise
    @rich_in_paradise 6 років тому +48

    Skip to 3:00

  • @zaooo
    @zaooo 6 років тому +19

    Thanks a lot for considering the non-local audience when doing audience polls.
    There's nothing more aggravating than watching a talk where the presenter skips over something because the locals grok it when it can be key to a remote person's understanding.

  • @snow8311
    @snow8311 6 років тому +7

    note 26:50: You can't actually declare a lambda to be nodiscard.

    • @GeorgeTsiros
      @GeorgeTsiros 5 років тому

      may a lamda be invoked in a way that discards the result 🤔

    • @VioletGiraffe
      @VioletGiraffe 5 років тому

      ​@@GeorgeTsiros, of course, why not. As soon as it returns something, and your invocation does not consume the returned value.

    • @GeorgeTsiros
      @GeorgeTsiros 5 років тому

      @@VioletGiraffe yes, obviously...
      auto f=()[]->{return 1;}; f();
      sorry if the syntax is not correct.
      i do not remember what i had in mind back then.
      most likely a brainfart

    • @GeorgeTsiros
      @GeorgeTsiros 5 років тому +1

      @@VioletGiraffe yes should have been []().

  • @JamesJones-iu1ey
    @JamesJones-iu1ey 5 років тому +34

    I'm not smart enough for this language. If I was writing an emulator I doubt I'd spend this much time obfuscating my code with the latest attributes and keywords just for the sake of it. I put a high value on readability and simplicity and I value my time. When it takes more than 100 columns and multiple keywords to write a correct method signature it's a sign you should take your language back to the drawing board. Nobody coming from another language is going to have a clue what is going on in c++ land and typing code should be one of the more trivial aspects of solving actual engineering problems. These cppcon talks feel short on motivating examples and tall on esoteric, introspective, snazzy new features. Which sucks because I want to be a better programmer in a pragmatic sense not just a guru.

    • @jamessandham1941
      @jamessandham1941 4 роки тому +8

      I feel the same way. I mean Jason clearly knows the language well and I have seen some pretty cool videos that he posts (for example we ported doom to c++ ) but I think he and some of these c++ gurus have missed the forest for the trees. The language is becoming completely unreadable. I mean I cant really think of a situation where I would use [[no discard]] and I wouldn't clutter up my code with yet another keyword.

    • @Falcrist
      @Falcrist 3 роки тому +4

      There are a TON of features in C++ that are nice for enforcing best practices, but make the code less readable. A lot of this stuff should have been default.

    • @skeleton_craftGaming
      @skeleton_craftGaming 7 місяців тому

      Attributes make your code easier to read though, that's their whole...

    • @Kobold666
      @Kobold666 Місяць тому

      C++ lost its way long ago. I wonder when they will come up with the idea to write source code in XML format.

  • @EmmanuelNebula
    @EmmanuelNebula 5 років тому +5

    What debugger or IDE is he using? 36:12

  • @SciDiFuoco13
    @SciDiFuoco13 4 роки тому +3

    37:10 who thought that was a good idea

  • @litbmeinnick
    @litbmeinnick 6 років тому

    ua-cam.com/video/DHOlsEd0eDE/v-deo.html What? Isn't it like "The longer type names get, the more useful fully-auto comes?"

  • @stefanplusplus917
    @stefanplusplus917 6 років тому +2

    8:48 :D

  • @max_ishere
    @max_ishere 3 роки тому

    Something that sounds easy but actually isn't. Sounds like conning yourself into something dangerously long.