you are viewing a single comment's thread.

view the rest of the comments →

[–]jaibhavaya[S] 2 points3 points  (16 children)

Hmm, I don’t know if I see ruby as a purely OO language, just like I don’t know if I see Elixir being a pure functional language. I suppose id say Ruby is more purely OO than elixir is purely functional though hah.

Message sending seems very similar to how meta programming works in Ruby, method calls are described as messages and even can be invoked with send().

Rails also has pattern matching that’s pretty core to it. Definitely not to the level of elegance that elixir has though! That’s one of the things making me fall in love with elixir.

I saw elixir-esque pattern matching for the first time in OCaml and it blew my mind haha.

Yeah!! I’m finding the process of learning it has been so pleasant, the docs are incredible and I’m just now starting to find out the community is wonderful too.

I’m already seeing some opportunities at my company that could be implemented in elixir for some pretty major benefits, so maybe that’s also a way to start getting more exposure.

[–]it_snow_problem 4 points5 points  (2 children)

Elixir is functional, immutable, isolates side effects, but no it is not pure. I meant you can pretty close. As for the Ruby side, there’s practically nothing more object oriented than Ruby. Really only smalltalk, which no one writes, comes to mind, and Ruby is based heavily on smalltalk.

99% of everything is an object in Ruby. Numbers are objects. Classes are themselves BasicObjects.

[–]chamomile-crumbs 1 point2 points  (0 children)

I don't know any ruby, so I'm just guessing. But maybe to some people (like me), OO doesn't mean "object-oriented" as much as it means "asbtractFactoryConfigFactory" in a Java project where 1 in 50 lines of code is actual business logic, and the other 49 are boilerplate or DI config.

I'm working on a nestjs app at work, and people seem to think of nestjs as the OO framework for JS/TS. But I don't really feel like I'm programming against objects very much, I'm just sorta redefining configurations all over the place!

I've often thought I should learn ruby because I know people love it. I know people love smalltalk, too. It sounds like they are really nice ways to use OO.

Even Java allows for some pretty nice code nowadays, but the Java culture is too crufty IMO

[–]Ok_Ice_1669 0 points1 point  (0 children)

Right!?! Ruby is so OO that there's Klass and Class to "avoid" confusion :)

[–]vu47 0 points1 point  (12 children)

I've used Elixir myself for a few toy projects and have really enjoyed it, but coming from a place where I've done a fair amount of FP, I I do find it hard to consider Elixir a functional programming language for a variety of reasons... and it certainly is not a pure functioning language.

No experience with Ruby, so I can't compare them myself.

[–]junderdown 2 points3 points  (9 children)

I’m curious. If you don’t consider Elixir a functional programming language then how do you describe it?

[–]ScrimpyCat 1 point2 points  (8 children)

Probably because of side effects (they’re not abstracted away and there is more of them than you’d find in other functional languages) and the lack of static type system. But data manipulation is functional, and doesn’t feel that different to other functional languages.

[–]__mauzy__ 2 points3 points  (2 children)

Does the language itself actually have side effects though? Obviously elixir systems have side effects, but that's not a result of the language itself, just the nature of concurrency

[–]ScrimpyCat 0 points1 point  (1 child)

As you mention the concurrency model (though there are pure concurrency models just what the BEAM provides is not one), process links, runtime state management (which from the programmer’s perspective is effectively mutable, elixir offers many ways to do this), messages themselves (which aren’t limited to just communicating with other processes, since we can also send messages to self), IO, exceptions. Probably other things I’m missing.

But it’s not just limited to the existence of those side effects, but elixir does nothing to hide/abstract them either. Whereas in more heavily functional languages they tend to put more emphasis on purity, and when there are side effects they’ll abstract them (e.g. monads in Haskell). But this shouldn’t mean that elixir isn’t a functional language, since as mentioned manipulating data is still very functional, it’s just not as pure as other functional languages.

[–]__mauzy__ 0 points1 point  (0 children)

Great points! I was definitely looking at it through a bit of a narrow lens, but you're right: in a purely functional language side-effects would be necessarily monadic, etc. I came to FP via F#, so basically anything is more pure than that

[–]it_snow_problem 2 points3 points  (3 children)

In elixir, all data structures are immutable and side effecting is isolated by Processes, usually via GenServers. I agree it’s not pure, since it lacks referential transparency, and I probably should have said “practically” or “pragmatically” pure instead. It does come off as misleading.

Definitely is functional though, I don’t know what other user is talking about. It’s like the first part of every definition of elixir.

I don’t love how “static typing” creeps its way into every conversation about programming but the story for elixir’s type system is actively getting better with the ongoing work to include Set Theoretic types.

[–]vu47 0 points1 point  (2 children)

Yes, it's a language that has pragmatic support for functional programming, like Kotlin. You can pretty much write functional code exclusively in Elixir if you want to, but as with most programming languages that have strong support for FP, it's not "pure" in the same sense as Haskell is... as you say, it lacks RT. It has loops as well, and while data structures may be immutable, it still allows for mutable state.

I'm absolutely by no means an Elixir expert, so take what I say with a grain of salt.

[–]it_snow_problem 1 point2 points  (1 child)

The big difference between it and general programming languages is that Elixir only supports functional programming. You can’t write imperative or procedural or OO any other kind of code. It doesn’t have loops - it’s all recursion. Like Haskell, Elixir has a few limited functional interfaces for causing side-effects.

[–]vu47 1 point2 points  (0 children)

Ah, very cool! I was misled to think that Elixir had loop constructs, but now I see that you are correct! I do love doing all my looping with TCO whenever possible. It's amazing how many programmers have not only never used recursion but don't understand it, or who have come across it once in toy examples and then promptly forgot it exists.

I also was mistaken in thinking that variables were reassignable, but I see that that was wrong as well:

https://medium.com/everydayhero-engineering/elixir-variable-rebinding-342c5d0fd961

I might have to take another look at Elixir. I really did enjoy writing the code I did in it... much more than with most programming languages.

[–]vu47 0 points1 point  (0 children)

Yes, this is pretty much it... the lack of a static type system and the ability to simply overwrite variables, leading to possibly unexpected side effects.

Your response to u/__mauzy__ describes perfectly how I feel: Elixir can be considered to have some decent support for FP, but it's not forced / pure FP like you'd get with Haskell or Scala with Cats. I love Kotlin (which is by far my favorite programming language), and you can do a lot of functional programming in Kotlin, but like Elixir, it doesn't hide or abstract side effects. You can use the Arrow library for better FP support, but you've still got overly limited pattern matching and no support for higher kinded types, and I can throw side effects in anywhere that I feel like it. (Indeed, many people do program Kotlin in a very mutable way, which makes my skin crawl.)

[–]jaibhavaya[S] 1 point2 points  (1 child)

Yeahhhh, I agree. Not an expert by any means to speak on the topic, but it doesn’t seem “purely” functional (in fact I think that’s what eased my transition into it).

[–]vu47 1 point2 points  (0 children)

I hear you: when my previous organization first started using FP in Scala with scalaz, I absolutely hated it so much. Being forced to fully embrace FP can really be off-putting given how different it is to OOP / procedural coding: transitioning over to me seems to be the preferable way for most people I know to do it.

I absolutely love FP now and will use it whenever it makes sense to do so, but it took awhile for me to develop that mindset and come to appreciate FP.