4 ms·
Former Ruby, now Elixir, developer here and I agree. The one use case where Ruby still wins for me, though, is a little one-off script. Last time I had occasio
by losvedir 10y ago
Former Ruby, now Elixir, developer here and I agree.
The one use case where Ruby still wins for me, though, is a little one-off script. Last time I had occasion to do that, I found you couldn't use any Elixir hex packages without generating a whole mix application. In ruby you could just globally install the gem and require it right into your script.
I forget why this came up, but I think it was something like just wanting to download a web page and parse out a certain bit of it into a CSV file or something like that. Pretty trivial in Elixir with HTTPoison and Floki, but no real way to use those in a one-off .exs file (I don't think?). Whereas in ruby, I've already got HTTParty and Nokogiri in there somewhere, and you can toss it together in a minute.
- _asummers 10y agoMix tasks are what you're looking for. You put them inside your application (we have them in /appa/your_app /lib/mix/tasks), define a run/1 function that takes in args, say "use Mix.Task", then you can make sure that things like Ecto are loaded and interact with your program's major entities, or use Poison or whatever it is that you care to do.
- CrystalLangUser 10y ago.... Or you could create a script.rb file, anywhere, and require gems if needed. Then type ruby script.rb. That takes no time at all, and using gems is extremely simple even with RVM if wanted.
- sjtgraham 10y agoThat works for quick and dirty scripts but it's not portable if you want to distribute it to others.
- amorphid 10y agoI like Ruby for one off scripts, too. In some cases though, I don't like having to install Ruby. If Elixir, or perhaps Erlang, is on the target box, an Elixir Escript is also a good option. I've picked up a fair bit of bash for easier tasks, too.
- networked 10y ago>In ruby you could just globally install the gem and require it right into your script. I've been using Elixir for one-off scripts lately and this is something I miss. In my book, it is a clear advantage that Ruby and other scripting languages have over Elixir. In the case of HTTP(S) my solution has been {data, 0} = System.cmd("curl", ["-sf", url]) but as soon as you need a JSON library it is time to create a project. (The "-f" flag ensures you get a non-zero exit status from cURL if the HTTP status code isn't 2XX.) I do not particularly like the usual global package installation model, though, because it means that you can only have a single version of a package available for your scripts to require. The best package management model for standalone scripts that I have seen is Groovy's [1]: a script can include a special directive that downloads a specific version of a package just for that script. Any versions can be stored in the global (per-user) package cache so that you don't have to redownload them every time a script runs, but your import statements always give you strictly the version you asked for. This is the model I'd adopt for Elixir. [1] http://docs.groovy-lang.org/latest/html/documentation/grape.html http://docs.groovy-lang.org/latest/html/documentation/grape....
- deleted 10y ago[deleted]
- deleted 10y ago[deleted]
- bythckr 10y agoI am currently working on a RoR project and I am looking at Elixir for a side project. Kindly advice how I can get started in Elixir.
- ramchip 10y agoThere is a tutorial right on the official website. I would start with this, it covers quite a lot of ground.