News for hackers. Stuff that matters.
Re:Opera moves to WebKit by jerhewet on Wednesday February 13, 2013 @08:07AM (#5212847)
Unhealthy? I've been longing for the day that all browsers are based on WebKit, because it means a real web programming language will be that much closer to replacing kiddiescript.

EDIT -- from http://wtfjs.com:

parseInt('06'); // 6

parseInt('08'); // 0

Your language is bad, and you should feel bad.

Re:Opera moves to WebKit by michael_h on Wednesday February 13, 2013 @08:55AM (#5213039)
This comes up every now and then. That code makes perfect sense. You write octal numbers by prefixing them with a zero, the same way you write hexadecimal numbers by prefixing them with a '0x'.

  strtol("06", NULL, 8);  //6
  strtol("08", NULL, 8);  //0
Is C bad? Should Kernighan and Ritchie feel bad?
Re:Opera moves to WebKit by T-hawk on Wednesday February 13, 2013 @11:53AM (#5214122)
C wasn't bad for making that design decision in 1973, to include syntactical space for octal numbers. Programmers actually used octal notation then. It made sense in an environment where contemporary tech included the PDP-8's 12-bit words (four octal glyphs) and displays of seven-segment numeric readouts (where octal is useful, as letters for hexadecimal can't be displayed and base-10 needs conversion logic.)

Javascript was bad for making that design decision in 1995, when nobody seriously used octal for anything, so the leading zero was vastly more likely to introduce a class of WTF bugs instead.

Re:Opera moves to WebKit by papsosouid on Wednesday February 13, 2013 @12:18PM (#5214279)
No, because strtol gives you the ability to see that the parse failed and where. You chose to give it NULL there, but you could choose to use the function correctly. You can't do it correctly in the javascript and PHP cases. In the PHP case, it is actually just a bug in the PHP codebase that octal digits are supported at all, and they don't use strtol correctly. Note that perl, python and ruby all support octal digits correctly, there really is no excuse for PHP and javascript not to.
Re:Opera moves to WebKit by user24 on Wednesday February 13, 2013 @12:25PM (#5214323)
> You can't do it correctly in the javascript ... case

Sure you can. Read the Fine manual: https://developer.mozilla.org/en-US/docs/JavaScript/Referenc...

tldr: parseInt("08", 10);

Re:Opera moves to WebKit by papsosouid on Wednesday February 13, 2013 @12:35PM (#5214385)
We're not talking about parsing in base 10, we're talking about parsing in base 8. I need to be able to tell if the parse succeeded or not, silently hiding errors is bad. The correct behaviour demonstrated in perl and python:

    $ perl -le 'print 07'
    7
    $ perl -le 'print 08'
    Illegal octal digit '8' at -e line 1, at end of line
    Execution of -e aborted due to compilation errors.
    $ python -c 'print 07'
    7
    $ python -c 'print 08'
      File "", line 1
        print 08
       	^
    SyntaxError: invalid token
Re:Opera moves to WebKit by user24 on Wednesday February 13, 2013 @01:01PM (#5214550)
Got to admit, I am disappointed that

> parseInt("08", 8);

returns 0 instead of NaN

Re:Opera moves to WebKit by nemetroid on Wednesday February 13, 2013 @06:13PM (#5216355)
Returning 0 makes perfect sense. parseInt matches an integer from the beginning of the string, so it reads the 0 and then stops at the 8 because 8 is not a valid digit in base 8.

    >>> parseInt("123foobar", 10)
    123
Re:Opera moves to WebKit by user24 on Thursday February 14, 2013 @06:16AM (#5218936)
Good point.
Re:Opera moves to WebKit by pcwalton on Wednesday February 13, 2013 @11:22AM (#5213880)
WebKit maintainers are opposed to replacing JavaScript. See:

https://lists.webkit.org/pipermail/webkit-dev/2011-December/...

Re:Opera moves to WebKit by brownell on Wednesday February 13, 2013 @08:50AM (#5213019)
I think you're missing something...

parseInt('08', 10); // 8