News for hackers. Stuff that matters.
Re:Ask HN: Why use semicolons to terminate statements in mod... by timknauf on Monday November 24, 2008 @04:51AM (#374637)
Keep in mind that I come from a mainly Python and Ruby background; both of those languages have always had newline-terminated statements. Yes, neither Python nor Ruby nor newline-terminated Javascript would return the desired result. But neither language seems to be suffering hugely as a result. (As far as I know.)

Why would you write a return statement like that in the first place? (Not intended as flamebait - I am genuinely curious to know.) If it is a simple typo that separates the 'return' from the '[1,2,3]', then isn't the negligent typist just as likely to leave off the all-important semicolon? Or is there a genuine reason you might want to put the [1,2,3] on a line by itself?

Re:Ask HN: Why use semicolons to terminate statements in mod... by halo on Monday November 24, 2008 @06:04AM (#374682)
JavaScript syntax lets you write statements over multiple lines - if the first line cannot be parsed correctly it assumes you meant to continue over to the second line. This leads to odd error messages and JavaScript being harder to debug without semicolons.

Note that this is different to, say, Python, where newline explicitly indicates termination of a statement.

Re:Ask HN: Why use semicolons to terminate statements in mod... by timknauf on Monday November 24, 2008 @06:28AM (#374698)
Well, Python will let certain statements continue over multiple lines as well, e.g.

  someFunction(parameterOne,
               parameterTwo)
I think maybe the difference is that Python has always treated newlines the way it does now. JavaScript, on the other hand, has developed idioms based on the semicolon model. So has the rug has been snatched out from underneith its users by suddenly making them optional? Does the change make a lot of useful idioms harder to implement?
Re:Ask HN: Why use semicolons to terminate statements in mod... by axod on Monday November 24, 2008 @06:03AM (#374680)
ok here's a more usual situation in which the programmer is blindly using their favorite bracketing style, and come across the issue...

function getObject()

{

    return       // returns undefined, not the object.

    {

        age: 30,

        name: "axod"

    }
}

Personally I hate that style of bracketing, but some swear by it.

Re:Ask HN: Why use semicolons to terminate statements in mod... by timknauf on Monday November 24, 2008 @06:21AM (#374695)
Yeah, not really my favourite bracketing style either. Good example though - it is conceivable that this could happen.