CppCon 2018: Richard Powell “How to Argue(ment)"

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ก.ค. 2024
  • CppCon.org
    -
    Presentation Slides, PDFs, Source Code and other presenter materials are available at: github.com/CppCon/CppCon2018
    -
    How many different ways are there to pass an argument? Why do we have so many? Which way should you be using? What does it mean when you use the wrong one?
    A function declaration is like the thesis statement in an essay. It should communicate both for the caller and the callee it's purpose, semantics, and side-effects. We often think this communication is in the form of comments, but a function's arguments also convey this information.
    This talk will catalog many the different ways to pass arguments. We will then explore which ones are redundant or nonsensical, and give meaning to the ones that remain. We will end with recommendations what types to use to express your intent, and empower you with fundamentals to write clearer function definitions.
    -
    Richard Powell, Audio Software Engineer
    I started using C++ 10 years ago to write a psychoacoustic audio encoder/decoder and have continued to explore how to make software that unlocks the potential of hardware to bring amazing applications to life. I graduated from UC Berkeley with a BS in Electrical Engineering and Computer Science, and worked throughout the Bay Area for the past 15 years. I enjoy teaching and learning about C++ and programming.
    -
    Videos Filmed & Edited by Bash Films: www.BashFilms.com
    *-----*
    *--*
    *-----*

ความคิดเห็น • 21

  • @jvsnyc
    @jvsnyc 3 ปีที่แล้ว +4

    I love this, because the beginning shows "How many basic ways does it appear you can pass something to a function?" and the answer is of course: "42". But like 10 dimensions collapsing down to 4 when we do the math, these also collapse down into a much smaller number that "make sense under normal programming conditions". Some of the ones that evaporate away are just silly, and some might come up once in a while in template meta-programming, but I am not upset at C++ or this presentation that it starts out at a higher number due to orthogonality. "You can pick your friends, you can pick your nose, but you can't pick your friend's nose."

  • @stera182
    @stera182 3 ปีที่แล้ว +2

    I definitely don't agree on raw pointer vs optional, for me raw pointers are definitely not good as it can express several different things, we can use it as another way of referencing a value, as a way to store an address of a dynamic allocation or for an optional value, as an iterator, as a sub collection or even a combination of those, pointers does not express the intent of the dev, optional does. And if you want to have an optional ref, just use std::optional, you can even do an alias like template using optional_ref = std::optional; for easier use. It is really important that your code reflect your intentions without even needing any comments. Don't use {} to express a null optional, use std::nullopt instead.
    How many times I've worked with a C library in C++ not knowing how will this library will do with the pointer I give it, how many time do I had to save. Ban raw pointers, really. It might be easier to use, but it's not good for expressivness and therefore for your code maintenance.

  • @younghsiang2509
    @younghsiang2509 ปีที่แล้ว +1

    I've been having those questions long time ago. Thanks for this great talk!

    • @CppCon
      @CppCon  ปีที่แล้ว

      Glad it was helpful!

  • @dos350
    @dos350 5 ปีที่แล้ว +10

    raw pointers are lit

  • @parnmatt
    @parnmatt 5 ปีที่แล้ว +1

    25m you could use an std::optional; though I personally would have a using alias to tidy the name

  • @WiktorWandachowicz
    @WiktorWandachowicz 5 ปีที่แล้ว +1

    Naming functions correctly is one important aspect of "Clean Code" - described in a book by Robert C. Martin (aka Uncle Bob). Making sure that functions do just one thing (otherwise they "cheat"), is another aspect of the same. I really love that you spread this wisdom using your own words.
    BTW. All object-oriented programmers, PLEASE read this book! You will not regret that!

  • @warrenbuckley3267
    @warrenbuckley3267 5 ปีที่แล้ว +3

    You can also pass an std::nullopt to a function taking an optional. I'm curious if when passing an empty initializer list if it gets implicitly converted to an std::nullopt.

    • @artombakrial-sarmini4968
      @artombakrial-sarmini4968 4 ปีที่แล้ว

      It does initialize an optional with nullopt, no conversion takes place, just 2 constructors doing same thing

  • @jvsnyc
    @jvsnyc 3 ปีที่แล้ว

    The pro-optional people hadn't mentioned one thing, how many languages have optional or nullable types in them now. Just in actual code at work, I've seen them in C#, Java and Swift in recent days, I believe also Scala and Kotlin. They don't all work exactly the same way, but I would say that the concept of Optional/nullable is pretty standard in most modern languages right now. So could readability to people who do indeed know C++ but often work in other languages as well be a +1 for optional?

  • @dkutagulla
    @dkutagulla 2 ปีที่แล้ว

    Slide58 is amazing reference slide

  • @p39483
    @p39483 2 ปีที่แล้ว

    C has only one way. Pass by value. Pointers are values. Isn't it ironic that the very features C++ needs to efficiently implement value semantics confuse the language with reference semantics and a hierarchy of value types that clutter function signatures?

  • @connorhorman
    @connorhorman 5 ปีที่แล้ว +2

    Did you miss Pass by Forwarding-reference?

    • @LeoHsieh
      @LeoHsieh 5 ปีที่แล้ว +3

      he said he didn't discuss monster-template, just every day propramming...

  • @connorhorman
    @connorhorman 5 ปีที่แล้ว +1

    Never as an output parameter. But void*,std::size

    • @connorhorman
      @connorhorman 5 ปีที่แล้ว

      I call raw pointers an optional reference or a memory view. Also you can foo(0) is giving a value for std::optional, and is giving no value for int*.