Hi Ivan,
It is a good idea to program in a functional style.
On Functional Programming (FP):
FP is great. I personally favour it because you get easier to read
code. We think in terms of data transformation where a function is a
transformer of input to output. The same input should give the same
output data. Side-effects are indeed discouraged - which makes code
more predictable. As Joe Armstrong of Erlang says, you should be able
to cut and paste a function elsewhere and it should just work as
expected. Even using OOP methods that is possible - just make sure
classes carry the *minimum* state and, if possible, split data and
methods into objects and/or modules. I program in Ruby almost without
using classes that mix code and data these days. Sometimes OOP is
good, for example File class will have a filehandle that it carries
around. But that is easy to understand, right? The Ruby standard
library is actually a good example of mixing OOP and FP - it is flat
and easy to understand. That is the goal.
On Immutable data:
Immutable data is actually badly supported in Ruby (I love Tony's
http://tonyarcieri.com/2012-the-year-rubyists-learned-to-stop-worrying-and-love-the-threads),
so I would not focus too much on that. The trick is to copy data - so
to make sure you don't change data in lists etc. When you transform an
object/list you first have to deep copy it to gaurantee a new object.
I do that consistently in the bio-alignment gem, for example. I does
mean (in Ruby) that we have to copy data all the time. It helps
prevent stupid bugs - that is the upside. I only cheat when there are
real performance considerations.
Conclusion:
I do use FREEZE now and then, but mostly for class variables that
should be constant. There is no deep-freeze for lists etc. For me FP
in Ruby, therefore, mostly means keeping data and functions apart and
avoiding, like you say, side effects. Also avoiding variable
reassignment is good practice - but Ruby offers no safety net there.
Having freeze all over the place won't make the software easy to read.
Pj.
On Sat, May 23, 2015 at 12:28:06PM -0700, Ivan Evgrafov wrote:
> Hi,
> only two days left before coding phase start so I want to summarize my
> progress up to this moment in the blog post. I shared my ideas about
> functional style and its usage in my project and provided some details
> about tools I'm going to use. I also wrote a few words about tests and how
> I implemented them.
> Much more details may be found in the blog -
> [1]
http://dilcom.github.io/pilot-gnuplot/2015/05/before-coding-starts/.
> Wish everyone to work on their projects with love and passion and to
> succeed in both evaluations.
> Regards,
> Ivan
> Ñ*Ñ*еда, 29 апÑ*елÑ* 2015 г., 22:20:04 UTC+3
> полÑ*зоваÑ*елÑ* Ivan Evgrafov напиÑ*ал:
>
> Hello,
> I'm very glad to have such an opportunity both to help the SciRuby
> community and improve my skills in programming. Thank you for accepting.
> This summer I will work on building a new gem for gnuplot. Gnuplot is a
> cross-platform command line utility for visualisation. It supports both
> 2D and 3D plots, may plot in cartesian, polar and parametric
> coordinates, allows to plot several data sets in one or several
> coordinate systems. I believe that this work will improve visualisation
> capabilities of Ruby and allow scientists to use it more widely. My
> proposal with much more project details may be found on [2]google
> melange. I also prepared several examples of things which may be done
> with gnuplot and I want to achieve with gem. They can be found in [3]my
> github repository.
> Now let me briefly introduce myself.
> I'm 4-th year student of Computer Science at Bauman State Technical
> University in Moscow, Russia. I'm programming Ruby for about two years
> and I'm going to use my current skills to develop the gem I proposed and
> also to improve my skills during development. I also hope to get
> familiar with TDD and CI tools during GSoC.
> Regards,
> Ivan
>
> --
> You received this message because you are subscribed to the Google Groups
> "SciRuby Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [4]
sciruby-dev...@googlegroups.com.
> For more options, visit [5]
https://groups.google.com/d/optout.
>
> References
>
> Visible links
> 1.
http://dilcom.github.io/pilot-gnuplot/2015/05/before-coding-starts/
> 2.
http://www.google-melange.com/gsoc/proposal/public/google/gsoc2015/dilcom/5629499534213120
> 3.
https://github.com/dilcom/pilot-gnuplot/tree/master/samples
> 4. mailto:
sciruby-dev...@googlegroups.com
> 5.
https://groups.google.com/d/optout
--