LanX has asked for the wisdom of the Perl Monks concerning the following question:

I have trouble providing a "reliable source" for WP to admit that Perl influenced JS, and am having a lengthy discussion at the talk page of JavaScript

This blog entry lists JS methods which were influenced verbatim by Perl.

This is done by grepping the original source code of JS for "Perl"

The referenced Chinese blog entry even has a screen shot.

The link to the original source is broken, can someone please help me proving that point?

Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery

  • Comment on Proving that Perl influenced JavaScript for WP

Replies are listed 'Best First'.
Re: Proving that Perl influenced JavaScript for WP
by karlgoethebier (Abbot) on Mar 29, 2025 at 23:30 UTC

    ”When I did JavaScript's regular expressions I was looking at Perl 4. I did step through it in the debugger, as well as read the code. And that gave me ideas; the implementation I did was similar. In this case the recursive backtracking nature of them was a little novel, so that I had to wrap my head around. It did help to just debug simple regular expressions, just to trace the execution. I know other programmers talk about this: you should step through code, you should understand what the dynamic state of the program looks like in various quick bird's-eye views or sanity checks, and I agree with that.” Brendan Eich in “Coders at Work: Reflections on the Craft of Programming” Peter Seibel 2009 page 158/159

Re: Proving that Perl influenced JavaScript for WP (updated)
by LanX (Saint) on Mar 29, 2025 at 23:30 UTC
    Googled this tweet, but the link to X seems broken

    BrendanEich

    Java inspired sort, which is in-place/mutating. TBH, JS1.0 in 1995 was under Perl influence; JS1.2 in 1997 fell more under Python influence.

    12:00 AM · Juli 4th, 2017

    https://x.com/BrendanEich/status/881996154115837952

    update

    I'm only able to see this tweet in Firefox, kind of weird.

    (Seems like you fired too many people, Elon!)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

Re: Proving that Perl influenced JavaScript for WP
by LanX (Saint) on Mar 29, 2025 at 20:32 UTC
    Hi

    This is a link the current source of the Spidermonkey implementation of JS Arrays:

    https://searchfox.org/mozilla-central/source/js/src/builtin/Array.cpp

    Searching for the word "Perl" shows a list of "Perl-ish methods" like join , reverse, push , etc

    /* Perl-ish methods. */ JS_INLINABLE_FN("join", array_join, 1, 0, ArrayJoin), JS_FN("reverse", array_reverse, 0, 0), JS_TRAMPOLINE_FN("sort", array_sort, 1, 0, ArraySort), JS_INLINABLE_FN("push", array_push, 1, 0, ArrayPush), JS_INLINABLE_FN("pop", array_pop, 0, 0, ArrayPop), JS_INLINABLE_FN("shift", array_shift, 0, 0, ArrayShift), JS_FN("unshift", array_unshift, 1, 0), JS_FNINFO("splice", array_splice, &array_splice_info, 2, 0),

    . The corresponding Perl functions can be found in perlfunc

    I'm sure a repo of JS 1.0 would show more detailed comments regarding Perl

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

Re: Proving that Perl influenced JavaScript for WP
by ikegami (Patriarch) on Mar 29, 2025 at 18:03 UTC

    1. What's WP? 2. Last link is 403.

Re: Proving that Perl influenced JavaScript for WP
by harangzsolt33 (Deacon) on Apr 01, 2025 at 13:21 UTC
    Yes, I have noticed that there are many similarities between Perl and JavaScript...the way they handle numbers for example. A variable scalar can hold a string or number, and what you do with it or how you treat it is going to determine whether it's going to be used as a number or a string. Both Perl and JavaScript has the ? : << >> / + - + -- ++ *= /= %= -= += <<= >>= operators. In JavaScript the % modulo operator works a bit differently, but both Perl and JavaScript stores numbers the same way. In JavaScript, you can use arguments[] just like in Perl you can use @_ but in Perl they did away with named arguments. Both JavaScript and Perl have regexes, although JavaScript is a bit limited. When it comes to Unicode characters, Perl requires a module to work with unicode strings, but in JavaScript the support is builtin from the start. In fact, your JavaScript functions and variable names can have unicode characters in them. In JavaScript, you can name your variables to start with a $ sign and write code that resembles Perl. Both Perl and Javascript have the eval function. Perl has "last" and "next," while JavaScript has "break" and "continue." They do the exact same thing. Both Perl and Javascript are quite lenient in the way they parse the source code (unless you use strict and warnings).

    Perl has vec(), pack() and unpack() and printf() and sprintf() which are entirely missing from JavaScript. Perl is very efficient at manipulating strings but not so fast working with arrays. JavaScript is just the opposite. It's very fast with arrays but slow with strings. Perl has hashes, while JavaScript has properties. I know, it's not the same, but it's a little bit similar.

      JavaScript or rather JS1.0 is mostly a baby Perl with Java syntax. The prototype object system from Self being the main difference (objects are kind of blessed hashes which inherit from other objects not classes)

      The claimed functional influence from Scheme is already present in Perl5. ( sub returns a function reference, making functions a first class object which can be treated like variables)

      Block scoping was later introduced into JS with let . ( var is a mess )

      The operators you list derive from C, a common predecessor for Perl and Java.

      Actually "typecasting" in JS is a major problem, JS has no "scalars".

      To better explain, there are two major ways to do dynamic typing.

      A) a type is determined when initializing.

      Like in Python where 3/2 is 1.

      Why? Because 3 and 2 are integers. (Python introduced something like // later to address the confusion)

      B) a type is determined by the operator.

      Like in Perl where 3/2 is 1.5 and 3 . 2 is 32

      JavaScript is a mongrel of both systems,

      and the rules how + behaves confuse(d) the shit out of people.

      You can remember that 1 + "1" is "11", but what will happen if you don't have full control about the types in the variables of a + b ?

      JS programmers must resort to tricks like

      'a+b+0' or 'a+b+""'

      (IIRC, this depends on precedence and I have to look it up to be sure UPDATE guess what, I got it wrong, have to correct this later.

      What's sure is that a+=0 becomes a number and a+="" a string )

      Perl fixed this with a lot of operators, but people complain that the code looks unreadable, because of all the symbols.

      But Brendan had 10 days to design the language which had to look like Java...

      They fixed a lot of stuff in the meantime and introduced some nice python features.

      But it's still annoying not to have pure hashes in JS ...

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      see Wikisyntax for the Monastery