• 0 Posts
  • 171 Comments
Joined 1 year ago
cake
Cake day: June 10th, 2024

help-circle


  • balsoft@lemmy.mltoProgrammer Humor@lemmy.mlInfallible Code
    link
    fedilink
    arrow-up
    5
    ·
    edit-2
    14 hours ago

    The difference is that (( is a “compound command”, similar to [[ (evaluate conditional expression), while $(( )) is “aritmetic expansion”. They behave in almost exactly the same way but are used in different contexts - the former uses “exit codes” while the latter returns a string, so the former would be used where you would expect a command, while the latter would be used where you expect an expression. A function definition expects a compound command, so that’s what we use. If we used $(( )) directly, it wouldn’t parse:

    $ even() $((($1+1)&1))
    bash: syntax error near unexpected token `$((($1+1)&1))'
    

    We would have to do something like

    even() { return $(($1&1)); }
    

    (notice how this is inverted from the (( case - (( actually inverts 0 -> exit code 1 and any other result to exit code 0, so that it matches bash semantics of exit code 0 being “true” and any other exit code being “false” when used in a conditional)

    But this is a bit easier to understand and as such wouldn’t cut it, as any seasoned bash expert will tell you. Can’t be irreplaceable if anyone on your team can read your code, right?

    I can’t think of many use-cases for ((. I guess if you wanted to do some arithmetic in a conditional?

    if (( $1&1 )); then echo "odd!"; else echo "even!"; fi
    

    But this is pretty contrived. This is probably the reason you’ve never heard of it.

    This (( vs. $(( )) thing is similar to how there is ( compound command (run in a subshell), and $( ) (command substitution). You can actually use the former to define a function too (as it’s a compound command):

    real_exit() { exit 1; }
    fake_exit() ( exit 1 )
    

    Calling real_exit will exit from the shell, while calling fake_exit will do nothing as the exit 1 command is executed in a separate subshell. Notice how you can also do the same in a command substition (because it runs in a subshell too):

    echo $(echo foo; exit 1)
    

    Will run successfully and output foo.

    (( being paired with $((, and ( with $(, is mostly just a syntactic rhyme rather than anything consistent. E.g. { and ${ do very different things, and $[[ just doesn’t exist.

    Bash is awful. It’s funny but also sad that we’re stuck with it.





  • balsoft@lemmy.mltoProgrammer Humor@lemmy.mlInfallible Code
    link
    fedilink
    arrow-up
    7
    ·
    edit-2
    19 hours ago

    Amateur! I can read and understand that almost right away. Now I present a better solution:

    even() ((($1+1)&1))
    

    (I mean, it’s funny cause it’s unreadable, but I suspect this is also one of the most efficient bash implementations possible)

    (Actually the obvious one is a slight bit faster. But this impl for odd is the fastest one as far as I can tell odd() (($1&1)))





  • Lots of interesting answers here. I figured I’ll pitch in too.

    IMHO there is no one true, universal meaning of life - just as there is no one meaning of any piece of art. I think the idea that everything around you must have a single meaning is a relatively modern one, which came from the requirements of efficient communication (which should indeed be precise and not open to interpretation).

    As it stands, it is up to you to interpret the world around you and find different meanings for yourself, just as you should do with art. If you are struggling to start, consider those questions: What do you enjoy? What makes you happy? What do you think is “good”, even if it makes you sad or uncomfortable? All those things are your personal interpretations of meaning of life. Or go ahead and make up something else, I’m not your dad.

    I was pondering why people fight so hard to beat diseases and live a few more years. What are they planning to do? Why exert effort just to be here longer when you don’t have a reason?

    As for this, I think when people realize the proximity of death and temporal nature of their life, they are much better at coming up with meanings. Maybe it is to see your partner or your children for a couple more years. Maybe it’s another couple of gaming sessions with your pals. Whatever it is, when you realize you don’t have much of it left, the importance of it typically rises dramatically from your perspective. If you’re struggling to visualize something so dramatic, imagine that your favourite food will be completely banned and criminalized in your country in couple weeks. Wouldn’t you want to enjoy it more before that happens?




  • Honestly this made me really sad that we’re stuck with this archaic, awful language as a primary way of programmatically interacting with our computers. And I don’t mean to say anybody has done anything wrong here - sh and bash were revolutionary and amazing for their respective times, and maintainers who are keeping bash alive now are heroes who deserve praise. However, many decisions made when sh was originally developed turned out to be footguns, still creating bugs today (despite shellcheck et al).

    nushell is somewhat promising but flawed (because it has to be built on the same system interfaces as sh, after all). The most annoying is that there’s no facilities for setting any metadata on data streams (in particular there’s no way to set the format of the data) so everything has to be marshalled manually, which would be OK for a proper programming language but really annoying for a shell. At least it fixes most of the quoting, escaping, interpolation, substition etc awfulness, and allows for manipulating data in a more structured way.

    I really don’t know if it’s even possible to make a language that would be a good convenient shell and at the same time not prone to bugs which are easily noticeable in other languages. I hope that something like this becomes a reality at some point.





  • There should be no updating unless enabled <…> and never nag the user.

    I disagree, at that point you might as well continue using Win10. Security updates are the #1 reason to do this. Most computer use nowadays is networked (actually in a browser), and it’s super important we keep that updated.

    If updating is turned on, it should be very conservative, updates hand curated by grandmasnixos, basically never uses software that hasn’t been proven rock solid for at least 6 months

    Eh, this sounds like a lot of work. Probably just use the stable channels, and only manually test when switching to a new stable channel.

    Rolling back any update should be one-click-trivial

    Agreed, should also be very obvious (like a label on the desktop that says “Issues after update?” and gives you a button to roll back and reboot)

    The desktop environment should be something occasional win10 using grandma will not get lost in

    This is the main question IMHO. I’ve not used any DEs for a while, so don’t really know which one would fit this best while also being simple and robust.


  • I think we can be even simpler than that. Don’t ask any questions. Simply generate the hardware-configuration.nix and have a single configuration.nix that is unchanged:

    • Some easy-to-use and simple DE. I’m thinking something like lxqt or xfce, maybe Pantheon - but that would be more familiar to Mac users than Windows. KDE seems way too complicated to just have it in configuration.nix without touching it, and it can sometimes break on updates.
    • Chromium (with pre-installed ublock origin)
    • Libreoffice
    • Some flatpak store (so that people can install apps without touching configuration.nix)
    • Make a simple “update” app that just pops up once in a couple weeks or so, prompts you to click a button and then runs npins update and nixos-rebuild boot, and finally annoys you until you reboot (it should also update to the next stable channel when that becomes available, and make that a big deal so that a user understands it might change some of their workflows)
    • Set up the bootloader so that if a generation “fails” (some script in the autostart of the DE doesn’t set a flag somewhere) on the next boot it boots a previous generation, kinda like Android’s A/B slot system but better. I don’t think systemd-boot allows this sort of thing, but I think it’s possible with a GRUB script
    • Maybe add a shortcut to open tmate and copy the URL to clipboard, so that you can send it someone in the know and they can help you troubleshoot
    • Finally, use impermanence to make sure everything outside /home, /nix, and wherever flatpak are stored, is wiped on every reboot and recreated from the generation, so that “reboot it” is a viable troubleshooting strategy.