Functional calisthenics
codurance.com
Functional calisthenics
1–10 of 37 posts
Re: Functional calisthenics
#2I remember when OOP came up, some people made functions illegal. So instead of
s = sinx(x)
the OOP way was
m = new Math() s = m.sin(x)
And instead of switch statements you had to derive a new class for each case call a virtual function. Very "OOP" but it led to the OOP equivalent of spaghetti code.
Are the functional guys also starting to leave the real world for the sake of being "pure"?
Re: Functional calisthenics
#3Isn't this going a little overboard? I remember when OOP came up, some people made functions illegal. So instead of s = sinx(x) the OOP way was m = new Math() s = m.sin(x) And instead of switch statements you had to derive a new class for each case call a virtual function. Very "OOP" but it led to the OOP equivalent of spaghetti code. Are the functional guys also starting to leave the real world for the sake of being…
I wouldn't expect anyone to follow them religiously in production code.
Re: Functional calisthenics
#4Isn't this going a little overboard? I remember when OOP came up, some people made functions illegal. So instead of s = sinx(x) the OOP way was m = new Math() s = m.sin(x) And instead of switch statements you had to derive a new class for each case call a virtual function. Very "OOP" but it led to the OOP equivalent of spaghetti code. Are the functional guys also starting to leave the real world for the sake of being…
m = new Math() s = m.sin(x)
would be "the OOP way" instead of x.sin
?Besides this nitpick, i concur with Veen. The post seems to be about exercises/challenges, not FP best practices.
Re: Functional calisthenics
#5Isn't this going a little overboard? I remember when OOP came up, some people made functions illegal. So instead of s = sinx(x) the OOP way was m = new Math() s = m.sin(x) And instead of switch statements you had to derive a new class for each case call a virtual function. Very "OOP" but it led to the OOP equivalent of spaghetti code. Are the functional guys also starting to leave the real world for the sake of being…
Nitpick, but why m = new Math() s = m.sin(x) would be "the OOP way" instead of x.sin ? Besides this nitpick, i concur with Veen. The post seems to be about exercises/challenges, not FP best practices.
Good point. I guess in C++ numbers aren't objects so you can't do this.
I hope they understand that this is just an exercise. I have seen too often these things being elevated into a religion.
Re: Functional calisthenics
#6Earlier quoted context omitted.
Nitpick, but why m = new Math() s = m.sin(x) would be "the OOP way" instead of x.sin ? Besides this nitpick, i concur with Veen. The post seems to be about exercises/challenges, not FP best practices.
" x.sin " Good point. I guess in C++ numbers aren't objects so you can't do this. I hope they understand that this is just an exercise. I have seen too often these things being elevated into a religion.
Yeap. I have no hard preference between sin(x) or x.sin, in an OOP context or not, as long as the language is somewhat consistent (e.g., it bothers me that Ruby has some of these functions on the numbers themselves, like 1.23.floor, but others live on Math, like Math.sin(42)).
Re: Functional calisthenics
#7Re: Functional calisthenics
#8Isn't this going a little overboard? I remember when OOP came up, some people made functions illegal. So instead of s = sinx(x) the OOP way was m = new Math() s = m.sin(x) And instead of switch statements you had to derive a new class for each case call a virtual function. Very "OOP" but it led to the OOP equivalent of spaghetti code. Are the functional guys also starting to leave the real world for the sake of being…
These rules are constraints on how to create your code
and are only intended to be applied when doing katas or
exercises.
These rules are an exercise to kick you out of an OOP mindset, not best practices for writing real code.By that same token, I think it is a good rule when practicing OOP to not allow bare functions. It helps train yourself to think "Is there a logical class that this method belongs to?" In real code, of course, the answer is often "no". But when first learning OOP, it's good to teach yourself to ask that question in the first place.
Your code isn't a good example of "the OOP way", though. A fluent OOP solution would be:
s = x.sin()
Another good rule when practicing OOP would be "No classes without state." That helps you avoid the habit of writing pointless "namespace" classes like the "Math" class you define here. Of course, again, sometimes it is useful to wrap a bunch of related behavior in a stateless class, but that should be the exception, not the default.Re: Functional calisthenics
#9Isn't this going a little overboard? I remember when OOP came up, some people made functions illegal. So instead of s = sinx(x) the OOP way was m = new Math() s = m.sin(x) And instead of switch statements you had to derive a new class for each case call a virtual function. Very "OOP" but it led to the OOP equivalent of spaghetti code. Are the functional guys also starting to leave the real world for the sake of being…
Nitpick, but why m = new Math() s = m.sin(x) would be "the OOP way" instead of x.sin ? Besides this nitpick, i concur with Veen. The post seems to be about exercises/challenges, not FP best practices.
Re: Functional calisthenics
#10I don't understand "no explicit recursion". How do you do any kind of binary tree search without recursion?