Re: classes and objects questions

2020-12-15 Thread ToddAndMargo via perl6-users

On 12/14/20 2:33 PM, ToddAndMargo via perl6-users wrote:

Hi All,

https://docs.raku.org/language/classtut

  "A tutorial about creating and using classes
  in Raku"

So far so good.

  "Raku has a rich built-in syntax for defining
  and using classes."

U. Forgot something did we?  What is a "class"?


Next up:

  "A default constructor allows the setting of
  attributes for the created object:"

U.  Forgot something else, did we?  What is
an "object"?


The "tutorial" leaves "class" and "object" up to
the reader to guess at from what looks like an
interesting example.


But, again forgetting things, The tutorial also
leaves the syntax up for guess work as well.  Not
described are "$.", "$!", ":$", ^$" what are they
and what are the rules for using them.

Next up:

  my $r = Rectangle.new(
   lower => Point.new(x => 0, y => 0),
   upper => Point.new(x => 10, y => 10));


Why are we using ".new"?

Why are we using the syntax for a hash (=>)?

And:
  $!upper.x

What is the rules and purpose for such?  Why
the "!" and why the "."?


I do realize the documentation is not meant for
beginners, but rather a refresher for advanced
users that do not need it, but this link definitely
said "tutorial" -- fifth word in.

Would some kind soul please fill in the missing
parts of the "tutorial" for me?

Many thanks,
-T



Okay, here are some Perl 5 definitions for PerlDocs:

https://perldoc.perl.org/perlglossary

class

A user-defined type, implemented in Perl via a package that 
provides (either directly or by inheritance) methods (that is, 
subroutines) to handle instances of the class (its objects). See also 
inheritance.



class method

A method whose invocant is a package name, not an object reference. 
A method associated with the class as a whole. Also see instance method.



object

An instance of a class. Something that “knows” what user-defined 
type (class) it is, and what it can do because of what class it is. Your 
program can request an object to do things, but the object gets to 
decide whether it wants to do them or not. Some objects are more 
accommodating than others.



Anyone want to add Raku modifications to the above?  I
like their "user-defined type" description.

I don't know what to make of "more accommodating than others".


--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~


Re: Missing NullPointerException

2020-12-15 Thread Konrad Bucheli via perl6-users

Hi Ralph

Thanks a lot for the extensive answer. 

I still consider it a trap because it does not do what it tells it does.

If I have:

say "launching drone";
$drone.engine.start;
say "engine started";

After I run the above I got both messages, but no propeller spinning. So I 
checked start() in and out, because that is where the problem is obviously.
But it was not, it was in engine().
And I want my programming language/runtime to tell me if I am doing obviously 
stupid things.
Note that it has nothing to do with the "pyramid of doom". It would make sense 
in a pure functional environment, but Raku is multi-paradigm, no? 

Now to be "safe" (as in fail fast) I have to always

say "launching drone";
# this intermediate variable is important defensive programming, else it will 
not explode on Nil if there are stupid errors in engine()
my $engine = $drone.engine;
$engine.start;
say "engine started";

which is the opposite of concise. 

But Raku is Raku, there is surely a way to make sure that my Nil explodes in my 
code. Is there a `use FailingNil`? 

Concerning documentation: I do not know where there is an appropriate place to 
warn about this behavior. There where we teach how methods are called? Surely 
it would not have found me. I look up a lot in documentation, but not such 
trivial stuff.

Cheers

Konrad

From: Ralph Mellor 
Sent: Saturday, 5 December 2020 15:58
To: Konrad Bucheli 
Cc: perl6-users 
Subject: Re: Missing NullPointerException 
 
On Thu, Dec 3, 2020 at 10:20 PM Konrad Bucheli via perl6-users
 wrote:
>
> What is actually the rationale for such a behaviour?

Ergonomically sound null safety.

First, consider what other languages have. Quoting
https://en.wikipedia.org/wiki/Safe_navigation_operator:

> In object-oriented programming, the safe navigation operator
> ... is used to avoid sequential explicit null checks ...
...
> In programming languages where the navigation operator
> (e.g. ".") leads to an error if applied to a null object, the safe
> navigation operator stops the evaluation of a method/field
> chain and returns null as the value of the chain expression.
...
> It is currently supported in languages such as Apex, Groovy,
> Swift, Ruby, C#, Kotlin, CoffeeScript, Scala, Dart and others.
...
> The main advantage of using this operator is that it avoids the
> pyramid of doom. ...

