diff options
Diffstat (limited to 'content/posts/2018/2018-02-05-why-perl6.md')
-rw-r--r-- | content/posts/2018/2018-02-05-why-perl6.md | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/content/posts/2018/2018-02-05-why-perl6.md b/content/posts/2018/2018-02-05-why-perl6.md index 4be3965..8938b49 100644 --- a/content/posts/2018/2018-02-05-why-perl6.md +++ b/content/posts/2018/2018-02-05-why-perl6.md @@ -18,7 +18,7 @@ make me like Perl 6, and why I try to use it wherever possible. Whet creating an application, you usually want to be able to specify some arguments at runtime. Most times this happens using command line arguments or options. Perl 6 allows you to specify these in the -[https://docs.perl6.org/language/functions#index-entry-MAIN](`MAIN`) subroutine +[`MAIN`](https://docs.perl6.org/language/functions#index-entry-MAIN) subroutine signature. For instance, if I want the application to accept two string arguments, I can @@ -49,7 +49,7 @@ sub MAIN ( By default, if there's a `MAIN` available in your Perl 6 program, but the arguments or options supplied by the user are incorrect, it will display the right way to invoke the command, called the -[https://docs.perl6.org/language/functions#index-entry-USAGE](`USAGE`). +[`USAGE`](https://docs.perl6.org/language/functions#index-entry-USAGE). Ofcourse, this message can be changed if you wish, but the default is quite good for most use-cases. @@ -58,7 +58,7 @@ option is intended for. Just for a liitle bit of additional user friendliness. Fear not, for this is also already covered by the defaults. In Perl, there was POD to document your code. In Perl 6, we have -[https://docs.perl6.org/language/glossary#index-entry-POD](POD) as well. And +[POD](https://docs.perl6.org/language/glossary#index-entry-POD) as well. And these comments can be inspected at runtime to provide the user some information. And that's exactly what the default `USAGE` also does. So if you want to add some helpful comments to the arguments or the program itself, @@ -100,13 +100,13 @@ my $a = $r² ÷ π; Now, if you're thinking "that looks neat, but how am I ever going to write these?", do not worry. Most operating systems and many editors have tools to let you input these. For instance, using `vim` with -[https://github.com/vim-perl/vim-perl6](`vim-perl6`), you can just write "pi" +[`vim-perl6`](https://github.com/vim-perl/vim-perl6), you can just write "pi" and hit space (or type any non-alphabetical character). But not everyone is using an OS or an editor that makes it easy. And for those -people, Perl 6 simply supports using -[https://docs.perl6.org/language/unicode_ascii](ascii based operators). The -previous block could also be written as follows: +people, Perl 6 simply supports using [ASCII based +operators](https://docs.perl6.org/language/unicode_ascii). The previous block +could also be written as follows: ```raku my $a = $r ^ 2 / pi; @@ -121,7 +121,7 @@ easily don't have to wait for this future, Perl 6 already supports it. Multi-core processors are virtually everywhere these days. Yet many programming languages still don't support multithreaded application development natively, if at all. In Perl 6, running something in a different thread is as easy as -wrapping it in a [https://docs.perl6.org/routine/start](`start`) block: +wrapping it in a [`start`](https://docs.perl6.org/routine/start) block: ```raku start { @@ -129,13 +129,13 @@ start { } ``` -`start` returns a [https://docs.perl6.org/type/Promise](`Promise`), which you can +`start` returns a [`Promise`](https://docs.perl6.org/type/Promise), which you can store in a scalar variable just like any other object. You can check on whether the `Promise` has completed already and check whether it died, for instance. Other aspects which can often be spread over multiple threads are loops or maps. For instance, consider the following -[https://docs.perl6.org/routine/map](map) function: +[`map`](https://docs.perl6.org/routine/map) function: ```raku @cats.map: { @@ -146,7 +146,7 @@ maps. For instance, consider the following This will pat each cat in turn, in the order they appear in the list. But you can speed up the patting process by patting multiple cats at the same time. And to get there, all you need to do is add a -[https://docs.perl6.org/routine/race](`race`): +[`race`](https://docs.perl6.org/routine/race): ```raku @cats.race.map: { @@ -157,7 +157,7 @@ to get there, all you need to do is add a This will attempt to pat the cats over multiple threads, speeding up the process to pat all the cats. If the result of the pattings needs to be in the same order as the patting order, you use -[https://docs.perl6.org/routine/hyper](`hyper`) instead of `race`: +[`hyper`](https://docs.perl6.org/routine/hyper) instead of `race`: ```raku @cats.hyper.map: { @@ -171,7 +171,7 @@ Object oriented programming seems to be getting out of fashion with the new generation of developers. But it's still in wide use, being taught at most universities, and is often easy to explain to new developers as well. -And Perl 6 has [https://docs.perl6.org/language/classtut#index-entry-OOP](OO) +And Perl 6 has [OO](https://docs.perl6.org/language/classtut#index-entry-OOP) support built into its core: ```raku @@ -188,7 +188,7 @@ class Foo ``` You can also have -[https://docs.perl6.org/language/glossary#index-entry-Multi-Dispatch](multi-dispatch) +[multi-dispatch](https://docs.perl6.org/language/glossary#index-entry-Multi-Dispatch) methods on your classes, which are methods with the same names, but accepting different arguments or argument types. For instance: @@ -210,8 +210,8 @@ class Foo ``` Which method is being used will be decided by the type of argument is being -passed in, in this case either a [https://docs.perl6.org/type/Str](`Str`) or an -[https://docs.perl6.org/type/Int](`Int`). +passed in, in this case either a [`Str`](https://docs.perl6.org/type/Str) or an +[`Int`](https://docs.perl6.org/type/Int). ## Functional programming @@ -221,10 +221,9 @@ well. You've seen the `map` example already while patting cats earlier, for instance. But there's much more on the functional playing field, such as the -[https://docs.perl6.org/routine/==%3E](`==>`) operator, known as the -[https://docs.perl6.org/language/operators#infix_==%3E](feed operator). It -simply passed the output of a statement as the last argument to the next -statement: +[`==>`](https://docs.perl6.org/routine/==%3E) operator, known as the [`feed +operator`](https://docs.perl6.org/language/operators#infix_==%3E). It simply +passed the output of a statement as the last argument to the next statement: ```raku @grumpy-cats |