HNHacker News
TopNewBestAskShowJobs

josevalim

4,367 karma · joined January 12, 2008

submissionscomments
josevalim··on An animated introduction to Elixir
Great job on the upgrades!

FWIW, if an element does not have an ID, then it is hard for morphdom to track when it moves around on the page. This will lead the hook to consider it is has been destroyed and mounted instead of updated.

About Phoenix, the generated apps definitely evolved a lot, but updating your Phoenix dependency should just work. If it doesn’t, please file a bug report!

josevalim··on An animated introduction to Elixir
Make sure you are also running Erlang/OTP 25. I will try to make this clearer in the installer!
josevalim··on An animated introduction to Elixir
I am sorry that this has been your experience.

I am obviously biased but I would stick around. :) I assume you started with LiveView early on, which means the documentation was sprouting and best practices still evolving.

Nowadays it is still pre-1.0 but much closer to its vision, so you should find better docs on the current practices. We now support components too, which declare each attribute, alongside their docs and types. So assuming you go through the update, I am hoping you will have a good time once it is done. And don’t hesitate to reach out in ElixirForum.com if you have questions.

Regarding types, we are researching types for Elixir: https://elixir-lang.org/blog/2022/10/05/my-future-with-elixi... - this is still years ahead, but I thought I would mention in context.

josevalim··on An animated introduction to Elixir
Right, Phoenix LiveView has been pre 1.0. We try to keep things deprecated for a while but we need to balance getting to 1.0 and supporting existing code. Now that it is getting closer, we can make it as a default in new Phoenix apps. :)

phx-hook always required IDs. They would misbehave (and warn) if you forgot the IDs, so could it be that you were relying on broken behavior? In any case the IDs can be enforced now, so it should be consistent, please file bugs if it does not work.

Upgrade to Phoenix v1.7 should be painless, because it only really changed generated code. Screencasts that use generators will be out of date though. In other words, best practices evolved (as they should) but code still works.

josevalim··on Why I program in Erlang (2012)
I am familiar with Scala and Haskell, but I was not familiar with ZIO. Thanks for sharing!
josevalim··on Why I program in Erlang (2012)
I am really interested in learning more about the libraries and abstractions you would use for #2 in Scala (or other FP languages). Could you provide some references so I can dig deeper? Thanks!
josevalim··on My Future with Elixir: set-theoretic types
That's a very good question. We could potentially do it, yes, but we would have to carefully benchmark and the benefits would still be limited to single modules (no cross module optimizations at the moment). So overall it is safest to not expect any meaningful gains. You will likely gain more by writing idiomatic code with patterns and guards. :)
josevalim··on My Future with Elixir: set-theoretic types
Hi, author here.

You do get a class of tests but I don't believe they are sufficient. For example, in the first article, we have this code:

    let contactFromEmail name emailStr =
        let emailOpt = EmailAddress.create emailStr
        // handle cases when email is valid or invalid
        match emailOpt with
        | Some email ->
            let emailContactInfo =
                {EmailAddress=email; IsEmailVerified=false}
            let contactInfo = EmailOnly emailContactInfo
            Some {Name=name; ContactInfo=contactInfo}
        | None -> None
While the types tell me that an email can be valid or not, and that the function may or may not return a contact, it does not tell me _which values_ will lead to those scenarios. The extrapolation is that this function could always return `None` and that would be alright from the point of view of types.

So perhaps you should still test that a valid email returns `Some contactInfo` and an invalid one returns `None`? Or maybe you have thoroughly unit tested `EmailAddress.create` and you feel confident in skipping tests here? Or perhaps you may want to test that `IsEmailVerified` is set to false (or maybe you even have logic that may set it to true in certain cases)?

In a nutshell, types would replace tests that assert on the states, but those are not the tests I write in the first place. The tests I write would rather focus which values give me certain states and assert which values inhabit those states.

josevalim··on Joy of Elixir (2020)
Agreed that the concurrency gap has narrowed in certain cases or either people don’t care, but I have always seen concurrency/distribution as “enablers”.

You can have the best concurrency story in the world, but if you don’t have good tooling or you don’t focus on the DX, then people will just leave (or perhaps not even start).

Concurrency/distribution is what allows Phoenix to be a real-time, productive, and scalable web framework on its own.

Nerves rely on fault tolerance to bring sanity to embedded systems.

And so on.

In turn those are led by teams who saw the language features and noticed they addressed many issues they were struggling with in other platforms.

But at the end of the day, for languages like Elixir, the frameworks and tools are much better equipped to attract developers than “raw” language features.

PS: disagree on the Erlang VM bit. JIT, dirty NIFs, and maps immediately come to the top of my head as big and important changes in the last 10 years. There have been many usability focused changes in the last 2 years too, in error messages, the shell (upcoming), etc.

josevalim··on Joy of Elixir (2020)
> it’s sort of a one trick pony right now. It’s a backend web tech. That’s obviously where the money is.

In terms of tech, I wouldn’t classify it as one trick pony. You can also build distributed systems (Erlang), high-end embedded systems (Nerves), data pipelines (Broadway), audio/video streams (Membrane) and more coming. :)

However, you are right that most of the money is on backend tech. But I wonder how much of it is a reflection of the market themselves? If backend web is 10-100x bigger than distsys, then we shouldn’t expect proportions to change drastically.

Data pipelines is one of the areas where we can grow, but data pipelines are only part of a data stack, so it is a fragmented offering. The hope is that with efforts such as Explorer and Nx, we can grow more into this space.

Edit: on the positive side, the recent efforts in data, ML, and native clients are all sponsored by primarily backend web companies. But we all know there is a long road between technical implementation and adoption.

josevalim··on Joy of Elixir (2020)
> the erlang vm was groundbreaking but in 1996 not post 2015. even now you can see people talking about how elixir makes parallel programming trivial when it's more or less trivial in all languages now

I have to strongly disagree with this argument. :)

It borders on “all languages are Turing complete, therefore they are equivalent”, but the truth is that the idioms a language highlights make a huge impact on the software we write.

For example, take immutability and concurrency. Making concurrency first class (not an extension), makes you think about concurrency first and you are usually better positioned to deal with Amdahl’s law (i.e. you can use all cores more efficiently).

When it comes to distribution, the same abstraction is used by both concurrency and distribution, which is more accessible, easier to test, etc. You get a unified model that is more than bytes over a socket, it includes dispatching to Erlang processes, entity monitoring and naming, etc.

Thats not even mentioning other features that come from Erlang processes, such as fault tolerance, preemptive scheduling, and instrumentation.

The only confusion - and perhaps what I would have done differently - is that many people equated Erlang distribution to RPC, and that’s something we should have made clearer from day one. Still, I would prefer any language that makes concurrency first class (such as Erlang, Clojure, Go), than one that doesn’t, and there are very few languages that make both concurrency and distribution first class. Personally, if a language doesn’t allow one to transparently multiplex on both IO and CPU, such as Node, then it does not have a good concurrency story.

josevalim··on Ask HN: So, what's up with Phoenix (web framework)?
Quick feedback:

1. The blog post is great and it shows there is indeed complexity around dynamic filters. I would love to see a solution that tackles it all the way down to form rendering :)

2. All of the Ecto API/syntax used in the blog post is documented, afaik.

3. You mentioned in another comment that Ecto does not support associations in queries, but it does: `join: c in assoc(p, :comments)` and that takes care of the ON condition and anything else you configure.

josevalim··on Ask HN: So, what's up with Phoenix (web framework)?
While I agree that Ecto is macro heavy, I don’t agree with this assessment for Phoenix. Macros in Phoenix are mostly contained within the router and then Plug (which is a thin contract).

Perhaps there are other factors that make Phoenix harder to grasp in your experience but I hope pointing out that it may not be macros help peel some of the complexity away.

Furthermore, if you get a bad stacktrace in either Phoenix or Ecto, please open up a bug report. Macros should not and do not imply bad stacktraces. In a very simplistic way, you can think of the Elixir compiler as a huge macro, and it still strives for great error messages and stacktraces. Many Elixir building blocks are implemented with macros too, and we have great error messages and traces there, and we aim for the same in Ecto and Phoenix.

