|
|
Subscribe / Log in / New account

An interview with Larry Wall (LinuxVoice)

LinuxVoice has an interview with Perl creator Larry Wall. "So I was the language designer, but I was almost explicitly told: 'Stay out of the implementation! We saw what you did made out of Perl 5, and we don’t like it!' It was really funny because the innards of the new implementation started looking a whole lot like Perl 5 inside, and maybe that’s why some of the early implementations didn’t work well."

to post comments

An interview with Larry Wall (LinuxVoice)

Posted Jul 15, 2015 10:43 UTC (Wed) by juliank (guest, #45896) [Link] (193 responses)

Oh please, keep the linguists away. Perl 6 is a joke.

Programming languages should not be like natural languages. Natural languages are completely fucked up disaster. A programming language should allow me to explicitly write down what I intent my program to do (or how to do it). It should not have dozens of shortcuts and different ways to say the same thing, like that Perl 6 abomination.

An interview with Larry Wall (LinuxVoice)

Posted Jul 15, 2015 11:26 UTC (Wed) by rsidd (subscriber, #2582) [Link] (149 responses)

It should not have dozens of shortcuts and different ways to say the same thing, like that Perl 6 abomination.
Isn't that also Perl 5's motto? ("There's more than one way to do it") I agree with your point, programming languages should be about precise, unambiguous communication. So I'm not convinced by Larry Wall's comments on natural language. My view is Perl was useful when there was nothing else, but since Python (and to a lesser extent Ruby) came along, far fewer people learned Perl out of choice.

An interview with Larry Wall (LinuxVoice)

Posted Jul 15, 2015 12:23 UTC (Wed) by khim (subscriber, #9252) [Link] (148 responses)

Perl was useful (and is useful) as WORN (write once, read never) language. Many way to do the same thing make it really easy to write something but make it really hard to understand what someone wrote and sometimes even hard to understand what YOUR wrote few years back.

It does not mean perl is completely useless, it just means it's niche is small.

An interview with Larry Wall (LinuxVoice)

Posted Jul 15, 2015 17:32 UTC (Wed) by b7j0c (guest, #27559) [Link] (3 responses)

All languages tend to WORN. You might be able to discern basic Java syntax, but can you determine all of the APIs and interfaces buried underneath? You might be able to tell me the type of a Haskell function, but can you tell me about the implications for lazy evaluation? Are you sure you have all cases of C undefined behavior memorized?

Parsing syntax is like 1% of the problem of dealing with most codebases.

An interview with Larry Wall (LinuxVoice)

Posted Jul 16, 2015 1:12 UTC (Thu) by marcH (subscriber, #57642) [Link] (2 responses)

> Parsing syntax is like 1% of the problem of dealing with most codebases.

This is quite like saying the CEO matters only for 0.001%, since he's just one guy among 100,000 others.

An interview with Larry Wall (LinuxVoice)

Posted Jul 19, 2015 21:26 UTC (Sun) by branden (guest, #7029) [Link] (1 responses)

"This is quite like saying the CEO matters only for 0.001%, since he's just one guy among 100,000 others."

That's a rather generous estimate of the marginal product of a CEO.

An interview with Larry Wall (LinuxVoice)

Posted Jul 19, 2015 21:30 UTC (Sun) by marcH (subscriber, #57642) [Link]

:-)

"matters" != "products"

An interview with Larry Wall (LinuxVoice)

Posted Jul 16, 2015 15:21 UTC (Thu) by nevets (subscriber, #11875) [Link] (140 responses)

I know I'm part of that niche. I have perl code from 10 years ago that I go back and still understand. Of course, my code uses a small subset of perl, thus it stays rather readable (I had a python coder once tell me that my perl code was the first perl program that he could understand).

I'm a big fan of C, and I try to program perl like C code, which is probably why I never could get use to python. I developed in python for 6 months and it never caught on to me. In fact, I have a much better time understanding my perl code than I do my python code ;-)

I maintain a few perl files in the Linux kernel, and I've refused to take patches that make them more "perl like". I try to keep them as C like as possible, as that keeps them readable. You can have a look and give your own opinion:

scripts/recordmcount.pl
scripts/kconfig/streamline_config.pl
tools/testing/ktest/ktest.pl

An interview with Larry Wall (LinuxVoice)

Posted Jul 17, 2015 10:34 UTC (Fri) by khim (subscriber, #9252) [Link] (139 responses)

It's possible to write readable code in any language, even in perl. Note that I've said "sometimes" it's even hard to understand code that your wrote few years back for a reason: I hear these horror stores about code one wrote then couldn't understand few years down the road very often yet I've never personally encountered that phenomenon - I only have trouble understanding code I wrote years or decades ago if someone else refactored it and made it "better" in the interim period and in that case problem is obviously in that someone else.

The perl's sin is in it's very destructive TIMTOWTDI idea. You can ignore it, try to use the freedom which perl gives you as little as possible, reject all patches which make your code more perl-like and so on, but then... what's the point? You'll be happier with python or even C. But if you embrace it and, even worse, start using it as an expression tool you make it impossible to extend your code while keeping it suitably stylized. Just like it's impossible to imitate Terry Pratchett style it'll be impossible to imitate your perl style! While it may be good for literature (it helps to sell your books) it's not all that good for programming (where people are supposed to be able to work on the same code together).

An interview with Larry Wall (LinuxVoice)

Posted Jul 17, 2015 11:04 UTC (Fri) by nevets (subscriber, #11875) [Link] (138 responses)

Well there has been other peoples' perl code that I had to work with and had no issue with understanding what they were doing. But I know more perl syntax than what I write. I'm more concerned about C programmers understanding my perl code.

As I said, I've used python heavily for 6 months and honestly I hated every minute of it. I hate python as much as people hate perl. I could not get use to the index only style of blocks. I need that visual to see the end of the block otherwise I start confusing which ones end where, especially when there's large blocks of if then elses used. It's also rather verbose in english words, which reminds me of COBOL. I had a discussion with someone before how some minds work better when dealing with mathematical syntax while programming, and less so with english words. I happen to be one of those, and people like me, usually prefer the perl way of doing things.

Note, my preferred language is C, which is another reason I like perl, as it looks more like C than python does. I use perl when I need to do file parsing or more complex shell scripts. But other than that, I have more C programs written than with any other language. I also will write bash scripts if I don't require parsing for simple tasks.

An interview with Larry Wall (LinuxVoice)

Posted Jul 17, 2015 11:12 UTC (Fri) by juliank (guest, #45896) [Link] (10 responses)

Python is more mathematical than Perl in syntax. Python does not have many keywords, not sure where you get the impression. Sure, there's and and friends instead of symbolic operators, but mathematics use words here too, and not symbols.

An interview with Larry Wall (LinuxVoice)

Posted Jul 17, 2015 11:55 UTC (Fri) by nevets (subscriber, #11875) [Link] (9 responses)

I don't know. I guess I just like:

 while (<>) {
    print;
 }

over

 for l in sys.sdtin.read():
     sys.stdout.write(l)

Whenever I write in python, I always feel like I'm writing too much.

Please note, this is my own opinion. I have no problem with other people preferring python, but it really pisses me off when I tell others that I prefer perl and they keep trying to convince me that I'm wrong and should prefer python.

An interview with Larry Wall (LinuxVoice)

Posted Jul 17, 2015 11:58 UTC (Fri) by juliank (guest, #45896) [Link] (1 responses)

Yeah, input/output is slightly more verbose. I was more thinking about calculations and stuff:

for i in ...:
[x for x in range(a, b)]
(a and b) or c

are all similar to standard mathematical notation.

An interview with Larry Wall (LinuxVoice)

Posted Jul 17, 2015 12:12 UTC (Fri) by nevets (subscriber, #11875) [Link]

Well, Perl has similar notation:

  foreach $x (@array)

  open(IN, "file") or die "could not open file";

An interview with Larry Wall (LinuxVoice)

Posted Jul 17, 2015 14:04 UTC (Fri) by raiph (guest, #89283) [Link]

say lines # Perl 6 equivalent

An interview with Larry Wall (LinuxVoice)

Posted Jul 18, 2015 14:06 UTC (Sat) by lordsutch (guest, #53) [Link] (4 responses)

You could simplify that Python example substantially:
for line in sys.stdin:
    print(line)

An interview with Larry Wall (LinuxVoice)

Posted Jul 18, 2015 14:37 UTC (Sat) by jwilk (subscriber, #63328) [Link] (3 responses)

And then you get extra LFs between the lines.
But hey, it's stil better than nevets's code, which doesn't even work. ;-)

An interview with Larry Wall (LinuxVoice)

Posted Jul 18, 2015 23:03 UTC (Sat) by nevets (subscriber, #11875) [Link] (2 responses)

Note, I tested that code on one box and typed it in manually in here. I accidentally transposed two letters so it didn't work.

for l in sys.sdtin.read():
     sys.stdout.write(l)

Better?

An interview with Larry Wall (LinuxVoice)

Posted Jul 18, 2015 23:08 UTC (Sat) by juliank (guest, #45896) [Link] (1 responses)

That's pointless anyway, why would you want to read() everything into memory (read() gives you a string of all file contents!), and then print it out character-by-character.

lordsutch provided the correct example.

An interview with Larry Wall (LinuxVoice)

Posted Jul 19, 2015 0:10 UTC (Sun) by nevets (subscriber, #11875) [Link]

I was just trying to show the differences between styles of perl and python using identical programs. Note, lordsutch's program is not identical, as it adds a blank line between each output.

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 18:58 UTC (Fri) by raiph (guest, #89283) [Link]

What's the simplest way to get that fixed width code display? Are you having to use HTML mode to get it?

An interview with Larry Wall (LinuxVoice)

Posted Jul 17, 2015 11:21 UTC (Fri) by rsidd (subscriber, #2582) [Link] (126 responses)

My personal experience -- about 12 years ago I had no familiarity with a scripting language but had done some scientific programming in C, and had just moved into bioinformatic work where manipulating text files was important. I had a fairly simple-sounding task, my boss used perl and asked me to learn and use it, I struggled for a week. My colleague said try python, I took two hours to learn the basics and then the task was done in half an hour. Depends how your mind works I guess. (On that occasion I wanted nested lists -- it was the logical way to do it but I couldn't figure out how to do it in perl. Apparently it can be done but the syntax was not obvious to me and stackexchange etc weren't around yet.)

Today the thing python has that I can't do without is list comprehensions, and I refuse to use another language unless it has that (C excepted, but only when absolutely necessary). Haskell has them (in fact Python got them from Haskell) but Haskell is a bit too purist for me. Julia has them, but in a limited way (no guards) which makes it much less useful.

What I'd like to see in python is pattern-matching a la Haskell, Ocaml etc.

An interview with Larry Wall (LinuxVoice)

Posted Jul 17, 2015 11:25 UTC (Fri) by rsidd (subscriber, #2582) [Link] (10 responses)

Replying to myself, sorry. The other thing that python has (and haskell, julia, ocaml, etc, but not perl) is the read-eval-print loop. And thanks to ipython it's really easy to go back and forth between the REPL and the code editor -- prototype functions in the REPL and then paste them into your editor, or paste a function into your REPL and then modify it, etc... Can't imagine working without that. And the ipython notebook interface is awesome. These days python is simply in a different universe from perl.

An interview with Larry Wall (LinuxVoice)

Posted Jul 17, 2015 16:25 UTC (Fri) by raiph (guest, #89283) [Link] (8 responses)

> The other thing that python has (and haskell, julia, ocaml, etc, but not perl) is the read-eval-print loop ... These days python is simply in a different universe from perl.

Please note that the OP is an interview about Perl 6, not Perl 5.

Perl 6 has a REPL.

An interview with Larry Wall (LinuxVoice)

Posted Jul 18, 2015 12:59 UTC (Sat) by rsidd (subscriber, #2582) [Link] (7 responses)

Please note that the OP is an interview about Perl 6, not Perl 5.

No. It is an interview with Larry Wall. This thread is about natural language vs programming languages. One example from the interview:

"LV: When you started working on Perl, what did you take from your background in linguistics that made you think: “this is really important in a programming language”?
The question wasn't even about Perl 5, it was about Perl from the very beginning. Some other questions are about perl 6, but not relating to NL.

Regarding your various comments above about "perl 6 can do this", like it or not, nobody uses perl 6 for serious work today. And it's not because of inertia or resistance to new languages (perl 6 seems to be a new language very different from perl 5): languages like Lua, Erlang, Go, Scala, Rust, Julia have all picked up followings in just the past few years. Python 3 too sees slow adoption but that is indeed because of inertia: it is mostly the same language as python 2 and people are switching over, but slowly.

An interview with Larry Wall (LinuxVoice)

Posted Jul 18, 2015 17:37 UTC (Sat) by raiph (guest, #89283) [Link] (6 responses)

> No. It is an interview with Larry Wall.

It's an interview with the creator of Perl 6:

PERL 6 HAS BEEN 15 YEARS IN THE MAKING, AND IS NOW DUE TO BE RELEASED AT THE END OF THIS YEAR. WE SPEAK TO ITS CREATOR TO FIND OUT WHAT’S GOING ON.

Larry seems happy to answer questions that aren't *obviously* about Perl 6 but I think you're mis-characterizing the interview overall. Did you notice that Perl 6 was the explicit or implicit topic of all four pull quotes?

> This thread is about natural language vs programming languages.

It does look like participants think that's what it's about. Most of it reads to me like prejudicial, overly simplistic, and often rude dismissals of the applicability of linguistics to programming language design.

> Regarding your various comments above about "perl 6 can do this", like it or not, nobody uses perl 6 for serious work today.

The same nobody I read about that's (not) using Python 3?

Is the guy who wrote "Used Perl 6 at a client to do static analysis of other languages, aiming to find hopefully-dead code and instrument it with logging. Confidently threw away over half a million lines in a 3 million line codebase." a nobody or is it just that the work he did and got paid for wasn't serious?

Yes, afaik, very few folk are using Perl 6 (which hasn't yet hit 6.0) for serious work today, far fewer than are using Python 3 (which hit 3.0 several years ago). I don't expect that to change much this year, and perhaps next year too, but there are good reasons to expect Perl 6 take up to occur much more quickly than Python 3 take up.

An interview with Larry Wall (LinuxVoice)

Posted Jul 19, 2015 4:54 UTC (Sun) by rsidd (subscriber, #2582) [Link] (5 responses)

(a) no need to shout, (b) it says
At FOSDEM 2015 in Brussels, we caught up with Larry to ask him why Perl 6 has taken so long (Perl 5 was released in 1994), how difficult it is to manage a project when everyone has strong opinions and pulling in different directions, and how his background in linguistics influenced the design of Perl from the start.
Ie, one of the three topics was perl 6, one was project management without specific reference to perl 6, and one was on the design of Perl from the start. This subthread is very much on-topic and is not specific to perl 6.

An interview with Larry Wall (LinuxVoice)

Posted Jul 19, 2015 15:20 UTC (Sun) by raiph (guest, #89283) [Link] (4 responses)

For the sake of sane discussion let's go with your view that the overall interview topic was not Perl 6 despite the headline (quoted above).

Even if the article was not about Perl 6, would you at least be willing to acknowledge that in your comment contrasting Python with Perl in relation to a REPL (the one that ends "These days python is simply in a different universe from perl") you accidentally or deliberately excluded Perl 6 from consideration?

----------------------------------------------------------------

> (a) no need to shout

If that's deadpan humor, well done. :)

Let's use Perl 6 to ftfy:

>>> print tclc "PERL 6 HAS BEEN 15 YEARS IN THE MAKING, AND IS NOW DUE TO BE RELEASED AT THE END OF THIS YEAR. WE SPEAK TO ITS CREATOR TO FIND OUT WHAT’S GOING ON."

>>> Perl 6 has been 15 years in the making, and is now due to be released at the end of this year. we speak to its creator to find out what’s going on.

Unfortunately that doesn't quite work. The `tclc` function acts on a single string (converting the first character to title case, the rest to lowercase), which is great as far as it goes, but this fails to title case the "w" in the "we" at the start of the second sentence of the Linux Voice headline, so, switching to OO phrasing:

>>> "PERL 6 HAS BEEN 15 YEARS IN THE MAKING, AND IS NOW DUE TO BE RELEASED AT THE END OF THIS YEAR. WE SPEAK TO ITS CREATOR TO FIND OUT WHAT’S GOING ON.".split(". ")>>.tclc.join(". ").say'

>>> Perl 6 has been 15 years in the making, and is now due to be released at the end of this year. We speak to its creator to find out what’s going on.

Is that better?

An interview with Larry Wall (LinuxVoice)

Posted Jul 19, 2015 17:04 UTC (Sun) by rsidd (subscriber, #2582) [Link] (3 responses)

Even if the article was not about Perl 6, would you at least be willing to acknowledge that in your comment contrasting Python with Perl in relation to a REPL (the one that ends "These days python is simply in a different universe from perl") you accidentally or deliberately excluded Perl 6 from consideration?
I was not aware that perl6 (a) was in production use (b) had a REPL. Good to know this. Regarding the universe remark, my python universe consists, in addition, of
  • ipython, including the notebook
  • numpy+scipy
  • matplotlib
  • cython
  • and occasionally other packages.
I have nothing against perl6 and will be happy if it has equivalents to all of the above, or will one day.

Note that the notebook interface these days (called JuPyter) is not python-specific: it works with R, Julia, Haskell, Ruby too. Note also that all of the above work fine with both python2 and python3. And they are just what I happen to use -- there are many vastly sophisticated python-based systems out there and nearly all of them have been ported to python3.

An interview with Larry Wall (LinuxVoice)

Posted Jul 19, 2015 23:59 UTC (Sun) by raiph (guest, #89283) [Link] (2 responses)

> my python universe consists, in addition...

Perl 6 was always supposed to interop with other universes in a friendly and intimate manner, including subsuming or being subsumed by other universes and using whatever bindings are available to get stuff done.

For example, with this class installed:

unit class Matplotlib;
use Inline::Python;
has $!py;
submethod BUILD() {
$!py = Inline::Python.new();
$!py.run('import matplotlib.pyplot')
}
method FALLBACK($name, *@x) { $!py.call('matplotlib.pyplot', $name, @x);

one can write:

use Matplotlib;

given Matplotlib.new {
.plot( ... a suitable data structure ...);
.ylabel('a string');
.xlabel('another');
.show;
}

Thus writing code in Perl 6 that uses Python libraries as if they were native Perl 6 libraries.

For a bit more explanation and discussion of this particular example see https://www.reddit.com/r/perl6/comments/399o82/python_mat...

I think this 3 minute video of the birth about a year ago of the Inline::Perl5 module (which was followed a few months later by Inline::Python, Inline::Lua etc.) is wonderfully heart-warming and technically impressive regardless of any like or dislike of the extremely complex looking Perl 6 code that it demonstrates: https://www.youtube.com/watch?v=m_Y-lvQP6jI&list=UU7P...

More generally, Perl 6 features, together with the Inline:: modules, already quite nicely package up cross-language data marshaling and function/method calling so that one can use Perl 6 data structures, functions, and objects via several other languages/run-times and vice-versa, sanely handling exceptions raised in the distinct run-times, and sub-classing, in Perl 6, classes defined in the other languages.

I've found this already works well in Rakudo for C (eg calling number crunching libs) and Perl 5 modules from CPAN. I've watched a video of a talk by Stefan about using Catalyst, a Perl 5 web framework, as if it were a Perl 6 framework. Aiui this intimate interop is fairly close for C++ and Java too, though I've no sense of whether the latter will be production grade ready or not by this Christmas.

An interview with Larry Wall (LinuxVoice)

Posted Jul 20, 2015 6:47 UTC (Mon) by rsidd (subscriber, #2582) [Link] (1 responses)

That's nice. It would be even cooler if the preceding periods weren't required (ie if you could just inline python code within the {} braces, maybe with an additional "inline" keyword or something -- I don't see why it should be harder to implement than what you've already done). But it looks to me like perl 6 is trying even harder to be a kitchen sink than perl 5. At the same time, even perl 5 users have a significant learning curve for perl 6. So I'll be a bit surprised if it really catches on -- but time will tell...

An interview with Larry Wall (LinuxVoice)

Posted Jul 20, 2015 22:59 UTC (Mon) by raiph (guest, #89283) [Link]

> It would be even cooler if ... you could just inline python code

Heh. It sounds like you're thinking you'd rather write code in python even if you were learning Perl 6. :)

But sure, you can do that. If you look at the original example you'll see the `run` method; you just call that with whatever code you want.

I don't think there's yet any way to use inline python using the sugar discussed in the design docs, which goes something like:

{ use Python:<2>; ... python code goes here ... }

An interview with Larry Wall (LinuxVoice)

Posted Jul 17, 2015 16:42 UTC (Fri) by dashesy (guest, #74652) [Link]

The only way better than copy-paste to iPython is to return an object from main, add autorelaod to iPython's profile, then every time you change the code (in a proper editor/IDE) it gets reloaded and you can rinse and repeat until you are happy. This works with fairly complicated classes, and not just methods too.

An interview with Larry Wall (LinuxVoice)

Posted Jul 17, 2015 12:06 UTC (Fri) by nevets (subscriber, #11875) [Link] (112 responses)

There is definitely some things I will admit that python does better than Perl. I had to do some number crunching once, and python has a lot built in that makes that easy. "Use the right tool for the job" is something I try to do.

I was a heavy C programmer before doing any scripting. I started with sed and awk, and wrote a lot of tools with just those too utilities. Then I came across perl and it was sed and awk on steroids.

For almost all my work, I first use C. If I need to do some command line interfaces, I'll use bash scripting, and if I need to do string parsing or file manipulation, I use Perl, because nothing beats the power of perl's regex ability. But some people have issues with that because the syntax is very cryptic. As I had a strong sed background, I had no problem with the learning curve there.

At the second Linux World Expo, there was a panel discussion with Larry Wall, Linus Torvalds, RMS, Guido van Rossum, and Eric S Raymond as the moderator (I don't believe such an open source power group has ever shared the stage before nor since). Larry was talking about how Perl was the fastest growing language in China, and it was expanding very well there. Linus quickly responded with "Of course it's doing well in China, they are use to dealing with incomprehensible symbols". The crowd roared with laughter. :-)

An interview with Larry Wall (LinuxVoice)

Posted Jul 17, 2015 16:21 UTC (Fri) by rsidd (subscriber, #2582) [Link] (2 responses)

Nice! Speaking of incomprehensible symbols, take a look at the getopt()-style macros in the FreeBSD chat.c from earlier years (sadly, they got rid of it circa 2008 in favour of "standard" getopt; sadly, also, lwn doesn't seem to accept the PRE tag, which precludes me from cut-pasting without much tediousness).

Here are the getopt() macros (going off-topic)

Posted Jul 19, 2015 10:52 UTC (Sun) by pr1268 (guest, #24648) [Link] (1 responses)

/*************** Micro getopt() *********************************************/
#define	OPTION(c,v)	(_O&2&&**v?*(*v)++:!c||_O&4?0:(!(_O&1)&& \
				(--c,++v),_O=4,c&&**v=='-'&&v[0][1]?*++*v=='-'\
				&&!v[0][1]?(--c,++v,0):(_O=2,*(*v)++):0))
#define	OPTARG(c,v)	(_O&2?**v||(++v,--c)?(_O=1,--c,*v++): \
				(_O=4,(char*)0):(char*)0)
#define	ARG(c,v)	(c?(--c,*v++):(char*)0)

God help whoever had to update/maintain that mess. I consider myself a fairly knowledgeable C programmer, but even that code makes me cringe...

Here are the getopt() macros (going off-topic)

Posted Jul 19, 2015 13:15 UTC (Sun) by lsl (subscriber, #86508) [Link]

I regularly use a set of macros written in the same spirit (but in a somewhat clearer way). I like them for their simplicity. Also there's no runtime support necessary, so you can use them anywhere, really.

There's also a variant (from the Inferno operating system) that supports arbitrary UTF8-encoded Unicode codepoints as flag characters:
https://bitbucket.org/inferno-os/inferno-os/src/tip/inclu...

An interview with Larry Wall (LinuxVoice)

Posted Jul 17, 2015 16:57 UTC (Fri) by raiph (guest, #89283) [Link] (102 responses)

> I had to do some number crunching once, and python has a lot built in that makes that easy.

In the meantime Perl 6 has basic math right in places where python et al go wrong: https://news.ycombinator.com/item?id=9791211

I think it'll be years before the Rakudo implementation really shines the way the design does, but the Perl 6 language is designed to be significantly better for number crunching than Perl 5 and Rakudo will ship with some of those improvements in place by the end of this year.

An interview with Larry Wall (LinuxVoice)

Posted Jul 17, 2015 19:06 UTC (Fri) by juliank (guest, #45896) [Link] (25 responses)

That is just very wrong. In Python 3, 7/2 = 3.5 and -7/2=-3.5.

Yes, .1+.2-.3 = 5.551115123125783e-17, but that is the expected in almost any programming language. Even Haskell does this. If you want decimal floating point, use decimal floating point. If you want rational numbers, use the fractions module.

This form of floating point arithmetic is an industry standard and deviating from it by default does not mean your language is better.

An interview with Larry Wall (LinuxVoice)

Posted Jul 18, 2015 1:54 UTC (Sat) by raiph (guest, #89283) [Link] (24 responses)

/o\ The original slides the HN comment was based on don't contain the error, just my HN comment. I've replied to the nearest replyable comment to post a correction (https://news.ycombinator.com/item?id=9906188).

Yes, almost all languages convert values like 0.1 and 1/10 in to floating point approximations, including Haskell, Python 3, and Perl 5. It is indeed not the end of the world; one simply has to learn to expect that, and learn to explicitly use a factional/rational/decimal type when the loss of precision matters.

But the primary reason it's that way is that the performance boost of fp approximation was considered worth the loss of precision and consequent violation of the principle of least surprise for naive users -- and that rationale hasn't held water for contemporary computer chips for years.

So, while it isn't the end of the world to work with the old ways of thinking, I expect robust new languages to trend toward, by default, automatically maintaining full precision (modulo range limits) for literals like 0.1 or 1/10.

An interview with Larry Wall (LinuxVoice)

Posted Jul 18, 2015 2:10 UTC (Sat) by Cyberax (✭ supporter ✭, #52523) [Link] (18 responses)

> So, while it isn't the end of the world to work with the old ways of thinking, I expect robust new languages to trend toward, by default, automatically maintaining full precision (modulo range limits) for literals like 0.1 or 1/10.
No. Your 'full precision' actually means "precision loss".

You CAN NOT store 0.1 as a limited binary fraction precisely. You can try to play games like "0.10000000000000009" is really "0.1" but that will inevitably bite some users who actually expect floating point to be precise and it won't be reliable anyway (what we should do with 0.10000000000000010?).

If you need decimal fractions - then use a decimal type.

An interview with Larry Wall (LinuxVoice)

Posted Jul 18, 2015 6:12 UTC (Sat) by epa (subscriber, #39769) [Link] (12 responses)

There is a third choice other than binary (which as you say can never store fractions like 0.1) or decimal (which works fine for 0.1, but cannot store 1/3). Many languages have a rational number type which can store all numbers expressible as A/B where A and B are integers. I think this is what Perl 6 uses by default and what the other poster was referring to.

An interview with Larry Wall (LinuxVoice)

Posted Jul 22, 2015 17:00 UTC (Wed) by salimma (subscriber, #34460) [Link]

And it's the default in many Lisps too

An interview with Larry Wall (LinuxVoice)

Posted Jul 22, 2015 17:53 UTC (Wed) by anselm (subscriber, #2796) [Link] (10 responses)

So you would presumably use 22/7 (or something like it) for π?

An interview with Larry Wall (LinuxVoice)

Posted Jul 22, 2015 18:33 UTC (Wed) by rsidd (subscriber, #2582) [Link] (9 responses)

It would be silly to default to ratios of integers. Technically every floating point number on a computer is a rational number. The issue is merely that what is a terminating decimal, like 0.1, need not be a terminating binary, and therefore decimal arithmetic translated to binary and back to decimal may not be what you expect. One has two choices then -- store it as 1/10 (and store π as 314159265358979323/100000000000000000) or store it in the proper machine representation. Most of us prefer the latter and know what the tiny differences from the "expected" answer mean. From raiph's remarks it would seem perl defaults to an integer-ratio for 0.1, and possibly even for π. What puzzles the rest of us is what is the benefit of this.

A sensible thing for a language to do, if it must bother with rational numbers without being asked, would be to use a rational representation when the number is explicitly given as a ratio of integers, and the machine floating point representation otherwise. So 1/10 would be rational and 0.1 would be a float, and their product would be coerced to be a float. Lisp, for instance, does this (at least common lisp does). Python on the other hand has a fractions module that must be used if this behaviour is desired, otherwise python 2 treats 1/10 as an int (0) and python 3 treats it as a float (0.1).

An interview with Larry Wall (LinuxVoice)

Posted Jul 22, 2015 19:49 UTC (Wed) by raiph (guest, #89283) [Link]

An interview with Larry Wall (LinuxVoice)

Posted Jul 23, 2015 3:49 UTC (Thu) by raiph (guest, #89283) [Link] (7 responses)

> It would be silly to default to ratios of integers [for pi]

Yes. Pi is irrational, not rational. Any finite representation of an irrational number is going to be approximate, no matter what.

> One has two choices then -- store [0.1] as 1/10 ... or store it in the proper machine representation.

Do you see that you've indulged in circular reasoning there? You've implied that a particular machine storage representation of rational numbers is not proper simply because it isn't floating point. (And, most ironically, you're saying this despite the former being a 100% accurate representation and the latter approximate.)

> Most of us prefer [an inaccurate representation over an accurate one]

I don't think that's true. I think most of us prefer the most appropriate representation for a particular use case if it makes a difference worth making for that use case.

This often means floating point. But, for many uses of rationals, especially decimals, exact rationals are a viable choice, indeed may I say obvious choice, if you care about accuracy and simplicity.

> From raiph's remarks it would seem perl defaults to an integer-ratio for 0.1, and possibly even for π.

Yes, for 0.1.

The π value built in to Perl 6 is stored as a floating point number.

> What puzzles the rest of us is what is the benefit of this.

Almost all practical rational math, eg decimal math where input and output values have any number of digits before the decimal point and up to 15 or so digits after, will be 100% accurate by default, whereas floating point can go wrong at one digit after the decimal point, such as with `0.1 + 0.2 - 0.3`.

So, treating rationals as rationals can provide two crystal clear benefits over floating point: accuracy and simplicity.

> A sensible thing for a language to do ... would be to use a rational representation when the number is explicitly given as a ratio of integers ... So 1/10 would be rational

Right. That's what Perl 6 does and most other languages do not.

> and 0.1 would be a float

0.1 is *exactly* the same number as 1/10. It's just specified with a different notation. Given that Perl 6 supports accurate rational processing it makes little sense to treat `123456789.987654321` as anything other than 123456789987654321/1000000000.

In Perl 6, if you want floating point then you explicitly coerce, eg `Num(0.1)`, or use scientific notation, which is universally understood to be approximate, such as eg `1e-1` for 0.1 or `2.99792458e+8` for the m/s speed of light.

An interview with Larry Wall (LinuxVoice)

Posted Jul 23, 2015 4:38 UTC (Thu) by rsidd (subscriber, #2582) [Link] (6 responses)

The π value built in to Perl 6 is stored as a floating point number
Ok, so π is built in -- is every conceivable required irrational also built in? e I would guess, but what about the golden ratio, the Euler-Mascheroni constant, etc etc? What about physical constants like the electronic charge, Planck's constant, etc, which are quantities measured to some accuracy and not exact fractions?
whereas floating point can go wrong at one digit after the decimal point, such as with `0.1 + 0.2 - 0.3`.
Huh? python (both 2 and 3) give me 5.551115123125783e-17 which is 17 digits after the decimal point, not 1 digit. Who exactly cares about this? If you were building a football stadium and your calculation gave you this sort of error, you would be wrong by one-hundredth the radius of an atomic nucleus.
Given that Perl 6 supports accurate rational processing it makes little sense to treat `123456789.987654321` as anything other than 123456789987654321/1000000000.
This is exactly where we disagree. You think treating 123456789.987654321 as a fraction is reasonable and even desirable. I think it is ridiculous. When you have a number with more than two or three digits after the decimal, it is almost certainly an inexact value -- a roundoff, or a measurement, or just a ballpark figure. There is absolutely no reason to treat it as a fraction. It hurts performance and does not improve accuracy. And when people want the fraction 1/10, they will write 1/10, not 0.1. Out of curiosity, were there any mathematical/scientific programmers behind these Perl 6 decisions?

An interview with Larry Wall (LinuxVoice)

Posted Jul 23, 2015 21:59 UTC (Thu) by flussence (guest, #85566) [Link]

> Ok, so π is built in -- is every conceivable required irrational also built in? e I would guess, but what about the golden ratio, the Euler-Mascheroni constant, etc etc? What about physical constants like the electronic charge, Planck's constant, etc, which are quantities measured to some accuracy and not exact fractions?

Why do you hold Perl 6 to an absurd standard here but languages like Javascript, PHP and Python get a silent free pass?

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 4:29 UTC (Fri) by raiph (guest, #89283) [Link]

> e I would guess, but what about the golden ratio, the Euler-Mascheroni constant, etc etc? What about physical constants like the electronic charge, Planck's constant, etc, which are quantities measured to some accuracy and not exact fractions?

Without installing anything you can compile:

say e**(i*π) + 1

... and get an approximation of the right result. (Yes, that i is the square root of -1.)

But I'm pretty sure that's about the maximum extent of it at the moment ie there aren't (m)any other mathematical constants defined in the standard setting.

> > whereas floating point can go wrong at one digit after the decimal point, such as with `0.1 + 0.2 - 0.3`.

> Huh? python (both 2 and 3) give me 5.551115123125783e-17 which is 17 digits after the decimal point, not 1 digit.

I was talking about the user *input* (one decimal digit, presumed accurate) not the computer generated *output*.

> When you have a number with more than two or three digits after the decimal ...

Numbers with just one or two digits after the decimal are considered an important use case. For example, writing 4.10 to represent 4 dollars and 10 cents.

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 5:53 UTC (Fri) by rsidd (subscriber, #2582) [Link] (3 responses)

Why do you hold Perl 6 to an absurd standard here but languages like Javascript, PHP and Python get a silent free pass?
I guess I wasn't clear enough. You said pi is a float because it's built-in and you know it is irrational, but if you write 3.14159265 it will be treated as the fraction 314159265/100000000. So I was asking what about other constants? If I write phi=1.61803398 why should perl assume that I have a fraction in mind? If I wanted a fraction I'd write a fraction. Other languages don't have this problem, you can define what constants you like and they will be treated as floats without coercion. In Perl 6, even you managed to get the coercion wrong here.
Numbers with just one or two digits after the decimal are considered an important use case. For example, writing 4.10 to represent 4 dollars and 10 cents.
This is a special case. For 4 dollars 10 cents, you will write 4.10, not 4.1 or 4.100. Changing how floats are treated in the language because of this special case is just weird. Counting in cents, as integers, is the sensible thing to do. But if you want smaller units than one cent (eg compound interest calculations), you want floats, not fractions.

Normally (ie when it's some other quantity, not money), when you write 4.10 you mean that it is known to a precision of two digits after the decimal point. If you write 4.1 it means you know it to 1 digit precision. If you mean the exact fraction you will write 4 1/10, not either of the above.

Anyway, enough of this argument. It is clear that you are convinced treating 4.1 or 3.14159 as fractions is the correct thing to do, will not be persuaded that it is wrong, and will not succeed in persuading others that it is right. Let us see if the Perl 6 way catches on. It's only been 15 years so far. Me, I have my eye on Julia.

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 9:53 UTC (Fri) by raiph (guest, #89283) [Link]

Maybe https://en.wikipedia.org/wiki/Decimal#Decimal_fractions will persuade you, at least about decimal fractions, where I could not.

Thanks for the exchange. :)

An interview with Larry Wall (LinuxVoice)

Posted Jul 26, 2015 15:56 UTC (Sun) by flussence (guest, #85566) [Link]

I get a strong impression you aren't even reading what you're arguing against, never mind who said it.

An interview with Larry Wall (LinuxVoice)

Posted Jul 28, 2015 9:06 UTC (Tue) by dvdeug (guest, #10998) [Link]

As long as you're writing 1.61803398, I don't see any justification for saying "If I wanted a fraction I'd write a fraction." A float is a fraction with a numerator between 0 and 2^24 and denominator of 2^24, times a power of 2. 1.61803398 looks a lot more like a decimal fraction then a floating point number. Maybe an explicit exponent, like 1.61803398E0, would make it clear that you wanted a float.

It's a trade-off of speed for less user surprise, and for a language with as little stress on raw speed as Perl, that's usually a good trade off. Accuracy is probably a wash; I bet there's a lot of times where you get back the exact best answer you could get with rationals where floats are less then precise, especially for less experienced users who aren't thinking in terms of IEEE754. I don't know Perl or Perl 6, but I assume if you want floats, you can explicitly demand them.

An interview with Larry Wall (LinuxVoice)

Posted Jul 18, 2015 7:49 UTC (Sat) by Wol (subscriber, #4433) [Link] (4 responses)

Actually, Pick has had that since (as far as I know) forever. It uses "fixed decimal" as opposed to floating point.

Mind you, it is a pain. The user/programmer has to explicitly manage the exponent ...

Cheers,
Wol

An interview with Larry Wall (LinuxVoice)

Posted Jul 18, 2015 19:05 UTC (Sat) by raiph (guest, #89283) [Link] (3 responses)

> The user/programmer has to explicitly manage the exponent

I'd enjoy comparing the Perl 6 design in this regard with pick's. I didn't find anything helpful when I spent a few minutes searching SO and wikipedia and googling; I'd appreciate a brief elaboration or link.

Perl 6 has a Rational role that is parameterized with a numerator and denominator. FatRats are Rational[Int,Int] which means they are arbitrary precision. Rats are (Rat64s which are) Rational[Int,Uint64] which means the denominator is limited to an unsigned 64 bit int; if a Rat overflows, "the denominator is automatically converted either to a Num or to a lesser-precision Rat, at the discretion of the implementation." (Hmm. Why not to a FatRat?)

The full gory details for this part of the Perl 6 language design (which may or may not exactly match the current Rakudo Perl 6 compiler implementation but ought to be close) are at http://design.perl6.org/S02.html#Numeric_Types

An interview with Larry Wall (LinuxVoice)

Posted Jul 19, 2015 9:11 UTC (Sun) by Wol (subscriber, #4433) [Link] (2 responses)

I can only talk really about Pr1me INFORMATION (and modern Picks seem to use floating to point to emulate fixed point :-( but ...

The Pr1me CPU was capable of doing BCD arithmetic, and had a load of microcode specifically to optimise all this sort of stuff. The Pick database was designed to store integers, and to store the mantissa in the data definition, not the data itself. As an example, let's store some price information in pounds in Pick - you'd put "199" in the data field, and "MD2" in the definition ("masked decimal 2"). That converts data at display time to 2dp, ie 1.99

So when you as the programmer are doing the maths, you have to be wary of multiplying MD-type fields, because MD2 * MD2 is, of course, MD4 and if you don't "correct" it to whatever datatype you're storing the result as, you can get some right funnies ...

Cheers,
Wol

An interview with Larry Wall (LinuxVoice)

Posted Jul 19, 2015 22:43 UTC (Sun) by raiph (guest, #89283) [Link] (1 responses)

> store the mantissa in the data definition, not the data itself.
> you have to be wary of multiplying [such] fields

Gotchya.

Iirc pick doesn't have (much of) a type system and you're describing the kind of problem that type systems address.

I don't see a parallel with anything Perl 6 specific atm.

Thanks for following up. :)

An interview with Larry Wall (LinuxVoice)

Posted Jul 20, 2015 14:34 UTC (Mon) by Wol (subscriber, #4433) [Link]

Pick have a type system? You must be joking!!!

imho that is both a great strength, and a massive weakness. Everything is a string. Works great (it really does). But the fact that all of your definitions are DEscriptive, rather than PREscriptive, *can* (not *is*) be a nightmare when you really really want to be certain something is, say, a number.

But on the other hand, it does make it easy to store things like "dead" or "unknown" in an age field :-)

Cheers,
Wol

An interview with Larry Wall (LinuxVoice)

Posted Jul 19, 2015 8:12 UTC (Sun) by zlynx (guest, #2285) [Link] (4 responses)

> But the primary reason it's that way is that the performance boost of fp approximation was considered worth the loss of precision and consequent violation of the principle of least surprise for naive users -- and that rationale hasn't held water for contemporary computer chips for years.

I suppose it depends on what you are using your computer for. In a scripting language I suppose you don't care about speed, so that would make sense.

But in some kind of physics simulation the user definitely cares about speed. No computer or computer cluster is ever fast enough and every 1% of FPU performance is desired and valuable.

An interview with Larry Wall (LinuxVoice)

Posted Jul 19, 2015 18:10 UTC (Sun) by raiph (guest, #89283) [Link] (3 responses)

> I suppose it depends on what you are using your computer for.

Sure.

> In a scripting language I suppose you don't care about speed

Not at all. The (supposed) language genre is irrelevant. Either a language can easily do what needs to be done or it can't. Speed often matters and when it does a tool is either capable of the performance you need or it is not.

> so that would make sense.

What makes sense (to me) is that a language has the right behavior by *default* as well as the right *possible* behavior if you want that instead.

In Perl 6 the default behavior is that `1/10 + 2/10 - 3/10` evaluates to zero rather than a small number. Imo a 10 year old that's just learned addition of simple fractions will consider this simple and accurate and appreciate this default way of looking at things.

> in some kind of physics simulation the user definitely cares about speed.

Sure.

In Perl 6 one can explicitly use a different type that explicitly represents a floating point number. The most generic floating point type in Perl 6 is Num.

One can write a Num literal:

my $foo = 1.234e-5; # use an 'e' to make a floating point literal

Now $foo contains a floating point number.

Or one can type a variable:

my Num $bar = 0.00001234

Now $bar contains a floating point number because Perl 6 automatically coerced the value to a Num.

> No computer or computer cluster is ever fast enough

Sure.

The misunderstanding in this thread about what Perl 6 does and doesn't do regarding floating point operations is just the start. The current Rakudo Perl 6 compiler implementation is too slow for it to be obvious, but Perl 6 has many features aimed at high-performance computing, from practical, easy-to-use parallel processing constructs to its sweet FFI with automated struct/object mapping.

An interview with Larry Wall (LinuxVoice)

Posted Jul 20, 2015 0:13 UTC (Mon) by raiph (guest, #89283) [Link] (2 responses)

Replying to myself:

> my Num $bar = 0.00001234

> Now $bar contains a floating point number because Perl 6 automatically coerced the value to a Num.

Turns out I'm wrong. Rakudo gives a compile time error:

Type check failed in assignment to '$bar'; expected 'Num' but got 'Rat'

It seems like one has to explicitly coerce (I've just checked this works):

my Num $bar = Num(0.00001234)

That slightly surprises me. I don't know why the compiler doesn't just coerce the rational literal in to a floating point number for me. I guess they can always upgrade it later from a compile-time error to a coercion if that's deemed wise.

An interview with Larry Wall (LinuxVoice)

Posted Dec 28, 2020 19:59 UTC (Mon) by raiph (guest, #89283) [Link] (1 responses)

2020 update of my own comment. One can now write type conversions like so:

my Num() $bar = 0.00001234

which will store a float in $bar by converting the rational 0.00001234.

An interview with Larry Wall (LinuxVoice)

Posted Dec 31, 2020 15:07 UTC (Thu) by flussence (guest, #85566) [Link]

Writing it as 0.00001234e0 also works. Spelling out exponents feels odd at first, but it turns out the same trick works in C.

An interview with Larry Wall (LinuxVoice)

Posted Jul 18, 2015 13:13 UTC (Sat) by rsidd (subscriber, #2582) [Link] (75 responses)

In the meantime Perl 6 has basic math right
In the first place, as others have pointed out, this is not "right". One needs to recognise that floating point numbers are stored in binary, not decimal, and to a limited precision. And your claim about python 3 is wrong (this is an incompatible change from python 2 that will perhaps benefit newcomers, like my 8-year-old son, but trips me up).
the Perl 6 language is designed to be significantly better for number crunching than Perl 5
Better than perl 5 maybe, but the above example suggests that it will be worse than other languages that treat floating-point numbers as the hardware treats them. I.e., any workaround to get around the realities of how the hardware works is going to slow down your number-crunching for no practical benefit.

An interview with Larry Wall (LinuxVoice)

Posted Jul 18, 2015 19:51 UTC (Sat) by raiph (guest, #89283) [Link] (73 responses)

> One needs to recognise that floating point numbers are stored in binary, not decimal, and to a limited precision.

Sure, but that's irrelevant. I was commenting on things like 0.1, which isn't a floating point number, and 1/10, which isn't either. (Or even 1/3, which isn't even decimal.) These are all rational numbers that can easily be stored in binary storage with no loss of precision by storing two integers instead of one floating point number.

This isn't rocket science; it's just that folk have gotten used to old ways of thinking and, in this thread at least, one can see that some folk aren't naturally open-minded.

> your claim about python 3 is wrong (this is an incompatible change from python 2 that will perhaps benefit newcomers, like my 8-year-old son, but trips me up).

Using ideone.com, Python 3.4:

print(.1 - .2 + .3)

returns

5.551115123125783e-17

(i.e. a very small number)

Afaik this has not changed in Python 3.5.

> the above example suggests that [Perl 6] will be worse than other languages that treat floating-point numbers as the hardware treats them.

Because you're still missing the point that this isn't about floating point numbers.

Perl 6 supports floating point numbers just fine. According to the relevant design doc: "On most platforms that means an IEEE 754 64-bit floating point number, aka "double precision".

> any workaround to get around the realities of how the hardware works is going to slow down your number-crunching for no practical benefit.

Imo accuracy-by-default and simplicity (math says 0.1 + 0.2 - 0.3 is zero and I would expect your 8 year old son to soon agree with that if he doesn't already) are both very practical benefits if they don't unduly slow down your number-crunching, especially if it's trivial to use floating point numbers if you so wish (which you may in most languages, including Perl 6).

An interview with Larry Wall (LinuxVoice)

Posted Jul 18, 2015 20:25 UTC (Sat) by juliank (guest, #45896) [Link] (6 responses)

> > your claim about python 3 is wrong (this is an incompatible change from python 2 that will perhaps benefit newcomers, like my 8-year-old son, but trips me up).
> Using ideone.com, Python 3.4:
> print(.1 - .2 + .3)
> returns
> 5.551115123125783e-17

He was probably refering to division (/) always producing floating point instead of int now (which has //).

> > any workaround to get around the realities of how the hardware works is going to slow down your number-crunching for no practical benefit.
> Imo accuracy-by-default and simplicity (math says 0.1 + 0.2 - 0.3 is zero and I would expect your 8 year old son to soon agree with that if he doesn't already) are both very practical benefits if they don't unduly slow down your number-crunching

True. But knowing about fractions at year 8 is quite advanced. That's more something for children >= 10. And even they mostly cannot really handle it.

An interview with Larry Wall (LinuxVoice)

Posted Jul 18, 2015 20:26 UTC (Sat) by juliank (guest, #45896) [Link]

What I wonder is why Python did not switch to decimal. It's slow as hell anyway, and unsuitable for numeric processing, so keeping double does not make sense performance-wise.

An interview with Larry Wall (LinuxVoice)

Posted Jul 19, 2015 3:29 UTC (Sun) by raiph (guest, #89283) [Link] (4 responses)

> He was probably refering to division (/) always producing floating point instead of int now (which has //).

OK.

So, to summarize, given the expressions `7/2` and `1/10 + 2/10 - 3/10`, Python 2 gets neither "right" where "right" is defined as what the correct basic math result would be; Python 3 and Perl 5 get one of them right (`7/2`); and Perl 6 gets both right.

> But knowing about fractions at year 8 is quite advanced.

Sure. That's why I lead with the likelihood of his son agreeing (that `0.1 + 0.2 - 0.3` is zero) "soon", by which I meant in a year or two, rather than already.)

> That's more something for children >= 10. And even they mostly cannot really handle it.

Sure. But I think kids who've finally gotten fractions will handle `0.1 + 0.2 - 0.3` being zero a whole lot more easily than they will handle it being a small number "because floating point".

An interview with Larry Wall (LinuxVoice)

Posted Jul 19, 2015 4:29 UTC (Sun) by Cyberax (✭ supporter ✭, #52523) [Link] (3 responses)

> where "right" is defined as what the correct basic math result would be
Let's see, basic math says that 1/10 number doesn't exist. Every child knows that it's 0.00011(0011) and thus can't be written precisely inside a finite number of digits.

So no, Perl 6 doesn't get them right. Python (and C, Haskell, Rust, Go, ...) get them right.

An interview with Larry Wall (LinuxVoice)

Posted Jul 19, 2015 21:46 UTC (Sun) by raiph (guest, #89283) [Link] (2 responses)

> basic math says that 1/10 number doesn't exist.

Would you object if I tweeted that?

An interview with Larry Wall (LinuxVoice)

Posted Jul 20, 2015 6:27 UTC (Mon) by Cyberax (✭ supporter ✭, #52523) [Link]

No, feel free to tweet it.

An interview with Larry Wall (LinuxVoice)

Posted Jul 20, 2015 6:36 UTC (Mon) by rsidd (subscriber, #2582) [Link]

If you were honest you would tweet the next sentence too (and a link to this thread).

An interview with Larry Wall (LinuxVoice)

Posted Jul 18, 2015 21:12 UTC (Sat) by Cyberax (✭ supporter ✭, #52523) [Link] (6 responses)

> Sure, but that's irrelevant. I was commenting on things like 0.1, which isn't a floating point number, and 1/10, which isn't either. (Or even 1/3, which isn't even decimal.) These are all rational numbers that can easily be stored in binary storage with no loss of precision by storing two integers instead of one floating point number.
The problem is in details. If you just want to store a rational number then it's perfectly OK.

However, once you start doing moderately complex math with true rationals, denominator grows really fast. Sooner or later you have to start normalizing them, causing precision losses.

That's why flexible rationals are not really popular, despite their seductive allure. People just stick to f64 if they want speed, since f64 peculiarities are well-known and are taught in all CS courses. Or people stick to decimal types if they need to mimick the way 'humans' do the arithmetic (primarily for financial stuff).

An interview with Larry Wall (LinuxVoice)

Posted Jul 18, 2015 22:35 UTC (Sat) by juliank (guest, #45896) [Link] (5 responses)

> Sooner or later you have to start normalizing them, causing precision losses.

Why does normalization cause precision loss?

An interview with Larry Wall (LinuxVoice)

Posted Jul 19, 2015 4:49 UTC (Sun) by Cyberax (✭ supporter ✭, #52523) [Link] (4 responses)

Once your denominator grows too large (because of mutually prime factors with the numerator) you have to lose some unnecessary precision.

Additionally, if you try to use trascedentals (even a simple square root!) then rationals again become useless.

So there's only a very narrow niche for them, and they are not used widely even though lots of languages have libraries supporting them.

An interview with Larry Wall (LinuxVoice)

Posted Jul 19, 2015 6:07 UTC (Sun) by mchapman (subscriber, #66589) [Link] (3 responses)

> Once your denominator grows too large (because of mutually prime factors with the numerator) you have to lose some unnecessary precision.

It seems to me that the people that are going to be using calculations involving a large number of coprime denominators are precisely the same set of people that will be quite happy to keep using floating-point numbers anyway. So long as it's clear where the transition from rational values to floating-point values lies (e.g. through a warning, or more explicitly through a lexically-scoped pragma), I see no reason why we can't satisfy all parties here.

An interview with Larry Wall (LinuxVoice)

Posted Jul 19, 2015 11:20 UTC (Sun) by khim (subscriber, #9252) [Link] (2 responses)

You can's satisfy all parties because use of fractions where floating point numbers are requested satisfy noone. It's like UTF-8 vs UTF-16. With UTF-8 you need to learn to live with with variable character width early and thus have a chance to produce working program. With UTF-16 your program pass all tests with flying colors (beause they all use BMP) yet fail for real users. Similarly with "fractions vs floating point numbers": if you language introduces floating point numbers early in (as in: 0.1 is not precisely 0.1) and distinguishes it from fractions (think guile: 7/2 will be 7/2 there it'll never automagically become 3.5) then you have a chance, if your language "does basic math" right then you will happily rely on it till you'll need sinus or square. Then you'll continue to rely in the fact that you language does basic math right, only to find out too late that sin2x + cos2x is not always 1.

An interview with Larry Wall (LinuxVoice)

Posted Jul 19, 2015 12:03 UTC (Sun) by mchapman (subscriber, #66589) [Link]

> You can's satisfy all parties because use of fractions where floating point numbers are requested satisfy noone.

I don't think of 0.1 as "requesting" any kind of numeric type. It's just a real number.

In Perl 6 that literal does happen to create a Rat value. But that sounds reasonable to me -- all decimal real numbers *are* rational. 0.1 and <1/10> are just two different textual representations for the same value.

So what if you really want to "request" a floating-point value for some reason? Easy: simply use that Rat as a floating-point value. You could assign it to a Num scalar, or you could use it with some operator or method that only works with Nums. It's easy enough to do the conversion. It is, after all, exactly the same conversion most other programming languages do when they interpret the decimal form in the first place.

To be honest, I would not be surprised if Perl implementations skip the Rat value completely if the decimal literal is used somewhere where it will be immediately used as a floating-point value. If the Rat temporary value isn't externally visible, constant-folding can turn it into a constant Num instead.

An interview with Larry Wall (LinuxVoice)

Posted Jul 20, 2015 8:39 UTC (Mon) by jezuch (subscriber, #52988) [Link]

> basic math

Any programmer who thinks that computers implement "basic math" is simply incompetent... unless you're doing purely symbolic calculations and/or have infinite-length registers.

[Yes, I did fall into that trap once or twice when I was at the university. But then I learned about proper numerical algorithms, numerical (in)stability etc. and I'm no longer incompetent ;)]

An interview with Larry Wall (LinuxVoice)

Posted Jul 19, 2015 4:50 UTC (Sun) by rsidd (subscriber, #2582) [Link] (58 responses)

As others clarified on my behalf, I was referring to python 3's treatment of integer division.

But 0.1 is very much a floating point number. If you want a fraction, you will write 1/10 and not 0.1. Python has a fractions module for those who need it. As cyberax and others said, 0.1 in decimal is not a terminating fraction in binary and until you design hardware that works in decimal, the alleged "correctness" of perl6 isn't correctness at all and is of no practical benefit to numbercrunchers.

An interview with Larry Wall (LinuxVoice)

Posted Jul 19, 2015 6:11 UTC (Sun) by mchapman (subscriber, #66589) [Link] (57 responses)

> If you want a fraction, you will write 1/10 and not 0.1.

That would be very un-Perlish. 0.1 is as much a rational value as 1/10 is, *until such time* you use it where it being a rational value does not make sense (e.g. as the input of a transcendental function). There's little need to do the rational-to-floating-point conversion (which is all that "parsing a decimal number" is in most languages, after all) before then.

An interview with Larry Wall (LinuxVoice)

Posted Jul 19, 2015 6:28 UTC (Sun) by rsidd (subscriber, #2582) [Link] (56 responses)

It hurts numbercrunching performance (raiph's original claim). If you don't care about that, then this is fine. The people who care about exact representation of rational fractions probably do symbolic algebra and use sage / maxima / mathematica for that...

An interview with Larry Wall (LinuxVoice)

Posted Jul 19, 2015 6:43 UTC (Sun) by mchapman (subscriber, #66589) [Link] (55 responses)

> It hurts numbercrunching performance (raiph's original claim). If you don't care about that, then this is fine.

I'm not sure that it needs to. If something can only be efficiently calculated using floating-point values, it's perfectly fine for the implementation to use that. I gave the example of transcendental functions. Except in a few specific cases, there's no sense in keeping rational values around there. I'm sure you can think of other examples.

So the discussion is really about *when* the rational-to-floating-point conversion takes place. In most mainstream languages, that happens pretty much immediately -- in those languages, 0.1 turns into the closest representable floating-point number straight away. But it doesn't have to work like that. That conversion could be delayed if it turns out be more useful. I suspect performance is not severely diminished by having this conversion done later.

And that is why keeping I say keeping 0.1 as a rational value, for as long as it makes sense to, is the Perlish way to do things. One of the ongoing themes in the Perl language is that "how you use a value" is more important than what type the value is -- e.g. a scalar *is* a number because you happen to use it in numeric operations, not because it has some kind of intrinsic "numberness". So if you have a value and you keep doing fairly sane, rational-value operations on it, why not keep it as a rational for as long as possible?

As noted by Cyberax, the denominator can easily blow up if you happen to use very *non*-rational operations on it. But I suspect the people doing such operations would be quite happen for it to switch to floating-point when that happens.

An interview with Larry Wall (LinuxVoice)

Posted Jul 19, 2015 18:08 UTC (Sun) by Cyberax (✭ supporter ✭, #52523) [Link] (54 responses)

It's a bad decision all around. You can't tell statically if "a+b" produces a rational (what if "a" is NaN?) and your operations start to depend on input values.

I'm a great believer that such things must be done explicitly. Want a rational? Sure, use a Rat type that limit you to sane operations representable with rational types (i.e. no transcedentals, easy on division, etc.). It might even be useful occasionally.

If you want speed, then use f64/f32 - they have known problems, but these problems are _known_ and they are taught in every CS 101 course. And floats are fast.

If you want "calculator-like" arithmetic with an occasional transcedental (think interest rate computation) then use fixed-point decimals. That's what people do in finance.

Mixing all three of them is a recipe for disaster. There's a reason this picture describes Perl6 pretty succinctly: http://bleaklow.com/images/2003/p6_cover_big.gif

An interview with Larry Wall (LinuxVoice)

Posted Jul 20, 2015 8:41 UTC (Mon) by epa (subscriber, #39769) [Link]

Why not have the safe but slow choice of rationals be the default, and if you want an approximation based on 32-bit or 64-bit floating point, ask for it explicitly? That seems more appropriate for a high-level language such as Perl.

An interview with Larry Wall (LinuxVoice)

Posted Jul 23, 2015 1:14 UTC (Thu) by dvdeug (guest, #10998) [Link] (52 responses)

If you want to tell statically what type a formula produces, and don't want your operation to depend on input values, then you want a statically typed language. Once you're talking about a language like Lisp or Perl or Python, you don't know what type "a + b" is going to return, and that's just a fact of life.

An interview with Larry Wall (LinuxVoice)

Posted Jul 23, 2015 17:51 UTC (Thu) by Cyberax (✭ supporter ✭, #52523) [Link] (49 responses)

Not really. With Python the type choices are static and you can be sure that your program prints "0.0" instead of "0" for all inputs.

An interview with Larry Wall (LinuxVoice)

Posted Jul 23, 2015 22:36 UTC (Thu) by dvdeug (guest, #10998) [Link] (48 responses)

$ python
Python 2.7.10 (default, Jul 1 2015, 10:54:53)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = 0
>>> b = 0
>>> a + b
0
>>> a = 0.0
>>> a + b
0.0

I don't see how this is any different from what you're talking about with Perl. The type choices aren't static; they depend on the input types.

An interview with Larry Wall (LinuxVoice)

Posted Jul 23, 2015 22:51 UTC (Thu) by Cyberax (✭ supporter ✭, #52523) [Link] (47 responses)

I don't see how this is any different from what you're talking about with Perl. The type choices aren't static; they depend on the input types.
Python variables are typed. Not so with Perl. So:
 cat script.pl
 $a=<STDIN>;
 $b=<STDIN>;
 print $a+$b;

 echo -e "1\n2" | perl script.pl
 3
 echo -e "1.1\n2" | perl script.pl
 3.1
 echo -e "aa\n2" | perl script.pl
 2
Now let's try that with Python:
$ cat script.py
 import sys
 a = sys.stdin.readline().strip()
 b = sys.stdin.readline().strip()
 print a+b

$ echo -e "1\n2" | python script.py
 12
$ echo -e "1.1\n2" | python script.py
 1.12
$ echo -e "aa\n2" | python script.py
 aa2
Everything is _predictable_. If you want your input to be treated as floats - you need to spell it out explicitly:
$ cat script.py
 import sys
 a = float(sys.stdin.readline().strip())
 b = float(sys.stdin.readline().strip())
 print a+b

$ echo -e "1\n2" | python script.py
 3.0
$ echo -e "1.1\n2" | python script.py
 3.1
$ echo -e "aa\n2" | python script.py
 Traceback (most recent call last):
   File "script.py", line 2, in <module>
     a = float(sys.stdin.readline().strip())
   ValueError: could not convert string to float: aa
The Perl's way is simply madness incarnate, and instead of fixing it, they are making it even more complicated with lots of potential for mischief.

An interview with Larry Wall (LinuxVoice)

Posted Jul 23, 2015 23:42 UTC (Thu) by dvdeug (guest, #10998) [Link] (7 responses)

"Python variables are typed. Not so with Perl."

I don't know what you meant by that; it is not true for the two obvious meanings. Untyped could mean that variables at compile time don't have defined types, as is true in both Python and Perl, or it could mean that values stored in variables don't have types at runtime or compile time, which is true for assembly languages and BLISS, but by no means Python and Perl.

Yes, Perl implicitly converts strings to either integers or floats before feeding it to the "+" operator, whereas Python doesn't. Python is hardly predictable, though; if your function takes two arguments and adds them, it could be adding integers or floats or any thing that overloads "+".

The big difference I see is the silent conversion of strings, and I suspect that's part of a bigger pattern of silent conversions in Perl that Python does have. But if you're dealing with just numbers, I don't see the Python model as being all that different from the Perl model.

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 6:18 UTC (Fri) by raiph (guest, #89283) [Link]

> Untyped could mean that variables at compile time don't have defined types, as is true in both Python and Perl

In Perl 6, variables are a kind of container. Containers in Perl 6 have a container type. For example, by default, an `@array` variable has an `Array` container type:

my @foo;
say @foo.WHAT; # (Array)

Container types have an 'of' type, the type of the things contained in the container. So one might have an `Array of Int`.

my Int @bar;
say @bar.WHAT # (Array[Int])

> or it could mean that values stored in variables don't have types at runtime or compile time

Values have a static type in Perl 6.

say 42.WHAT # (Int)

Binding of values to containers can have additional dynamic constraints, used to select or reject arguments based on their run-time value not just their compile time type.

subset NameOfFileThatExists of Str where *.IO.e;
multi sub bar (NameOfFileThatExists $name) { ... }
multi sub bar ($doesntexist) { ... }
bar("foo")

"file".IO.e returns True if "file" exists in the current directory. So the bar("foo") call will dispatch to the first bar if "foo" exists and to the second bar if not.

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 8:26 UTC (Fri) by Cyberax (✭ supporter ✭, #52523) [Link] (5 responses)

> I don't know what you meant by that; it is not true for the two obvious meanings. Untyped could mean that variables at compile time don't have defined types, as is true in both Python and Perl, or it could mean that values stored in variables don't have types at runtime or compile time, which is true for assembly languages and BLISS, but by no means Python and Perl.
There's a small but crucial difference - Python does not do any guessing when you read a variable from an external source. And there's no heuristics for incompatible types - you simply get errors.

Actually, I got bitten by it today. As if on cue, someone used "==" to compare numeric values in Perl, and it even worked fine. That is, until someone started using fractional values as an input.

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 8:50 UTC (Fri) by dvdeug (guest, #10998) [Link] (4 responses)

Perl did not guess their format when it read them in; it read them in as strings. You implicitly told Perl to convert them to numbers when you used a numeric operator on them; if you were concerned that you knew exactly what type they would be converted to, you could have converted them yourself. There are of course heuristics for incompatible types in Python, as I demonstrated by doing a + b with a floating point and b an integer; the only question is how incompatible and in what ways.

If you want to argue that strings should not silently convert to numbers, that's an argument. It seems far away from any discussion of rational numbers in Perl 6.

"use warnings" would tell you if you use "==" on strings. There's shared responsibility when you screw up by using a questionable feature in a language that the system you use has warnings on.

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 9:34 UTC (Fri) by rsidd (subscriber, #2582) [Link] (1 responses)

If you want to argue that strings should not silently convert to numbers, that's an argument. It seems far away from any discussion of rational numbers in Perl 6.
Floats should not silently convert to rationals. And apparently this doesn't even require an operation. Merely writing "3.14159" makes perl6 treat it as 314159/100000. It's hard to imagine that this has security implications, though. Just needless complexity and inefficiency.

What happens when interfacing with a C library (say GSL)? Are these "rationals" then converted into floats before calling? And are the return values converted back to "rationals"?

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 19:19 UTC (Fri) by raiph (guest, #89283) [Link]

> Floats should not silently convert to rationals.

I can't imagine any language doing that. If your comment is aimed at Perl (5 or 6) then I think this is another manifestation of overall confusion about decimal fractions.

https://en.wikipedia.org/wiki/Decimal#Decimal_fractions

> Merely writing "3.14159" makes perl6 treat it as 314159/100000.

Just for emphasis: https://en.wikipedia.org/wiki/Decimal#Decimal_fractions

Hopefully you'll spend a few seconds reading this wikipedia link and you'll go "ahhh". :)

> What happens when interfacing with a C library (say GSL)?

One uses explicit typing in the signature (the list of parameters) of the Perl 6 functions that call the C functions. For example:

sub add(int32, int32) returns int32 is native("libcalculator") { * }

means that one must call the `add` function with two native 32 bit ints.

See http://doc.perl6.org/language/nativecall#Passing_and_Retu... for some more details.

> Are these "rationals" then converted into floats before calling?

They can be. It's controlled by explicit types and explicit type coercions in the signature. For example:

sub foo(Num(Rat), Num) ...

would be callable with:

foo(13/17, 26e3)

> And are the return values converted back to "rationals"?

Rakudo does not currently support signature based coercion of the return value; I don't know whether there's a plan to one day support that.

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 20:43 UTC (Fri) by raiph (guest, #89283) [Link] (1 responses)

> Perl did not guess their format when it read them in; it read them in as strings.

Perl 6 lets users directly specify input types for command line args:

perl6 -e 'sub MAIN (Int $int, Rat $rat, $string) { .print and "\t".print and .WHAT.say for $int, $rat, $string }' 42 2 Foo

Usage:
-e '...' <int> <rat> <string>

perl6 -e 'sub MAIN (Int $int, Rat $rat, $string) { .say and .WHAT.say for $int, $rat, $string }' 42 2/10 Foo

42
(Int+{orig-string[Str]})
2/10
(Rat+{orig-string[Str]})
Foo
(Str)

Perl 6 displays an automatically generated usage message until you pass arguments that correspond to the specified types.

When you do, it stores the typed values and the original string values so you can use either as appropriate to your needs.

The design docs suggest a similar mechanism is supposed to be applicable to input other than command line args but Rakudo doesn't support that yet afaik.

> You implicitly told Perl to convert them to numbers when you used a numeric operator on them

A nit: I'd say that treating operands of the `+` operator as numbers is explicit, not implicit.

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 22:36 UTC (Fri) by raiph (guest, #89283) [Link]

> A nit: I'd say that treating operands of the `+` operator as numbers is explicit, not implicit.

And, if I did, I'd be wrong.

https://en.wikipedia.org/wiki/Type_conversion

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 0:26 UTC (Fri) by mchapman (subscriber, #66589) [Link] (2 responses)

> Everything is _predictable_.

You're making a false comparison there. It would be equally predictable in your Perl code had it used string concatenation instead.

I don't see a big difference between what Perl and Python are doing here. In both cases, the programmer has to know what kinds of values they are working with. With Python that's encoded in the value's type; with Perl that's encoded in the value itself. But either way, if you're taking in a string from the outside world and want to use it in your program you still need to *validate* that string -- in Perl you might use Scalar::Util::looks_like_number. Once validated, the way that value's type is encoded seems to be largely irrelevant.

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 8:21 UTC (Fri) by Cyberax (✭ supporter ✭, #52523) [Link] (1 responses)

> You're making a false comparison there. It would be equally predictable in your Perl code had it used string concatenation instead.
Who said that I want concatenation? I simply want a behavior that doesn't depend on the exact details of input (which very well might be malicious).

> I don't see a big difference between what Perl and Python are doing here. In both cases, the programmer has to know what kinds of values they are working with. With Python that's encoded in the value's type; with Perl that's encoded in the value itself.
There's a fundamental difference here - with Perl6's braindead number treatment, $a + $b can mean DIFFERENT things for different numbers.

Really.

> Scalar::Util::looks_like_number.
Which number? Rational, float, integer, bigint?

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 11:46 UTC (Fri) by mchapman (subscriber, #66589) [Link]

> Who said that I want concatenation?

Your Python code asked for it. It seems reasonable to expect that if you're comparing two code snippets you wanted them to do roughly the same thing.

> There's a fundamental difference here - with Perl6's braindead number treatment, $a + $b can mean DIFFERENT things for different numbers.

When does it not mean "add them together and produce a result that is the closest representable value to the answer"?

I have only passing familiarity with Perl 6, but I would be totally surprised if this were ever not the case.

But in Perl 5, whether a particular scalar should be treated as a number or a string depends only on the operator or builtin doing the interpretation. The + operator, for instance, interprets whatever you give it as a number.

There are rules as to how this interpretation is done, and those rules are consistently applied. It seems that you think those rules aren't legitimate because they are based on the value, rather than some "type" associated with that value. If that's actually the case, then I'm afraid no explanation is likely to satisfy you. That's simply how Perl works.

> Which number? Rational, float, integer, bigint?

Again, I refer to Perl 5 only.

Scalar::Util::looks_like_number returns a true value iff Perl thinks the scalar "looks like a number". It's really just as simple as that. "Looks like a number" is quite well-defined by Perl. It has nothing to do with "types", because Perl doesn't have types in that sense.

In practice, something that "looks like a number" can be used as if it actually were an integer or a float, assuming Perl actually had such things.

Why does it not matter whether it's an integer or a float? Simple: that only matters when you use the value. The integer-ness or float-ness of the value is not intrinsic to the value itself. If you use it in an operation that demands a float, it will act like a float. If you use it in an operation that demands an integer, it will act like an integer. Same for strings and booleans. The value isn't any of these, but it will happily act like one if you ask it to.

I really hope this explanation makes sense to you, even if you don't happen to like it. I'm out of ways to explain it!

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 0:29 UTC (Fri) by mrons (subscriber, #1751) [Link] (9 responses)

I don't see your point here. The perl code is predictable.

You used the + operator so in "$a+$b" $a and $b are to be treated as numbers.

If you wanted $a and $b to be treated as strings, you would use "$a . $b"

If the python code, when I look at "a+b", I have to examine the rest of the code to determine what "a+b" means (addition or concatenation).

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 8:18 UTC (Fri) by Cyberax (✭ supporter ✭, #52523) [Link] (8 responses)

> I don't see your point here. The perl code is predictable.
It's not.

> You used the + operator so in "$a+$b" $a and $b are to be treated as numbers.
Which numbers? Rationals, floats, doubles, integers, bigints?

And the answer, of course, is ANY OF THEM (depending on the Moon's current phase and Mars's relative position to it).

> If you wanted $a and $b to be treated as strings, you would use "$a . $b"
BTW, the fact that "+" happily works with strings without any errors is another braindead idea.

An interview with Larry Wall (LinuxVoice)

Posted Jul 26, 2015 16:17 UTC (Sun) by flussence (guest, #85566) [Link] (7 responses)

> BTW, the fact that "+" happily works with strings without any errors is another braindead idea.

Perl 5 has errors for that. You can enable them by typing "-w" on the command line. They're off by default; little things like that are why code from 20 years ago still runs correctly in it unmodified.

I'd say any language where I can't be sure of the return type of "a + b" at a glance is more brain damaged.

An interview with Larry Wall (LinuxVoice)

Posted Jul 26, 2015 18:57 UTC (Sun) by Cyberax (✭ supporter ✭, #52523) [Link] (6 responses)

> I'd say any language where I can't be sure of the return type of "a + b" at a glance is more brain damaged.
Ah, so you do agree that not being able to tell what comes out of "a+b" is braindamaged. Like not being able to tell whether it's float, rational or bigint.

An interview with Larry Wall (LinuxVoice)

Posted Jul 26, 2015 20:06 UTC (Sun) by dvdeug (guest, #10998) [Link] (1 responses)

In Python, "a + b" could return literally any type, any value. All it takes is the appropriate "def __add__ (a, b): return value" in some class somewhere. That being "brain damaged" is an opinion I'm not going to get into, but it's not different between Perl and Python.

An interview with Larry Wall (LinuxVoice)

Posted Jul 26, 2015 23:02 UTC (Sun) by anselm (subscriber, #2796) [Link]

In Python, "a + b" could return literally any type, any value. All it takes is the appropriate "def __add__ (a, b): return value" in some class somewhere.

That applies to Perl, too – see “perldoc overload”.

An interview with Larry Wall (LinuxVoice)

Posted Jul 27, 2015 0:03 UTC (Mon) by mchapman (subscriber, #66589) [Link] (1 responses)

> Like not being able to tell whether it's float, rational or bigint.

Perl guarantees it's a scalar. If the result is an integer, the scalar will "look like" an integer. If the result is a floating-point value, the scalar will "look like" an integer.

"Looks like" in Perl is as strong a guarantee as "has a type of" in Python or some other languages. I would like to think you are merely unwilling to acknowledge this idea, not incapable of it. Either way though, I don't think there's anything more I have to say on the matter.

An interview with Larry Wall (LinuxVoice)

Posted Jul 27, 2015 0:06 UTC (Mon) by mchapman (subscriber, #66589) [Link]

> ... the scalar will "look like" an integer.

And obviously that should be "... floating-point value".

An interview with Larry Wall (LinuxVoice)

Posted Jul 27, 2015 17:08 UTC (Mon) by flussence (guest, #85566) [Link] (1 responses)

> Like not being able to tell whether it's float, rational or bigint.

You're almost getting it now, yes. Don't you just hate it when mathematical operators are commutative and return *numbers*? How dare they.

Maybe I should have used a more extreme example: "(a + b) * a / b". Does that return a number, a string, or a runtime error?

An interview with Larry Wall (LinuxVoice)

Posted Jul 27, 2015 17:13 UTC (Mon) by Cyberax (✭ supporter ✭, #52523) [Link]

>Don't you just hate it when mathematical operators are commutative and return *numbers*?
WHICH numbers? They behave differently.

> Maybe I should have used a more extreme example: "(a + b) * a / b". Does that return a number, a string, or a runtime error?
In Python it's either a floating number or a runtime error (barring bizarre operator overloads).

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 9:26 UTC (Fri) by rschroev (subscriber, #4164) [Link]

Python variables are typed.

Maybe close enough for the discussion, but not exactly right. For the sake of correctness: Python variables (names really) aren't typed; Python values are.

See e.g. Python Objects for an explanation how Python objects work.

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 11:00 UTC (Fri) by raiph (guest, #89283) [Link] (24 responses)

> Python variables are typed.

Python variables are not typed.

> Not so with Perl.

Perl 6 variables are typed.

--------

A Perl 6 equivalent of your examples:

echo -e "1\n2" | perl6 -e 'say get() + get()'
3
echo -e "1.1\n2" | perl6 -e 'say get() + get()'
3.1
echo -e "aa\n2" | perl6 -e 'say get() + get()'
Cannot convert string to number: base-10 number must begin with valid digits or '.' in '⏏aa' (indicated by ⏏)
in block <unit> at -e:1

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 11:14 UTC (Fri) by rsidd (subscriber, #2582) [Link] (16 responses)

Cyberax's point was the implicit conversion of strings to numbers, which occurs via the "+" operator. Apparently what has changed in perl6 is that the "+" operator no longer works on strings. On the other hand, if you use "~" the same input gets treated as strings. The implicit conversion is not only for values from stdin either, it could be any string. So you have
---
$ perl6 -e 'say "2" ~ "2" '
22
$ perl6 -e 'say "2" + "2"'
4
---

Why is this a good thing? Why isn't it telling me that I can't use the "+" operator on strings?

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 11:48 UTC (Fri) by mchapman (subscriber, #66589) [Link] (14 responses)

> Why is this a good thing? Why isn't it telling me that I can't use the "+" operator on strings?

Why should it? You asked for numeric addition; you got numeric addition. Why would you want it not do what you asked for?

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 12:03 UTC (Fri) by rsidd (subscriber, #2582) [Link] (9 responses)

Because it may be a bug? Oversmartness is bad whether it's pwrl or MS Excel. When I try to add strings the compiler/interpreter should tell me and not silently change the type! There is a reason programs in Haskell tend to run correctly the first time.

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 12:28 UTC (Fri) by mchapman (subscriber, #66589) [Link] (1 responses)

> Because it may be a bug?

It could be, yes. All code can be wrong.

I'm sure Perl 6 has a way to say "test that $a and $b are both Ints, throw an exception if they're not, otherwise add them together and, if the result can be stored in an Int, return that result, else throw an exception". You'll probably find it's a few more characters than + though.

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 22:19 UTC (Fri) by raiph (guest, #89283) [Link]

Oh, I'm sure there are lots of ways. We're talking about Perl here. :)

The first thing I came up with:

($a,$b) ~~ :(Int, Int) or fail; $a + $b;

The `:(...)` bit is a literal signature, exactly like the ones that appear in function definitions. The `~~` "smartmatch" operator, with these operands, does a trial bind of the argument list on its left with the signature on its right.

I skipped testing the result because an Int can store arbitrarily large integers, and if all of RAM was consumed by a truly vast integer, an exception would (should) be raised by lower levels of the stack.

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 21:21 UTC (Fri) by dvdeug (guest, #10998) [Link] (6 responses)

As the old quip goes "If you want Haskell, you know where to find it."* It really seems out of place in a subthread comparing Python and Perl.

* I found that frustrating in the early 90s, as C was widely available and PL/I was not.

An interview with Larry Wall (LinuxVoice)

Posted Jul 25, 2015 4:12 UTC (Sat) by rsidd (subscriber, #2582) [Link] (5 responses)

Python is heavily influenced by Haskell (indentation and list-comprehensions are two obvious examples). So it's not irrelevant.

An interview with Larry Wall (LinuxVoice)

Posted Jul 25, 2015 5:02 UTC (Sat) by dvdeug (guest, #10998) [Link] (4 responses)

Haskell's first release was in 1990; Python was created in 1990 and released in 1991. So it doesn't seem likely that indentation or any other early feature was influenced by Haskell. The type system, in particular, is very unHaskell. In these features, Perl and Python differ pretty marginally.

An interview with Larry Wall (LinuxVoice)

Posted Jul 25, 2015 11:56 UTC (Sat) by anselm (subscriber, #2796) [Link] (3 responses)

It's pretty safe to say that Python's use of indentation for structure was not a Haskell influence. This is fairly obvious considering that the ABC programming language, which Guido van Rossum worked on at CWI before starting Python, also used indentation for structure. ABC had been around for more than a decade before Python was released.

List comprehensions, OTOH, were only added to Python way later, namely with version 2.0, which was released in 2000. It would not be entirely unreasonable to consider them influenced by Haskell.

As far as the type systems of Perl and Python are concerned, I think there are considerable differences. The observation that Perl doesn't really differentiate between numbers and strings, calling them “scalars”, while in Python strings are a special case of a (“non-scalar”) container type that also includes tuples and lists would be one's first clue that the type systems of Perl and Python are not really very similar at all.

An interview with Larry Wall (LinuxVoice)

Posted Jul 25, 2015 12:37 UTC (Sat) by dvdeug (guest, #10998) [Link] (2 responses)

List comprehensions are listed as being derived from Haskell by one of the sources linked from Wikipedia. It's not that surprising a claim.

"Considerable" is in the eye of the beholder. When compared to Haskell, they look quite similar, both dynamic systems with heavy OO mixture and no type inference.

An interview with Larry Wall (LinuxVoice)

Posted Jul 26, 2015 3:19 UTC (Sun) by mathstuf (subscriber, #69389) [Link] (1 responses)

> no type inference

Maybe I'm just not parsing your statement properly, but Haskell does all kinds of type inference…

An interview with Larry Wall (LinuxVoice)

Posted Jul 26, 2015 18:47 UTC (Sun) by nix (subscriber, #2304) [Link]

Let's expand that sentence:

When compared to Haskell, Perl and Python look quite similar, both dynamic systems with heavy OO mixture and no type inference.

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 15:59 UTC (Fri) by anselm (subscriber, #2796) [Link] (3 responses)

The problem is really that, as far as the “+” operator in Perl (5, at least – I haven't looked at Perl 6) is concerned, "123foobar" or for that matter "bazquux" are bona-fide numbers and therefore perfectly eligible to be added numerically. This tends to throw people off at times when instead they expect their compiler or interpreter to complain about a type mismatch.

Having said that, in Perl you wouldn't expect “+” to do string concatenation because that operator is called “.”. Now as far as the “.” operator in Perl 5 is concerned, 123 and 3.1415 are bona-fide strings and therefore perfectly eligible to be concatenated.

I teach Perl classes (among other subjects) for a living and in my considered opinion it is not a simple language to teach. Perl's idiosyncratic approach to evaluating expressions is something that many people find difficult to get to grips with, and previous experience with saner languages doesn't really seem to help a lot. It's not that what Perl does is illogical – it does have a certain twisted logic to it –, it's just that it's strange. Also, to really appreciate Perl you need to know C, the shell, sed, and awk, and few people nowadays do (at least the ones who end up in my classes generally don't). These days I prefer teaching Python because for all its shortcomings it is much easier to explain to people.

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 23:40 UTC (Fri) by raiph (guest, #89283) [Link] (2 responses)

> [treating 123apples as a number] tends to throw people off at times when instead they expect their compiler or interpreter to complain about a type mismatch.

Fwiw, Perl 6 no longer accepts "baz" as a number, insisting that a string must start with decimal digits if it's to successfully coerce to a number.

There's a saying on #perl6 that every DWIM ("Do What I Mean") has a corresponding WAT. One has to weigh the supposedly positive value of DWIMs against the negative value of their WAT(s).

I hear that, in your opinion, the WAT is not worth the DWIM, especially when it comes time to teach the language.

I'm curious if you can see and thus express any significant value to the DWIM even while it's not enough to counter the WAT?

> I teach Perl classes (among other subjects) for a living and in my considered opinion it is not a simple language to teach.

I'm curious what your student mix is between non-programmers learning programming by learning Perl and programmers in other languages learning Perl.

There are a bunch of programming teachers in the Perl community and I've watched their input help shape Perl 6, which was in part about cleaning up the language and making easy things easier. Perhaps you yourself contributed.

The upshot is that one can get a whole lot done with truly trivial code like:

say lines

> Also, to really appreciate Perl you need to know C, the shell, sed, and awk

Fwiw I don't think that applies to Perl 6.

An interview with Larry Wall (LinuxVoice)

Posted Jul 25, 2015 0:15 UTC (Sat) by anselm (subscriber, #2796) [Link] (1 responses)

I'm curious what your student mix is between non-programmers learning programming by learning Perl and programmers in other languages learning Perl.

Most of the people I've taught Perl to over the years were programmers with experience in other languages, ranging from Visual BASIC to things like C++ or Java. These people have the advantage that they already know about things like variables, conditionals, and loops. Stuff like $foo[1] vs. @foo[1] tends to confuse them, as does scalar context vs. list context in general. As I said, this stuff has its own twisted logic behind it, but from a language-learner POV it wasn't the smartest idea to design the language that way.

say lines

I'm getting the distinct impression that Perl 6 should not have been called Perl. If it ever actually comes around it will create lots of confusion among our customers because they will have to figure out whether they want us to teach Perl 5 or Perl 6.

In any case, demand for Perl classes hereabouts has dwindled to near-zero anyway. I'm teaching way more Python these days than Perl, and I can't even say I'm sorry. I was a Perl programmer in the late 1980s when we were waiting for the first (pink) Camel book to come out, and have followed the language for a very long time – including, e.g., consulting with O'Reilly on the German translation of the Perl 5 version of Programming Perl – but I don't use Perl for new projects anymore. Not if the code will take more than one screenful of lines, anyway.

An interview with Larry Wall (LinuxVoice)

Posted Jul 25, 2015 3:55 UTC (Sat) by raiph (guest, #89283) [Link]

> $foo[1] vs. @foo[1] tends to confuse them

Yeah. That's gone in Perl 6:

my @foo = 0,1,2,3; say @foo[1];
1

> scalar context vs. list context

Yeah. Context is still very much a thing in Perl 6.

> I'm getting the distinct impression that Perl 6 should not have been called Perl.

Right. I can see it being renamed sometime in the next 5 years, with the leading candidate new name being Camelia. But Larry has refused to even consider that prior to getting a 6.0.0 shipped (which is currently scheduled for this Christmas).

> If it ever actually comes around it will create lots of confusion among our customers because they will have to figure out whether they want us to teach Perl 5 or Perl 6.

I'm sure it's going to put in enough of an appearance globally to at least cause confusion. :)

> In any case, demand for Perl classes hereabouts has dwindled to near-zero anyway.

Where's here?

> I'm teaching way more Python these days than Perl, and I can't even say I'm sorry.

Sure. I like the Perl 5 community, and love Perl 6, but when I've eased newbies into scripting in the last few years I've started with Python, not Perl.

> I don't use Perl for new projects anymore. Not if the code will take more than one screenful of lines, anyway.

I think the same is true of a lot of folk.

The Perl 6 design is clearly aiming at programming-in-the-large just as much as it is scripting. But the only semi-serious test of its characteristics in that regard that I'm aware of is the compiler toolchain. So it seems like the jury is going to still be out for at least another few years on that.

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 21:52 UTC (Fri) by raiph (guest, #89283) [Link]

> Apparently what has changed in perl6 is that the "+" operator no longer works on strings.

Sorry, my previous comment may have been confusing. The default Perl 6 number parsing now rejects a string that does not start with a decimal number.

> $ perl6 -e 'say "2" ~ "2" '
> 22
> $ perl6 -e 'say "2" + "2"'
> 4

> Why is this a good thing?

There are several things I can do with your question. I can consider it a simple, well-formed question and process it that way. I can consider it potentially dangerous, in part or whole, and process it on my own terms, picking out what's non-dangerous about the question and deal with that bit. Or I could just reject it as not something I am willing to process.

For subjective input, Python tends toward the third option, to keep itself and its users sane in their world. Perl tends towards the middle, to keep itself and its users sane in theirs.

> Why isn't it telling me that I can't use the "+" operator on strings?

Well, first, because you can. :)

If you don't want that you can stop it in a given lexical scope:

multi sub infix:<+> (Str, Any) { fail "nope" }
say "2" + 4 # dies with "nope" message

One of the design assumptions in Perl 6 is that companies, teams and individual developers, will want to tighten or loosen strictness to suit their own view of what's dangerous, what's ill formed. Perl 6 makes it simple to bundle such policies in to single `use` statements that apply lexically. And these can be added to the ecosystem so that those with a similar philosophical mindset for a particular use-case can easily follow the same policies.

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 11:26 UTC (Fri) by rsidd (subscriber, #2582) [Link] (6 responses)

> Python variables are not typed.

They're typed. The following is an example of how it should work.

>>> a = "2"
>>> type(a)
<type 'str'>
>>> from fractions import Fraction as Fr
>>> a = Fr(3,4)
>>> type(a)
<class 'fractions.Fraction'>
>>> b = 2.5
>>> type(b)
<type 'float'>
>>> c = a*b
>>> print c
1.875
>>> type(c)
<type 'float'>
>>> d = Fr(4,5)
>>> e = a*d
>>> type(e)
<class 'fractions.Fraction'>
>>> print e
3/5

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 11:55 UTC (Fri) by mchapman (subscriber, #66589) [Link] (5 responses)

> They're typed.

No, they're not. Your code is printing out the types of the *values* inside those variables.

Python quite happily lets you do:

>>> a = 4
>>> a = "forty two"

If these Python variables were typed, then the second assignment would throw an exception. It doesn't.

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 12:11 UTC (Fri) by rsidd (subscriber, #2582) [Link] (4 responses)

You're changing the binding: the new a is different from the old a. You can do that in any language, perl, C, even haskell. You're going to tell me haskell variables aren't typed?

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 12:24 UTC (Fri) by mchapman (subscriber, #66589) [Link] (2 responses)

> You're changing the binding: the new a is different from the old a.

OK, this just sounds like a problem of nomenclature. When I think of "variable", I think of "the symbol typed by the programmer", not "the value to which that symbol is currently referring".

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 16:00 UTC (Fri) by peter-b (guest, #66996) [Link] (1 responses)

Well, to be perfectly pedantic, there are three things involved here:

1. The symbol
2. The slot bound to the symbol
3. The value stored in the slot

Most programming languages attach type annotations to (2) or (3).

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 16:15 UTC (Fri) by anselm (subscriber, #2796) [Link]

As far as Python is concerned, it is counterproductive to think of variables in terms of “slots” that can have “values” stored in them because that isn't really how the language works. Names in Python are really more like sticky labels attached to objects. If you stick your label on a new object, the type of the previous object you stuck it on doesn't matter, but as long as the label sticks to the same object, the type of that object determines what you get to do with it. Also, objects can have more than one label sticking to them.

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 21:46 UTC (Fri) by dvdeug (guest, #10998) [Link]

In C, if you run across

r_t funct (a_t a, b_t b) {return a + b;}

a, b and the return value all have specific types known at compile time and invariant at runtime. On the other hand, you can pass values of arbitrary type to

def add (a, b): return a + b

and a and b and the return value have no types at compile time, and can have a number of different types during the runtime of the program. There's a big difference there.

And it seems weird to say that Python variables are typed in this sense; it's like bragging that Python supports lowercase characters, except that way more programming language (implementations) have had problems with lowercase characters then have not had typed variables in this sense. As far as my memory will reach, only BLISS of all the non-assembly languages has not had types attached to their values either at compile or runtime.

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 4:48 UTC (Fri) by raiph (guest, #89283) [Link] (1 responses)

If you're thinking of Perl 6 as "a language like Lisp or Perl or Python" you might be missing that Perl 6 has static typing (as well as dynamic tiebreaking during binding). The "optional" aspect of this typing means the coder doesn't need to be explicit but Perl 6 assigns types to values and variables anyway, whether it's Int, Rat, Num or some other number type, or Str or Bool, or the generic Any, or whatever.

An interview with Larry Wall (LinuxVoice)

Posted Jul 24, 2015 6:37 UTC (Fri) by dvdeug (guest, #10998) [Link]

The most recent version of Python has optional static typing, and I'm sure some dialects of Lisp have as well. Values stored in variables almost always have types in languages that don't have mandatory static typing. High-performance interpreters almost always infer types for values and variables as early as possible, but there's always Any to fall back on if that can't be done.

An interview with Larry Wall (LinuxVoice)

Posted Jul 18, 2015 19:55 UTC (Sat) by flussence (guest, #85566) [Link]

You have the wrong impression. Perl 6 already has 32/64-bit IEEE floats (and most other types you can describe in C) if code asks for them, they're just not a default any more since integer fractions became a first-class type.

An interview with Larry Wall (LinuxVoice)

Posted Jul 17, 2015 17:12 UTC (Fri) by raiph (guest, #89283) [Link] (5 responses)

> If I need to do some command line interfaces, I'll use bash scripting

Perl 6 has a nice feature for whipping up CLIs with help messages:

sub MAIN ($move-from, $move-to) { rename $move-from, $move-to }

If you run that without the right args you get an automatically generated usage message:

Usage:
foo <move-from> <move-to>

For a brief discussion of this feature see https://perl6advent.wordpress.com/2014/12/22/the-cool-sub...

An interview with Larry Wall (LinuxVoice)

Posted Jul 18, 2015 9:22 UTC (Sat) by lsl (subscriber, #86508) [Link] (4 responses)

Quite nice. The result of calling it with a non-existant source file name exhibits a bit too much magic for my taste, though. But yeah, I'm a total perl6 noob anyway.

> Cannot find method 'postcircumfix:<( )>'
> [stack …]

An interview with Larry Wall (LinuxVoice)

Posted Jul 18, 2015 20:07 UTC (Sat) by raiph (guest, #89283) [Link] (3 responses)

It works for me (in that it displays a suitable error message). What's the result of perl6 -v and/or what's the exact code you're trying?

An interview with Larry Wall (LinuxVoice)

Posted Jul 19, 2015 11:54 UTC (Sun) by lsl (subscriber, #86508) [Link] (2 responses)

% cat rename
> #!/usr/bin/perl6
> sub MAIN ($move-from, $move-to) { rename $move-from, $move-to }

% ./rename
> Usage:
> ./rename <move-from> <move-to>

% touch a && ./rename a b # works
% ./rename a b
> Cannot find method 'postcircumfix:<( )>'
> in block at src/gen/m-CORE.setting:18243
> in any at /usr/languages/perl6/runtime/CORE.setting.moarvm:1
> in method rename at src/gen/m-CORE.setting:18241
> in method rename at src/gen/m-CORE.setting:18248
> in sub rename at src/gen/m-CORE.setting:18800
> in sub MAIN at ./rename:2
> in block <unit> at ./rename:2

This is perl6 version 2015.03 built on MoarVM version 2015.03

So not quite up-to-date. Will re-test with something more recent.

An interview with Larry Wall (LinuxVoice)

Posted Jul 19, 2015 12:15 UTC (Sun) by lsl (subscriber, #86508) [Link] (1 responses)

And indeed, this issue was already fixed.

https://rt.perl.org/Public/Bug/Display.html?id=125279

An interview with Larry Wall (LinuxVoice)

Posted Jul 20, 2015 0:27 UTC (Mon) by raiph (guest, #89283) [Link]

Thanks for following up. I'm glad it worked. :)

An interview with Larry Wall (LinuxVoice)

Posted Jul 17, 2015 16:20 UTC (Fri) by raiph (guest, #89283) [Link]

> I wanted nested lists ... I couldn't figure out how to do it in perl.

In Perl 6:

[foo, bar, [baz, qux], waldo]

would nest the [bax, qux] list within an outer list.

> list comprehensions

In Perl 6:

say .uc if .chars < 5 for words "foo waldo qux"

prints:

FOO
QUX

> What I'd like to see in python is pattern-matching

Perl 6 supports pattern matching when binding (of any object or data structure to any other).

The classic example is resolving which of multiple functions to call. A trivial example:

multi sub foo ([@, $item]) { say $item }
multi sub foo ([$item, @]) { say $item }

foo [[1,2],3]; # 3
foo [1,[2,3]]; # 1

For more info about "destructuring parameters", see http://doc.perl6.org/type/Signature#Destructuring_Parameters. For a more complex example, see http://rosettacode.org/wiki/Pattern_matching#Perl_6.

An interview with Larry Wall (LinuxVoice)

Posted Jul 17, 2015 20:42 UTC (Fri) by sorpigal (guest, #36106) [Link]

(On that occasion I wanted nested lists -- it was the logical way to do it but I couldn't figure out how to do it in perl. Apparently it can be done but the syntax was not obvious to me and stackexchange etc weren't around yet.)

To do this in Perl5 you need references (because lists flatten automatically). In fact almost everything in Perl5 is (or ought to be) done via refs, it's just not necessarily obvious.

Nested lists are done this way:

my $matrix = [
    [0, 1, 2,],
    [3, 4, 5,],
    [6, 7, 8,],
];
foreach my $row ( @{$matrix} ){
    foreach my $col (@{$row} ){
       print $col;
    }
    print "\n";
}

Twelve years too late, but better than never. The syntax for nested data structures in Perl can get quite bad if you're not careful but it doesn't have to be unpleasant.

An interview with Larry Wall (LinuxVoice)

Posted Jul 16, 2015 17:24 UTC (Thu) by jnareb (subscriber, #46500) [Link] (2 responses)

What "there is more than one way to do it" (TIMTOWTDI), and CPAN, helps with is whipituptude - you can write script to do your thing quickly. Compare Java, where mere Hello World is multi-page monstrosity.

An interview with Larry Wall (LinuxVoice)

Posted Jul 16, 2015 19:02 UTC (Thu) by marcH (subscriber, #57642) [Link] (1 responses)

> Java where mere Hello World is multi-page monstrosity.

Correct but off-topic and thus not fair. This is the main reason why:
http://steve-yegge.blogspot.com/2006/03/execution-in-king...

Another reason is the culture (induced by the above?) for adding a zillion of wrappers and other boilerplate layers of indirection.

An interview with Larry Wall (LinuxVoice)

Posted Jul 16, 2015 23:45 UTC (Thu) by dlang (guest, #313) [Link]

> Another reason is the culture (induced by the above?) for adding a zillion of wrappers and other boilerplate layers of indirection.

Actually, I think the different culture between Perl and Java is _extremely_ significant and drives a lot of the differences. It's not just and afterthought.

An interview with Larry Wall (LinuxVoice)

Posted Jul 15, 2015 14:02 UTC (Wed) by epa (subscriber, #39769) [Link] (41 responses)

That is a very purist position and there are, in the end, few languages that don't have dozens of ways to express the same thing. Even a relatively austere language like C has language features which overlap and where the decision on which to use ends up being a matter of taste (while or for, or just goto? If statement or ternary operator? Should the comma operator be used or not? And so on).

The skill of programming is not to express yourself unambiguously to the computer - that goes without saying - but writing so that a human reader will understand the intent. Different ways to express the same operation convey different nuances of intent and are usually helpful to the reader. It can become a problem if some of the idioms are so obscure, or have such convoluted semantics, that they get in the way of understanding the program. But you have to make some assumptions about the target audience. A Lisp program may be crystal clear to a Lisp programmer despite appearing a mudball of (()) to someone not familiar with that family of languages.

An interview with Larry Wall (LinuxVoice)

Posted Jul 15, 2015 15:31 UTC (Wed) by coriordan (guest, #7544) [Link] (8 responses)

I don't read any purist position in that post. He said "dozens" is too much and perl 6 goes way too far. He didn't say programming languages should only have one way to do each thing.

I agree with what you say, but I don't see it as contradicting what you replied to.

An interview with Larry Wall (LinuxVoice)

Posted Jul 16, 2015 9:46 UTC (Thu) by epa (subscriber, #39769) [Link] (7 responses)

The number of different ways to do something provided by a language also depends on what is included in 'the language'. The C language itself does not provide data structures such as linked lists or hash tables, or any input/output primitives. Once you add the standard C library you get the question of whether to use puts() or printf() - or sprintf() followed by puts(), and so on. Add a library for data structures and you then can choose whether to use a vector, a linked list, a tree... These combinations multiply together pretty fast to give easily 'dozens' of ways to achieve a fairly simple operation such as picking the top three integers from a sequence. With a higher-level language, more data structures and manipulation operations are part of the core language and the syntax tends to be more compact, so it is not a surprise to see many different ways to express even a single line of code.

Take Python as an example, often held up as a contrast to Perl. "There should be one obvious way to do it" is certainly a fine principle and one that Perl could sometimes take note of. But in Python too you can choose between lambdas, list comprehensions, explicit loops (of several types, with some interesting ways to break out of the loop); lists, dictionaries or perhaps tuples; and of course different ways to structure object-oriented code. Again there are easily dozens of ways to achieve a relatively simple operation. And this is a good thing.

I don't have experience with Perl 6 so I can't comment on details, but I will say that if the language includes more powerful tools like grammars, these obviously provide new ways to tackle a problem, and so several more "ways to do it".

An interview with Larry Wall (LinuxVoice)

Posted Jul 16, 2015 12:21 UTC (Thu) by coriordan (guest, #7544) [Link] (6 responses)

I think we were all in agreement on pretty much all of that from the outset.

An interview with Larry Wall (LinuxVoice)

Posted Jul 16, 2015 14:38 UTC (Thu) by raiph (guest, #89283) [Link] (5 responses)

juliank:
> A programming language ... [with] dozens of shortcuts and different ways to say the same thing ... [is an] abomination

epa:
>> there are easily dozens of ways to achieve a relatively simple operation [in lang x]. And this is a good thing.

An interview with Larry Wall (LinuxVoice)

Posted Jul 16, 2015 17:45 UTC (Thu) by coriordan (guest, #7544) [Link] (4 responses)

But we all know the difference between what "dozens" means in a perl context and in the context of practically every other language.

If anyone wants to be pedantic they can find thousands of ways to add two numbers in Python, but that doesn't change that someone saying "Perl goes too far" is not a "purist" opinion and that we know what they mean.

An interview with Larry Wall (LinuxVoice)

Posted Jul 16, 2015 22:06 UTC (Thu) by raiph (guest, #89283) [Link] (3 responses)

> But we all know the difference between what "dozens" means in a perl context and in the context of practically every other language.

Sure. As epa explained, there's no substantial difference in terms of what is used in practice by equally competent programmers, but in Perl's case it's an "abomination" and in the other it's "a good thing".

> saying "Perl goes too far" is not a "purist" opinion

Given the context of railing against alternate forms of expression, it sounds like a succinct definition of a purist opinion to me. You might want to look up the definition of purism, especially as it relates to a language.

An interview with Larry Wall (LinuxVoice)

Posted Jul 17, 2015 2:25 UTC (Fri) by coriordan (guest, #7544) [Link] (2 responses)

"Perl goes too far" means "I've no problem with languages going in that direction but if I had the choice I would rather go somewhat less far".

This is about as far as one can get from "purism".

An interview with Larry Wall (LinuxVoice)

Posted Jul 17, 2015 15:07 UTC (Fri) by raiph (guest, #89283) [Link] (1 responses)

Please don't confuse your words with others', even if you think you're paraphrasing them.

"I've no problem with languages going in that direction but if I had the choice I would rather go somewhat less far" is reasonable and clearly not purist. But those are your words, not juliank's.

juliank said "Programming languages ... should not have dozens of shortcuts and different ways to say the same thing". That's classic purism. That's what epa commented on. That's what I was following up on.

An interview with Larry Wall (LinuxVoice)

Posted Jul 17, 2015 17:03 UTC (Fri) by coriordan (guest, #7544) [Link]

> That's classic purism.

Well then we read his words very differently.

An interview with Larry Wall (LinuxVoice)

Posted Jul 15, 2015 15:33 UTC (Wed) by karkhaz (subscriber, #99844) [Link]

It's not about purity, but rather practicality. Languages that +enforce+ or encourage uniformity beget far more maintainable code. On projects with more than a few developers, the barrier to entry for new contributors is much higher when the codebase is peppered with a dozen different styles and idioms. One doesn't often see huge projects in Perl, but C++ is another notable example here---you get massive codebases in C++, with each developer using a different subset of it and tackling a problem in a different way.

Some languages (like Python) have an explicit philosophy about uniformity, and the comunity encourages new learners to adopt the commonly-agreed best practices of the language. Ruby is better than Perl, but it's explicitly designed to be 'fun' to code in---this is great for your personal hacks, but not so much for maintainability. You do still find some community encouragement of coding style in Ruby, whereas Perl people seem actively to delight in writing ingenious, unreadable code.

An interview with Larry Wall (LinuxVoice)

Posted Jul 15, 2015 15:35 UTC (Wed) by juliank (guest, #45896) [Link] (19 responses)

Some overlapping might be useful, yes

But I don't think Perl is very readable. It's an obscure language. Consider:

class Task {
  has Task @!dependencies;
  has Bool $.done;
}

You have to admit that it would be much more readable this way:

class Task {
  has private Task @dependencies;
  has public Bool $done;
}

Not only has the private/public keyword thing been around for quiet some time, so people are familiar with it if they are used to OOP, it is also immediately obvious to anyone reading the code, even if they do not understand programming. There's no point to reduce visibility annotations to a single character.

Other thing: Using ~ for string concatenation and ~~ for matching is weird. ~ has always been a symbol for approximation of sorts, nobody I know used it for concatenation.

A good language design should take best practices, and not re-invent the wheel everywhere.

An interview with Larry Wall (LinuxVoice)

Posted Jul 15, 2015 15:37 UTC (Wed) by juliank (guest, #45896) [Link]

BTW, it's also very nice to read in English with words.

An interview with Larry Wall (LinuxVoice)

Posted Jul 15, 2015 17:34 UTC (Wed) by b7j0c (guest, #27559) [Link] (1 responses)

Mutating syntax is a triviality for any dynamic language. You can write Perl in latin if you want.

An interview with Larry Wall (LinuxVoice)

Posted Jul 15, 2015 18:16 UTC (Wed) by Wol (subscriber, #4433) [Link]

> You can write Perl in latin if you want.

That's the problem. Although I really did write some of my early code (Fortran 77) in Latin when I was a young programmer :-) And the manager understood it :-)

Cheers,
Wol

Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))

Posted Jul 16, 2015 4:19 UTC (Thu) by raiph (guest, #89283) [Link] (15 responses)

You've misunderstood Perl 6 "private/public" semantics. I'll try to clear that up as I respond to your suggestions about syntax.

Private
=======

Almost all the Perl 6 code I've seen uses the `!` symbol for private attribute declarations. I've read many Perl 6 coders say they prefer to use it.

But the `!` is optional. One can write as you suggest for the private attribute except missing out the word `private`:

class Foo { has Task @dependencies; # declare a private attribute that's an array of Tasks }

Public
======

A public accessor is a method, not an attribute.

A method is called using `.` syntax. Thus, assuming a public accessor method called `done` has been written for a class `Foo`, one might write code such as `say Foo.new.done` and it'll work.

The typical way to get a public accessor method written is to ask Perl 6 to automatically generate it for you:

class Foo { has Bool $.done; # declare attribute, generate public accessor }

The `.` is there in the declaration to remind one of a method call.

All methods called with `.` are public method calls so I'm not seeing the benefit of using the word 'public'. And dropping the `.` would be a big backward step imo.

So...
=====

Use `.` for declaring both a private attribute and public accessor method.

Then use the same `.` for calling the method -- with associated semantics/performance (run-time method resolution that only the JIT can optimize).

Use `!` (or simply omit the `.`) for declaring a private attribute.

Then use the same `!` (or not) for reading/writing the private attribute -- with associated semantics/performance (compile-time direct attribute access that's inlinable by an AOT optimizer).

---------------------------------------------

> Using ~ for string concatenation ... is weird.

I still recall the first time Larry explained his choice. It looks like a piece of string. If this mnemonic doesn't instantly make you go "ahhh", well, you're weird. :P

---------------------------------------------

> A good language design should take best practices, and not re-invent the wheel everywhere.

Sure. It sounds like we just disagree on what best practices to focus on and when innovation is a good thing.

Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))

Posted Jul 16, 2015 17:51 UTC (Thu) by bronson (subscriber, #4806) [Link] (14 responses)

Wow, for noewcomers it sounds like public/private is fairly unreadable/unintuitive. You might have made juliank's point better than juliank did.

~ may look like a string, but it doesn't look like a string concatenator to me. And ~~ definitely doesn't look like a matching operator. But then, it took me a long time to get used to =~.

Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))

Posted Jul 17, 2015 18:26 UTC (Fri) by raiph (guest, #89283) [Link] (13 responses)

> Wow, for noewcomers it sounds like public/private is fairly unreadable/unintuitive.

Really? Once again:

has $foo; # declare attribute
say $foo; # read attribute

has $.foo; # declare attribute and method
say $.foo; # call method

Does that really not make sense to you?

Imo, this should be readable and intuitive for most folk who are used to using `.` for method calls. And forgetting my opinions and shoulds, in actuality I've not seen any newcomers talk about getting tripped up by this when learning Perl 6.

> ~~ definitely doesn't look like a matching operator. But then, it took me a long time to get used to =~.

Yeah, I always disliked =~ and I've heard others say the same.

I'm OK with ~~. Given the usual meaning of ~, it does approximately match a matching operator.

Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))

Posted Jul 17, 2015 20:24 UTC (Fri) by sorpigal (guest, #36106) [Link] (12 responses)

Some people, especially people who are down on Perl, are anti-sigil. Sigils outside of Perl are seen as hard to read and having more of them is obviously bad. I view the negative reaction you're seeing here as simple anti-sigilism.

Sigils are a good thing. They make code easier to read (and understand). If you find this isn't true *you're just not using enough of them*.

As for concatenation, ~ makes as little sense as . or and is no harder to type than +. It only seems weird because it's young. If you want weird, try := for an assignment operator! It's ugly, hard to type and makes no sense... to me, because I don't use many languages that require it. All syntax is intuitive given time. Meaning comes from usage, not the other way around.

Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))

Posted Jul 17, 2015 20:29 UTC (Fri) by juliank (guest, #45896) [Link]

:= is the common way to write a definition in mathematics. It makes sense for definitions, but certainly not that much for re-assignment.

Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))

Posted Jul 20, 2015 10:13 UTC (Mon) by leifbk (guest, #35665) [Link] (6 responses)

I was a carpenter before I started to program in Turbo Pascal in the 80s. It was easy for me to visualise the assignment operator := as a saw with a handle, while the test for equality = is similar to a yardstick.

Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))

Posted Jul 20, 2015 11:56 UTC (Mon) by juliank (guest, #45896) [Link] (5 responses)

I don't understand you and others doing this.

I just remember := as a token. I do not try to relate syntax to real world elements. Why would I do that when I can just remember := in a few milliseconds.

Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))

Posted Jul 20, 2015 14:44 UTC (Mon) by Wol (subscriber, #4433) [Link] (2 responses)

> I don't understand you and others doing this.

Because you are not him!

You're coming over a bit as "my way is the only way" - the exact opposite of Perl's TMTOWTDI. Be careful - that attitude can get you into trouble.

Most people like GUIs. I hate them. But then, I'm happy to accept that other peoples' brains are wired differently. Expecting everybody to be a clone of yourself won't get you very far.

(Oh - and why is it a good idea to assume a linguist can't design a language? If he's a professional doing it for the pay, I'd be inclined to agree, but if he's an amateur being paid to do what he loves, then ...)

Cheers,
Wol

Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))

Posted Jul 20, 2015 15:08 UTC (Mon) by juliank (guest, #45896) [Link] (1 responses)

> > I don't understand you and others doing this.
> Because you are not him!
> You're coming over a bit as "my way is the only way" - the exact opposite of Perl's TMTOWTDI. Be careful - that attitude can get you into trouble.

I did not mean this in a negative way. I'm just curious that some people do this, and other's don't. I would have never thought about mnemonics, so this is a new and interesting thing for me.

Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))

Posted Jul 20, 2015 20:16 UTC (Mon) by Wol (subscriber, #4433) [Link]

I know I repeatedly refer to Dick Feynmann, but read about him and counting numbers in your head. Apparently, if you try to count 60 seconds, it won't be a minute, but it WILL be consistent - when I tried it it always seemed to take me about 47 seconds.

Anyways, Dick and his undergrad mates did this, and Dick was amazed when one of them would quite happily hold a conversation while doing it. Turns out this guy counted by "seeing" a ticker-tape go by. What he couldn't do was watch a TV program while counting.

Dick, on the other hand (like, I think, most people including me), counted silently in his head and had no trouble watching - then recalling - the TV but there was no way he could hold a conversation while counting.

Different people are most definitely wired differently. And that is now one of the big tensions with "linux" - all these guis, gnome, kde, X even, are all "against the spirit" of Unix. It's a pretty safe bet all the original Unix luminaries were word-smiths, not visual people. I'm not saying that's good or bad, just that it *is*. I know all this emphasis on guis alienates me.

Cheers,
Wol

Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))

Posted Jul 22, 2015 19:20 UTC (Wed) by raiph (guest, #89283) [Link] (1 responses)

I suspect you related `:=` to something that already exists, eg its use in conventional math notation.

If not, why, regarding the "private/public" feature discussed elsewhere, would you not be able to just remember `!` as a token that means private?

Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))

Posted Jul 22, 2015 21:17 UTC (Wed) by mathstuf (subscriber, #69389) [Link]

Think of it as the bubble over characters' heads in Metal Gear Solid when you try to peek at them.

Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))

Posted Jul 21, 2015 7:31 UTC (Tue) by jezuch (subscriber, #52988) [Link] (3 responses)

> If you want weird, try := for an assignment operator! It's ugly, hard to type and makes no sense...

Oh, to the language designers a couple of decades ago (before C, basically), it made perfect sense. Assignment is definitely *not* the same thing as equality in mathematics. The latter is a declaration of equivalence of two symbolic expressions; the former is an instruction to perform a side effect (in imperative languages). So it makes sense to use a different symbol. Now we're all brainwashed by C so when we see "if (a = b)" something inside us screams "this is a mistake!!!" ;)

Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))

Posted Jul 21, 2015 15:48 UTC (Tue) by dashesy (guest, #74652) [Link]

Now we're all brainwashed by C so when we see "if (a = b)" something inside us screams "this is a mistake!!!" ;)
More like, that "if (a = b)" bug now has its signature engraved in our genome, and the immune system shows symptoms of allergy including twitching in the eyes and fever.

Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))

Posted Jul 21, 2015 16:34 UTC (Tue) by sorpigal (guest, #36106) [Link] (1 responses)

I'm well aware of where := comes from; it makes total sense and it's clearly a logically superior choice to plain =. I chose it as an example because I expected everyone to be familiar with it. The point is that what's normal is what we normally do or think and what's weird is what's foreign. There's a history of using + and to a lesser extent . for concatenation, so of course those seem reasonable. I expect that after six months of use ~ will have become easy to read and it would be jarring to use another operator when switching to another language.

Perhaps it's not clears, so I'll emphasize: I mean this as much for sigils as other syntax choices.

Private/public attributes/methods (was: An interview with Larry Wall (LinuxVoice))

Posted Jul 22, 2015 20:16 UTC (Wed) by Wol (subscriber, #4433) [Link]

And for me, the natural concatenation operator is ":"

I = 10
I = I : "00"
I = I * 5
PRINT I

Which gives me "5000" :-) Oh the joys of untyped variables :-)

Cheers,
Wol

An interview with Larry Wall (LinuxVoice)

Posted Jul 16, 2015 1:53 UTC (Thu) by marcH (subscriber, #57642) [Link] (10 responses)

> The skill of programming is not to express yourself unambiguously to the computer - that goes without saying - but writing so that a human reader will understand the intent. Different ways to express the same operation convey different nuances of intent and are usually helpful to the reader.

You seem on the verge of dropping the computer from the picture and pretending it's direct human-to-human communication: that could not possibly be more wrong.

Writing code is not writing so another human reader understands "the intend"; it's writing so another human reader understands what you want the OBTUSE AND STUBBORN MACHINE to do, to the tiniest detail so it does not crash some day in the future. The computer is the elephant in the tea room, using up all the space and violently squashing you against the walls as soon as you try (and fail) to have any kind of vaguely "normal" human conversation with nuances, poetic ambiguities, meaningful silences and cultural assumptions. There is a way to whisper some direct human-to-human communication without the machine hearing: it's called comments - but please not the code! By the way: who has never been puzzled by some comment from a non-native English speaker?

Even mathematical and physical languages are wishy washy compared to programming languages. The very last thing I want today's machines to do is trying to guess what someone's broken English means; including mine (especially mine). I'll revisit only once C-3PO exists for real.

Maybe C-3PO stands a chance to be implemented in Perl6 if the latter releases in the next few decades. And Larry Wall will look like a visionary then. But no Perl today, no thanks.

An interview with Larry Wall (LinuxVoice)

Posted Jul 16, 2015 10:27 UTC (Thu) by epa (subscriber, #39769) [Link] (9 responses)

If that were the case then obfuscated, minified, or shrouded source code would be just as easy to work with as the original. After all if all you need to convey to a human reader is exactly what you need to make the machine do, then variable names a01, a02, and a03 are just as good as lower_bound, upper_bound, and middle. The semantics of what the code does are exactly the same either way. And you could replace all loops with if-goto, again still specifying to the tiniest detail what the machine must do.

But although the a01 code expresses exactly *what* you are getting the machine to do, it says nothing to a human reader about *why*. You could, I suppose, write code in this style and rely on comments to explain the intent, but normally it is better to use both ways of communicating, so that both the program code (through meaningful variable names, routine names, code structure and ordering) and the comments give a human reader some idea of what you were thinking and what all this highly specified, minutely detailed code is intended to be *for*.

An interview with Larry Wall (LinuxVoice)

Posted Jul 16, 2015 15:24 UTC (Thu) by marcH (subscriber, #57642) [Link] (8 responses)

> but normally it is better to use both ways of communicating,

Absolutely. It is difficult because programming languages must be both completely unambiguous (unlike Perl) and help humans to understand code *as well*. Not just one or the other.

The (successful) approach to square this circle and make code easier for humans *without* helping ambiguities, corner cases and bugs is: higher level of abstractions and mathematics. Not natural languages. Yes this means that programmers with a mathematical and scientific background and/or taste (rather than... linguists) make better programmers. How's that new?

An interview with Larry Wall (LinuxVoice)

Posted Jul 16, 2015 15:50 UTC (Thu) by epa (subscriber, #39769) [Link] (4 responses)

Any programming language is unambiguous, and that includes Perl. The problem may be that the rules to decide the meaning of a program may be too complicated and hard for humans to remember - so in Perl, the { character can be the start of a block of code, or the start of an anonymous hash, and while in principle the choice is unambiguous, in practice the rules used are complex and hard to predict unless you are intimately familiar with the parser. Fortunately, if the wrong choice is made then it will be a syntax error, so there isn't in practice a problem of writing and running a program with the 'wrong' semantics.

Most of the syntactic sugar in Perl or any language (like having both 'for' and 'while', or having both 'if' and 'unless') does not introduce any ambiguity or uncertainty about how a program will be parsed and executed.

An interview with Larry Wall (LinuxVoice)

Posted Jul 16, 2015 16:02 UTC (Thu) by marcH (subscriber, #57642) [Link] (3 responses)

> Any programming language is unambiguous, and that includes Perl.

Quote from this nice and short interview of an incredibly smart person:

> Arguably in Perl 1 through to 5 we didn’t manage it quite adequately enough. Sometimes the computer was confused when it really shouldn’t be. With Perl 6, we discovered some ways to make the computer more sure about what the user is talking about, even if the user is confused about whether something is really a string or a number.

"...discovered some ways to make more sure even if the user is confused"?! Bye Perl!

An interview with Larry Wall (LinuxVoice)

Posted Jul 16, 2015 17:52 UTC (Thu) by raiph (guest, #89283) [Link]

Larry wasn't talking about how confusing Perl is or isn't.

What Larry was talking about was the concepts that A) sometimes coders are confused (this is true in any language) and B) it's a good thing to provide better error messages (this is also true in any language) and that Perl 6 is better able to provide better error messages when a coder is confused.

An interview with Larry Wall (LinuxVoice)

Posted Jul 17, 2015 9:04 UTC (Fri) by epa (subscriber, #39769) [Link]

I understood that to be referring to dynamic typing where the same value can be interpreted as either a string or a number. That is the way Perl works - polymorphic values but monomorphic operators (so that there are separate operators for string equality and numeric equality). But Larry's remark is purposely quite vague so it could be referring to several things.

An interview with Larry Wall (LinuxVoice)

Posted Jul 18, 2015 19:15 UTC (Sat) by flussence (guest, #85566) [Link]

> "...discovered some ways to make more sure even if the user is confused"?! Bye Perl!

I believe this is referring to design decisions like $a + $b producing either a number or helpful type mismatch error message, whereas in the language holding the front of the web together, addition is a non-commutative operator and also "grapefruit" is a legal return value.

Maybe with a little education you'll be offended at the right languages?

An interview with Larry Wall (LinuxVoice)

Posted Jul 16, 2015 17:39 UTC (Thu) by raiph (guest, #89283) [Link] (2 responses)

> programming languages must be both completely unambiguous (unlike Perl)

Perl 6's grammar is defined in terms of Perl 6 Rules (https://en.wikipedia.org/wiki/Perl_6_rules) which are PEGs (https://en.wikipedia.org/wiki/Parsing_expression_grammar) which "can not be ambiguous". Were you talking about Perl 5 or are you imagining that the Perl 6 grammar is not completely unambiguous?

> programmers with a ... scientific background and/or taste (rather than... linguists)

"Linguistics is the the scientific study of ..." (from https://en.wikipedia.org/wiki/Linguistics). You are presenting a false dichotomy.

> make better programmers

Please cite non-controversial scientific evidence for this claim.

Also, I'm curious; do you self-identify as having a mathematical or scientific background and/or taste and as being a better programmer?

An interview with Larry Wall (LinuxVoice)

Posted Jul 16, 2015 17:48 UTC (Thu) by juliank (guest, #45896) [Link] (1 responses)

Well, Philosoph is a "science" too.

But in practice...

An interview with Larry Wall (LinuxVoice)

Posted Jul 17, 2015 12:35 UTC (Fri) by Wol (subscriber, #4433) [Link]

Actually, it's the other way round. Science is a subset of Philosophy.

But then, unless you have at least some clue as to why it makes sense to argue how many angels can dance on the head of pin - I did know, but have forgotten - you're likely to dismiss Philosophy as irrelevant. Unfortunately, mathematicians and scientists have specialised so much, they've forgotten where their disciplines came from.

(Newton was a "Natural Philosopher" - he dabbled in maths, physics, alchemy, medicine, the lot. They hadn't invented those disciplines back then :-)

Cheers,
Wol

An interview with Larry Wall (LinuxVoice)

Posted Jul 16, 2015 1:15 UTC (Thu) by flussence (guest, #85566) [Link]

> It should not have dozens of shortcuts and different ways to say the same thing

Agreed, we should all switch to HQ9+.

What might be Perl 6's strengths

Posted Jul 15, 2015 12:01 UTC (Wed) by coriordan (guest, #7544) [Link] (4 responses)

I'm still sceptical that perl 6 will be a widely used language but I am looking forward to its release because I'm wondering what concepts other free interpreters will copy, not at the language level but in layers such as parrot or NPQ.

What might be Perl 6's strengths

Posted Jul 16, 2015 1:23 UTC (Thu) by flussence (guest, #85566) [Link]

If you're expecting to learn something positive about Parrot by waiting until Perl 6's release you're in for a rude awakening.

MoarVM/NQP strengths (was: What might be Perl 6's strengths)

Posted Jul 16, 2015 16:17 UTC (Thu) by raiph (guest, #89283) [Link] (2 responses)

At the bottom, VM level
=======================

NFG? The NFG ("Normalization Form Grapheme") implementation in MoarVM provides O(1) timing performance for "character" operations, where "character" is "what a user perceives as a character" per the Unicode standard. Afaik this is the first time such a feature has been built in to a VM.

Failure objects? These are delayed exceptions. They seem to me to be the only sane way to practically handle arbitrary parallel processing. To investigate further, start at the high level with http://doc.perl6.org/type/Failure.

Representations? Since pretty much the start the Perl 6 design has specified a MOP that could fully and efficiently interop with arbitrary object system semantics and with arbitrary C code implementing said semantics. That tall order eventually translated to 6model and Representations. To investigate further, start with the first feature listing at http://moarvm.org/features.html.

At the middle, NQP, layer
=========================

VM feature abstraction? NQP isn't the first middle layer to work between compiler front-ends and back-ends but it contains 8 years worth of development of non-leaky abstractions that create a unified API atop the specifics of diverse VMs (JVM, MoarVM, Parrot).

Grammar engine? See https://en.wikipedia.org/wiki/Perl_6_rules for a high level discussion. If folk come to appreciate the high level characteristics of Perl 6 Rules then NQP's contribution will presumably become interesting too.

To investigate NQP further, start with http://edumentab.github.io/rakudo-and-nqp-internals-course/

MoarVM/NQP strengths (was: What might be Perl 6's strengths)

Posted Jul 23, 2015 1:46 UTC (Thu) by dvdeug (guest, #10998) [Link] (1 responses)

I'm not sure what you're counting as leaky abstractions, but string-using code over a VM that uses NFG and a VM that uses UTF-16 is going to be able to tell the difference; either Perl6 code that expects NFG will be incredibly slow on the JVM, or calling other JVM languages is going to involve a conversion of every string. Compiler magic can only go so far.

As Joel Spolsky said: "All non-trivial abstractions, to some degree, are leaky." Is that not the origin of the phrase "leaky abstraction"?

MoarVM/NQP strengths (was: What might be Perl 6's strengths)

Posted Jul 24, 2015 0:31 UTC (Fri) by raiph (guest, #89283) [Link]

> As Joel Spolsky said: "All non-trivial abstractions, to some degree, are leaky." Is that not the origin of the phrase "leaky abstraction"?

Ugh. Thank you for calling me out about this and doing it gently.

Prudence suggests I stop right here. But I was trying to convey something useful when I wrote the nonsense "non-leaky abstraction" and I want to have another go.

----

In 1992, Kiczales proposed a principled, general solution to the problem later popularized by Spolsky. My TL;DR version would be "build atop [something like] the CLOS mop".

http://www2.parc.com/csl/groups/sda/publications/papers/K...

----

Perl 6 adopts Kiczales' solution wholesale. CLOSish mop mechanisms drive everything from the high level down to as close to the metal as the underlying systems allow.

In particular, the NQP layer implements its abstractions of run-time VM features, and object and function interfaces with other languages, using NQP meta objects.

http://edumentab.github.io/rakudo-and-nqp-internals-cours...

----

When I used the ill begotten phrasing "non-leaky abstractions" I meant "abstractions that can, in principle, be relatively easily tweaked by users so they give correct and performant results -- ie don't leak -- for a given use-case".

> string-using code over a VM that uses NFG and a VM that uses UTF-16 is going to be able to tell the difference; either Perl6 code that expects NFG will be incredibly slow on the JVM, or calling other JVM languages is going to involve a conversion of every string.

First, let me note that I personally don't expect to see Perl 6 *officially* supporting running on the JVM for at least another year.

I think you chose well to pick the NFG abstraction as being especially prone to leakage in the sense of serious performance ramifications when Perl 6 is running on the JVM and especially when one is passing strings back and forth between Perl 6 and another JVM language.

One mitigation is that code that doesn't use character level operations, eg just copies whole strings, compares whole strings, passes strings back and forth between Perl 6 and some other JVM language, etc., could just use some type that `does Unicodey` with an appropriate encoding, eg UTF-16, rather than using Strs (NFG strings).

But yes, it's going to be interesting to see how NFG on JVM pans out. :)


Copyright © 2015, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds