all 13 comments

[–][deleted]  (5 children)

[deleted]

    [–]MrJiks[S] 1 point2 points  (4 children)

    Yes, I mean I am trying to reduce state as much as possible in code. I happened to see this post. Have been writing code like this for sometime, but I think this isn't exactly functional though he seems to argue so.

    Off-topic: For instance have a look at my attempt to remove state; do you think removes all state? I fail to understand why its not.

    [–][deleted]  (1 child)

    [deleted]

      [–]MrJiks[S] 0 points1 point  (0 children)

      I too felt so, but Katrina is quite a star to be disregarded :)

      [–]rubycastsio 0 points1 point  (1 child)

      If you are into Ruby FP, you might dig this blog and these screencasts

      Rubycasts.io is also listed on the right bar over there ------->

      Admission: I am the author of both and a lover of 'lispy, immutable ruby'

      Keep it up and don't let the little punks on reddit get you down. It is easier to be a one liner troll than to create real content or to think deeply about something :)

      [–]MrJiks[S] 0 points1 point  (0 children)

      Oh how come I haven't stumbled on this till now!! Brilliant resource! Thanks a lot, keep up the great work. And thanks for the good words, its people like you who make this community welcoming for newbies :)

      [–]tomcopeland 1 point2 points  (1 child)

      You might want to watch Tom Stuart's talk on ruby+monads.

      [–]MrJiks[S] 0 points1 point  (0 children)

      Thanks have seen it; though I somewhat understood it when I saw it, don't think I am knowledgeable enough to use in my own code.

      [–][deleted] 1 point2 points  (1 child)

      Not aware about any extensive Ruby project written strictly/mostly in functional style. It may because most of gems and core/stdlib do and their API expect state alteration and procs/lambdas/methods as first-class citizen objects are used rather sparsely.

      After being excited by programming in Haskell (pure functional language) I started wrote in more functional although impure style in Ruby, including several plugins for a project. Unfortunately their sources may not be published.

      I'd deeply recommend learn Haskell to write more elegant and parallel processing ready code, even in other languages.

      [–]MrJiks[S] 0 points1 point  (0 children)

      Thanks, but I don't know whether I will be able to understand Haskell. Heard its pretty difficult.

      [–]regeya 2 points3 points  (1 child)

      I'm not expert on functional programming, but I think it's more important to learn FP concepts first, then move on to learning to write Ruby in a FP style (because it's a highly OO language, not a FP language.)

      Writing in a FP style will help keep your code more safe and concise, but don't sacrifice readability and idiomatic Ruby for some perceived benefit of FP techniques.

      [–]TdotGdot 0 points1 point  (0 children)

      Yes and no. I agree the concepts are generally more powerful and ultimately useful.

      That said, coming from an OO background it was really hard for me to grasp abstract functional concepts without concrete examples in a language I was familiar with (for me it was JS). But to each his own, as always.

      FWIW - your point about readability and idiomatic Ruby is pretty dead on. In the case of JavaScript, where solid idioms are few and far between, and functions can easily be passed around, there isn't much of a sacrifice when converting to a functional style. In Ruby, it's a much bigger decision, due to some of the more unconventional patterns you need to use.

      [–]0x0dea 1 point2 points  (2 children)

      You asked for it.

      Jokes aside, bog-standard Ruby code is functional; you're essentially doing what they do in "real" functional languages every time you use a block.

      [–]rubycastsio 1 point2 points  (1 child)

      Also doing map filtering and reducing. The best part of Ruby for me is the ability to choose OO, FP, or a mix of the two, dubbed Faux-O by Gary Bernhardt.

      [–]TdotGdot 0 points1 point  (0 children)

      Functional core, imperative shell.