josevalim··on Ask HN: So, what's up with Phoenix (web framework)?
Please open up a thread on ElixirForum about template inheritance and CC me. If you include Python examples, I can help translate them to function components. :)
josevalim··on Ask HN: So, what's up with Phoenix (web framework)?
The pain points that you brought up (forms and live component exchange) are real and they are definitely in our radar.

For example, the new function components are meant to reduce the reliance on LiveComponent and ease the learning curve. We don’t have an answer for complex forms yet.

I truly think the programming model is solid and is the next step in building server driven interactive and real time applications. But we will definitely stumble here and there as we iron out the finer details. :) thanks for the feedback!

josevalim··on Ask HN: So, what's up with Phoenix (web framework)?
You can do it using JS.push from the linked page. You can also use execJS to execute any JS event, including push, from anywhere. I am not sure if this helps though. :)
josevalim··on Ask HN: So, what's up with Phoenix (web framework)?
Generally speaking, if it can be done in the client, it should be done in the client.

Phoenix.LiveView.JS aims to tackle the obvious cases but it also documents a pattern that I tend to use a lot in my apps: https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.JS.htm...

The pattern above has a benefit that the dispatch still comes from Phoenix, so you are not relying on IDs or query selectors to attach functionality. You can see how we use it in Livebook here: https://github.com/livebook-dev/livebook/blob/main/assets/js.... However, if the callbacks get too complex, then you may indeed want to test them via headless browsers.

josevalim··on Differentiable programming from scratch
Thank you for sharing, this was a great article!

I had to implement autodiff from scratch for Nx (https://github.com/elixir-nx/nx) about 18 months ago and this would have helped me so much! I spent roughly a month chasing a bug because I was not handling the case of duplicated incoming nodes and you outline it very clearly. I will be recommending the article from now on to anyone who needs to understand how autodiff works.

josevalim··on JIT/GPU accelerated deep learning for Elixir with Axon v0.1
It uses [Nx](https://github.com/elixir-nx/nx/tree/main/nx#readme) (think of it as an equivalent to numpy/jax) which uses Google XLA's as one of the possible backends to compile and run on the GPU.
josevalim··on JIT/GPU accelerated deep learning for Elixir with Axon v0.1
> The ONNX runtime seems to be the only really valuable part.

I actually disagree. :)

If all we had was bindings for ONNX, then we would have to tie ourselves to a single format (and potentially a single runtime). However, having ONNX built on top of a solid foundation (Axon), we get more flexibility and solidity to handle the moving ML landscape.

As an example, I would actually prefer to load pre-trained models from Hugging Face directly into Axon and bypass ONNX altogether. The most immediate benefit for an Elixir developer is that they don't need Python on their machine for the ONNX conversion. But it also means that I can slightly tweak pre-trained models too. And that's another win.

Perhaps your point is that nobody will train a neural network from scratch in Elixir, and maybe that's true, but I would be wary of looking at ONNX as the only possible outcome of the work done so far.

Indeed there is an associated high risk to new efforts like this but that's often part of creating something new. I have heard countless times that there is no value in creating a new programming language, until the value was suddenly there.

josevalim··on Catalog of Elixir-specific code smells
I recommend you to open up an issue as the goal of the repository is to have such discussions! I think the biggest question, in this particular code smell, is where to draw the line. The sample function is definitely small enough to justify it but at some point the smell will kick in. So perhaps the smell needs a clarification? Or perhaps it should be grouped alongside a series of "long ***" smells which make it clear the issue is length.
josevalim··on Ask HN: Is Erlang an albatross to Elixir adoption?
This is fantastic feedback. I always love reading posts like yours. Three quick notes to complement what you said:

* The formatter is always a balancing act. The behaviour you see is because people get really upset when we don't respect their line breaks (and, as you correctly said, we can't later know which newlines were introduced by us). You can try formatting more frequently to get feedback sooner (that's what I do: I usually type code with no indentation whatsoever and "collaborate" with the formatter as I go).

* I am thinking really hard about the struct problem and trying to find a balance between getting some of the guarantees of structs without having to hijack a whole module.

* Re namespaces, agreed they are not as powerful as namespaces in other languages, because they are not actual entities. However, you shouldn't run into issues. If you do recall what it was, feel free to reach out or post something in the forum. The dot notation can be useful in aliases (which a different separator would not help).

Have a good week!

josevalim··on Ask HN: Is Erlang an albatross to Elixir adoption?
It was not the purpose of the language nor I believe it is its primary effect. It was the immediate effect though.

At last ElixirConf, I remember asking for a show of hands on people's backgrounds, and I would say Ruby was 40-50%. It is impossible to know how it applies to the community as a whole, but I think the idea that Elixir is "Erlang for Ruby" is several years dated at this point.

josevalim··on Explorer – A library to bring dataframes to Elixir
I am not sure I agree with the OTP bits.

We often tend to compare having to learn OTP with “not having to learn OTP” but the reality is that we need to compare OTP with concurrency tools in other languages (e.g. threads, locks, mutexes).

Of course, one can say: “I wouldn’t use threads in other languages” but that’s potentially a bigger problem, as you end up with software which can’t easily exploit concurrency (which is especially important in the data domain).

I still think what you said has some truth to it, but I think the frame of reference is a bit off. I would rather learn a bit of OTP to get concurrency and fault tolerance rather than learn nothing and get none of it. :)

