• 8 Posts
  • 47 Comments
Joined 6 months ago
cake
Cake day: June 2nd, 2024

help-circle






  • Completely depends on how often you need to write boilerplate code, and how error-prone it is.

    After writing hundreds of instances of ‘fetch this from the server and show an error if it doesn’t work’, I finally wrote a helper for that. It took 2 hours, shouts at me if I use it wrong, and instantly makes my classes easier to read because all the boilerplate is gone. As an added bonus, the invocation is so small that Copilot can write it error-free, which it couldn’t before.

    So fetching things is now a thing of a few seconds instead of one minute with a chance of making a mistake. I say it’s worth it.




  • bleistift2@sopuli.xyztoProgrammer Humor@lemmy.ml#godot #GodotEngine
    link
    fedilink
    English
    arrow-up
    12
    ·
    edit-2
    1 month ago

    Programs aren’t written by a single team of developers that speak the same language. You’d be calling a library by a Hungarian with additions from an Indian in a framework developed by Germans based on original work by Mexicans.

    If no-one were forcing all of them to use English by only allowing English keywords, they’d name their variables and functions in their local language and cause mayhem to readability.

    [Edit:] Even with all keywords being forced to English, there’s often half-localized code.

    I can’t find the source right now, but I strongly believe that Steve McConnell has a section in one of his books where he quotes a function commented in French and asks, “Can you tell the pitfall the author is warning you about? It’s something about a NullPointerException”. McConnell then advises against local languages even in comments




  • Is this not rude:

    I checked the code and I’m appalled. There are more BLOBs than source code

    No. The commenter is voicing their own feelings and explains why they have them. There is neither blaming nor rudeness here.

    And this:

    I understand that removing BLOBs isn’t a priority over new and shiny features. But due to recent events, this should be rethought.

    It would have been nice if you had explained why you think this is rude. The author expresses understanding that the maintainers’ priorities don’t align with the author’s. This seems to be an uncontroversial statement to me.

    Then the author explains (I agree, it’s more a hint than an explanation) why they think the priorities should be changed. In my view their argument is sound. Again, there is no blaming or rudeness here.

    They should have opened with a complement

    I assume you mean “compliment”.

    I’ve often heard of the “sandwich technique” – start with a compliment, then voice criticism, end with another positive thing. I find this is an appropriate procedure when voicing open feedback, that is, good things and bad things. However, this is a Github issue. Its whole point is to point out a perceived problem, not to give the maintainers a pat on the back or thank them.








  • Exceptions are just bad. They are a separate, hidden control flow that you constantly need to be wary of. The name itself is a misnomer in my opinion, because they’re rarely exceptional: errors are not just common, but an integral part of software development

    They may be a part of software development, but they should not be common during the normal execution of software. I once read the hint, “if your app doesn’t run with all exception handlers removed, you are using exceptions in non-exceptional cases”.

    Throwing an exception is a way to tell your calling function that you encountered a program state in which you do not know how to proceed safely. If your functions regularly throw errors at you, you didn’t follow their contract and (for instance) didn’t sanitize the data appropriately.

    Errors as values are much clearer, because they explicitly show that a function may return an error and that it should be handled.

    I disagree here. You can always ignore an error return value and pretend that the “actual” value you got is correct. Ignoring an exception, on the other hand, requires the effort to first catch it and then write an empty error handler. Also (taking go as an inspiration), I (personally) find this very hard to read:

    res, error = try_something()
    if error {
      handle_the_error(error)
      return_own_error()
    }
    res2, error2 = try_something_else(res)
    if error2 {
      handle_other_error(error2)
      return_own_error()
    }
    res3, error3 = try_yet_something_else(res2)
    if error3 {
      handle_the_third_error(error3)
      return_own_error()
    }
    return res3
    

    This code mingles two separate things: The “normal” flow of the program, which is supposed to facilitate a business case, and error handling.

    In this example, on the other hand, you can easily figure out the flow of data and how it relates to the function’s purpose and ignore possible errors. Or you can concentrate on the error handling, if you so choose. But you don’t have to do both simultaneously:

    try {
      res = try_something()
      res2 = try_something_else(res)
      res3 = try_yet_something_else(res2)
      return res3
    } catch (e) {
      // check which error it is and handle it appropriately
      throw_own_exception()
    }