Many aspects of Raku's design are better solutions than are found
in older PLs like those listed above. This is an example. Instead of
devs having unsafe operations by default, and having to write `?.`
to get safety, in Raku one just writes `.` and always gets safety.

> For me it was an unexpected trap

This statement couples deep wisdom (the "for me" qualification,,
deferring it till after you'd first asked about what the rationale was,
and sharing your experience) with a Canby.[1]

It's clear that you were missing some knowledge, and that it
bit you, and are now exploring how best to learn from that.

I accept without reservation the claim it was "unexpected". (That
is the sort of thing that is typically experienced and reported by
request of our right hemispheres, and it is generally reliable.)

I also recognize what I imagine as a negative effect associated
with classifying this experience / situation as a "trap", and the
negative affect associated with applying that classification, which
is to say your right hemisphere's experience of that classification.

With that said, I now wish to engage our respective unreliable
left hemispheres, the ones that drive classification, and wish to
suggest another way to view this situation.

I would argue that you are classifying safe navigation as a trap,
and thus likely experiencing it negatively. Perhaps for you this
can/will instead become a gift (perhaps also unexpected)?

A fundamental part of human experience is interpreting one's
reactions to things in the light of further knowledge and/or
experience. Larry has made it clear to me that this is one of
the keys to his approach to life, and to PL design, in both the
sense of how he approaches a PL's design and how the PL's
designed features reward those who think the same way. (I
have found this endlessly inspiring.)

Applying that to your experience, you could alternately view
what happened as a surprise that arises from Raku's default
of safety, which is about freedom (avoiding both the extensive
boilerplate of the pyramid of doom, and the modern shorter
but still boilerplate additional ?), and not, it could reasonably
be argued, about a trap.

cf my discussion of what Vadim Belman had classified as a WAT in
https://www.nntp.perl.org/group/perl.perl6.users/2018/09/msg5418.html

> It all went fine only the side effect was not there. I then figured
> out after some time that one of methods returned Nil and
> somehow silently it did not do what I expected.

The "somehow" was automatic safe navigation, By definition,
this is silent as far as it goes.

But if you think about it, it wasn't *entirely* silent. You

Re: classes and objects questions

2020-12-15 Thread ToddAndMargo via perl6-users

On 12/15/20 12:34 AM, WFB wrote:



JJ may be right about the OO thing, but it makes the
tutorial pretty much useless.  How "class" and "object"
*relate* to Raku needs to be explained.


When we are talking about describing Classes and Objects in a few words, 
then I agree. Searching on the web reveals lots of tutorials for Java, 
C# and so on with at least a few words about what classes and objects are.



"The best is the enemy of the good".  It is better to
slum it a bit and make the tutorial useful. JJ will
hate it, but he will live.

I don't think JJ hates useful tutorials. But he has to find a balance. 
Look in the Raku/doc repository 
. Every week ~15 
commits. And most of them on Sunday. Of course you can spend all day and 
make the classtut perfect, at least what is your understanding of 
perfect. But there is a lot more to be documented and maintained. You 
have to find a level of detail that provides information for all readers 
and to have only a limited amount of time and resources. That is JJ 
trying to do.
You are trying to shape the documentation for your needs. Sometimes the 
best documentation is not your documentation.
In this case adding links for the Variables and a few sentences about 
classes and objects would probably not hurt but I would listen to the 
arguments JJ has. Because he knows the big pictures.


Best


I like Parrots idea about using links, so advanced
users don't have to wade through  what they already
know and the rest of us can figure out what is going
on.

I have been looking at some Perl 5 Class tutorials
to try to get a hang on what is going on.  But since
we do not have reference pointers ...


Re: classes and objects questions

2020-12-15 Thread ToddAndMargo via perl6-users

On 12/15/20 7:00 AM, Parrot Raiser wrote:

Raku allows for several different programming paradigms; procedural,
functional, (as in languages like LISP), and object-oriented. It is
possible to write purely procedural Raku, while ignoring O-O features
completely, though it does take some dodging.

