[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    Re: ruby has the native block oriented style, why not go as a FP language?
From:       Andy Maleh <andy.am () gmail ! com>
Date:       2022-02-21 4:59:11
Message-ID: CAAZkKDLtGPQd-LYJwBKsXfi3aaeUv=uYB-b6tmbQDyDrtEFa7g () mail ! gmail ! com
[Download RAW message or body]

> I know a FP language has these features:
> 1) immutable values
> 2) purely functions (no side effect, input decides the only output)
> I think ruby is quite easy to build purely functions. if it adds the
> features of immutable value types, then can we treat it as a FP language?
> if ruby supports both FP and OOP styles, that will be more wonderful (at
> least for me).
> What do you think of it? Thank you.

This is simply not true! That is modern hype-following kind of FP that
many uneducated programmers blindly followed after they saw some
Youtube videos.

To learn true FP, go get a degree at a top American university like
MIT or watch their videos at least. FP as in Lisp/Scheme (some of the
oldest FP languages) did have mutation. They were not impractically
strict about it. You can avoid mutation sometimes when needed in very
rare cases, but there are times when mutation is OK too. The benefits
of immutability are 99% of the time over-exaggerated. I've seen real
code written by those hypers and it's often more complicated than any
code with mutation to the point that it negates all the benefits they
claimed.

Anyways, to people who truly understand FP (less than 0.1% of the
programmer population), OOP is nothing but an advanced application of
FP of simply smart data that knows its operations through
polymorphism. I even blogged about that to explain it, but to this
day, it falls on deaf ears with many people who are chasing FP hype:

https://andymaleh.blogspot.com/2019/07/is-oop-compatible-with-functional.html

Really, what I blogged is a combination of stuff I learned from my
Computer Science undergrad and some videos from MIT Computer Science
lectures from the 80's that confirm it. Everybody with a Computer
Science degree who doesn't just blindly follow Internet hype knows
what I said about no conflict existing between OOP and FP. In fact,
Ruby is a perfect application of both when performance is good enough
in using a dynamically typed programming language.

In the rare cases you need to make the trade-off of extra performance
at the expense of language expressibility, you can use C, C++,
Crystal, Swift, or Java.

But, the Scala type of FP is just a long experiment that should have
ended as soon as Java implemented Scala's features of Lambda
Expressions in JDK8. I know the ins and outs of Scala usage in real
life professional projects and they're not good. One company I worked
at suffered from many issues for using Scala, such as many styles of
code in their codebase that were unmaintainable, people trying to push
different styles of FP as the right style and not writing pragmatic
code, Scala versions breaking compatibility with older versions,
etc...

Scala is not a good language except when it was an initial language
experiment in the mid-2000s. There is nothing Ruby can learn from
Scala, yet the contrary might be true. I know because I've seen DSLs
in both languages and the ones in Scala are very stiff, have odd extra
characters like underscore, and are obtrusive compared to the DSLs in
Ruby which are very fluid, minimal, and software-engineer-friendly.


On Sun, Feb 20, 2022 at 11:01 PM Bitfox <bitfox@bitfox.top> wrote:
> 
> for example, the code taking a block (anonymous func) is quite native in ruby:
> 
> > [1,2,3,4].map {|s| s+1 }
> 
> => [2, 3, 4, 5]
> 
> 
> 
> It's quite similar to the functional programming language such as scala:
> 
> 
> scala> List(1,2,3,4).map {_ + 1}
> 
> val res0: List[Int] = List(2, 3, 4, 5)
> 
> 
> 
> for comparison, python is ugly for this kind of stuff:
> 
> 
> > > > map(lambda x:x+1, [1,2,3,4])
> 
> [2, 3, 4, 5]
> 
> 
> 
> And perl is more ugly:
> 
> 
> $ perl -le '@x= map {$_ + 1} (1,2,3,4);print "@x"'
> 
> 2 3 4 5
> 
> 
> 
> It's even quite easy to implement my own blocking based func:
> 
> 
> > class Array
> 
> > def myfind
> 
> > if block_given?
> 
> > map {|s| yield s}
> 
> > end
> 
> > end
> 
> > end
> 
> => :myfind
> 
> 
> > [1,2,3,4].myfind{|s| s > 2}
> 
> => [false, false, true, true]
> 
> 
> 
> I know a FP language has these features:
> 
> 
> 1) immutable values
> 
> 2) purely functions (no side effect, input decides the only output)
> 
> 
> I think ruby is quite easy to build purely functions. if it adds the features of \
> immutable value types, then can we treat it as a FP language? 
> 
> if ruby supports both FP and OOP styles, that will be more wonderful (at least for \
> me). 
> 
> What do you think of it? Thank you.
> 
> 
> 
> Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>



-- 
Andy Maleh

LinkedIn: https://www.linkedin.com/in/andymaleh
Blog: http://andymaleh.blogspot.com
GitHub: http://www.github.com/AndyObtiva

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic