this post was submitted on 21 May 2024
207 points (96.4% liked)
Programming
17509 readers
356 users here now
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities !webdev@programming.dev
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
As someone who has done way too much shell scripting, the example on their website just looks bad if i'm being honest.
I wrote a simple test script that compares the example output from this script to how i would write the same if statement but with pure bash.
here's the script:
Comment out the line you dont want to test then run
hyperfine ./script
I found that using the amber version takes ~2ms per run while my version takes 800microseconds, meaning the amber version is about twice as slow.
The reason the amber version is so slow is because: a) it uses 4 subshells, (3 for the pipes, and 1 for the $() syntax) b) it uses external programs (bc, sed) as opposed to using builtins (such as the (( )), [[ ]], or [ ] builtins)
I decided to download amber and try out some programs myself.
I wrote this simple amber program
it compiled to:
and i actually facepalmed because instead of directly accessing the first item, it first creates a new array then accesses the first item in that array, maybe there's a reason for this, but i don't know what that reason would be.
I decided to modify this script a little into:
so now we have 1000 items in our array, I bench marked this, and a version where it doesn't create a new array. not creating a new array is 600ms faster (1.7ms for the amber version, 1.1ms for my version).
I wrote another simple amber program that sums the items in a list
which compiles to
This compiled version takes about 5.7ms to run, so i wrote my version
This version takes about 900 microseconds to run, making the amber version about 5.7x slower.
Amber does support 1 thing that bash doesn't though (which is probably the cause for making all these slow versions of stuff), it supports float arithmetic, which is pretty cool. However if I'm being honest I rarely use float arithmetic in bash, and when i do i just call out to bc which is good enough. (and which is what amber does, but also for integers)
I dont get the point of this language, in my opinion there are only a couple of reasons that bash should be chosen for something a) if you're just gonna hack some short script together quickly. or b) something that uses lots of external programs, such as a build or install script.
for the latter case, amber might be useful, but it will make your install/build script hard to read and slower.
Lastly, I don't think amber will make anything easier until they have a standard library of functions.
The power of bash comes from the fact that it's easy to pipe text from one text manipulation tool to another, the difficulty comes from learning how each of those individual tools works, and how to chain them together effectively. Until amber has a good standard library, with good data/text manipulation tools, amber doesn't solve that.
This is the complete review write up I love to see, let's not get into the buzzword bingo and just give me real world examples and comparisons. Thanks for doing the real work ๐