• Anders429@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    We need clearer rules on which pull requests require code reviews.

    Weird to me that any pull request would not require a code review.

  • akash_rawal@lemmy.world
    link
    fedilink
    English
    arrow-up
    0
    ·
    1 year ago

    The code had not been unit tested before

    Because the smoke test procedure on our staging environment is currently a completely manual process without any automation.

    Why do we have to keep learning to test and automate our tests as hard lessons?

    Why do software engineering lectures not teach us about testing? If I were asked to teach software engineering (which TBH I shouldn’t be qualified to do just yet) I’d start with testing.

    • BB_C@lemm.ee
      link
      fedilink
      English
      arrow-up
      0
      ·
      1 year ago

      Funny how you got successfully distracted by the procedural failure dance, where the obvious, as expected, got zero mentions. Giving software engineering lectures seems to be right up your alley.

      If I was the author of that commit, or any crates.io developer, I would have wanted to be called out for not constructing URLs correctly. That’s the obvious first fault here. Not even hinting at that would have felt so cringe.

      • MooseBoys@lemmy.world
        link
        fedilink
        English
        arrow-up
        0
        ·
        1 year ago

        I can’t tell if your comment is intentionally sarcastic but it sure sounds like you’re saying “just don’t write buggy code in the first place!”

        • BB_C@lemm.ee
          link
          fedilink
          English
          arrow-up
          0
          ·
          1 year ago

          It’s about not ignoring the clear underlying cause of the bug that is screaming at everyone who reads the bug description.

          Include something along the lines of “We will use the URL crate and utilize its API to avoid trivial URL construction errors like this one in the future”, and I may take your postmortem seriously.

          A flawless developer does not exist, and at no point did I fault any developer directly for their development work. But that doesn’t mean we should ignore something that is/was clearly and inherently wrong with the code. You would think this is all stating the obvious.

          So it’s not "just don’t write buggy code in the first place!”. It’s “this code could clearly have been written in a way that would have prevented this bug from ever taking place”.

          And yes, good code matters. A good language matters. A good type system matters. A good use of a good language with its type system, patterns, abstractions, ecosystem, and all it got to offer matters. This is Rust afterall. If those things don’t matter, then we might as well let the code be written in Python or JS, and fully recommit to the church of TDD.

          • gnus_migrate@programming.dev
            link
            fedilink
            English
            arrow-up
            0
            ·
            1 year ago

            A good language matters. A good type system matters. A good use of a good language with its type system, patterns, abstractions, ecosystem, and all it got to offer matters.

            Eh research shows otherwise. Rust eliminates defects for a very particular set of problems, but when it comes to logical correctness it isn’t better or worse than other languages. If those problems are prominent in your domain(such as you have to write a ton of concurrent code), Rust makes sense. Otherwise being well rested will have a bigger impact on the quality of your code than the best type system in the world.

            In terms of dev practices, the only practice demonstrated to have a consistent positive impact on code quality is code reviews. Testing as well, but whether it’s TDD or other kinds of testing doesn’t really matter.

                • BB_C@lemm.ee
                  link
                  fedilink
                  arrow-up
                  0
                  ·
                  1 year ago

                  Eh research shows otherwise. Rust eliminates defects for a very particular set of problems, but when it comes to logical correctness it isn’t better or worse than other languages.

                  Can you concede, at least to yourself, that you made ^ this ^ up?

                  By the way, what you claimed “research shows” is so ridiculous that it’s hilarious that you wrote it while being serious.

                  Hell, I cheekily mentioned Python and JS in particular because the former introduced type hints and the latter triggered creating TS as a saner shield.

                  Btw, that wrongly-constructed URL wasn’t even an external one. We literally have web frameworks that make sure non-external URLs with invalid paths are impossible to construct. In other words, attempting to construct a wrong one would be a compile error.

    • Anders429@lemmy.world
      link
      fedilink
      English
      arrow-up
      0
      ·
      1 year ago

      I’ve always thought it weird that the intro CS course I took at my university didn’t even mention unit testing. After being in the industry for several years, it’s become obvious that the majority of what I do is just writing tests.

      • philm@programming.dev
        link
        fedilink
        arrow-up
        0
        ·
        edit-2
        1 year ago

        And then there’s me, who almost never writes unit tests 😬

        (With strong typing I can minimize explicit tests, and I like to iterate fast, but I guess it really depends on what you’re developing, backend in production that is not allowed to fail, is probably something different than a game)

        • sugar_in_your_tea@sh.itjust.works
          link
          fedilink
          arrow-up
          0
          ·
          1 year ago

          Unit tests shouldn’t be testing types, even if your language isn’t typed. It should be testing logic and behavior. If there’s an if condition, it should be tested.

          • philm@programming.dev
            link
            fedilink
            arrow-up
            0
            ·
            1 year ago

            Yeah you’re right, tests should test logic. But static typing certainly helps reducing a lot of tests, which would be necessary in different untyped languages. Also you can sometimes encode your logic in types. Typing also helps reducing logic issues. But as previously said, it depends on what you’re doing. I’m prototyping/researching a lot, and tests often hinder progress for me. Maintaining a backend in production is a different story.

            • sugar_in_your_tea@sh.itjust.works
              link
              fedilink
              arrow-up
              0
              ·
              1 year ago

              That is absolutely true as well. We’re porting a codebase to TypeScript and we were able to eliminate a bunch of test cases that were essentially testing type-correctness (e.g. can’t pass a boolean to a date processing library). But those were bad tests to begin with, because there was no good reason for those tests to exist to begin with (we were pretty exhaustive with the invalid type checking even when the intended types were obvious).

              Strict typing helps eliminate useless tests. And Rust types go further than most languages, such as exhaustive match, types that can exclude zero, and the near-complete lack of a null value.

              If you’re never going to publish the code, I agree, tests aren’t necessarily helpful. Then again, I find writing tests helps me understand my own code better, so I still do it when doing research tasks (e.g. we were testing the potential performance benefits of porting an expensive algorithm to Rust, so my tests helped me benchmark it), though my tests are a lot less exhaustive and tend to be more happy path integration tests instead of proper unit tests.

              • philm@programming.dev
                link
                fedilink
                arrow-up
                1
                ·
                1 year ago

                I find writing tests helps me understand my own code better, so I still do it when doing research tasks

                Hmm interesting, I try to optimize readability of the actual code itself, so that when I read it again after some time, that I quickly get what this is about, if there’s a edge-case or something I thought about while coding, I’ll just add a TODO comment or something like that. I feel like reading tests is a “waste of time” for me most of the time (hard take I know ^^).

                But all this obviously only applies for researching and fluid code (code that likely will be refactored/rewritten soon), when it’s solid code targeting production etc. I’ll add unit tests if friction/hassle is low, and integration/E2E tests for the overall thing. But as I said, I’m mostly in fluid/fast moving codebases that are more difficult to test (e.g. because it does gpu rendering or something like that).

                • sugar_in_your_tea@sh.itjust.works
                  link
                  fedilink
                  arrow-up
                  1
                  ·
                  1 year ago

                  When I jump into a new codebase, my first instinct is to look over the examples and the unit tests to get a feel for how things are intended to work.

                  When prototyping, I generally write a few “unit” tests as a form of example code to show basic usage. For example, if I’m writing a compiler for a new toy language, I’ll write some unit tests for each basic feature of the language. If I’m writing networking code (e.g. a game server), I’ll write some client and server tests that demonstrate valid and invalid packets. These generally fall somewhere between unit and integration tests, but I do them in a unit test style. When the project stabilizes, I’ll go through and rewrite those tests to be narrower in scope, broader in line coverage, and simpler, and keep a few as examples (maybe extract to the readme or something).

                  That’s my workflow, and I like knowing that at least part of it is tested. When I mess with stuff, I have a formal step to change the tests as a form of documenting the change I made, and I’ll usually leave extensive comments on the test to describe the relevance.

                  Code readability counts, but I don’t think it’s enough. The codebase I work on day to day is quite readable, but it’s very complex since there are hundreds of thousands of lines of code across over a dozen microservices, and there’s a lot of complexity at the boundaries. When I joined the project, I read through a lot of the tests, which was way more helpful to me than reading the code directly. The code describes “how,” but it doesn’t explain “what” or “why.” Tests get into “what” extensively, and “why” can be understood by the types of tests developers choose to write.