• 2 Posts
  • 16 Comments
Joined 1 year ago
cake
Cake day: June 13th, 2023

help-circle




  • Aloso@programming.devtoRust@programming.devThe ???? operator
    link
    fedilink
    arrow-up
    6
    ·
    edit-2
    11 months ago

    If all you do in the Err(e) => ... match arm is returning the error, then you absolutely should use the ? operator instead.

    If the match arm also converts the error type into another error type, implement the From trait for the conversion, then you can use ? as well.

    If you want to add more information to the error, you can use .map_err(...)?. Or, if you’re using the anyhow crate, .with_context(...)?.



  • Apparently the maintainer trusted the first-time contributor enough to propose tackling another bug.

    There is no trust needed when asking someone to fix a bug. It’s not like the maintainer would lose anything if the contributor failed to fix the bug.

    Besides, I think it is natural to want recognition when you do a lot of work for free. Many other people wouldn’t do this unpaid work at all; recognizing their contribution is the bare minimum of good manners. Even in a company where employees are paid for their work, it is customary to give credit to co-workers who have helped you. Most people don’t like to work in places where they don’t feel appreciated, and that is also true in Open-Source.


  • It’s not possible to instantiate or assign, which is more like a never type than a unit

    Actually, this is because void is not a type, it is just a keyword, a placeholder used instead of the return type when a function doesn’t return anything.

    If it were a bottom type, that would mean that a method returning void must diverge, which is simply not true.

    Also, if it were a bottom type, it would be possible to write an “unreachable” method

    void unreachable(void bottom) {
        return bottom;
    }
    

    Even though it couldn’t be called, it should be possible to define it, if void was a bottom type. But it is not, because void isn’t a bottom type, it’s no type at all.



    • Svelte/Vue/React components need to be compiled
    • JavaScript should be minified if the project has a significant size
    • File names should have a content hash, so they can be cashed in the browser
    • Even with HTTP/2, there’s still a case to be made for bundling hundreds or thousands of JS modules into a single file for better performance
    • Bundlers give you a dev server with live reload and hot module replacement for great developer experience
    • Setting up Vite is really easy and requires minimal configuration (compared to Webpack, for example)

  • Easy interop with legacy code is how kotlin took off, so maybe it will work out?

    Good interop was a requirement for widespread adoption, but not the reason why programmers want to use it. There’s also null safety, a much nicer syntax, custom DSLs, sealed classes, type inference, data classes, named and optional arguments, template strings, multi-line strings, computed properties, arbitrary-arity function types, delegation, custom operators, operator overloading, structural equality, destructuring, extension methods, inline functions and non-local control flow, reified types, …

    Some of these features have since been added to Java.






  • I do not use AI to solve programming problems.

    First, LLMs like ChatGPT often produce incorrect answers to particularly difficult questions, but still seem completely confident in their answer. I don’t trust software that would rather make something up than admit that it doesn’t know the answer. People can make mistakes, too, but StackOverflow usually pushes the correct answer to the top through community upvotes.

    Second, I rarely ask questions on StackOverflow. Most of the time, if I search for a few related keywords, Google will find an SO thread with the answer. This is much faster than writing a SO question and waiting for people to answer it; and it is also faster than explaining the question to ChatGPT.

    Third, I’m familiar enough with the languages I use that I don’t need help with simple questions anymore, like “how to iterate over a hashmap” or “how to randomly shuffle an array”. The situations where I could use help are often so complicated that an LLM would probably be useless. Especially for large code bases, where the relevant code is spread across many files or even multiple repositories (e.g. a backend and a frontend), debugging the problem myself is more efficient than asking for help, be it an online community or a language model.