in reply to RFC: Math::Triangle (Perl 6)

I find using a class just to represent angles, overkill.

Replies are listed 'Best First'.
Re^2: RFC: Math::Triangle (Perl 6)
by holli (Abbot) on Sep 18, 2017 at 12:44 UTC
    That is because you think Perl 5. Perl 6 is full OO. There is absolutely nothing in the language that isn't an class/object, not even things like keywords. Thus there is no overhead to avoid.
    use v6; 1.say; #prints 1
    So using a class even for something relatively simple is not overkill, instead not using a class is impossible.


    holli

    You can lead your users to water, but alas, you cannot drown them.
      That is because you think Perl 5. Perl 6 is full OO. There is absolutely nothing in the language that isn't an class/object, not even things like keywords. (...)
      use v6; 1.say; #prints 1 [download]
      So using a class even for something relatively simple is not overkill, instead not using a class is impossible.
      I disagree with this view.

      Granted, there is one (low) level of abstraction where this is kind of true. Kind of true, because the fact that you can write 1.say; does not necessarily mean that the literal integer 1 is an object. As far as I can say, this is more a form of boxing or perhaps autoboxing: in a sense, the primitive type is converted into an object for the sake of using methods on it, but 1 is really a primitive or native type, not really an object. But that's not my main point.

      Even if this view of yours were to hold and if I were to admit (solely for the sake of argument) that "everything is an object," this would be a very low-level view of the language. You admittedly need OO programming to create new types. But that does not mean that you have to do all your programming at this low level. Perl 6 offers many (often higher) levels of abstraction (or programming paradigms), such as declarative programming (e.g. regexes and grammars), functional programming (data pipelines, higher order functions, closures, etc.), concurrent and parallel programming (promises, etc.), and of course more traditional procedural or imperative programming. Or even logic programming, if you are willing to take some extra efforts. So that not using a class is actually far from impossible.

      We, as programmers, have to decide which level of abstraction to use, and you and I may agree or disagree on that. But saying that everything should be OO is just at variance with the Perl (5 or 6) philosophy, and, IMHO, plainly wrong.

      That is because you think Perl 5

      Not really. I was actually thinking in a mathematical way.

      I didn't mean overkill as inefficiency from a computational point of view, but overkill as introducing a new concept for something that is just a number.

        But it isn't just a number. It's an angle. That conveys meaning. Angles have multiple representations for example. In Radians and Degrees, and who knows what else. Hence the Math::Angle class has a method "degrees" and a method "radians". Converting a degree value to radians:
        say 75°.radians; # yes the ° is a custom constructor. alternatively Ma +th::Angle.new(degrees=>75).radians;
        Also it behaves like a number where it makes sense.
        ok 75° < Math::Angle.new(radians => pi);
        Or even
        ok 75° + 75° == 150°;


        holli

        You can lead your users to water, but alas, you cannot drown them.