Object-oriented.programming first surfaced in the mid 1960s in
research projects, but was more generally visible by 1980. Like all
new programming concepts, it was going to cure cancer, bring about
world peace, and produce bug-free software. (And didn't, of course.)
It naturally had its specialised jargon, designed to ensure tribal
solidarity and repel infidels. It gradually spread with languages like
C++, (1979-83),  but remained a niche concept until Sun introduced
Java in 1995.

https://www.indeed.com/career-advice/career-development/what-is-object-oriented-programming

With the success of Java, later Javascript, and other new languages,
O-O and its jargon became
sufficiently mainstream that even many programmers working with other
languages learned the terminology. I suspect that many programmers
trained since the mid-90s assume that it's the only way to code, and
that objects and classes are inherent parts of everyone's universes.

If you were discussing the assembly language for bicycles, any
documentation could reasonably assume an understanding of frames,
wheels, pedals, and bell-cranks. Equally, any discussion of
object-oriented features can reasonably assume an understanding of
generic concepts like objects, classes, and inheritance, provided it
points out local weirdnesses. Repeating all the basics would make the
text cumbersome.

Perhaps the best approach would be a hyperlink to a generic
description (of which there are probably thousands already on the Web)
the first time a terms is introduced. The naive could follow it to
enligtenment, while the cognoscenti would not be distracted by it.


That would be an excellent way of doing it!

Loved the prose in your writing too!

Thank you!

I have been reading Perl5 tutorials on what classes
and objects are.  Since we do not have references
pointers, its is going to be fun.


Re: classes and objects questions

2020-12-15 Thread Parrot Raiser
Raku allows for several different programming paradigms; procedural,
functional, (as in languages like LISP), and object-oriented. It is
possible to write purely procedural Raku, while ignoring O-O features
completely, though it does take some dodging.

Object-oriented.programming first surfaced in the mid 1960s in
research projects, but was more generally visible by 1980. Like all
new programming concepts, it was going to cure cancer, bring about
world peace, and produce bug-free software. (And didn't, of course.)
It naturally had its specialised jargon, designed to ensure tribal
solidarity and repel infidels. It gradually spread with languages like
C++, (1979-83),  but remained a niche concept until Sun introduced
Java in 1995.

https://www.indeed.com/career-advice/career-development/what-is-object-oriented-programming

With the success of Java, later Javascript, and other new languages,
O-O and its jargon became
sufficiently mainstream that even many programmers working with other
languages learned the terminology. I suspect that many programmers
trained since the mid-90s assume that it's the only way to code, and
that objects and classes are inherent parts of everyone's universes.

If you were discussing the assembly language for bicycles, any
documentation could reasonably assume an understanding of frames,
wheels, pedals, and bell-cranks. Equally, any discussion of
object-oriented features can reasonably assume an understanding of
generic concepts like objects, classes, and inheritance, provided it
points out local weirdnesses. Repeating all the basics would make the
text cumbersome.

Perhaps the best approach would be a hyperlink to a generic
description (of which there are probably thousands already on the Web)
the first time a terms is introduced. The naive could follow it to
enligtenment, while the cognoscenti would not be distracted by it.


Re: classes and objects questions

2020-12-15 Thread WFB
JJ may be right about the OO thing, but it makes the
> tutorial pretty much useless.  How "class" and "object"
> *relate* to Raku needs to be explained.
>

When we are talking about describing Classes and Objects in a few words,
then I agree. Searching on the web reveals lots of tutorials for Java, C#
and so on with at least a few words about what classes and objects are.


>
> "The best is the enemy of the good".  It is better to
> slum it a bit and make the tutorial useful. JJ will
> hate it, but he will live.
>
I don't think JJ hates useful tutorials. But he has to find a balance. Look
in the Raku/doc repository
. Every week ~15
commits. And most of them on Sunday. Of course you can spend all day and
make the classtut perfect, at least what is your understanding of perfect.
But there is a lot more to be documented and maintained. You have to find a
level of detail that provides information for all readers and to have only
a limited amount of time and resources. That is JJ trying to do.
You are trying to shape the documentation for your needs. Sometimes the
best documentation is not your documentation.
In this case adding links for the Variables and a few sentences about
classes and objects would probably not hurt but I would listen to the
arguments JJ has. Because he knows the big pictures.

Best

>
> -T
>