Test Driven C++ - Phil Nash - CppCon 2020

Поделиться
HTML-код
  • Опубликовано: 13 сен 2024
  • cppcon.org/
    github.com/Cpp...
    ---
    We know that testing is important, but writing tests is hard and takes time - and can be demotivating when you want to hack out features.
    But what if we flipped the whole thing around? It turns out that by writing tests first the dynamic changes in unexpected ways. Testing becomes easier. Adding features becomes easier. The dopamine hit you get from seeing something work becomes more frequent. Time lost to bugs and regressions virtually disappears. You start to get invited to bigger and better parties!
    Ok, one of those statements is not guaranteed - but the rest are! If you've never tried TDD (perhaps you have heard of it but been skeptical), or maybe had a bad experience in the past, this talk will give you a sound intro to how it work, how you can get started, and what you can expect to achieve.
    ---
    Phil Nash
    Developer Advocate, JetBrains
    Developer Advocate at JetBrains, author of Catch/Catch2, co-host of cpp.chat, host of C++ London, chair and organiser of C++ on Sea.
    ---
    Streamed & Edited by Digital Medium Ltd - events.digital-medium.co.uk
    events@digital-medium.co.uk
    *-----*
    Register Now For CppCon 2022: cppcon.org/reg...
    *-----*

Комментарии • 45

  • @chadgregory9037
    @chadgregory9037 2 года назад +8

    "The dopamine hit you get from seeing something work becomes more frequent. "
    OK OK, you got me

  • @piotrarturklos
    @piotrarturklos 4 года назад +31

    I think that the design stage before writing the first test is totally dependent on the project. Sometimes you already have an idea of what to write and sometimes it is just too complex, to the point that you have to do write a lot of extra research code before even beginning to creating your production solutions. I think one of the keys to efficiency is to actually distinguish those modes and alternate between them. This goes against TDD, which is a more strict process. I do AI programming for a living, so I may have more research tasks
    than some other people, but I think that my point is universal.
    This is the main point lacking from this presentation. Phil didn't even properly explain what are the requirements of the snakes and ladders program (interactive program? simulation? other?). The presentation assumes that the Board data structure is what we should be writing. One consequence is that I cannot tell what would I be writing in his place, for example if I would actually attacking the problem from an entirely different angle.
    This is not to say that TDD is not useful (I like it), it's just not really *placed* into the development process by this presentation.

    • @bakedbeings
      @bakedbeings 2 года назад

      Sounds like a valid point to me: the first requirement of testing is a great description of the problem, and games are usually a lot of sub problems all going on at the same time.

    • @AllanTheBanjo
      @AllanTheBanjo Год назад +2

      @@bakedbeings I think it was a pretty terrible example of TDD. There was no description at the outset of what the code module was intended to do and before creating any tests he started implementing data structures!

    • @vb9950
      @vb9950 11 месяцев назад

      True, but also when the developers get more experienced I'm quite sure they can lean it towards more of TDD by writing tests first then development.

    • @yrussq
      @yrussq 9 месяцев назад

      That's not the TDD that is problem, it's the people that have distorted to the point of ridiculousness an idea that you need to write code and design apps so that it would be convenient to cover it with tests AFTER it's written.

  • @Runoratsu
    @Runoratsu 4 года назад +6

    I think writing a passing test _can_ be part of TDD: When the test assures a behaviour you know you will have to touch will not get broken by your implementation (but you assume it might or will be). Although I guess whether you consider that part of it or not is pretty philosophical.

  • @JohanSandgren1973
    @JohanSandgren1973 3 года назад +6

    I would enjoy if the instructor when coding, wrote the interface first (step by step when writing new tests), and no code until the interface required a change and other implementation. That would make more sense and he would show how he then follows the TDD cycle he presented at start instead of doing it against the rules he presented, in reverse order.

    • @bakedbeings
      @bakedbeings 2 года назад +4

      Yeah, a stub that passes, then functionality that breaks it, then passes, then refactor.

    • @theLowestPointInMyLife
      @theLowestPointInMyLife Год назад

      @Kuberlog the CyberRanging Hacker its irrelevant, totally superfluous step

  • @sophiecouch7119
    @sophiecouch7119 2 года назад +1

    Great video :) Thanks for the code tutorial section, following along with it helped loads.

    • @CppCon
      @CppCon  2 года назад

      Great to hear! Thank you for your comment.

  • @ecosta
    @ecosta 4 года назад +2

    Thumbs up for thinking about colourblindness after referring to a diagram with red and green boxes.

    • @philnash3269
      @philnash3269 3 года назад +3

      I'm glad it was noticed. I've talked about the RGR cycle a lot before, and usually forget to make mention - I'm trying to be more mindful!

  • @johnmcleodvii
    @johnmcleodvii Год назад

    We tried Automated testing with mocks and very quickly came to the conclusion that the mocks were getting in the way as we were spending far more time rewriting mocks when minor changes were required to the component being mocked. In particular modifying the database schema in almost any way would cause an extraordinary number of mocks to have to change. We gave up on DB mocks and just used a DB that started in a known state.
    Also the tests were taking nearly a day to run.
    I know we were doing something wrong, but I'm still not certain what. We were bolting automated tests onto a large legacy system.

    • @MaximoPower2024
      @MaximoPower2024 8 месяцев назад

      Cuando se hace TDD no tiene mucho sentido incluir las bases de datos (ni los interfaces gráficos) en los tests. Los tests siempre deben ser rápidos.

  • @messerschnitt7943
    @messerschnitt7943 3 года назад +3

    Why did you actually write the struct Portal and the portals map before writing a test? As you initially told that we should write a test before writing *any* code.... And for the initial board test and class those portals don't seem to be needed at all (not even for the first versions of the landOn method), they only seem to be needed in somewhat later stage of development... ?

    • @philnash3269
      @philnash3269 3 года назад +2

      Good question. I didn't really explain it this time. Normally, when I use this example, I say that this is very declarative code that captures the essential model. Not that it shouldn't have tests - but the tests are about bringing the model together with the interface. I was also quite pushed for time - still ended up running out!

  • @6754bettkitty
    @6754bettkitty 3 года назад +1

    Thanks for the explanation of TDD!

  • @huzifa30
    @huzifa30 2 года назад +1

    thank you , great talk

    • @CppCon
      @CppCon  2 года назад

      Glad you liked it!

  • @relascope
    @relascope Год назад

    C#.Net and C++/CLI: Can it be effectively used with Catch2?

  • @badassopenpolling
    @badassopenpolling 6 месяцев назад

    Where was Catch.cpp ????

  • @badsham227
    @badsham227 4 года назад

    Cant wait!!

  • @kuijaye
    @kuijaye Год назад

    What presentation software did he use for this talk?

  • @DanielHinojosa
    @DanielHinojosa 4 года назад

    Excellent example

  • @eyesopen6110
    @eyesopen6110 5 месяцев назад

    At the end of a sprint, you'll have 100% of the tests and 40% of the task completed. "Management" is not smart enough to understand that more tests = more time. They are not free.

  • @relascope
    @relascope Год назад

    Very good example of Buddha's middle path. Real purists would have forced the portals- map to be also Test-Driven. Just data. Like you won't force a Db-Connection-String by a test, although it might be used in an integration test...

  • @Terszel
    @Terszel 4 года назад

    Catch2 is amazing

  • @mahdies9620
    @mahdies9620 2 года назад

    your laptop fan is quiet, looks like you bought a new macbook

  • @juliengpy1594
    @juliengpy1594 3 года назад +6

    The code written is way too bloated: a simple uint32_t tile[101]; is enough to do everything you want.
    tile[i] == i => not a special case
    tile[i] > i => ladder
    tile[i] < i => snake
    tile[i] == 100 => WIN
    No need for Portal, no need for Action, no need for a board, no need for a map.
    Imho, TDD did not help you write better code.

    • @philnash3269
      @philnash3269 3 года назад +5

      There are certainly different approaches - and some of the choices I made were at least partially to give me an opportunity to talk through them. That said, I'm not sure I agree that an array based approach is "simpler" at a conceptual level.

    • @nikitavasilev6904
      @nikitavasilev6904 3 года назад

      But what if your board size is more then 1'000'000 squares and you have only few snakes and ladders?

    • @juliengpy1594
      @juliengpy1594 3 года назад +1

      @@nikitavasilev6904 Different problems, different solutions.
      In this case the board is known and defined very precisely, so there is no need to consider different board sizes or different ladder/snake distributions.

    • @juliengpy1594
      @juliengpy1594 3 года назад +3

      @@philnash3269
      I have put a small C file to better illustrate: github.com/Julien-goupy/yt_comment/blob/master/code.c
      I used the knowledge of the game to make design decisions, used the simpliest code possible and used outputs to detail the intended logic making it very easy to understand, to test and debug.
      I suspect that using TDD increase the complexity of one's programs as one lose the big picture and what are the underlying hypothesis/knowledge of the problem.

  • @therealcornkid
    @therealcornkid 4 года назад +1

    Does anyone know what IDE he was using?

    • @Seanmooney8202
      @Seanmooney8202 3 года назад

      i belive its clion it could vscode but im pretty sure its clion with the left hand menus minimised

    • @superscatboy
      @superscatboy 3 года назад +2

      CLion.
      He mentions the name several times.

    • @philnash3269
      @philnash3269 3 года назад +1

      CLion (from JetBrains) of course :-)

    • @nikitavasilev6904
      @nikitavasilev6904 3 года назад +1

      Clion from JetBrains

    • @shrishailgajbhar3191
      @shrishailgajbhar3191 3 года назад

      CLion. He said in the video.

  • @yrussq
    @yrussq 9 месяцев назад

    This is the most ridiculous and nonsensical approach i've seen. It's like hitting your hand with a hammer before hitting the nail to ensure it hurts. What world do you live in? The world where you walk into your neighbor's dog house before you get into yours just to be sure? It looks like somehow you've come to conclusion that you feel smarter thinking backwards. As for normal people it's more common way to thing with logical sentences from start to finish and put the restricting roadblocks after you've build a road not before.
    I just don't get how anyone could have taken the paradigm of the software development that has embraced the crucial necessity of the test coverage in mind projecting onto the application/code design and turned it into something where low quality tests are required to be written before code. And all that is done in stuttering chunks. What a waste of time and intellectual resources!

    • @yash1152
      @yash1152 8 месяцев назад

      take a step back - the quoted part happens only when the paradigm is followed mindlesssly word to word. the way i was introduced in perl was that:
      * you first design the interface of say your API or CLI. (edit: so yeah, 54:34)
      * then you write proper tests - the interactions you think will happen and corresponding to which your application should perform expectedly.
      * then you write the code to make those tests pass.
      so yeah, it goes back to 3:45 behaviour or design driven development
      this vid only shows those be broken to absolutely small steps - which gave you impression of "low q tests" - but you can leave that and operate on whatever level and block size you are comfortable to work on upon.
      the "demo" part shown here may not be greatest thing - but that is cause
      * good and small samples are hard to come up with, and
      * live demos are sometimes difficult.
      > _"where low quality tests are required to be written before code"_