22 ms·
Amber: Programming language compiled to Bash
- viraptor 2y agoI wish nushell had a similar compiler. It would help with using it on servers.
- HKH2 2y agoRust, except using existing executables (or dynamic libraries) instead of downloading packages and waiting ages for it to compile? Seems like a great idea.
- IshKebab 2y agoThis is not even remotely an alternative to Rust, nor is it intended to be. It's a replacement for Bash.
- HKH2 2y agoI know, but it looks like it is heading in that direction.
- karmarepellent 2y agoAdding to your point, I also instantly regarded Amber as an alternative to other higher-level languages. Especially scripting languages that require elaborate ahead-of-time setup. Amber will surely score some points here due to its portability in the Linux world. But other commenters seem to see it as an alternative to writing Bash scripts. So which will it be?
- michaelmior 2y ago> Variable declarations can be overshadowed - this means that you can redeclare the existing variable with different data type in given scope if you need to. I'm having a hard time deciding why I would want this. It seems more likely to result in bugs than being a useful feature.
- mort96 2y agoIt's a common practice in Rust at least, where instead of having a mutable variable which you modify across several lines, you declare a new immutable variable with the same name on those lines. I like it, but I guess it really just comes down to preference and what you're used to.
- mst 2y agoI quite like that pattern, but I think 'with a different datatype' should result in a small gnome climbing out the back of the computer and hitting the developer with a mallet.
- mort96 2y agoMeh. I don't mind: let thing = whatever(); let thing = thing.unwrap(); EDIT: what the hell I say I don't mind a particular pattern and that's enough for a downvote? Not that I care but I find this surprising
- michaelmior 2y agoI guess I haven't read enough Rust code to come across this patterns, but I don't think I particularly like it. Perhaps I would get used to it though :)
- kbp 2y agoIt works the same way in Haskell, eg main = do let x = 2 let x = "foo" y <- pure 3 y <- pure "bar" putStrLn $ x ++ y which is really the same as main = let x = 2 in let x = "foo" in pure 3 >>= \y -> pure "bar" >>= \y -> putStrLn $ x ++ y So it works pretty naturally where each assignment is kind of like a new scope. If the type system is good, I don't think it really causes issues.
- mort96 2y ago
- v3ss0n 2y agoWhy would someone need to compile to bash..
- kitd 2y agoBash is available by default on a huge range of OSes.
- v3ss0n 2y agoWhy would someone need to compile to bash.. how about just use python instead
- fforflo 2y agoI had done a SQL-like ->Bash "language," and the reason was that I wanted to have access to CLI tools as-is, in my case, curl programs. Had I chosen Python as a target, I'd have to use requests/urllib, which would be much more verbose. The same applies if one needs awk, sed, etc... The constructs are just there. Also the fact that you can just pipe to bash, makes development much easier.
- usrusr 2y agoYou certainly should. Even if you know some bash and zero python I suppose, because bash is just so "special". But only if your target environment has python, and that's not a given, not a zero-cost change, in this age of short-lived containers. The use case for a "compile to bash" language would be compile in a dev-operated environment and commit both source and output, which would then run on later stages in the CI/CD pipeline that might very well not have python. And those stages will absolutely not have your "compile to bash" tool, which would ideally be included along with the source unless it's somehow as near-omnipresent as python. This one appears to be implemented in rust, I'd certainly feel more optimistic about depending on it as a script authoring tool if it was e.g. a python script that could be included with my "pre-bash" source, and/or packaged in, say, npm.
- DaSHacka 2y agoAnd enjoy a mad scramble to rewrite everything after Python 4 releases? For all its faults, after a Bash script works once, it usually just keeps working.
- IshKebab 2y agoPython isn't nearly as likely to be installed already as Bash is.
- up2isomorphism 2y agoCompile to Bash? Why not compile to English then?
- fforflo 2y agoI don't share the "oh my, why bash, why not English then?" sentiment in the comments. I've done a bunch of DSLs (CLI with some elaborate syntax really) that compile to bash as a target. It just works for me. Bash is always available; the constructs you can use are there (coreutils are mostly enough for the primitives and xargs for parallelization) It has been great so far for basic cases. Where things get complex (as other's have said) is handling failures, errors and intrinsic cases. That's when you're reminded why people didn't stuck with bash in the first place and we got other scripting languages.
- reisub_black 2y agoWhy does the documentation need WebGL? I have WebGL disabled in my main browser for privacy reasons (super-easy to fingerprint), and I only get to see 'Application error: a client-side exception has occurred (see the browser console for more information).' with an error about ThreeJS initialization in the console. I assume it's for the fancy animation, and I find that ridiculous. Loading a whole 3D library just to show a fancy animation. This could have been done much simpler by using an animated image format, though admittedly with less functionality - but is it even needed? I fear the whole industry suffers from overengineering and this is just a symptom. Even if you're convinced you need the fancy animation, why not gracefully fallback to not showing it and still make the docs usable?
- cqqxo4zV46cp 2y agoThe reality is that in disabling WebGL, you have an incredibly unusual configuration and the author didn’t test for it. Stop making this a philosophical argument. Why does the documentation need WebGL? It doesn’t, but the web has moved beyond just addressing “needs”. Why do you need to be on HN? You don’t. Yet here you are. I’m not arguing that the juice is worth the squeeze here, but your argument has a false premise that you’re exploiting to make the situation sound more absurd than it is.
- cess11 2y agoI don't think it's incredibly unusual. On sensitive machines in corporate settings you commonly disable pretty much everything on every page that isn't in the 'trusted zone' or whatever. Personally, by default I shut down all the browser crap that might needlessly allocate RAM or allow memory leaks or slurp cycles without giving me some kind of value. I think this allows me to hold at least a few hundred extra tabs open. For technical documentation I expect text, hypertext and static images, if you're going to require JS and WebGL and whatnot I'm going to assume you aren't entirely honest with me about the information we're about to share and I'll probably sandbox a scrape of the documentation if I really need it.
- auxfil 2y ago
- Woshiwuja 2y agothats one ugly site
- philmitchell47 2y agoSeems horrendously brittle. I'd trust badly written bash over this.
- msl09 2y agoGreat stuff. I hate having to write bash scripts and this seems like a great way to create scripts that will run on even old linuxes. Seems that there are a few sections missing in the documentation, stuff like the standard library and the extended documentation about handling failure, very alpha indeed :^D. I'll definitely be keep an eye on this one.
- pgt 2y agoWould be great if a compiler existed that compiles ClojureScript or Babashka code to Bash.
- ceving 2y agoI like the Kafkaesque design: https://i.imgur.com/U1mpq7e.png https://i.imgur.com/U1mpq7e.png
- saurik 2y agoSomething I noticed when I went to copy/paste something off the web page for this comment: at least some of the text on this page is in the form of an SVG?! That just feels gratuitous to me, particularly given how annoying it is to not be able to copy it :/. https://amber-lang.com/pipelines/compile.svg https://amber-lang.com/pipelines/compile.svg It also, hilariously, feels a bit fitting given my actual complaint ;P. if [ $(echo ${__0_age} '<' 18 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; Look: I appreciate that this is a shell script, and they often aren't "fast", but if I'm writing code in a script and have a comparison it at least might be in some tight loop and the performance different of spawning bc and sed into a subshell is frankly brutal. if [ "${__0_age}" -lt 18 ]; then
- cvrajeesh 2y agoIs this a transpiler or compiler?
- gloria_mundi 2y agoBoth, since a transpiler is a type of compiler.
- auxfil 2y ago[dead]
- bogwog 2y agoThis is interesting, but I don't see why I would use this instead of Python or Go? With those I'd get portability, modern features, etc but with the added bonus of a powerful standard library and ecosystem. Don't get me wrong, I hate writing shell scripts, so this is definitely an improvement over that. It just doesn't seem like the most practical solution (unless I'm missing something).
- okennedy 2y agoBash is ubiquitous and stable, making bash scripts incredibly portable. All of the other languages you bring up are great for authoring code, but have a non-zero amount of friction when running code in the wild. Python may be omnipresent, but you can rarely count on a specific version or the presence of specific libraries. Go requires compiling platform-specific binaries. Even JVM- or JS-based software requires installing a separate toolchain first. If you want to write some code (e.g., a launcher, installer, utility code, etc...) that is almost certainly going to run on any computing device created in the last several decades, bash is your language.
- ModernMech 2y agoWhy doesn’t Amber have equivalent issues? Such as depending on a specific version of bash, or specific executables to be installed. Also does bash run on windows outside of WSL? Amber seems to argue that it doesn’t support Windows because Windows doesn’t support bash. That would cut against the idea that bash can target more devices than Python, which runs natively on all platforms.
- sundarurfriend 2y ago> Also does bash run on windows outside of WSL? Git Bash is pretty ubiquitous on developer machines in my experience.
- ModernMech 2y ago"pretty ubiquitous" is what I'm referring to here. OP seemed to imply that because the other options have "non-zero friction" that targeting bash has zero friction. But you have to make sure bash is there, and if it's not, you have to install a toolchain that may include an entire operating system. I guess I just don't understand how having the user install git bash or WSL any different from having them install Python or JVM?
- vhmc41 2y agoI was really confused because there's also a Amber Language that compiles to JS: https://amber-lang.net/ https://amber-lang.net/
- queuebert 2y agoFittingly the now-defunct Amber Rapid was a blindfolded chess tournament.
- supriyo-biswas 2y agoI love the concept of a language like this, though I haven't evaluated amber in detail. I want to do more complex things using bash for devops stuff, because it's mostly working with other command line tools. You could directly use APIs and SDKs of cloud providers, but then things become an order of magnitude more complex than just writing the bash script. However, when you do that you encounter bash's weaknesses, like not supporting a nested structure like Map<String, Map<String, Int>> and so on. Having to wrangle tools like jq, sed and awk all together to work around the lack of proper data structures and string manipulation is no fun either. Something like amber could bridge the gap while still being portable across systems.
- fluidcruft 2y agoI sort of see that, but at the same time why not just compile to python instead? I get that python can be less convenient syntactically for "scripting" type things, but if you're writing in what's effectively a DSL that gets transpiled for a different interpreter anyway...
- lytedev 2y agoI'm guessing because Bash is "more everywhere" than Python.
- KerrAvon 2y agoAs slow as Python is, though, Bash is more slow. Much more slow.
- hnlmorg 2y agoIt’s actually fork() that’s slow, rather than Bash itself. If you were to write Python code that did a of its business logic by spawning new processes rather than using its core libraries (which are written in C) then you’d find Python would be just as slow too. But the exact point of Bash and other shells is to make launching new processes easy. This is the point that people miss when they say “write it in a real programming language”. Shells solve an entirely different problem to other languages. And “real” programming languages suck at working with other executables in a quick and convenient way.
- hasante 2y agoGood stuff - always wanted to write bash but not really write bash or learn it deeply. It's amazing world seeing these tools come out. Just built a CLI a couple days ago with golang and it was an incredible experience where these things have come. Things - acute product dev tools. Tools to create peculiar or not soo common tools.
- hasante 2y agoGood stuff - always wanted to write bash but not really write bash or learn it deeply. It's amazing world seeing these tools come out. Just built a CLI a couple days ago with golang and it was an incredible experience where these things have come. Things - acute product dev tools. Tools to create peculiar or not soo common tools.
- forinti 2y agoI dunno, why not just use Perl or Python?
- 1propionyl 2y agoLooking at the output I find myself thinking: "if this kind of thing caught on, it would only be a matter of time until someone proposes a BASM (Bash ASM)..."
- adamtaylor_13 2y agoI love the idea, but having spent so much time learning the ins and outs of bash I feel like I’d rather just use bash. To say nothing of the Lindy Effect. Bash will probably be here in 50 years. This probably will not.
- slushy-chivalry 2y agoI think a superset of bash with strong types makes more sense than a brand new language that compiles to it. This is what makes typescript so successful (aside from other things) is that you can just drop it into your project and incrementally adopt it.
- ape4 2y agoCall it "typebash" - easily understood by everyone
- fb03 2y agoI think this is a cool concept, and all, but honestly, at this point, why just not use Python3 as your project's scripting language, and reap all the benefits of a simple, typesafe/autocomplete ready language with broad IDE support, and no intermediate 'compile step' which generates "don't touch" code?
- aiisjustanif 2y agoBecause the project might require a script that is delivered to many Linux servers with less dependencies and not having to install a new language.
- aruametello 2y agoI can see some very niche cases where an embedded system has bash not much else and "taking the most you can out of bash" could end up being useful. besides that? probably nothing.
- anonu 2y agoMaybe I lack a bit in creativity: but what purpose does this serve? Almost all machines have a python or even perl interpreter if you really need to go there.
- partdavid 2y agoWhat you think is ubiquitous is actually pretty narrow, and your perspective is biased based on your own experience; by "machines" you could mean containers, VMs (of a dozen different virtualization technologies), on a bunch of OSes and OS variants let alone distributions of same. You probably think something like an embedded Linux on a fleet of soft switches is a "niche case" but in the real world people work on these kinds of things all the time. I don't think Python is as ubiquitous as you think is is; but regardless, mere presence is not the only problem. What Python are you even talking about? Which version? How is the user supposed to handle dependencies? If something like this has utility, it's to minimize the configuration management problem you're giving the user. "Use Python" is definitely not the answer to that. This doesn't seem to be a terribly good implementation of the idea, but it's not a bad idea, on its own.
- leni536 2y agoI like the idea, but the example suggests that it invokes external programs for trivial stuff, like comparing a variable to an integer (invokes bc and sed). I would prefer if it compiled to pure bash, and only invoked external programs if explicitly called for. But I guess emulating some feature in pure bash is hellish, that's exactly I don't want to write that manually either though.
- fluidcruft 2y agoMaybe it's targeting that ancient GPLv2 bash (that MacOS still ships for ideological reasons).
- wavemode 2y agoI can't envision a circumstance where I would use this over perl. Every Unix system under the sun has perl. Even MacOS has perl.
- LectronPusher 2y agoI haven't seen a mention of the Oil Shell (https://oilshell.org https://oilshell.org) project's OSH/YSH yet and I'm quite surprised. Oils goal is that OSH is just a new Bash implementation (although not bug-for-bug) but with an upgrade-path to the more modern YSH for real programming with type safety etc, but still as a shell language. One of their exciting ideas is using code as data in a somewhat lisp-like manner to allow function introspection in YSH etc. Based on other comments it seems like Oil Shell is much more principled in working to actually understand Bash as it exists and presenting an alternative language. I would be interested in what differentiates Amber and whether they have a response to Oils?
- biggestlou 2y agoOil shell requires osh to run. That means that you can't run Oil scripts on systems that only have Bash installed.
- greggyb 2y agoOsh is stricter than bash. Anything written to osh should run in bash with no issues whatsoever. Ysh implements new, non-compatible syntax and semantics. Osh and ysh are two different shell languages from the Oils for UNIX project. The release build generates a single binary, oils-for-unix, and installation creates two symlinks for the two different shell personalities, similar to how the bash binary will behave in its POSIX-compliant mode when it is invoked as sh. There is no "Oil shell" now, at least not without ambiguity.
- partdavid 2y agoIt's an entirely different problem; the problem being solved here is not "use a better shell than bash". It's targeting bash as a universal runtime because it's (kinda sorta) ubiquitous.
- deleted 2y ago[deleted]
- Too 2y agoWhat’s the use case for that though? Nobody writes shell because they want a shell language. It’s written purely out of necessity because that’s the lowest common denominator installed on all systems. Something that Amber here provides a potential exit path out of. Oil would have to reach a really critical mass before it can compete, which is sort of a catch 22 situation.
- throwaway894345 2y agoMan, I'll bet that's a real joy to debug.
- queuebert 2y agoHaving some array syntactical sugar alone would be invaluable for us casual Bash programmers.
- maupin 2y agoI like how the website is as easy to read as a glossy magazine brochure in a gloomy cave entrance on an overcast day.
- ARandomerDude 2y agoWhy would a person go this route instead of a higher-level scripting language (Python, JS, Ruby, etc.) or a full-blown binary (Go, Rust, etc.)? I don't get it. Asking not to be rude but to be educated.
- tmvphil 2y agoI would assume because bash is deployable to more locations with fewer assumptions. Scripting requires environments to be set up correctly to run, and binary makes architecture assumptions.
- replwoacause 2y agoVery interesting. Don’t think I’ve seen anything like this before. How would the speed on something like this be compared to PowerShell, for example? Is it faster because it’s compiled? Could I write a web server in it?
- notdefio 2y agoIt's not compiled in the way that C is compiled. Transpiled would be a better term (though there are debates on where the line is). Amber code gets turned into bash code, and run by a bash interpreter. So at best Amber's performance will match Bash's performance. I've seen people say bash is faster than PowerShell, but I don't have benchmarks to back it up. Even so, I wouldn't recommend using it for performance intensive tasks such as writing a web server. The great advantage I see for Amber is being able to write scripts in a sane language (bash is not enjoyable to write), and have those scripts be able to run anywhere that Bash is installed.
- replwoacause 2y agoThanks that makes sense.
- jordemort 2y agoI think this is a pretty interesting idea. I could see myself using this on one of my previous embedded jobs; we needed to stuff a bunch of complex logic into our initramfs and the only interpreter we could really fit in there was the sh from busybox. We ended up with a pretty hairy shell script that probably would have been nicer to write in Amber.
- nathan_compton 2y agoThis really can only work if the error messages map back to the right line number, right? I used to f with transpilation and if you can't get the error line at least, its a really huge overhead for not much gain, given that transpilation can only move the semantic needle so far.
- Retr0id 2y agoBash is nice, but if we're going to all the effort of transpilation, I'd really like to see plain POSIX sh as the target
- nerdponx 2y agoThe generated code already looks kind of insane, I can imagine it would only be worse without the benefit of Bash features.
- sgarland 2y agoTHIS. Why does this: if age < 18 { echo "I'm not an adult yet" } else { echo "I'm an adult" } compile to this: __0_age=30; if [ $(echo ${__0_age} '<' 18 | bc -l | sed '/\./ s/\. \{0,1\} 0\{1,\}$//') != 0 ]; then echo "I'm not an adult yet" else echo "I'm an adult" fi instead of this: __0_age=30; if [[ ${__0_age} -lt 18 ]]; then ... If you're going to compile to Bash, then use Bash-isms. EDIT: `-gt` is POSIX, but tbf if there's no input sanitization, then bash (or sh) will choke on the float. In that case, as long as you aren't trying to round, you could use parameter substitution to truncate: __0_age=17.6; if [[ ${__0_age%%\.*} -lt 18 ]]; then ... EDIT2: TIL that parameter substitution is POSIX [0] Section 2.6.2 [0]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V...
- nick238 2y agoSo you want it to compile to POSIX sh but you're unhappy it doesn't use more POSIX-incompatible features? Maybe full POSIX sh compat is WIP, or in some simpler cases maybe it already is?
- olejorgenb 2y agoRetr0id, not sgarland want posix. > Maybe full POSIX sh compat is WIP Still - I sure hope it's possible to do a comparison in sh without spawning two processes.
- dpc_01234 2y agoIf I need an extra tool that will compile stuff, I might as well use a normal compiled or scripting language. Which I often do.
- Retr0id 2y agoBut then your compiled binaries are not portable cross-architecture, or your scripts require a compatible interpreter to be pre-installed.
- dpc_01234 2y agoWorth it. With Amber (and anything like it) you need an Amber compiler to be able to work on the script. And half of the reason to use a "script" is the ability to edit them if need arises. Also since I'm 100% Nix now, I require `nix` installed everywhere anywhere, and if there's `nix`, anything else is available in a reproducible way.
- galdosdi 2y agoCool idea. In practice: they already did this and it's called PERL! Why would I ever use this instead of just using perl5, which solves all these problems already and is preinstalled on every Unix machine I've ever seen (and I've seen a lot from HPUX to AIX) since there's always some ancient innards component that depends on it, so it's basically impossible to remove... And even if you don't know perl, you're better off learning it than Amber, because perl may not be super popular anymore but it's still way way bigger with way more resources and libraries and documentation and even people you could hire etc etc (If you prefer python2, you can probably get close to but not quite the same level of universal compatibility)
- melodyogonna 2y agoI find all the "Why should I use this when X exist" nonsensical. If you can't see any use for it then it's not for you. There are a whole lot of people who will find this more attractive than Perl.
- galdosdi 2y agoBecause they've heard the "lol perl is line noise" jokes and taken them very seriously instead of the jokes they are. Perl is way more mature with way more libraries, stability, documentation, etc. I hope I don't have to work with some young fool who decided without trying that perl, an incredibly well documented language, is "too hard" and instead signed our whole team up to work with some experimental 3 month old language with who knows what weird bugs and quirks, none of which youll find info about on stack overflow, because almost nobody has ever used it Reminds me of the days about 10 years ago when all the kids were obsessed with no SQL and MongoDB for use cases that were smaller than SQLite -- purely because they were scared to learn SQL You'll understand where I'm coming from after you get more experience and have had multiple jobs where you had to maintain architecture with poor choices due to an inexperienced original author using cool shiny tech that offers little advantage over the more mature tech, and you spend much of your time working around and maintaining something that has no stack overflow coverage at all
- 2y ago
- Jaxan 2y agoI know it’s not done to comment only on the websites appearance, but on a small screen the website is a mess: https://pasteboard.co/JoVqLPM106ks.png https://pasteboard.co/JoVqLPM106ks.png
- therealmarv 2y agoI would use it if we can do a (best-effort) import of existing bash scripts into Amber.
- jamesponddotco 2y agoSlightly off-topic, but in many posts mentioning Bash, the overall consensus seems to be that when a script gets too big you should switch to using a more full-featured programming language instead. Which is fine, I get the reasoning. But imagine you need to deploy a server but for whatever reason you can't use Puppet, Ansible, or other configuration management tools. You need to write a deployment script using a "real" programming language. How would you tackle the problem using Go, for example? Does anyone have examples of deployment or install scripts written in Go, Rust, or whatever else? Thinking out loud I assume you would need a zypper (assuming openSUSE) package with Repository and Package structs and their methods, a secrets package to handle getting secrets from your secrets manager and setting them, and I'm drawing a blank on everything else. As a system admin I picked up Go a few months ago to slowly reduce my Bash usage, but I still find myself using Bash whenever I have to write a install script because of how easy and fast it's to write compared to other languages.
- deleted 2y ago[deleted]
- praseodym 2y agoYou can use a tool like gorun (https://wiki.ubuntu.com/gorun https://wiki.ubuntu.com/gorun) to run Go source code as if it were a shell script, by putting gorun in the shebang line. Of course the disadvantage is that you need to Go have the toolchain installed everywhere you want to use the Go script, so it's definitely not as portable as using a regular shell script.
- Karrot_Kream 2y agoGo is definitely a decent solution but I'm surprised why you aren't using Python. Most Linux and BSD distros have access to a default install of Python. Even if the version is a bit old, if all you're doing is hydrating templated configuration and doing bookkeeping for eventually running a binary with some parameters, older versions of the standard library will do just fine.
- jamesponddotco 2y ago
- Alifatisk 2y agoThe homepage is good looking and I applaude them for that, but I gotta admit, it's almost too dark for me to see some of its content. I think grey text on black background is risky move.
- snickerer 2y agoI totally understand the drive to a more modern shell language. But why translate Amber into bash, why not execute it directly? Why there isn't an Ambersh? We got some great BASH alternatives: Zsh, Fish, Elvish, Nushell, Xonsh. I did not evaluate them all, but if Amber is even better, why not have Ambersh? Can somebody please explain?
- bar000n 2y agomaybe you want to run scripts on machines where you can't install everything you want (alternative shells)
- krunck 2y agoThe Amber installer is itself created from Amber. I suppose that makes sense.... I would prefer that it produces code with a bit more whitespace for readability.
- phaedryx 2y agoHow many "Amber"'s do we need? e.g. https://github.com/amberframework/amber https://github.com/amberframework/amber https://amber-lang.net/ https://amber-lang.net/ https://ambermd.org/tutorials/ https://ambermd.org/tutorials/ https://openjdk.org/projects/amber/ https://openjdk.org/projects/amber/ I'm probably grumpy, but I like unique names.
- rbren 2y agoI had a brief idea for transpiling bash here: https://github.com/rbren/baml https://github.com/rbren/baml The thing I'm most proud of is the installation--you just put a single base64 encoded line at the top of your script, and everything works magically.
- albinekb 2y agoNeat! We did something in the similar spirit after having too many beers once : https://github.com/LinusU/monofile https://github.com/LinusU/monofile The idea was to be able to mix languages in a single file, including the implementation
- graypegg 2y agoI kind of wish this was a tool to author bash, or better yet very compatible POSIX sh. (versus being using bash as a compile target that a human isn't meant to read) It's a bit of a stretch, but comparing it to something like MJML for HTML emails. [0] It doesn't make great HTML, but it's not unreadable and standard quality for HTML emails. It just handles all of the weird things you have to consider for maximum email client compatibility. It's basically a bunch of HTML macros, with react being an implementation detail under the hood. It's not like it's bringing any new features to HTML emails, because if it did, the output WOULD be unreadable. If this was just some type hints, and cleaner syntax around sh, that I think would be really useful. This in it's current state is just sort of a tech debt generating machine. If something is built in amber, it's because we can only use bash for some reason, but if we can use bash we could either... use bash, or we could call something else (Ruby, Python, etc), from a 2 line bash script. [0] https://mjml.io/try-it-live https://mjml.io/try-it-live (click "View HTML" to see outputted source.) Edit: Idea, it would be cool if you could define the environment available to the final script when using the compiler. That way, if there was something you wanted to distribute, the person building your project could say "this docker container I'm running this in won't have sed, but it will have bc and awk" or something.
- Humphrey 2y agoLove the idea, but I've found myself switching to Python once my bash scripts get to complex. Easy to maintain, and doesn't need compiling.
- DemocracyFTW2 2y ago> In Amber, there is a rule that allows you to use a : symbol where you intend to write only one statement, wherever you can write a block of code. This can be handy when you want to perform multiple conditions with a single statement each. This feature, optional omission of delimiters in the special case of a single statement per branch, originated in early C and has since facilitated untold numbers of bugs, not least the spectacular Heartbleed bug (which has its own homepage, https://heartbleed.com https://heartbleed.com).
- hi-v-rocknroll 2y agoAdjacent: I've yet to find a good bash transpiler (to C at least), but I think it would help make some slower scripts usable.
- adityamwagh 2y agoThe design of the website is so damn cool.
- burky 2y agoThis looks similar to a tool I discovered a while back called Batsh. But Amber looks a lot more polished and has some nice safety about it. https://github.com/batsh-dev-team/Batsh https://github.com/batsh-dev-team/Batsh
- mrbluecoat 2y agoBoth tools look useful (although I lean toward Amber's ECMAscript syntax). I liked this comment from batsh: > Both Bash and Batch are messy to read and tricky to write due to historical reasons. You have to spend a lot of time learning either of them and write platform-dependent code for each operating system. I have wasted lots of time in my life struggling with bizarre syntaxes and unreasonable behaviors of them, and do not want to waste any more.
- thezipcreator 2y agothe website doesn't seem to render right on Firefox for some reason (works with Chromium tho)
- pubg 2y agoStrangely the website links do not work unless you enable Javascript (e.g. to the GitHub project page). Why do people make things this way? Let a plain old link be a link..
- kbenson 2y agoSeems to render fine on Firefox mobile for me, but maybe I'm just not noticing what's broken.
- cristoperb 2y agoyeah the landing page is pretty broken on Firefox for me, but the docs site works: https://docs.amber-lang.com/ https://docs.amber-lang.com/
- deleted 2y ago[deleted]
- Groxx 2y agoThis is equal parts horrifying and impressive and useful. I'm unsure how to feel.
- geocrasher 2y agoHorrified and Impressed.
- iansinnott 2y agoOdd that (on desktop) the actual install URL is obscured by a gradient.
- cstrahan 2y agoYou mean this text below "Download for $OS"? curl -s "https://raw.githubusercontent.com/Ph0enixKM/AmberNative/master/setup/install.sh https://raw.githubusercontent.com/Ph0enixKM/AmberNative/mast..." | $(echo /bin/bash) I guess it would be too long to fit (aesthetically) on the page. The "copy" icon off to the left copies that line to your clipboard.
- srid 2y agoNow someone needs to add this to Nix, by providing an alternative to `writeShellApplication`: https://nixos.asia/en/writeShellApplication https://nixos.asia/en/writeShellApplication
- manlobster 2y agoI don't love the $...$ syntax for executing commands. Using $ as a string delimiter is very strange to my bash-accustomed eyes. It's a shame that they provided such weird syntax for the most important thing you tend to do in a bash script, while providing fairly nice syntax for everything else.
- chii 2y agoand i dont like how it's inconsistent that echo is not using the $ syntax (which makes sense internally, as it's a built-in, rather than executing the $echo command). Overall, it is cute and neat, but i find that if you are looking to write bash scripts that require this level of programming, you'd be better off writing it in python, or perl. Only in very austere environments can this be utilized, but the requirement of having `bc` installed means you must also have the ability to run package installation, so might as well run the package installation for a full on programming language!
- chrisjharris 2y agoI think that this does fill a niche. You can still compile to bash outside of this austere environment, and run the scripts within it. And python isn't very ergonomic for running external shell commands (or, say accessing environment variables), the syntax for doing so in amber looks much neater.
- freedomben 2y ago> the requirement of having `bc` installed means you must also have the ability to run package installation I don't remember ever installing bc, but I use it frequently and it's always there. Are you sure it's not already part of most base systems?
- poikroequ 2y agoThis looks very promising! I've been wanting something like this for years, a nicer shell scripting language which compiles to Bash so I can run it almost everywhere. I don't think Amber is not quite there yet, missing some pretty essential shell features, but is off to great start. I'll be keeping an eye on this. Maybe this is still early in development, but I don't see anything for pipes or redirection. Is this a planned feature? That's an essential feature of any shell and I can't see myself getting much done in Amber without it, especially pipes. I suggest adding more examples to the home page, especially side by side comparisons with Bash. The home page is somewhat lacking in content right now.
- spooneybarger 2y agoI was confused by Amber Smalltalk's pivot. Turns out it is just a newer language deciding to use the same name as an existing one. The domain is almost exactly the same as well. https://amber-lang.net/ https://amber-lang.net/
- SuperHeavy256 2y agoThis looks abandoned lol.
- ModernMech 2y agoAt first I felt the same way, because as a language designer I feel there are enough good names out there that new projects should be able to go find one that isn't taken. However, having looked at this case I'm not against it for several reasons. First, it looks like the project has been abandoned. There hasn't been an issue closed in 2 years, and the latest copyright date is 2019. That might not be enough to sway me, but then you have to realize the project doesn't even really call itself a language. They are "Amber Smalltalk". This is an implementation of Smalltalk, not a language itself. Amber is an implementation of the Smalltalk language that runs on top of the JavaScript runtime. Pharo Smalltalk is considered as the reference implementation. So you see this is an implementation of Pharo Smalltalk that runs on JS. Finally, and the nail in the coffin, over the past couple years in the mailing list there has been little activity -- nominally a monthly message from a single user advertising the "UK Smalltalk User Group Meeting" which sounds interesting but not really about Amber Smalltalk as a project per se. No one is using it, no one is working on it, and it wasn't a language in the first place. I would say that it's fine for an actual language project to pick up the name.
- vfclists 2y agoThere should be a link on the home page linking to the amber-lang.net to avoid confusion. Strange. It seems to have gone down shortly after this Amber announcement. It was up the day I read this announcement.
- riffraff 2y agoSame for me. There's still plenty of unused gemstones as programming languages so perhaps the authors may still decide to change their name.
- orthecreedence 2y agoQuick note to the creators: the website looks almost exactly like every other "here try this cool command-line utility so we can hook you and start charging a service fee for it" startup website and I instantly distrusted it. The design communicates that you're selling a product, not providing an open-source utility. That said, very interesting syntax. I agree with others about the $...$ being kind of odd, but other than that this is really cool.
- nickm12 2y agoI had the same exact reaction. Being an open source project doesn't mean the website has to be ugly or bare bones (though plenty are). But this is sending the wrong expectations about the project.
- robxorb 2y agoSomehow I didn't get that impression from the website at all. I thought it was clear, functional, told me everything I needed to know in the order I needed to know it, and also looked nice - tying into the "amber" branding well. Maybe I just don't spend enough time on websites that are designed to hook me in and start charging a fee? ;)
- pmontra 2y agoIt's not a big deal by I second that. I also thought, "let's see how they are making money out of this". I clicked on the github link and found out it's GPL 3.0, all of it, no open core or similar stuff. Maybe a tiny note about it being open source could help.
- PartiallyTyped 2y agoAlso a note about it being Free as in Beer.
- pasc1878 2y agoNo as I really don't understand that - beer costs money.
- lifeofguenter 2y agoImpressive project. But I always feel that if you reach a certain complexity in your bash scripts, you should rather pivot to any other $lang. Bash scripts should be simple glue between programs (unix-principle).
- DaSHacka 2y ago> Bash scripts should be simple glue between programs If a script is literally just running a list of commands and occasionally piping the output from one to another, you may as well make it POSIX compliant (therefore a sh script) since you're not using any features of Bash anyway. > But I always feel that if you reach a certain complexity in your bash scripts, you should rather pivot to any other $lang. This is a common critique, but what other lang? I make Bash scripts all the time for system administration tasks, and they largely just werk™ as long as you have Bash (90% of the time pre-installed) and the necessary commands. From there, any command can be readily called, piped, or saved to variables/arrays, and Bash has powerful (enough) native math and string manipulation capabilities. Meanwhile with Python there's always some hassle installing dependencies with pip(x) and virtual environments, plus the unfortunate rare Python 2 encounter where you either gotta rewrite the whole thing in python 3 or figure out how to install the old Python 2 runtime and 3rd party python 2 libraries used in the script on your distro. I don't see the appeal of sonething like the OP though. I can't imagine the "precompiled" scripts are so much more readable its worth the incomprehensible mess it appears to generate with the "compiled" script. Why are people so afraid of Bash?
- geocrasher 2y agoI have to agree. Bash works fine in its environment, and while there are times when another language might be more appropriate for whatever reason, Bash works. I can run it on any box I have access to and if I stay away from utils that aren't preinstalled, I don't need to worry about dependencies. I've found that python is far more version and dependency driven.
- nickm12 2y agoI think the use case for this is where you need a bash script on a machine where you can't easily install and maintain a runtime.
- omoikane 2y agoAssuming that these are typical outputs from Amber: https://github.com/Ph0enixKM/Amber/blob/master/setup/install.sh https://github.com/Ph0enixKM/Amber/blob/master/setup/install... https://github.com/Ph0enixKM/Amber/blob/master/setup/uninstall.sh https://github.com/Ph0enixKM/Amber/blob/master/setup/uninsta... The inconsistent indents and decorated variable names made them less readable than hand-written Bash scripts. I understand that most compiler outputs are not meant to be human readable, but generally we would get minification and/or obfuscation in exchange for losing readability, and Amber doesn't seem to offer those yet.
- 5e92cb50239222b 2y agoNothing can be done about variable names, but format inconsistencies can be autofixed with shfmt. I've been using it for years and it's been solid. https://github.com/mvdan/sh https://github.com/mvdan/sh
- ape4 2y agoAnd why is it using [ instead of bash native [[
- weaksauce 2y agoI think it's targeting a really old bash for max compatibility... and also it's super early alpha software
- pubg 2y agoIt's interesting Amber doesn't seem to be leveraging Bash-native Regexes via: if [[ "${foo}" =~ ^someReg[e][x][p][r]$ ]]; then ... What value exists in going to such great lengths to target super old and anqtiquated versions of Bash? It becomes very limiting for this poor new language :-s Maybe still just the earliest of early days? Javascript-style RegExs along the lines of: if (s.match(/my[R]egex[H]ere/)) { .. Would be pretty nice and handy.
- 1oooqooq 2y agoi think they do this since there's no source map or symbol mapping support on the debugger (which is just bash errors lol) would be nice if it was the source and script at the same time. as in a comment at the bottom or top is the source or something.
- VagabundoP 2y agoThis fits my use case where I want to run some system commands but Python is too heavy.
- deleted 2y ago[deleted]
- yau8edq12i 2y agoI guess I don't understand the point. Could someone summarize why I would use this rather than writing my utilities in something that doesn't compile to a quirky, limited programming language?
- kitd 2y agoBecause the runtime for those utilities is available on just about every Linuxy OS there is. Saves you having to install the runtime separately, eg in your CI pipeline.
- yau8edq12i 2y agoIt's not much of a "runtime", though. How is it better than a plain executable?
- kitd 2y agoOk if your scripting language compiles to plain stand-alone executables and has good built-in support for processing shell commands and their IO.
- plasticeagle 2y agoIt's not, really. The claim would be that it's portable, but bash can be a little finicky in that respect. The documentation didn't mention what version of bash is required, but it'll be something. And plenty of systems will have old versions of bash - especially once you move out of the world of "my laptop" - obviously. As has been mentioned elsewhere, it makes many times more sense to just learn bash, than to learn this. You likely already know some, and it excels at the jobs it's designed for - which is chiefly to launch processes and pipe output around. Subshells are elegant, even if making sure everything launched by your script is 100% finished before you exit can be a pain. I doubt Amber fixes that problem in any case.
- carlinigraphy 2y agoTo my eye, this does not look good. I consider myself to be quite proficient in bash. I write a lot of bash professionally. I've written a compiler (transpiler?) for a strongly typed configuration language that outputs bash. There are three main problems I see here. (1) Pipelines, subshells, and external dependencies. The example on the website compiles a conditional `if age < 18` into this monstrosity: if [ $(echo ${__0_age} '<' 18 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ] Pipelines and subshells are "slow". Not tremendously. But it adds up. Also, what's the point of having types in your language if you're not going to use native arithmetic when applicable: if (( __0_age < 18 )) Perfectly fine to alert users that floats will require an external dependency (such as dc), but integers will be handled in native arithmetic contexts. Seems mildly insane that a conditional this simple would require a pipeline including `echo`, `bc`, and `sed`. Now the user needs to ensure the correct external CLI tools are installed, and match the expected versions. Hope they account for BSD vs. GNU variants. Eek. (2) Namerefs. > Arrays cannot be nested due to the Bash limitations Arrays absolutely can be nested... with some trickery. Consider: # Top level array w/ pointers to children. declare -a arr1=( arr2 arr3 ) # Child arrays. declare -a arr2=( item1 item2 ) declare -a arr3=( item3 item4 ) for ref in "${arr1[@]}" ; do declare -n sub_array="$ref" printf '%s\n' "${sub_array[@]}" done The `declare -n` line is where the magic happens: https://www.gnu.org/software/bash/manual/html_node/Shell-Parameters.html https://www.gnu.org/software/bash/manual/html_node/Shell-Par... This is a fairly trivial operation that I'd assume the authors would know about. It's fast and allows for the creation of arbitrarily complex objects. Even rudimentary classes. (3) Just learn bash. I'm perpetually confused by people taking every opportunity to not just... learn bash. An otherwise skilled programmer will somehow forget everything they've learned when beginning a shell script. Surely it can't be harder to learn the fundamentals of shell scripting than to learn whatever flavor-of-the-month alternative is?
- forgotpwd16 2y ago>having types in your language Per docs[0], seems types are rudimentary. For numerics there's only one type for any number. Good remark regarding GNU vs others. This isn't seem be noted anywhere. [0]: https://docs.amber-lang.com/basic_syntax/data_types https://docs.amber-lang.com/basic_syntax/data_types
- gmdrd 2y agoThere is a typo in the docs: Notice that when executing a single expression, Amber automatically includes it's standard library for you.
- robxorb 2y agoAs it's common - if someone doesn't realise what it is, it's: its it's should be its not it's.
- liampulles 2y agoWhat I really want for scripting usecases is a language that has modern language concepts (easy to use arrays and maps, text formatting strings, etc) but that allows me to call commands as easily as I could call functions. Maybe there are existing scripting langs that make this so? Ambers approach is not bad but I feel it could be even better.
- cglong 2y agoHave you taken a look at PowerShell? It can infer whether you're invoking a command or function. Disclaimer: I work at Microsoft, but not on PowerShell.
- mst 2y agoIt's generally quite doable to write functions for that, e.g. in perl - use IPC::System::Simple qw(capture); use Sub::Install qw(install_sub); foreach my $command (qw(foo bar baz)) { install_sub $command => sub { capture($command, @_) } } ... my $output = foo($x, $y); # will throw if calling 'foo $x $y' returns non-zero (there's a Shell.pm but it's not as helpful with errors; I should probably consider rewriting it a more modern way) Note that if you're distributing code p3rl.org/App::FatPacker will produce a single fat script that has (pure perl) dependencies included so you don't need to install anything (except for having a perl VM in $PATH). There's also multiple libraries that provide a '$' function in JS (which may be why amber picked that delimeter) and then you can do let output = await $`foo ${x} ${y}`; (the template string's variable parts get autoquoted) Note that bun.sh has a 'bun compile' subcommand that bolts together your (pure JS) code and the static bun binary to produce a single file you can also copy around. I'd suggest avoiding backticks in ... everything. In shell, $() is nicer, and both perl's and ruby's backticks require effort to use safely. No idea re python but I see no reason you couldn't do the function generation thing if you wanted to, and somebody's probably librarified it already.
- klibertp 2y agoRash (https://rash-lang.org/ https://rash-lang.org/) and Oil (https://www.oilshell.org/release/latest/doc/ysh-tour.html https://www.oilshell.org/release/latest/doc/ysh-tour.html) come to mind. Xonsh, too, as mentioned. Powershell too. Most high-level languages have packages that implement DSLs for running and connecting subprocesses. Python has both `subprocess` in stdlib and things like plumbum (https://plumbum.readthedocs.io/en/latest/index.html https://plumbum.readthedocs.io/en/latest/index.html) or fabric as 3rd party packages. Scala has a little DSL ("echo 1" #| "cat" !) for this in stdlib. How lightweight the syntax is depends on how DSL-friendly the language is, so things like Ruby or Raku might be your best bets.
- casey2 2y agoIt seems to generate very bad/odd shell so I won't use it. I also question the mindset that conflates programming with using a program. It seems until some philosopher explains the difference programming can't move forward. Aside from that shell is the way many (most?) people interact with their computer, so some may find it offensive.
- deleted 2y ago[deleted]
- classified 2y agoIs this some kind of hoax? The page just shows an image. This looks very suspect.
- ephimetheus 2y agoI was hoping for a solid way to handle subprocesses, and especially how to handle failures. They have something in the docs, but it seems a bit underwhelming, in terms of how status codes and failures are handled. It’s probably better than straight bash, but I feel like there’s more to be done here. Also: I don’t see mentioned how pipes affect the exit code propagation (i.e. pipefail).
- evnix 2y agoI wish there was a solution for something like Download(file.gz) and that gets converted to either a wget or curl based on what the system has.
- sgarland 2y agodl_tool=$(command -v curl || command -v wget) if [[ ${dl_tool} == *curl* ]]; then dl_cmd="${dl_tool} -sLO $1" elif [[ ${dl_tool} == *wget* ]]; then dl_cmd="${dl_tool} -q $1" else printf "%s\n" "ERROR: curl and wget not available, exiting" fi Can easily be turned into a function.