dogweather
After using Elixir for a long time I can’t wrap my mind around Python’s APIs.
So with the help of functoolz curry, flip, and pipe, I can write HTML parsing code like this:
def parse_title(dom: XmlResponse) -> Title:
name = pipe(
dom
, html.xpath("//TITLE-TEXT")
, text.titleize
)
number = pipe(
dom
, html.xpath("//TITLE-NUM")
, text.split(" ")
, seq.get(1)
)
children = _parse_divisions_or_articles(number, dom)
url = _source_url(number)
return Title(name, number, children, url)
I’m not re-writing any of these functions. I’m just wrapping each of them with a little code to give them a consistent interface. And once they each have this new API, they can be easily chained together.
Anyone else adapting other languages to the Elixir fluent API style? I don’t get much love from the Python community when showing this kind of code. ![]()
Trending in Discussions
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
Hi there! :wave:
@frigidcode and I (but mostly him) have been running an Elixir Book club, we’re almost done with Designing Elixir Syste...
New
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with.
But I don’t use it anymore.
Serverless was the promis...
New
Lately I’ve been thinking about how to organize components as a LiveView application grows. One of the pain points I’ve found (for myself...
New
What IDE or editor are you using for Elixir development?
Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
Other Trending Topics
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
In 2021 I started a new library called Tempo with the objective of modelling time as a set of intervals - not as instants. In 2022 I gave...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #metaprogramming











Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
kokolegorille
I think You would get the same kind of love from the Elixir community when showing Object Oriented Elixir code
Eiji
Definitely no! In programming that’s the only one thing I call my personal anti-pattern (i.e. that’s my opinion without linking to some resources). I’m 100% against forcing solutions known from other languages in a way you wrote. Simply, every language is different. It have other styles and expectations. There was a talk about pipes in
Erlang, but it was hard to implement, because inErlangthe data we work on is in the last function argument instead of first. ForcingElixir-like pipes intoErlanghave no sense as simply there would be no reasonable use case.Speaking generally the problem often is not what you do, but how you do. You can force other language features and deal with expected hate or write a new features inspired by other languages. It’s not shame for others to improve, but nobody would agree to change habits because something is better in other languages. Same goes for law. You do not force law articles from country you born as it’s simply stupid. However you can instead propose changes to existing law system.
That’s endless topic i.e.
assimilationvsintegrationivanov
I got to attend the annual American Geophysical Union (AGU) fall meeting that was in San Francisco a few weeks ago, thanks to a pass from Matt Rocklin (author of functoolz and also dask). Someone there was also sharing similar positive sentiments about this kind of chaining, and said how it felt functional and Lisp-like, to which Matt responded something like “that’s exactly why I built it, I was re-writing in Python pieces that were missing for me that I was used to having in Clojure”.
I’d call it
cross-pollinationsodapopcan
Hello and welcome to the forums!
I have nothing wrong with cross-pollination so long as its adopted by a language’s community as a whole. I also whole-heartedly applaud doing experiments. But I’m otherwise with @Eiji’s here. Coming across business code that someone decided to write in an idiom completely foreign to the language I’m working in is the worst. I’m actually getting a little worked up thinking about the several times this has happened to me
Is that how it’s
", ".join(["Hello", "World!"])or something? I’ve heard Pythonistas say this makes more sense (somehow). I honestly don’t know much Python, though!dogweather
That’s very even-handed and balanced—a hard act for me to pull off.
I don’t think it’s language design differences. I attribute it to their ages: Python is decades older than Elixir and it carries some baggage:
I’ve researched this deeply and the best I can see is, Python’s battling paradigms are present due to historical reasons.
In contrast, Elixir was designed with advantage of seeing was Python, Ruby, etc. did well and not so well. Ruby, in turn, was designed looking at Python. Even though everything in Python is an object, method chaining couldn’t be universally applied. Ruby sought to correct that in its design.
dogweather
I totally agree. I would never produce code like this for a client. This is my personal indie project, and I prioritize my productivity.
Doh! yeah, it’s
join()that kills me. It’s implemented only on string objects, not on lists or iterators.I want to break up and refactor code where it’s meaningful. Not because a decision made in the 1980’s hasn’t been overturned. I like thinking about language design, and ponder these issues.
Concrete example from my code
I found this in about 3 minutes of looking. Incredibly, I see four different paradigms present in this one section of code. (!)
The worst part of this, for me, isn’t the poor maintainability from the need to shift between different styles. It’s that these “semantic roadblocks” of intermediate variables were essentially forced on me by the paradigm changes.
E.g., global replace is a string method when the pattern is a string. When the pattern become a regex, it’s now a library call conventionally namespaced with
re.. So whatever data flow you were coding needs to shift paradigms due to this implementation detail.Ruby (really, Matz) saw this, and fixed it by simply making
String.sub()accept either a string or regex pattern.Eiji
Ok … wait, no! That’s not “ok”!
Umm … I never know
Pythonis so … well … Why do “we” force it for children in schools? What do “we” teach them?I heard
Pythonis good for beginners, but now I see something else …XP- memes are too old for “young blood”:so they decided to introduce new one:
Now I better understand why
Pythoncommunity does not like your idea. The 5th paradigm would be a hell for them even if it’sElixir’s paradigm. Please let them rest at least for now at the start of 2024.Happy New Year!
dimitarvp
This should be qualified with context: many people said that learning an immutable FP language made them write more understandable, clearer, easier to read, easier to debug and test code in imperative OOP languages.
It’s not about trying to make Python stand on its head. It’s about writing Python that is… less ugly and hard-to-work-with Python.
Languages should indeed cross-pollinate as @ivanov said.
One prominent example: after Rust made enums (sum types) prevalent in compiled languages – nevermind that OCaml and Haskell had them for ages before that but oh well
– then many people started wanting them in other languages.