Skip Navigation
Jump
Why I Prefer Exceptions to Error Values
  • In Maybe monadic, its monadic bind will automatically resolves any failed computation, and don't need explicit checking.

    for example, the code in Haskell looks something like the following:

    fib: Int -> Int -> Maybe Int
    fib max_depth idx =
      do
         guard (0 <= max_depth)
         n1 <- fib (max_depth - 1) (idx - 1)
         n2 <- fib (max_depth - 1) (idx - 2)
         return (n1 + n2)
    

    Haskell type class system automatically figures out this is a maybe monad, and check for error accordingly.

    Notice, unlike the C code the author provide, this haskell code will exit immediately when n1 failed and never compute n2, similar to the behavior of the exception code. Thus I believe his point about performance is at least unjustified, if not wrong.

    Another interesting fact about this code is that there is nothing that is built into the compiler/interpretor (except the do expression, which is just a minor syntactical sugar). For this code, the compiler designers don't need to design special semantics for raise and catch. Everything here, guard, return, and the Maybe monad (which is in charge of propagating errors) is defined by the user, using normal functions, no metaprogramming involved.

    Wouldn't effect systems still be considered exceptions, but handled differently?

    Yes, unlike monad, the error in algebraic effect is propagated by the compiler/interpretor, instead of user defined. But unlike implicit effect, explicit effect (algebraic effect, throwable, etc.) makes it clear how the code can go wrong.

    Although explicit error through monad or algebraic effect is more clear in general, there are special cases where explicit effect is undesirable. One such example is effect pollution: low-level effects that are unlikely to cause impure behaviors are unnecessarily propagated through the call stack. This problem can make the code more verbose and difficult to handle.

    4
  • Jump
    Why I Prefer Exceptions to Error Values
  • The more I read about these kind of article the more I am amazed that our digital future is at hand in utterly incompetent people.

    This person clearly have no understanding of monadic error (AKA Maybe/option monad or slightly more advanced Either monad), which is the first monad we teach at a class targeting second year undergrad.

    The performance comparison is just plain factual error. The functional error code will continue to compute n2 when computation of n1 failed; the same do not happen in the exception version. If you compare codes with completely different traces, of course they will have different performance...

    A properly implemented monadic error will return as soon as compute for n1 failed, and never execute the rest of the code. This is the default and idiomatic behavior in Haskell, OCaml, F#, and rust. This performance problem doesn't even happen in LINQ-style handling like in C# and Kotlin (maybe also Typescript?).

    The point of monadic error is that its control flow is local, whereas exception is non-local. Specifically, the exception can be handled and occur anywhere in the code base, with no indication on the type level. So programmers will be constantly worrying about whether the exception in a function call is properly handled.

    Even worse, when you try to catch a certain error, there is always the risk to accidentally catch similar exceptions in a library call or someone else's code. Writing good code with try-catch requires a lot of principle and style guides. But unlike monads, these principle and rules cannot be enforced by the type system, adding extra burden to programmers.

    In fact, we have known for a long time that non-local control flows (goto, break, contiune, exception, long jump) are the breeding ground for spaghetti code. As an evidence, many non-local control flows (goto, long jump) are baned in most languages.

    That being said, there are certainly cases, with proper documentation, that exception style is easy to write and understand. But I think they are very specific scenarios, which have to be justified on a case-by-case basis.

    19
  • Jump
    After charger, Apple removes USB-C cable from the box
  • Many people don't know usb-c cable is universal, and apple only advertises chargeing iphone with macbook and ipad charger.

    I imagine most of these people use an iPhone, and they will certainly waste their money on an "Apple cable".

    Plus many of these tech-illiterate people are likely on a lighting iPhone with a barrel jack Windows, they won't even know they need a new charging cable until they realize their old lighting cables don't work.

    2
  • Jump
    Bunny living space
  • I have never litter trained a baby rabbit, but they generally just poop where there is hay.

    Sometimes it is also helpful to pick up their droppings and put it in the litterbox, but it is largely not necessary.

    3
  • Jump
    Bunny living space
  • They are different, the little balls are hard poop, which they will not eat. I think cencotrope are only on their butt, but I am not sure.

    3
  • Jump
    Anybody know how to get lossless audio on linux?
  • Then if you care about the artists being compensated fairly, you can CD+rip; if not, streamrip/torrent will produce a lot less waste and much more convenient.

    TBH most big names are millionaires anyway, I probably would care much more about my convenience than them getting paid 5 bucks for all my troubles.

    5
  • Jump
    Anybody know how to get lossless audio on linux?
  • If you can download music, you can either host your own using navidrome, or just use a local player like auxio.

    The only downside to this approach is that the artists you like might not get compensated fairly, as most streaming service pay by stream times. This is also why I prefer buying music than streaming.

    1
  • Jump
    Code Smells Catalog
  • as far as I know, C# don't have proper ergonomic monadic bind as in F# (computation expression), Haskell (do expression), and Ocaml (let*), but I could be wrong.

    1
  • Jump
    Code Smells Catalog
  • Honestly, it is much more code to use loop with non-local control like break, continue etc. (variable initialization, append, variable mutation in loops...) than just calling a collect function (which I assume just means to_list). In the above example, in most programming language I know, you don't even need to collect the result into a list.

    Not to mention, large loops with non-local control is a breeding ground for spegatti code. Because you no longer have a consistent exit point to the loop, thus making the semantics hard o reason about.

    In many languages, there are type class / trait / interfaces (whatever you want to call them) that allows lazy structures to share the same API as strict ones.

    5
  • Jump
    Anybody know how to get lossless audio on linux?
  • bandcamp is great! you can just pay and download music in whatever format (flac, wav, mp3), no questions asked.

    They don't have the Taylor Swifts of the world, but most indy bands and artists are on there, which is good enough for me.

    For classical music, there is presto music, but their download experience is not as straight forward as bandcamp IMO.

    30
  • [Question] Setting up a bridged network for HomeAssistant in KVM Fedora

    cross-posted from: https://mander.xyz/post/16531580

    > I have tried to follow several tutorial to setup using either ip or nmtui: > - https://linuxconfig.org/how-to-use-bridged-networking-with-libvirt-and-kvm > - https://www.redhat.com/sysadmin/setup-network-bridge-VM > > However, the bridge inherits the MAC address of host after enslaving the host hardware enp1s0.... This causes my router to give both the host and the bridge the same ip address, making the ha instance inaccessible. > > The red hat tutorial clearly show that the bridge and the host have different IP, so I was wondering if I am doing something wrong. > > --- > > Alternatively, I can set the home assistant vm to run in NAT and port forward from host, but I have several devices that communicate over different ports. So it would be annoying to forward all these ports. Not to mention, many appliances don't have documentation about the ports they use. > > I can also potentially use virtualbox, but it is not well supported on silverblue, especially with secureboot enabled.

    0

    cross-posted from: https://mander.xyz/post/16531247

    > I have tried to follow several tutorial to setup using either ip or nmtui: > - https://linuxconfig.org/how-to-use-bridged-networking-with-libvirt-and-kvm > - https://www.redhat.com/sysadmin/setup-network-bridge-VM > > However, the bridge inherits the MAC address of host after enslaving the host hardware enp1s0.... This causes my router to give both the host and the bridge the same ip address, making the ha instance inaccessible. > > The red hat tutorial clearly show that the bridge and the host have different IP, so I was wondering if I am doing something wrong. > > --- > > alternatively, I can set the home assistant vm to run in NAT and port forward from host, but I have several device that communicate over different ports. So it would be annoying to forward all these ports. Not to mention, many appliances don't have documentation about the ports they use. > > I can also potentially use virtualbox, but it is not well supported on silverblue, especially with secureboot enabled.

    11

    I have tried to follow several tutorial to setup using either ip or nmtui:

    • https://linuxconfig.org/how-to-use-bridged-networking-with-libvirt-and-kvm
    • https://www.redhat.com/sysadmin/setup-network-bridge-VM

    However, the bridge inherits the MAC address of host after enslaving the host hardware enp1s0.... This causes my router to give both the host and the bridge the same ip address, making the ha instance inaccessible.

    The red hat tutorial clearly show that the bridge and the host have different IP, so I was wondering if I am doing something wrong.

    ---

    alternatively, I can set the home assistant vm to run in NAT and port forward from host, but I have several devices that communicate over different ports. So it would be annoying to forward all these ports. Not to mention, many appliances don't have documentation about the ports they use.

    I can also potentially use virtualbox, but it is not well supported on silverblue, especially with secureboot enabled.

    1

    Hi all Nix experts,

    I recently started using nix to manage my dev environment on my immutable distro, and I need some help.

    I was wondering if I am using a large package like TexLiveFull, how to make sure nix don't delete large packages after I close the shell? I also don't want this package to be available in my global environment, as I don't need to use it outside vscode.

    Another question is how to keep my packages up-to-date. I don't do serious development work, thus I typically perfer my package and dev-tools to be on the latest version. I prefer to have a little management of this as possible. Ideally, every time I start up a nix shell, the package manager will grab the latest version of the package if possible without requiring additional interaction from me. Is this possible?

    Finally, is there any way to bubblewrap programs installed by nix to only access the file within the starting path of the shell? I don't imagine this is possible, but it would definitely be nice if nix has some security feature like this.

    Thanks in advance for your help! I understand parts of this post might be ridiculous. I am still new to nix. Please correct me if I am not using nix in the "correct" way.

    7

    cross posted: https://mander.xyz/post/8561230 from technology@beehaw.org

    Piped link: https://piped.video/watch?v=NXhmnQzZ7n8

    Article link: https://www.ifixit.com/News/88815/the-worst-in-show-2024-losers-are-in

    4

    cross posted: https://mander.xyz/post/8561230 from technology@beehaw.org

    Piped link: https://piped.video/watch?v=NXhmnQzZ7n8

    Article link: https://www.ifixit.com/News/88815/the-worst-in-show-2024-losers-are-in

    2

    Piped link: https://piped.video/watch?v=NXhmnQzZ7n8

    Article link: https://www.ifixit.com/News/88815/the-worst-in-show-2024-losers-are-in

    16

    TIL Canadian Bacon is Not a Canadian Thing; Hawaiian Pizza, On The Other Hand, Is Invented in Canada.

    Inspired by the video by Gem and Impulse from Hermitcraft. In the video, Impulse told Gem (a Canadian) that he had hawaiian pizza with canadian bacon on it; and Gem got really confused in what constitute a "Canadian bacon".

    Apparently Canadian bacon is called "Canadian" because it is originally imported from Canada to New York. Not because it is popular or invented in Canada.

    On the other hand, Hawaiian pizza is a true cultural amalgamation. It is invented by a Greek in Canada inspired by his experience cooking Chinese food. One of the culture it doesn't connect to is Hawaii, its name comes from the brand of pineapple the inventor was using.

    https://en.m.wikipedia.org/wiki/Back_bacon https://en.m.wikipedia.org/wiki/Hawaiian_pizza

    5

    I have setup my fedora to use LUKS encryoted partitions. But entering two passwords gets quite tiring, as I shutdown my laptop quite often to get the benefit of LUKS (I am assuming nothing is encrypted when in suspend, please correctme if I am wrong)

    I am thinking about setting up TPM autodecrypt. However, I was wondering does the decryption happen on boot or after I login?

    If it happens on boot, then it seems like the benefit is pretty limited compare to a unencrypted drive. Since the attacker can simply boot my laptop and get the unecrypted drive.

    Am I missing something here? I was wondering is there a way for me to enter my password once and unlock everything, from disk to gnome keyring?

    19

    Just a curiosity. Theoretically FRP (factory reset protection) can use the current login password as a way of authentication after reset. But everything on the web states that you will need a Google account to take advantage of he feature.

    6
    shop.fairphone.com Fairphone 5 | Fairphone

    Designed for you. Made Fair. Discover the newest member of the Fairphone family.

    With 5 years of OS support and 8 years of security update.

    Related threads:

    • https://lemmy.world/post/4130880
    • https://lemmy.world/post/4129394
    • https://feddit.nl/post/2555704
    188

    There is no blog article yet, but a email has been sent to some people who pre-ordered the AMD version.

    > Unfortunately, due to electrical issues we recently found during validation along with late firmware delivery from our silicon vendors, we’ve had to delay the start of mass production for Framework Laptop 13 (Ryzen 7040 Series) until September. We’ll be shipping as many pre-orders as we can before the end of September, but we anticipate that many orders originally in Q3 batches will need to move into Q4. We have prepared substantial production capacity, so we don’t expect the late start to cascade into delays in later batches.

    The reason is basically (as far as I understand) because this is the latest iteration of a product, and many drivers are not ready for the product, hence making it hard to conduct effective testing.

    And also there are serveral small complications with new hardwares (again, paraphrasing the email):

    • The back USB-A expansion card will draw high amount of power when it is empty or pluged in with a USB 2.0 device
    • The back HDMI/DP will draw high amount of power, but they are working on fixing the issue through firmware
    • The windows installer do not come with the up-to-date wifi driver, yet requires user to log into a microsoft account
    • Some linux distro with older kernel might not have wifi good general support out of the box, until updating the kernel, which probably will be covered by either official guide or community guide.

    Fortunately, other expansion card like storage, USB-C, and USB-3.0 works fine, and they state that Fedora 38 "will work smoothly out of the box". And they are working on fixing all of these issue or provide detailed guide to tweak these issue yourself.

    10

    I am not comfortable that signal depends proprietary google library. However, I find that Molly lags significantly behind signal (around 1 to 2 weeks, so maybe not as significant as I thought), but I am just concerned that if there is a security fix in signal, molly will not be able to react as fast.

    I am also quite frustrated with the general lack of communication from the signal team (for example the lack of communication regarding username). I doubt they will have the good will to help molly when there is a critical security fix.

    It is frustrating that signal no longer seems like the gold standard for privacy any more; unfortunately, all my friends are on there (ironic, isn't it...).

    48

    For now both DIY and prebuild edition (all configurations) are in batch 4 which ships in late Q4 2023.

    4

    AMD's official promo of framwork laptop 16.

    0
    frame.work Framework Laptop 16 pre-orders are now open

    We’re excited to share that Framework Laptop 16 pre-orders are now open, with configurations powered by the latest AMD Ryzen™ CPUs and AMD Radeon™ GPUs.

    TLDR:

    The laptop is devoloped with collabration with AMD and cooler master, using both AMD CPU and GPU.

    Price starts at $1399 for DIY and $1699 for prebuild, adding a Radeon graphics module brings the starting price to $1799 and $2099 respectively. Purchase a laptop with graphics module will recieve a free download code for starfield premium edition.

    First batch ships in Q4 2023.

    0

    Secure camera is really good. However I find google camera works better in low light with fast moving object, like in door photo of moving pet etc.

    For my use case, I have to install GCAM on my main profile, since my wife like to use it; and I don't want to go through the hassel of transferring photos between profile. But of course, I denied internet access and setup storage scope for GCAM.

    But that left me wondering, am I just making my life harder by using secure camera as default? Since it seems that although secure camera is pretty good, it is not as optimized as GCAM. I already have GCAM on my phone, so I cannot think of any privacy benefit by not setting it as the default.

    What do you think? do you use GCAM or secure camera, and why?

    15
    arstechnica.com Fairphone 4—the repairable, sustainable smartphone—is coming to the US

    Fairphone teams up with the developer of the /e/ Android fork to enable US sales.

    Edit: This article was already posted here yesterday.

    https://lemmy.world/post/1062252

    10