3 ms·
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 no
by timknauf 18y ago
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?
- axod 18y agook 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.
- timknauf 18y agoYeah, not really my favourite bracketing style either. Good example though - it is conceivable that this could happen.
- halo 18y agoJavaScript 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.
- timknauf 18y agoWell, 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?