Perl 6
This is a modal window.
The media could not be loaded, either because the server or network failed or because the format is not supported.
Formal Metadata
Title |
| |
Subtitle |
| |
Alternative Title |
| |
Title of Series | ||
Number of Parts | 150 | |
Author | ||
License | CC Attribution 2.0 Belgium: You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal purpose as long as the work is attributed to the author in the manner specified by the author or licensor. | |
Identifiers | 10.5446/34466 (DOI) | |
Publisher | ||
Release Date | ||
Language | ||
Production Year | 2015 |
Content Metadata
Subject Area | |
Genre |
00:00
OvalIndividualsoftwareMultiplication signPersonal digital assistantSoftware bugWeightWave packetSoftwareDynamical systemFormal languageOrder (biology)Process (computing)Element (mathematics)XMLComputer animation
01:04
OvalLengthRevision controlFormal languageData miningSpring (hydrology)Multiplication signDevice driverLink (knot theory)Basis <Mathematik>Hecke operatorNumberComplex (psychology)Computer animation
02:07
File formatParameter (computer programming)SoftwareComputerDiscrete element methodDivision (mathematics)IntegerNegative numberImplementationPoint (geometry)CASE <Informatik>Number theorySystem callImplementationIntegerExecution unitOnline helpLimit (category theory)NeuroinformatikMassSpecial unitary groupInfinityJunction (traffic)Profil (magazine)MathematicsFormal languageCompilerSocial classEvoluteImage resolutionMappingComputer programmingMetropolitan area networkPhysical systemException handlingSoftwareCartesian coordinate systemNumberCalculationCategory of beingFile formatTerm (mathematics)Level (video gaming)Type theoryNichtlineares GleichungssystemGraph coloringPerl 5QuicksortOrder (biology)Complex numberComputer animation
07:20
Endliche ModelltheorieOvalDivision (mathematics)Shift operatorElement (mathematics)Fibonacci numberFunction (mathematics)InfinityLoop (music)Regulärer Ausdruck <Textverarbeitung>TypprüfungData typeError messageCodeLoop (music)IntegerShift operatorMultiplicationEstimatorCategory of beingNumberSpiralEndliche ModelltheorieNeuroinformatikMathematicsQuicksortFormal languageAsynchronous Transfer ModeFunctional (mathematics)Floating pointPower (physics)Sampling (statistics)Parameter (computer programming)RecursionFibonacci numberTypinferenzRational numberElectronic signatureGraph coloringRight angleProcess (computing)Sheaf (mathematics)ExpressionSystem callInteractive televisionMultiplication signCASE <Informatik>Exception handlingSubject indexingPoint (geometry)Rule of inferenceGoodness of fitGame controllerProfil (magazine)Universe (mathematics)Software testingINTEGRALElectronic mailing listFile formatInterior (topology)DivisorMereologyDescriptive statisticsRun time (program lifecycle phase)Moment (mathematics)Type theoryLevel (video gaming)Social classComputer programmingDifferent (Kate Ryan album)CoprocessorWaveSerial portSoftware developerNumeral (linguistics)Fraction (mathematics)Programming languageFigurate numberLogarithmic spiralStatement (computer science)Unit testingDivision (mathematics)Irrational numberSoftware bugStack (abstract data type)Compilation albumNP-hardComputer animation
15:49
Parameter (computer programming)Constraint (mathematics)SubsetFunction (mathematics)Cache (computing)Fibonacci numberCurve fittingMultiplicationDynamical systemFormal languageTerm (mathematics)Electronic signatureParameter (computer programming)WordDeterminismCartesian coordinate systemWorkstation <Musikinstrument>Uniform resource locatorCASE <Informatik>Negative numberConstraint (mathematics)Type theoryArrow of timeOrder (biology)Boolean algebra1 (number)SubsetDefault (computer science)Variable (mathematics)Core dumpLogic gateBitMultiplication signCodeWritingAreaMathematicsMiniDiscSocial classObject (grammar)ChainRevision controlCasting (performing arts)Functional (mathematics)State of matterSystem callSound effectData structureCache (computing)Limit (category theory)Point (geometry)Software testingString (computer science)Java appletFibonacci numberMathematical structureLeast squaresProgramming languageRecursionGraph (mathematics)Boom (sailing)DatabaseInformation technology consultingFluid staticsDifferent (Kate Ryan album)Hydraulic jumpSpacetimeMessage passingMoving averageObject-relational mappingAsynchronous Transfer ModeComputer programmingInterior (topology)Level (video gaming)InfinityLoop (music)Computer animation
24:06
MultiplicationType theoryOvalPoint (geometry)Boom (sailing)Real numberMultiplication signLimit (category theory)Uniform resource locatorSlide ruleLine (geometry)Functional (mathematics)Point (geometry)Parameter (computer programming)CASE <Informatik>SubsetValidity (statistics)Client (computing)Software developerCondition numberString (computer science)Error messageSocial classDefault (computer science)Object (grammar)Dot productType theoryAttribute grammarGame controllerPower (physics)Moment (mathematics)CodeMessage passingHecke operatorRight angleArithmetic meanSet (mathematics)Logical constantConstraint (mathematics)BitFormal languageWritingNeuroinformatikForm (programming)Computer programmingProgramming languageIntegerAxiom of choiceRange (statistics)Operator (mathematics)Revision controlPoisson-KlammerAlgebraic closureTypprüfungTypinferenzInstance (computer science)Variable (mathematics)Cartesian coordinate systemMathematicsPolarization (waves)Boom (sailing)Mobile WebWordMultiplicationMedianOnline helpRegular graphInfinityRule of inferenceFocus (optics)1 (number)Process (computing)Physical lawNatural numberVideo gameReading (process)Information privacyWebsiteComputer animation
32:24
Point (geometry)OvalLimit (category theory)Core dumpJava appletCodeProper mapElectronic mailing listInfinityLogical constantOpen setProgrammer (hardware)MultilaterationComputer fileCategory of beingControl flowInferenceFormal grammarQuicksortCAN busAreaMassLine (geometry)Product (business)Multiplication signRight angleEinbettung <Mathematik>String (computer science)Process (computing)Basis <Mathematik>Formal languageVector potentialMereologyFunctional (mathematics)PlanningPower (physics)Data miningWordInfinityPrime idealKeyboard shortcutSlide ruleSinc functionMedical imagingDirected graphComputer fontOrder (biology)Sound effectObject (grammar)Social classBookmark (World Wide Web)Open setType theoryElectronic mailing listConstraint (mathematics)Computer programmingDifferent (Kate Ryan album)EstimatorForm (programming)CodeDefault (computer science)Network topologyLie groupDeclarative programmingJava appletPrime numberRegulärer Ausdruck <Textverarbeitung>Revision controlError messageTypinferenzTerm (mathematics)Software testingFluid staticsPlastikkarteMatching (graph theory)Interior (topology)BitPoint (geometry)Attribute grammarReal numberGoodness of fitIterationMessage passingLogical constantProgramming languageSource codeComputer animation
40:42
SequencePoint (geometry)Loop (music)CodeFile formatParameter (computer programming)Fibonacci numberSequenceInheritance (object-oriented programming)Open sourceBlock (periodic table)SummierbarkeitNumberArrow of timeGeometryProcess (computing)Formal languageConstraint (mathematics)CASE <Informatik>QuicksortMereologyDeclarative programmingError messageElectronic signatureSocial classMultiplication signRun time (program lifecycle phase)Stability theoryOperator (mathematics)Profil (magazine)AbstractionDemosceneElectric generatorRange (statistics)Line (geometry)Electronic mailing listCategory of beingException handling2 (number)Rule of inferenceVariable (mathematics)Alphabet (computer science)Term (mathematics)Different (Kate Ryan album)Sound effectMoment (mathematics)Figurate numberHecke operatorMultiplicationDot productCoefficient of determinationBitArithmetic progressionSystem callSource codeInfinityArithmetic meanAlgebraic closureNP-hardComputer animation
49:00
GoogolComputer animation
Transcript: English(auto-generated)
00:07
Hello, folks. First thing, I want to apologize to you. If you folks have seen my talks before, you know that generally I leave a lot of time at the end of talks for questions. I don't have that time this time. Please hold your questions until the end. I probably won't
00:22
actually be able to get to them, but you can bug me in the hallway or there's plenty of other folks who know Pearl Six really, really well. For the people who don't know me, Curtis Poe generally knows Ovid on the net. All my company, we do bespoke software development, usually in Pearl. We also do training in Pearl,
00:42
databases, Git. Today's talk is a dynamic language for mere mortals. Pearl Six, with the unwinding assistance of one Manuel Seron. Manuel, are you here? He's actually a pythonista, so he looks down on all of us. I just want you to know that, but thank you very much for your comments, which helped.
01:05
So, if you wanted to learn how to drive a car, you might be interested in a car, maybe you don't know much about them. I have a couple of friends of mine who are race car drivers, and you can ask them about this. And they could tell you what that spring does, what that nut does, what that thing does. They can
01:22
tell you all this stuff about engines, about fuel oil ratios, about gear ratios, about how brakes work. Hi, Ivar. All these things that by the time you're done, you might be intimidated as heck by this and say, I don't want to have anything to do with cars, this is scary. But the reality is, most of us know we just get in a car and drive. It's simple. We don't have to look under
01:43
the hood. And I've heard three primary complaints about Pearl Six. A, the length of time, can't knew much about that. B, the version number, can't knew much about that. C, the complexity, that's interesting. There's a lot of very complex languages out there, such as Pearl Five, C++, et cetera. The
02:01
reality is, most of what we do on a day-to-day basis, it's pretty easy in Pearl Six. And you'll understand some of that by the time we're done. But first, basic math. This is almost like a lightning talk before the actual talk, something very frustrating to me, because basic math, can anyone solve for X? Oh, come on. Okay, forget about computers. Forget about computers.
02:29
What is the value of X in this equation? What would your teacher have created you on? Okay, so since you folks are a little slow, X is 3.5. We
02:52
know that. We know that. Ruby doesn't think so. Python Two doesn't think so. TCL doesn't think so. BC is a wonderful tool. It's an arbitrary
03:06
precision calculator built into many systems, and it says three. So there's a bunch of one-liners I wrote to demonstrate this issue. In fact, I wrote a one-liner in C. As a matter of fact, we actually get a warning
03:26
about this. But no, C's type system sucks. C does not give us a warning. The compiler gives us a warning because, well, percent F in the format, that says double, but it expected an int. What's up with that? We switched that. Okay, fine. We got the three again. Purpose of
03:43
software is to help humans. It is not to help computers. I've actually argued with people. They've told me, no, three is the correct answer, because integer operand integer gives an integer. No, it does not. We know it does not. So always keep that in mind when you're thinking about software. Stop forgetting about what the computer does. Stop
04:02
thinking about the limitations of the computer. Think about what do I need as a human in order to solve my problems? And then sometimes the implementations are going to bite you, and that's frustrating. We'll actually see an example of that later. But software is there to help humans. Forget about integer math. So we know Pro 5 actually gets the right answer in this case. So you
04:27
know 7 divided by 2 in integer math gives you 3. What does negative 7 divided by 2 give you? If you know the answer, don't call it out. If you don't know the answer, use your intuition. What should it give you? Minus 3, minus 4. So
04:53
who here thinks minus 3 for integer math? Who here thinks minus 4 for integer math? A few more hands. Okay, so C, yeah,
05:06
minus 3. So all of you said minus 4 were wrong. What do these other languages all say? Well, Perl, we know, gets it right. Perl 5. And they say minus 4, minus 4, minus 4,
05:20
minus 3. So a room of very smart, intelligent people with a not difficult math problem were not able to reason what sort of answer they would get. So this is a junction. Yes, it's a superposition. So by the way, so C said negative 3,
05:44
except it's not that simple because if you're using C 89, the wrong answer that you get is implementation dependent. So you can have a perfectly correct program in C 89, ship it off to someone else, and it will fail for them just because they happen to use a different compiler.
06:02
Frustrating, to put it mildly. Let's do it again. First of all, does this look difficult for anyone? Okay, 0.1 plus 0.2 is 0.3. Minus 0.3 is 0. X equals 0. 0 equals 0.1
06:23
plus 0.2 minus 0.3. Forget about computers. Would your teachers in math class have said this is correct? Yeah. What does Perl think about this? That's a very small number. But it's not a small number in one sense,
06:45
because if you think about it in terms of math, there's infinite, in number theory, there's infinite many numbers between that and zero. In fact, in terms of something called L if null, there's as many numbers between that and zero as there are between 18 quadrillion and zero. Zero we know has special properties. So one divided by
07:02
zero is 18 quadrillion. That is an exceptional number. That is not an exception. Or let's multiply the mass of the sun by zero. That's 110 trillion kilograms, or as Enrico Fermi would tell us, roughly the size of Mount
07:21
Everest. Yes, as all of you suspected, Mount Everest is nothing more than a floating point error. I know the languages tend not to do any better, you know, Ruby, Python 2, TCL, BC. BC actually gets this right, but considering that it can't figure out seven divided by
07:40
three, you know, it's not very reassuring. And Pearl 6 says zero. If you're wondering what's going on, it's like, ooh, he just pulled a rabbit out of a hat. So floating point numbers, basically the way this is typically done in computers is they estimate the number that comes after the decimal point. You
08:01
have reciprocal powers of two, which wind up getting added up, the one, zero, zero, one, et cetera, to estimate what that number should be, to approximate what that number should be. And there's many things you can't get exact, which is why point one plus point two minus point three can't quite add up to zero in floating point math. Pearl 6
08:22
gets it right. How does it do this? I talked about the engine looking under the hood. Most of the time in this talk, I don't want to look under the hood. But this time, just to give you a little peek of what's going on, so here we've got divide by zero, which is, you know, we've got an exception exactly what we want. If you just type Pearl 6
08:41
at the command prompt, hit return, you're dropped into a simple REPL. Pearl 6, everything's an object, so you can call methods on them. There is the what method, which says it's a rat. It's actually, that means it's a rational number. There's a role called rational, which is why they can't call it a rat. So it has a numerator, three, a denominator, ten. Nude is a method on
09:02
rational numbers, which returns a list of the numerator and denominator. Pearl's just basically serialization, says, you know, it's kind of like data dumper, sort of. But it prints it out in a format that hopefully can be serializable. What's interesting is down at the bottom, that's 3.1415927 is sort of pi. And the reason I say it's sort of pi is
09:23
because, you know, pi is an irrational number. But now, instead of letting the vagaries of floating point mathematics choose how inexact it is, you can choose how inexact it is. So we're going to forget about that because most of the time, you just do your math and it's going to work for you. It's going to work nice and cleanly. The errors you
09:42
see in Stack Overflow, why didn't this work? Why couldn't I compare those floating point numbers? Why couldn't I divide these and, you know, get the right answer? Tiny little things like that, gone. Not all the time, but Pearl-6 tries really, really hard to be a language for humans, not for computers. But instead, I'm going to talk
10:01
about functions. Yes, reciprocal is a stupid function. This is someone who got really carried away with the idea of don't repeat yourself. But the reason I'm going to talk about functions is one of the most common classes of errors we have in computer programming languages today is that different pieces of your program have to talk to each other, which means generally you have to pass data back and forth. And you can unit test
10:22
everything to death, but if you don't integration test, if you don't test how things talk to one another, you're going to find all sorts of bugs. But you can't test exactly how everything talks to each other all the time because you've got the path problem, etc. So it's really nice if you have good control over what you're actually getting in there. So if you're not
10:41
familiar with Pearl-5, you might wonder what the shift is, and then you might really wonder what this dollar underscore zero or this, you know, this num equals shift or, you know, why do we have to use parentheses there? That's embarrassing. So you can write, you know, something analogous to all of those in Pearl-6. We don't want to do
11:00
that. That's really embarrassing. But before we talk about functions, not everyone likes the Fibonacci sequence as an example. Oh, this doesn't map to the real world, even though it really, really does. But I won't go into that. Why do we often use Fibonacci function when we are talking, teaching people recursion, teaching people how basic functions work? A, they're very, very easy
11:24
to map to the mathematical description of what the Fibonacci function is. So it's very easy to show them that way. It's easy to show the elegance of recursion with them. It's also very, very easy to understand them. It's very easy to describe them. And what problems do you have with recursive functions? You
11:41
might forget the base cases. Very common problem. That's a human problem. You might not validate your arguments well. That's a very common problem. That's a human problem. You might blow the stack via deep recursion. That's a very common computer problem. So you have all sorts of failure modes, which this incredibly simple thing can examine in
12:01
a simple function, which is why I like to use the Fibonacci series. And it's simple. So zero, one, you start with that, add those together, you get one, then one plus one is two, add that, append that, one plus two, three, et cetera. This is the Fibonacci series, which has fascinating mathematical properties I won't go into right now. Logarithmic spiral of our galaxy is based upon
12:20
Fibonacci spiral, by the way. So all sorts of neat stuff about that. And to write it, got a basic function signature, nth. The nth Fibonacci number, in this case, we're indexing from zero. So that's actually ninth. So given nth, when zero, zero, when one, one, this is like Perl, the last
12:40
statement evaluated or expression, whatever. When I say statement or expression evaluated, returns, yeah, whatever. Last thing you evaluate returns the number, returns its value as what you're supposed to get back. And here, Fib nth minus one plus Fib nth minus two, this is almost exactly the mathematical definition of Fibonacci numbers. Really simple, really easy. And
13:01
aside from that simple signature right there, that's how we'd write that in Perl five. And in fact, if you use modern Perl, like 520, use the experimental signatures. Signatures have been around before most of us were born. Use experimental signatures, use the given win statement in there. It
13:21
would be almost exactly the same. It might actually be exactly the same. Yeah, you need the parens there. So say Fib eight works. But now we have an infinite loop. We remembered our base cases of win zero and win one, but three point seven, well, that's not going to work because nth minus one and nth minus two will never hit
13:42
our base cases. That's kind of unfortunate. So we've got an infinite loop. It means we have to have an integer for nth. And how would we do this in Perl five? So this actually has a bug. This actually has a bug. This
14:01
actually has a bug. Every single one of those is buggy and there's plenty of other ways you can write that and most of those ways are going to have bugs. And it's such a pain to do that many developers just, they do what we do in dynamic languages. We say we're going to hope we got the right data and most of the time it works. And when it doesn't work, we have to figure out where that wrong data came from and we hope that it fails
14:21
rather than just silently corrupting our data. It's a pain. So all of those are actually buggy in different ways. And now we just slap an int on there and we say it's an integer and now this becomes a runtime failure. Not true. I'll explain in a moment.
14:40
So adding the int is what we call gradual typing in Perl 6. They're strictly optional. If you don't want to use them, don't. If you don't want to use them, put it on there and it's nice. That will be a runtime failure in Perl 6 except in this particular case. So when 0, 0, how does it know what when 0 means? Internally, as I understand
15:00
it, what happens is it calls the dot what method on 0, says it's an int, which must have the value of 0. So you can actually supply a subclass of int and I imagine it should still work. And then for one it does the same thing called dot what figures out it's an int, an int which must have the value of 1 so it knows to call this 1 or here. Here, when it checks this, because this
15:20
is hard coded, it's going to call dot what on 3.7. It's going to see the signature can't possibly match an int. This is actually a compile time failure. That code, it's not possible to run this code. It doesn't make any sense. You can't do it. So Perl's going to say no. This is what we call type inference. A magical thing. It's a
15:40
magical thing but it's simple. But it's still not there because now we can call negative 3. So negative 3 is going to be an infinite loop because the minus 1 and the minus 2 are never going to hit our base cases. So we just got a subset. Constraint type check failed for parameter int and negative 3. So what is
16:00
this? Where star? The asterisk is an example of the whatever class and I like to read that generally as whatever I got. Int int where whatever I got greater than equal to 0. You can't pass in a negative value because you'll get a constraint type failure. But this is
16:21
actually getting kind of clunky here. Int int where whatever I got greater than equal to 0. What if you have multiple parameters being passed to this sub? That's going to be frustrating. So you pull it out into a subset. Subset non negative int of int where whatever I got greater than 0, greater than equal to 0. And then we just declare this as a non negative int. In other words, basically declare
16:41
your own types on the sub and apply with an easy to read syntax and use them where you need them. Does this look like rocket science to anyone? Does this look to anyone in this room like it's so mind-bendingly complicated that it's just not going to fly?
17:03
It isn't. I am ramping up. But honestly, Perl 6 is a new language. It is a sister language to Perl 5 the way C Sharp is a sister language to Java. And I mean that in terms of also quality. That's really not hard. You do have to learn how to read a new language, but that's
17:21
simple. And then we get the constraint type failure. So signatures. For popular dynamic languages, I'll just call those dynamic languages after this. You know, mainly we're talking about Ruby, Python, JavaScript, whatever. You get maybe depending upon the language one through four, optional, entirely
17:41
optional. Basic ones, you just name the variable default. If you don't pass in foo, it'll have the value of 3. Named variables, you put a colon in front of that and then you call it by name, you value. Or there's another syntax for that, which I won't go into right now. Gradual typing, we slap a Boolean on there. That's
18:01
got to be a Boolean value you type in or else boom, you pass in or boom. And then subconstraint string name where whatever we got, cars greater than zero. So the last two generally aren't available in the popular dynamic languages, but they're really easy in Perl 6. And optional. The
18:21
last one, I really like that last one, that this particular constraint subset, non-empty string of string where whatever we got, cars greater than zero. I hate, hate, hate all the time expecting to get a string and I have to check to see if it's an empty string. Here, I'm just writing my own type on the fly saying this better not be an empty
18:41
string and I just declare it there. I don't have to write a class, I don't have to jump through any hoops, I don't have to remember to check anymore do I actually have data in this string. And this is a common problem across many programming languages, not just the dynamic ones. And I know dynamic, static, rather loose, but bear with me on that. So I
19:00
also think, by the way, this I think will be the most popular subset declared in Perl 6, some variant of this to make sure you're getting non-empty strings. But I like this one, subset first name of string where zero is less than whatever we got cars, less than 256 sub first name blah. That I suspect will be very popular in ORMs where you need to map your
19:21
types directly to the constraints the database will allow. So if you have MySQL and you're not in strict mode or better and it has this nasty habit of truncating your data, don't worry, Perl 6 will protect you. I love MySQL, if you do any consulting on that it is a license to
19:40
print money, I swear. But it's slow, you start hitting Fibonacci numbers in the 20s and on up, particularly like 25, this really slows down to the point where it becomes unusable because we're blowing the stack with deep recursion. I'm
20:00
not going to walk through the recursion graph. I assume most of you are familiar with it, if you're not, I apologize. But basically we keep recalculating the same values over and over. One of the ways to deal with that is we cache the values. So a state variable will return its values in between sub calls. So we just have this cached state variable.
20:20
Unless cached nth exists, this colon exists is an adverb in Perl 6. Again, different language, you're going to have to learn some new syntax here. Unless cached nth exists, win 0, 0, win 1, 1, default cached nth is blah, and then we return the cached value. That's not too hard here, but if you start having
20:41
larger recursive functions, that gets to be a little bit annoying having to go through there and instrument everything to handle your caching. But every recursive function will be rewritten as an iterative function if you wanted to skip the caching. But now we started to lose the mathematical beauty of what we had in that, and that's now you can't just glance to that and say, oh, that
21:00
works. You now have to do a desk check or write a bunch of tests to say, is that actually doing what I wanted it to do because it's not the same structure anymore. Because remember, that was your mathematical structure that you had, and this is the body of the recursive sub. Those map really well together. It's very easy to follow. You want to keep that. So just slap
21:22
in this cache trait on there and it will handle the caching for you. You generally want to do that with pure functions. Given this value, it's guaranteed to return the same value every time, doesn't have side effects. You probably won't want to do that with a get customer method because the get customer might, the customer might
21:41
mutate in the meantime or anything which will change or has a lot of disk IO. But for pure functions, just slap is cached on there. It's an example of Perl 6 taking a very common problem that we face all the time and just building it into the language to say, here's a feature for you that you can use. Try not to cut yourself with it. So first
22:06
of all, is everyone with me so far? Yeah, this is not hard stuff. Most of this is basic. I'm just showing you how Perl 6 does it. So a lot of you folks know that I'm writing a text-based MMORPG in Perl, and
22:21
characters can travel to other areas of a space station. They can travel to other space stations. They can travel to other stars via wormhole jump gates. And this is my character travel to method. We're going to start moving into a little bit of OO. By the how am I doing on time? More than 15? Oh,
22:42
I'm doing better than I thought. Great. So this is actually my dispatching for, you know, if location is a station area, travel to station area, if location is a station, this is kind of a simplified version. But that comment, my kingdom for MMD, that is verbatim from my code. This
23:01
is, as I add more location types that you can go to, you know, having a bigger if-else-if chain, very frustrating. I could do this. I could slap a roll on our locations, if you're not familiar with rolls, I apologize. I could slap a roll on location and say if location does location and
23:21
location travel to character. This is unfortunate because now I'm using object-verb-subject syntax instead of subject-verb-object, which makes this harder to actually understand. So I might say location travel to by character when you have to contort yourself on method names.
23:40
That's a code smell. And in this case, the code smell is I don't think locations should know about characters. I'm coupling them too tightly. Locations should know, don't have to know anything about the characters traveling in them. I'm distributing the character knowledge too far. But characters do have to know about the locations they are traveling too. So I want the characters to have that knowledge. Reduce the coupling.
24:00
And in Perl 6, I would just do this. Multi-method travel to station area. Station star. Very simple. Many programming languages have this today. Here we're dispatching on type. Perl 6 will say what types of arguments do we have. And it will dispatch for you accordingly. It makes your code much simpler. And you don't have to worry about missing the
24:20
case of, you know, you can't travel to this location because we didn't find a type I should have had an is cache trait in there, but I wanted this to fit on the slide. So more than one way to do
24:40
it, obviously. Return types. That's another one. Very useful. So sub-foo returns bool. What is some other sub-return? In looking at this code, you cannot tell. It is not possible to tell just from this one line of code.
25:00
But what you know looking at this return type is if this returns anything other than a bool, this is going to blow up. So here say yes a foo yes is the desired behavior. If we tried to return a string, type check failed for return value, expect that's pretty easy. Where we're going to be writing
25:20
functions all the time and one of the most common classes of errors passing data around much easier to constrain the values return bool as I was guaranteed and some other developer comes along later and decides in this condition I'm going to return a string maybe an error message. Your
25:40
code will blow up as expected to protect you from having bad data. And of course you can use the subsets that you defined earlier. Sub foo returns non negative integer. You can have very complicated types you're declaring on the fly and assert them all over the place to make sure that you're not getting bad data passed around. You don't have to
26:00
keep writing that validation code all over the place. Or as I usually see with most of my clients they just don't bother to write the validation code and kind of hope it works. Now we're I talked about methods a little bit. Now we're going to look at classes. Classes are
26:22
where it's really going to be strange for you at times because some of the syntax will look a bit odd again new language but it's really impressive what you can do with them. And the choice of a point class might be a little controversial for those who are familiar with OO programming. This is not designed to show you OO programming. This is designed to show you
26:40
some features of pearl six so just keep that in mind. Class point has dollar point x this point is kind of a that's a secondary character punctuation mark is called a twigil in pearl six and the point just kind of helps you remember because we call methods with points is that's a attribute for that class
27:00
so has point x zero has dollar point y equals zero the equals zero is the default value if and the dollar point x this is what the instance value this is the instance variable you're going to have here's string overloading method string and i just return in
27:20
brackets dollar point x dollar point y my point point new x y say point x five say point y three let's say point in you know in a quotes for the string overloading you got five point three so that's okay so that you know dollar point that extra punctuation mark might look a little bit
27:41
strange but it's very purlish doesn't look too difficult i would think this is an immutable point object you can declare it you cannot change it maybe you want to change it here's the point where it's going to start looking a little funky so remember the colon in front of the variable means that this is a named variable so you
28:03
y three but we'll be using this on the set method down here and the equals the dollar point y means if we don't pass it in this is going to be the default value so down here we did not pass in x so it's going to retain dollar point x so if we don't pass in x to the set method it's going to retain whatever's value was so we can use set to set either
28:22
x or y and what the heck is that dollar point dollar bang x dollar bang y pearl six likes to make a lot of things immutable there's a lot of benefits to this there's a lot of safety to this won't go into this right now but basically if you want to
28:42
change these by default these are read-only attributes so you can expose them people can read them you cannot change them to change them use the internal form which has the bang which is like danger will robinson danger you're changing the internals of this but now you set x and or y and you can say point down here we see 517 this actually worked appropriately
29:07
so the syntax takes you a bit to get used to it it's really not hard once you understand what's actually going on but you can you can actually set y to foo so we already know about gradual
29:20
typing in pearl six so just declare y is a real if you want to now if you try and set y to boom it'll blow up no extra work for validation it works as you expect it to work but uh i'm now declaring those with read write and getting rid of that set method because the reality is the cartesian plane the x and y values can be any of infinite values depending
29:43
upon what your computer can actually support and now since we know it can be any real value whatsoever why not let people set it directly to real values and you can say point dot y equals 17.3 and it works we've now exposed the attributes we've got a little bit of type safety there
30:04
so some of the languages don't they recommend you don't expose these values but remember you can declare subsets to get much much finer grain control over what you allow so it's easier to expose stuff if you want to again i'm not saying this is a perfect example it's just showing you some of the power of what we have here so i might say x and y can only be from negative
30:23
10 to 10 so subset point limit of real where negative 10 less than equal to whatever we got less than equal to 10 then has point limit and now if i set that to negative 17. now if i set that 17.3 it again blows up as we expect so i'm gradually building all of this stuff up
30:43
so we'll get to the conclusion in just a moment does anyone have any questions at this point i think we've got the time for it i'm sorry that means it's read right now my apologies i probably glossed over that too fast attributes in pearl six by default are read only for safety
31:06
and also i believe there's some performance benefits to that here we're deliberately saying it's read right so you can go ahead and try and set the value even though we've set the value to a legal value and then we've got the defaults of equals zero but those defaults
31:21
don't make sense why should a point object start at the origin so we can now simply say equals die dollar dot x is required or dollar dot right y is required this actually generates a closure it's not evaluated at the time this equals so this will only be evaluated if you didn't pass in a value for x or y so now we've made these required you cannot instantiate an invalid object
31:47
and we can't set it to an invalid value here i'm doing negative 10 dot dot 10 the dot dots a range operator pearl six is smart enough to realize subset point limit of real where negative 10 to 10 means the same thing as that version so that's another way of writing that
32:08
constraint or you know if i wanted to get kind of silly here i could drop the of real and say negative 10.0 to 10.0 i didn't say subset point limit of what pearl looks at the point
32:22
zero looks at the hard-coded constants and uses those to figure out what type we have type inference yes yes that's going to be a rat i've already tested it it does effectively behave the way you want it to that was something i was hoping to not go into discuss the differences between
32:40
real and rat here in reality i probably would not do this i'm just trying to show people some of what's available on this i would probably be a little more explicit and use the of real until i start feeling more comfortable with what's going on i'll try and get your question afterwards because i want to make sure how how am i doing for time actually okay what's
33:08
your question no sometimes they're forced to compile time this it's pearl it's a late mining language but there are times when pearl can detect where something cannot work if you
33:25
have a hard-coded constant you know 3.7 and you try and pass it to a function which only accepts an int it will know this at compile time correct me if i'm wrong but it's my understanding that there's possible plans of doing more with type inference in the future but the concerns
33:42
are making it so that we have human readable error messages is this correct yes so yes they're cautious about it because it is problematic but the power the potential is there so so
34:10
i have showed the negative 10 to 10 so here i notice up here i'm getting rid of the string method i don't like this string overloading so instead i'm just going to say say point pearl
34:21
and i get the serialized version point new x 5 y 7.2 now let's stop just for a moment and think about what we have here ignoring the class declaration i have three lines of code they're actually pretty easy lines of code to read i've declared basically a new type with
34:41
constraints on the fly i've declared the two attributes for the class i've made them mutable and i've made them required they have to have default values does this look really hard to read i'd given the fact that it's a brand new language that it's not pearl not pro 5 does this
35:00
look hard to read three lines of code here it is in corporal 5 that's effectively the same thing in corporal 5 those three lines of code but we know we don't use corporal 5 objects anymore so there's moose so moose is still a little bit more painful oh there's c++ there's java
35:29
there's python 3 what's that no that that that legitimately was java on that one so python 3 um can't really declare type so there's a class up there to simulate that
35:47
there's javascript ruby my favorite was go i had to shrink the font size in order to get this to fit on the darn slide because go um it may be a wonderful language but oh my goodness it's verbose
36:01
look at that just that is very powerful very expressive and it's simple it's really not that hard it's a new language it's like if you don't know how to speak french you're gonna have trouble speaking french i speak french but not fluently so occasionally i struggle when i read it
36:23
but i'm getting better that's what happens with the new programming language but nothing i've shown you is hard and one of the heart most painful classes of problems of passing data around is made so much simpler than pearl six so i love that example so for your day-to-day code it is more correct and it's safer you can actually enforce
36:48
constraints easily on how you're passing data to and from functions all the time this is part of the reason incidentally why a lot of static languages i use the term loosely there's a lot of tests that they often won't write because they know they don't have to test
37:02
what happens if that function return receives a string instead of an int because it's not allowed to so there's a lot of declarative stuff you can bake in there and there are fewer tests you'll have to write so pearl six it really is large there's there's no question about that a lot of people know about that but it is large language so is pearl five so c++ so so so many others
37:24
but the common features that we often need on a day-to-day basis particularly the things we fall down on they're baked into the language they're there for you it has proper oh oh i wish i could have dug into that a lot more but we only have so much time it actually is easy to read most of those examples once you understand what's going on they're not hard at all and as
37:46
i mentioned it's safer it's very powerful there's all sorts of resources you know here's just a few of them i was amazed when i was writing this hitting a free note talking to pearl six folks just how helpful they are in saying this is what's actually going on these are the
38:02
things you can do it was just it was a wonderful experience i thought i was going to be bugging them too much like no no we love to talk about this i do have bonus slides i could whip through real fast or i could take a couple of questions bonus slides or questions every time
38:24
i ask that question people always pick slides you fools so this is the part which tends to scare people this is an infinite lazy list of we're going to get all prime numbers from one to whatever basically infinity and we're going to assign it to those constant primes we can declare
38:43
constants it's going to be immutable so say all the primes up to 10 we get all the prime number the first 10 prime numbers and pearl six tries very hard to make sure all your lists are lazy there's all sorts of benefits to that make sure your lists are lazy when appropriate if we don't have an invicant in front of the dot it calls it on the topic dollar underscore
39:04
so that's what's happening with this and the first 10 primes are calculated the rest will not be calculated unless needed so if you're iterating over the infinite list of primes until you're looking for a prime which fits your property you can declare it like this and then it'll just break out when you need it to so lazy lists they're very handy but you know constant
39:24
you know having that very that sigil in front is kind of ugly so you can go ahead and drop that if you want to here's a common how much time do i have left oh awesome so here's a problem
39:40
uh this actually happened to me when i was a junior programmer it was kind of embarrassing so you know writing a simple filter um and we just want to print the lines from a file matching stuff so this junior programmer like me the idiot writes a little eight line file runs it through here works great and then hits that 45 gigabyte file in production and it bombs can anyone tell me why for each what what is special about free yes it slurps slurps all of
40:12
it in so in pearl six my file handle equals open file there's other ways you can write this this being pearl but this is lazy you can go ahead and read that huge file because it's
40:24
automatically lazy so in many times the distinction between while and four kind of goes away so in pearl five four reads and lists which automatically flatten while tends to use iterators here just that's lazy say line if line smart match whatever a regular expression
40:41
or you know we can write it a little more compact we can just filter it directly not even worry about the rest line and just say the line so lazy list they're just a wonderful thing the fibonacci numbers you saw earlier yeah this part hurts people so now we have three dots
41:03
instead of two that's uh a sequence generator is that the name think sequence operator instead of a range operator it's a sequence operator and it knows how to generate a sequence of numbers we'll explain what the heck this means in just a moment saying fibonacci is up to them again lazily calculates fibonacci sequence yeah what the heck is that whatever we got plus
41:25
whatever we got dot dot dot whatever you do so sequence operator is an arithmetic sequence if we have two numbers there then it's going to say it's an arithmetic sequence and it will be able to figure out how to lazily calculate that say the first 10 numbers of this arithmetic sequence
41:42
0 2 4 6 did i get 2 8 no so that's pretty simple so does this kind of make sense 0 2 we're going to generate a sequence up to whatever we happen to need it looks strange but it works and it's lazy so it won't calculate that off to infinity
42:03
but if you have three numbers up front this is a geometric sequence and pro six will figure out what you need there so two four eight dot dot dot two up to whatever we need we say in our sequence up to the first 10 numbers two four eight blah up to 1024 anyone recognize that geometric sequence
42:24
yeah it comes in kind of handy sometimes that was awful but sometimes the sequences we need like fibonacci are a little bit more complicated than this so we can do something like this we have this arrow what is this arrow we have a b
42:46
a plus b sequence generator so this is actually this is a pointy block this starts a sub here are the parameters the sub is going to take a plus b so it knows the next first thing first two things you had before it in the list are going to be added together to generate the
43:03
next item and then you'd have the one in the one added together generate the next item which is a two then you add the one and the two added together generate the next item this is how you generate a complex sequence if it has you know this regular format you might notice this pointy block isn't that what we saw after a four declaration that's the exact same syntax as
43:24
what you have on the four pearl reuses that syntax a lot so get used to it so you saw this on the four array arrow you know the arguments are taking off there the block of the for loop that's the same thing sequence generator f2 whatever we need but we can simplify that in this case this generates an anonymous closure on the fly and
43:45
the whatever we got whatever we got is the first and second argument up to the whatever whatever we got zero one added together makes one the one in the one added together makes two the one of the two added together blah blah that is how that infinite fibonacci sequence
44:02
is generated very simply and this is the sort of stuff which scares people scared me when i first saw it it took me a while to understand once i did it's like oh that's actually not hard that's part of the language we're going to be learning about as we dive into it more which we can't today at least not with me
44:21
this is some of the stuff which kind of scares people when they see the pearl six enthusiasts talking about uh you know stephan earlier when he was talking about inline pearl five and stuff like that it's like that looked kind of scary to some folks but day-to-day i mean it's wonderful stuff but day-to-day that's not what you're actually going to be using most of the time or it's going to be abstracted away behind the scenes for you the simple stuff yeah it's easy yes well people who use css anyway or
45:05
never mind what do you mean by how stable is the runtime stable has
45:23
i cannot comment on that i'm talking more about the usage but anyone else if you needed to run for a year i probably wouldn't use pearl six yes those are uh those are traits
45:54
which you can apply to things which can modify their behavior it does look a little strange because you can say class dog is mammal and the term is is
46:04
overloaded there it might be a trait it might be a parent class so that's one thing you'll have to get used to but traits are something you just slap on stuff and it can modify how their behavior is and in fact you can open up the source code most of it's written in something called nqp which is a little bit more dense a little bit harder to understand
46:22
but you can actually read through them to see how they're implemented yeah oh it's not nqp oh i apologize thank you uh do i have time for another question okay yes yes constraints
46:51
over multiple variables uh so but every successive one has to be greater than the prior one
47:15
yeah that that shouldn't be a problem because right there i have the star plus star i'm assuming
47:20
i can it should be easy to put you know star less than star put a constraint and then modify it on the fly but or when i'm going back to the where constraints yeah that shouldn't be hard i don't know the exact syntax of throwing the exception on that but that shouldn't be hard uh yeah what's the scoping on that
47:57
okay i've got one minute left so i think that's uh does anyone have an easy question i can
48:03
answer in 60 seconds unless you have 55 seconds left yes uh um you can you can foresight just
48:21
call it a real call it a numb okay okay thank you