[HN Gopher] Scripting with Elixir
___________________________________________________________________
Scripting with Elixir
Author : lawik
Score : 102 points
Date : 2023-06-12 07:20 UTC (15 hours ago)
(HTM) web link (underjord.io)
(TXT) w3m dump (underjord.io)
| hospitalJail wrote:
| I didn't understand the use case. I had chatgpt try to find one,
| maybe dependency management(eh, I got conda for that) and
| parallel processing(eh, I got pool for that).
|
| Seems like a no-brainer to go with python for the long term. Why
| would anyone take the time to use this?
| tikhonj wrote:
| I mean, if you value popularity more than any sort of intrinsic
| quality of your tools then, yeah, sure, it's a "no-brainer".
| But that rather strikes me as a "no-brainer" way of making
| decisions.
| knoebber wrote:
| two reasons:
|
| 1. you prefer functional style languages, such as elixir 2. you
| want to avoid `pip install` ing dependencies
| OkayPhysicist wrote:
| If you already write a lot of Elixir for it's application-level
| superpowers, then being able to hammer out a script in a
| language you're fresh on is nice. Combine that with better
| developer ergonomics (package handing in Python is inane, for
| one), and it's not a bad choice.
|
| No one should be learning Elixir solely for the purpose of
| writing short, one-off scripts, though.
| tempest_ wrote:
| Futzing with pythons terrible multiprocessing is one of least
| favorite parts of the language.
| freedomben wrote:
| If you know elixir, but don't know python, it seems like a no-
| brainer to choose language you know over language you don't.
| Plus the portability and dependency management of Python has
| traditionally been a nightmare. Elixir has great solutions to
| both of those problems for scripting contexts.
|
| Another case, if your code base is in Elixir, picking an
| unrelated different language (python) would (IMHO) be as silly
| a decision as picking elixir for scripts when you have a python
| app, and I would strongly question that person's judgment and
| fitness for making sustainable and maintainable technical
| decisions.
| Jtsummers wrote:
| > Overall I would recommend scripting in whatever language you
| are most comfortable in that is at least reasonably comfortable
| for scripting. A quick script benefits from a low barrier
| between thought and execution. Use what makes sense for you. I
| find Elixir surprisingly good as a scripting language ever
| since the introduction of Mix.install.
|
| Because the author likes Elixir and its trivial concurrency
| story. But they also wrote the above: Use what you want, for
| them it's Elixir. Why complain about other people's preferences
| when they aren't actually foisting it on you?
| aeturnum wrote:
| I really want scripting in Elixir to be better - and the addition
| of Mix.install() is a great step forward - but there are still a
| lot of awkward elements. Elixir will require you to be in a
| module to define a function and then respect module namespaces
| when calling them - which makes sense in a normal context but I
| find it to be annoying while scripting. Likewise I don't think
| dialyzer, the Elixir / Erlang static type analyzer, will run on
| script files.
|
| That said I think the underlying lack of data mutability really
| increases the potential for code reuse and scripting.
| jolux wrote:
| you can define functions outside of a module using fn blocks
| skndr wrote:
| There's also defining a module and then `import`ing it.
| skndr wrote:
| I've been finding Livebook (https://livebook.dev/) really useful
| for iterating on a script or manipulating some data in a
| reproducible way. I'll often try out one solution and if that
| doesn't work, create a new section and collapse the old one to be
| able to go in a different direction.
| gigatexal wrote:
| interesting. As a data engineer I have been indoctrinated to
| think about things as various transformations and so the
| functional approach to things is very nice. I've also been
| wanting to learn/play with Elixir.
|
| In the Python space, though not the same, the ergonomics of which
| kinda get you there, there's this: pipe
| https://pypi.org/project/pipe/
| lawik wrote:
| The pipes are really very nice.
|
| They are actually even nicer under Livebook:
| https://livebook.dev/
|
| It can let you drag-drop reorder, enable/disable, steps in a
| pipeline: https://github.com/livebook-
| dev/livebook/blob/main/lib/liveb...
|
| It is really wild.
| behnamoh wrote:
| I like pipes but I'm not sure if it's pythonic. What if other
| people need to maintain/debug the code?
|
| Granted, it's not as much of a learning curve as personal
| Lisp macros.
| whalesalad wrote:
| If you haven't played around with it - you might dig Livebook
| https://livebook.dev
| sb8244 wrote:
| I haven't used Elixir for scripting yet, but I really like the
| idea of including deps at the top of the file. It's always been a
| pain to manage this in other scripting environments. I did
| scripts with Ruby in past and it didn't end up being easy to use
| because of external deps.
| networked wrote:
| You can declare dependencies at the top of a script file in a
| few languages, though usually through a third-party tool. I
| have a page on my site with a list of such languages and tools:
| https://dbohdan.com/scripts-with-dependencies.
| tomjakubowski wrote:
| good ol' nasty jupyter notebooks support this:
| %pip install foo~=1.5 %pip install bar~=1.7
| import foo import bar
| impulser_ wrote:
| This would require you to install and run jupyter.
| Mix.install just requires Elixir being installed.
| radiospiel wrote:
| TBF ruby lets you use inline bundler. See
| https://bundler.io/guides/bundler_in_a_single_file_ruby_scri...
| sb8244 wrote:
| Oh that's awesome. I didn't know about this (or not sure when
| it was released.)
|
| edit: it's been out since 2015 it looks like. Not sure why
| but I didn't know about this before. It would have been
| useful.
| [deleted]
___________________________________________________________________
(page generated 2023-06-12 23:00 UTC)