Live data from Hacker News

Amber: Programming language compiled to Bash

amber-lang.com

111–120 of 330 posts

Re: Amber: Programming language compiled to Bash

#111

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.

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

Re: Amber: Programming language compiled to Bash

#112
post #85

Earlier quoted context omitted.

'WebGL disabled' is a pretty strong fingerprint anyways

"Disabled" is not metric among those who have disabled it, while WebGL enabled allows identifying different browsers with WebGL enabled. I know what you mean, but statistically, I don't think that it is easier to guess the person from those who have disabled it versus the list of all browser fingerprints where is that matching or very close unique fingerprint.

[deleted]

Re: Amber: Programming language compiled to Bash

#114
post #110

This 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).

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

Re: Amber: Programming language compiled to Bash

#115
post #69
post #55

Earlier quoted context omitted.

> Just learn bash. There are many reasons why it is to be avoided. For me the deal breaker was that one time I spent 2h debugging a script only to find out there was an extra space character that made the whole thing break silently. I would be willing to learn a sane language, but bash isn't one. If you need to know of a million tiny gotchas to implement even the simplest task safely and portably, then there isn't an…

Have learned a bit of bash but that's what has kept me going on always. There's no point in learning million little inconsistencies all of which aren't even documented anywhere like a MDN or MSDN if you will.

That's about where I gave up too. You make it sound like you disagree with me when in reality you do. There is no real reason to write any production code in bash or any other shell language.

Re: Amber: Programming language compiled to Bash

#116

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

It's useful in Rust where you might parse input as a string and then convert it to a number.

It's better than having a variable named age and another one named age_num or the opposite, str_age and age.

Re: Amber: Programming language compiled to Bash

#117
post #55

To 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 if [ $(echo ${__0_age} ' Pipelines and sub…

> Just learn bash. There are many reasons why it is to be avoided. For me the deal breaker was that one time I spent 2h debugging a script only to find out there was an extra space character that made the whole thing break silently. I would be willing to learn a sane language, but bash isn't one. If you need to know of a million tiny gotchas to implement even the simplest task safely and portably, then there isn't an…

> 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 tiny gotchas to implement even the simplest task safely and portably

Then you'd absolutely hate Perl, to the level of pulling your or The Camel's hairs out.

This is how programming languages work. They have straights and curvy parts, and there are some chicanes (quirks). So yeah, if you need to use bash, you need to learn it.

Re: Amber: Programming language compiled to Bash

#118
post #55

Earlier quoted context omitted.

> Just learn bash. There are many reasons why it is to be avoided. For me the deal breaker was that one time I spent 2h debugging a script only to find out there was an extra space character that made the whole thing break silently. I would be willing to learn a sane language, but bash isn't one. If you need to know of a million tiny gotchas to implement even the simplest task safely and portably, then there isn't an…

You know that your shell environment is not forced on you, right? You can just switch to ZSH, fish, etc. The only time this complaint is valid is if you're in a professional environment and you're not allowed to use alternate shells in your account, for some reason.

> The only time this complaint is valid

I've dealt with bash scripts running in high load production systems and I'm very happy I don't have to any more.

There is a reason my comment was a response and not a standalone statement. The OP was explicitly speaking about using it a professional setting.

Re: Amber: Programming language compiled to Bash

#119
post #110

This 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).

Bash 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 insta…

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

Re: Amber: Programming language compiled to Bash

#120

Earlier quoted context omitted.

Bash 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 insta…

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

> Also does bash run on windows outside of WSL?

Git Bash is pretty ubiquitous on developer machines in my experience.

Post reply on HN