Live data from Hacker News

Amber: Programming language compiled to Bash

amber-lang.com

181–190 of 330 posts

Re: Amber: Programming language compiled to Bash

#181
post #142

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

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

Re: Amber: Programming language compiled to Bash

#183
post #148

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…

I didn't realize we were going so far back. In that case, Perl may be more convenient than Python/Go, and almost certainly a better choice than bash. Still, > 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. Can you give an example of a "several decades" old devic…

A few days ago, I tried running some code that hasn't been updated in about 5 years. The python launcher has bit-rotted, so now I need to rewrite it. The other 99% of the project compiles fine.

Things like perl (without CPAN) and bash generally take backward compatibility more seriously than python does.

My experience with python (even ignoring the 2 to 3 debacle) is that you can run code on machines that were setup +/- six months from when the software was written. That's unacceptable for non-throwaway use cases unless your company is willing to burn engineering time needlessly churning software that's feature complete and otherwise stable.

Re: Amber: Programming language compiled to Bash

#184

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

Re: Amber: Programming language compiled to Bash

#185
I 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.

Re: Amber: Programming language compiled to Bash

#186
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…

> 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

Re: Amber: Programming language compiled to Bash

#187
This 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.

Re: Amber: Programming language compiled to Bash

#188
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…

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

This sounds like using `a = b` instead of `a=b`, something you learn in an introductory Bash tutorial. It's not a good argument to say "I didn't learn Bash and it cost me 2 hours, therefore I should continue to not learn Bash."

Re: Amber: Programming language compiled to Bash

#189

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

> 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 co…

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

Re: Amber: Programming language compiled to Bash

#190

Earlier quoted context omitted.

On a machine where you can't easily install and maintain a runtime but you can install bash and amber and bc and sed?

No, because you don't need to install Amber, and bc and sed are pretty much guaranteed to be installed already if bash is.

GitBash (MinGW) doesn't ship with bc or dc, but it does ship with awk.
Post reply on HN