Live data from Hacker News

Amber: Programming language compiled to Bash

amber-lang.com

191–200 of 330 posts

Re: Amber: Programming language compiled to Bash

#191

Earlier quoted context omitted.

> I spent 2h debugging a script only to find out there was an extra space character that made the whole thing break silently. When I was learning C++, I lost 2 days because of an extra ";" in an if statement. However this does not mean C++ is an insane language. It means it has quirks. > I would be willing to learn a sane language, but bash isn't one I kindly, but strongly disagree. > If you need to know of a million…

> However this does not mean C++ is an insane language. It means it has quirks. Any sufficiently quirky technology is indistinguishable from insanity. https://yosefk.com/c++fqa/index.html

You're right. To be fair, I'm absolutely immune to these kinds of quirks in any technology, and just adapt. This causes me to dislike no languages, and just work with them if they fit to the problem I have at hand.

This trait baffles a couple of my friends with no end.

BTW, That's a great link. Thanks a lot.

Re: Amber: Programming language compiled to Bash

#193

What 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.

Rash ( https://rash-lang.org/ ) and Oil ( 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 ) or fabric as 3rd party packages. Scala has…

Oil/ysh looks very much like what I would like - thanks!

Re: Amber: Programming language compiled to Bash

#194

Bash 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

The generated code already looks kind of insane, I can imagine it would only be worse without the benefit of Bash features.

Re: Amber: Programming language compiled to Bash

#196

I haven't seen a mention of the Oil Shell ( 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 in…

It'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.

Re: Amber: Programming language compiled to Bash

#197

If I need an extra tool that will compile stuff, I might as well use a normal compiled or scripting language. Which I often do.

But then your compiled binaries are not portable cross-architecture, or your scripts require a compatible interpreter to be pre-installed.

Re: Amber: Programming language compiled to Bash

#198

Bash 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

The generated code already looks kind of insane, I can imagine it would only be worse without the benefit of Bash features.

THIS. Why does this:

    if age 
compile to this:

    __0_age=30;
    if [ $(echo ${__0_age} '
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/V...

Re: Amber: Programming language compiled to Bash

#199

If I need an extra tool that will compile stuff, I might as well use a normal compiled or scripting language. Which I often do.

But then your compiled binaries are not portable cross-architecture, or your scripts require a compatible interpreter to be pre-installed.

Worth 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.

Re: Amber: Programming language compiled to Bash

#200

Very 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?

It'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 inten…

Thanks that makes sense.
Post reply on HN