PS: “mix new” does not generate supervision trees by default.

josevalim··on Elixir and Machine Learning: Nx v0.1 released
Yes, and I have replied we are not trying to make Elixir the new AI language either.

In any case, I was not speaking about this comment exclusively. It is a recurring pattern. But given you have somehow managed to make this my fault, I will drop the conversation. Have a good one!

josevalim··on Elixir and Machine Learning: Nx v0.1 released
I believe we have one. Does this address work for you? https://dashbit.co/feed
josevalim··on Elixir and Machine Learning: Nx v0.1 released
Hi @joelbluminator, may I ask you why you feel the need to frequently jump on Elixir threads here and on Reddit and be negative about other people's work?
josevalim··on Elixir and Machine Learning: Nx v0.1 released
That's an excellent question!

We are not trying to make Elixir the new AI language, but one possible language for AI. @hosh covered some of the use cases in his reply and I can add two more insights:

* Lately we have seen functional ideas brought into Python through projects like JAX and Thinc.ai and I think exploring those concepts within a functional language is both interesting and exciting (and we are not the only ones doing so!)

* Besides IoT and data pipelines, there is potential in mixing some of the current ML trends, such as Distributed and Federated Learning, with the capabilities of the platform

We likely aren't much attractive to Python developers right now, unless you are interested in contributing/designing ML tooling (for learning, hobby, or professional reasons) or you have a use case that suits one of the mentioned strengths of the platform.

josevalim··on Elixir and Machine Learning: Nx v0.1 released
I am not informed enough to give actual estimates. :)

Although your estimates for JIT improvements seem low on my experience. Compilation times are consistently half of what they were before and test suites range between 33% to 50% faster. Even Whatsapp reported server efficiency increased by 25% and many other factors are likely at play there (source: https://twitter.com/wcathcart/status/1385253969522413568).

I _assume_ we will continue seeing improvements on this front, especially if at some point we start doing cross module optimizations!

josevalim··on Elixir and Machine Learning: Nx v0.1 released
This release means we are getting closer to prod usage but Nx requires one of the existing compilers/backends to shine. So I am hoping we will see production uses once we officially release Torchx/EXLA packages too.

---

Curiously, I had two ideas for the name Livebook:

1. An interactive book to teach LiveView. LiveView is a new approach for developing web apps and I thought it could be worth exploring different non-traditional ways of teaching it too!

2. Livebook as code notebooks (what we got!)

It just feels a great fit for the platform, considering Phoenix, LiveView, Distributed Erlang, etc. So why not? :) And I am curious to see if and how we can contribute new ideas to the already extensive ecosystem of code notebooks!

← PreviousPage 9 of 15Next →