DEV Community

Cover image for Are You a Confused Programmer? Learn a Functional Language

Are You a Confused Programmer? Learn a Functional Language

Pan Chasinga on April 06, 2020

Full disclosure: I'm an easily confused programmer. My mind does not work like a whiteboard genius. I was born an artist, best at scribbling than...
Collapse
 
ghost profile image
Ghost

I never thought about it but something clicked, a few months I started to learn Rust after years with Python, I must emphasize the fact that Python is as "clear" as it can be, is like writing boring English, take normal English, get rid of synonyms, there you go, Python. So I was really scared about Rust, yet after not long I started to understand it, don't get me wrong, borrows and lifetimes take time to grasp and I'm still battling, but without noticing my code started to look more functional, in fact I learned what functional was after the fact, Rust is not purely functional but you can do it if you like AFAIK or you could do OOP if that is your jam. You made some interesting points, I'll pay more attention to it, thanks.

Collapse
 
pancy profile image
Pan Chasinga

Rust is great!

Collapse
 
ghost profile image
Ghost

indeed it is, I'm really enjoying it, and the web ecosystem is getting very good, very fast.

Thread Thread
 
pancy profile image
Pan Chasinga

Actix web rocks.

Collapse
 
kspeakman profile image
Kasey Speakman

I think I am a confused programmer too. I also tried many languages and ended up settling on F# as the one that seems the best balance between readable and concise. It is in the ML family with OCaml and Haskell, but it takes more after OCaml. I wrote about our back-to-basics approach here. I've seen style this described as Python with static typing. I like that. Additionally, I like being able to opt into some of the slightly more advanced patterns when the code benefits from being optimized for conciseness. Like URL routing or validation.

Collapse
 
pancy profile image
Pan Chasinga

I had strong-armed myself more than once into F# but the .NET orientedness has been quite hard to overcome as a Unix programmer. I also had a hard time adopting many cool languages like Clojure and Scala because they are tied to the JVM.
F# is a great usability improvement to Ocaml IMO.

Collapse
 
kspeakman profile image
Kasey Speakman

It's much better now since F# is well-supported on .NET Core. We run our F# stuff in production on linux machines in docker containers. I can sympathize though. I have done some initial explorations of Clojure, and digging into the JVM ecosystem is a learning curve. I imagine coming to .NET is similar.

Collapse
 
jkgan profile image
Gan Jun Kai

I strongly agree with your post. I'm using Elixir at my work (ya I like Ruby-like syntax) and using Rust in my free time. I have to say I love it. Pattern matching is fantastic. The expressiveness of these languages is just so pleasant to work with.

PS: Ruby also getting pattern matching in the latest version

Collapse
 
pancy profile image
Pan Chasinga

You're blessed to be working full-time in Elixir!

Collapse
 
evolveris profile image
Lia • Edited

This was a well-worded and interesting insight.

As a growing developer, the feeling that I get around is that I will not become a "serious" developer if I don't know my way OOP and the plethora of languages that are used for it - functional programming is never ever mentioned. Maybe that's something that only I am experiencing, and it's not something up for generalization. So hearing that other people simply don't find some languages as comfortable as they could be - is a refreshing thought. Makes me reconsider the way I'm approaching the things that I have/should learn.

After reading this and the comments, I think I might just give Haskell a try! 🤓

Collapse
 
pancy profile image
Pan Chasinga

Thank you for the thoughtful words.
In my opinion, there are many things that flourish because of the right timing and turns of events on top of their merits. Some things do get lost in time despite their tremendous values.

OOP was popularized by the advent of C++, but also because of the context around it (modernism) in which the general people view the world merely as objects and what they can do. Once that rolls downhill it's just hard to stop it in its track. If you look at the history of all programming languages you'll see that the line tracing from LISP to ML/Miranda seemed to have stopped bluntly, giving room to C++, Java, and eventually Python to flourish.

However I think from now on OOP will be on a decline, providing newer languages tend to ditch class inheritance entirely (Go and Rust, to name a few). The code and applications today are vastly more complex than before that more begin to see having mutable states everywhere in OOP are just beyond human programmers to control. A big popular proof that functional programming is growing on us lies in the most popular JavaScript library -- React.

What most people think or say isn't always correct. It might have been, but never age well. I sure hope you'll give any functional language a try.

Collapse
 
sobolevn profile image
Nikita Sobolev

If you like functional programming, static type checking, and Python then you should probably check out dry-python/returns library.

It is a collection of typed monads, transformers, and composition helpers. Works great with and without mypy.

Check it out!

GitHub logo dry-python / returns

Make your functions return something meaningful, typed, and safe!

Returns logo


Build Status codecov Documentation Status Python Version wemake-python-styleguide Checked with mypy


Make your functions return something meaningful, typed, and safe!

Features

  • Provides a bunch of primitives to write declarative business logic
  • Enforces better architecture
  • Fully typed with annotations and checked with mypy, PEP561 compatible
  • Has a bunch of helpers for better composition
  • Pythonic and pleasant to write and to read 🐍
  • Support functions and coroutines, framework agnostic
  • Easy to start: has lots of docs, tests, and tutorials

Installation

pip install returns

You might also want to configure mypy correctly and install our plugin to fix this existing issue:

# In setup.cfg or mypy.ini:
[mypy]
plugins =
  returns.contrib.mypy.decorator_plugin

We also recommend to use the same mypy settings we use.

Make sure you know how to get started, check out our docs!

Contents