r/programming • • May 09 '22

Vlang as a scripting language for docker image entry point

https://vincenzopalazzo.medium.com/422e6a9d64ed
0 Upvotes

19 comments sorted by

10

u/Venthe May 09 '22

Why one would choose Vlang over python in terms of scripting an entrypoint?

Note, that one of the benefits of shell (or python) is to have it humanly readable; so compilation is not a benefit here ;)

-1

u/nikita2206 May 09 '22

Generally I wouldn’t choose Python because it’s a whole new runtime that adds to the docker image, not to mention the potential for version conflicts that I still sometimes encounter with Python programs. Shell isn’t human readable enough though, not for large scripts at least. I wish there was a lightweight scripting runtime which language had readable C-like syntax (Python or whatever), good data types with arrays and shit (unlike with Shell), standard library and a way to import dependencies that are resolved at runtime (so that the entire script is just one file, even if it has dependencies declared at the top of the file), and support for some Shellisms that make it so easy to do some things in Shell like running an external program and storing its output in a variable and piping (and exec and signal handling) - you know without the verbosity that would be required to do this in any OOP language.

4

u/radarsat1 May 09 '22

sounds like you are describing xonsh

2

u/crazyjoker96 May 09 '22

this is another think that I would like to use!

2

u/nikita2206 May 09 '22

Looks really good! It's not as heavyweight as I expected this to be, only 12MBs zipped

8

u/slayeriq May 09 '22

I don't see why you would have version conflicts when running in a container. Containers isolate an application together with its dependencies.

-2

u/nikita2206 May 09 '22

Yup you're right about this. It's just that you sometimes have to watch out for which version you install in the first place, admittedly not a problem with scripts that you yourself are writing. I don't have anything against python in general, just that a bunch of my wants that I pointed out for a shell-like language for scripting are not met by Python.

6

u/FoleyDiver May 09 '22

Lua meets most of your needs, minus the dependency management and signal handling. But that got me thinking - why do you need signal handling in a docker entry point? What are you doing besides some basic parameter checking and exec-ing? Isn’t the entry point just a quick sanity check before handing control off to the main program?

2

u/nikita2206 May 09 '22

I believe I went a bit off the OP's subject and started thinking about scripting languages, not only for the docker image's entrypoint.

13

u/Innf107 May 09 '22

For those that aren't aware, you might want to read this article before getting excited about V.

Granted, the article is almost three years old, but just looking at their documentation, it doesn't seem like a lot has changed.

V's marketing is still misleading and frankly dishonest.

My personal favourite example from their documentation (emphasis mine)

functions are pure by default, meaning that their return values are a function of their
arguments only, and their evaluation has no side effects (besides I/O).

This is an interesting definition of 'side effects'.

-20

u/AmitGold May 09 '22

It's a shame V isn't as popular as it should be. It's as simple as Go but with immutability by default, null safety and better error handling

21

u/[deleted] May 09 '22

It’s so simple it doesn’t even manage memory, it just leaks! Genius solution if I may say so.

The things you listed aren’t major problems with Go. Sure it would be nice I guess, but V is far from being a real language still

21

u/[deleted] May 09 '22

V is far from being a real language still

That’s a nice way of saying “it’s a Patreon grift”.

6

u/qq123q May 09 '22

Good that more people see it for what it is.

11

u/[deleted] May 09 '22

There have been no substantial changes since the “V is for Vaporware” article. The pattern of overpromising and severely underdelivering is still pretty obvious.

3

u/Innf107 May 09 '22

Error handling is not a major problem with Go?

What would you consider "major problems with go" then?

2

u/[deleted] May 09 '22

Some might find it an inconvenience with such an expressive way to handle errors, but it's not an issue for most, and far from a major issue. Most Go programmers I have spoken with regarding errors, mostly coworkers, have come to the conclusion that the error handling felt too expressive at first, but it's actually very easy to understand what happens under unwanted behavior due to the simplicity.

5

u/Innf107 May 10 '22 edited May 10 '22

Well, the issue with Go's error handlin is not that it is "too expressive".

One issue is, how easy it is to accidentally forget to handle errors, since one might just forget to check the returned error value.

If the error is rare, you're probably not going to run into the bug for a while and Go's "default values are good actually" approach means that it might take you a while to track the origin of the missed error case, since the garbage value returned instead (in case it's not a reference type, nil will probably blow up pretty quickly) might be a "valid" result for the remaining code, just not the one you wanted.

Even if you always make sure to handle every error, that is anything but expressive. Littering your code with hundreds of

if err != nil {
    return err
}

is just error prone and distracts from the actual logic.

Worst of all, this is part is pretty easy to solve! Just add an expression like f()? expressions, where E[f()?] is just transformed into

x, err := f()
if err != nil {
    return err
}
E[x]

(I swear I'm not a Rust shill, Rust's approach just fits extremely well here :) )

4

u/Strum355 May 09 '22

Its as unpopular as it is for very very good reasons. These downvotes arent for nothing