GNU social JP
  • FAQ
  • Login
GNU social JPは日本のGNU socialサーバーです。
Usage/ToS/admin/test/Pleroma FE
  • Public

    • Public
    • Network
    • Groups
    • Featured
    • Popular
    • People

Embed Notice

HTML Code

Corresponding Notice

  1. Embed this notice
    Phantasm (phnt@fluffytail.org)'s status on Wednesday, 15-Jul-2026 03:18:51 JSTPhantasmPhantasm
    in reply to
    • Haelwenn /элвэн/ :triskell:
    • Junes
    • DulceKennedy
    • pistolero
    • SilverDeth
    • Slim Jim
    • CMD
    @p @j @Junes @SilverDeth @lanodan @ElDeadKennedy @ceo_of_monoeye_dating
    Alright time for a necro after I had a "fun" time with C's terrible early-return style error handling and the whole reason why I mentioned Elixir's `with` as a way better way of handling errors/cases.

    Case in point attached code I tried to write as elegantly as I can write C. All it is supposed to do is (un)set a window property and create it when it doesn't exist, because mpv is dumb and still renders video to an unmapped window and iconified window. There are 3 goto's to cleanup code that are equivalent to just copy-pasting the same early return statements three times, and a single early return when the first function call fails.

    It handles an edge case (property creation), errors and the actual purpose of the function in a single top-down fashion normal for imperative languages. The purpose of the function is stuck completely at the bottom, the "what it needs" and "what it does" is completely split by "but what if this happens instead" code; the whole paradigm of reducing cases until a final desired one at the bottom didn't serve this function well at all. It made it harder to grasp, understand and frankly ugly.

    This is the whole point of why I prefer sticking all the checks for the desired purpose at the top, which Elixir's `with` is perfect for, writing the actual purpose of the function right below that, and the whole "but what if this happens instead" goes at the bottom after the actual purpose without interrupting the main purpose of the function at all. You have "what it needs", "what it does" and only after that the "but what if this happens instead".

    PS: Too lazy to loop the XGetWindowProperty call to get all properties without dropping anything.
    image.png
    In conversationabout 3 months ago from fluffytail.orgpermalink

    Attachments


    1. https://upload.fluffytail.org/media/ce/9b/d0/ce9bd0a62eb69dedf3f33a25c47789f35cff3996d9122e08d2b5ee1fe8f9760d.png?name=image.png
  • Help
  • About
  • FAQ
  • TOS
  • Privacy
  • Source
  • Version
  • Contact

GNU social JP is a social network, courtesy of GNU social JP管理人. It runs on GNU social, version 2.0.2-dev, available under the GNU Affero General Public License.

Creative Commons Attribution 3.0 All GNU social JP content and data are available under the Creative Commons Attribution 3.0 license.