halchester
Beginner in Elixir, any suggestions?
Hello guys, I’m a beginner in Elixir and I haven’t done any fp by far. I just want to know if there’re any tips and tricks. I’m mainly planning to use Elixir with phoenix for my website servers. If you guys could help me, it’d be very great!
Chester
Most Liked
Sebb
struct be like …
struct ▷ struct ▷ struct ▷ struct
… object be like
object ▷ o̵b̵j̷e̸c̵t̵ ▷ o̴͊͜b̶̭̃j̷̧̐e̷̫͂ć̵͍t̷̹͌ ▷ ō̴̹͙͑b̴̲̯̂̽j̵̻̓̿͝e̸̺̓͂̏ĉ̷̓ͅt̶̢̪͓͗͐̽
benwilson512
Hey @halchester, welcome! I’m not sure if this is really a “trick” but my main advice to all Elixir newbies is: develop comfort with Elixir fundamentals before writing a webserver. Phoenix is a very functional approach to webservers, and if you’re used to mutable data you’re gonna have constant problems.
Fortunately, the fundamentals are pretty small. I also think that, unless you’re jumping straight into LiveView or Channels, the fundamentals can exclude OTP or processes in general. You mostly just need to have a good feel for how to work with immutable data, and a decent working knowledge of major standard library modules (Enum, String, etc).
John-Goff
The point is that the four step pipeline in the functional version will only be affected by those four steps, whereas with the object oriented version it matters what the global context of the function pipeline is, since some, or even all, of those methods in the OOP version access global state. If they aren’t accessing global state, then you’ve written a pure function inside of your OOP, which kinda defeats the point of debating oop VS fp in the first place. That is, in the functional version you can be confident that the same four function pipeline will always return the same result. You can more easily compose things when you only need to know the input and output values, as opposed to the input values, output values and global state in the OOP version. It’s about keeping less stuff in your head at any one given time.
Sebb
May I add: Sure you “can do that in {language-with-mutability} also”, but: I don’t know you did when I read your code and I bet you don’t also (except you always program pure, then you should use a language supporting persistent data structures).
Immutability is a (the?) key point in FP. Be aware that you give up a superpower (mutating everything,
everywhere, anytime) and exploit what you get back:
- programs are easier to understand
- programs are (way) easier to test (if you manage to keep the core pure and push everything unpure to the boundaries (see https://www.youtube.com/watch?v=arYOSYrjC8s and Functional Core, Imperative Shell)
- (with time) programs are easier to write. But you have to unlearn some stuff, and you have to think more, especially about data-structures (see https://forum.elixirforum.net/t/picking-up-fp-coming-from-oop-split-thread/33187/97)
- in sum you have a higher chance for good code
To get started the elixir-track at https://exercism.io/ is great and if you like video courses I can recommend Developing With Elixir and OTP Course | The Pragmatic Studio.
otuv
I knew it would upset someone (or many). I still fail to see the conceptual difference.
If you want to know the value of struct.x in step four you have to access the value or look at what transformations have been done.
If you want to know the value of object.x in step four you have to access the value or look at what transformations have been done.
Of cause the object can potentially lie to you about current state but unless you do stuff you should not there is no difference as I can see.
I still prefer the fp way but if someone can enlighten me I happily try to get the full point 








