3 ms·
Coming from Python [...] For example, in C-like languages, you can omit curly brackets after a conditional expression if you only have one stateme
by mratzloff 14y ago
Coming from Python [...]
For example, in C-like languages, you can omit curly brackets
after a conditional expression if you only have one statement:
if (condition)
action();
But what happens if we add a new statement:
if (condition)
action();
action2();
Of course, that doesn't seem to be an issue in Python, the language he's coming from.
Most of his points are similarly contrived and could be equally applied to Ruby, a language which doesn't require parentheses and quite a lot of developers seem to like, or Python which is similarly whitespace-dependent and quite a lot of developers also seem to like. But inflammatory headlines do drive traffic from HN...
Given that CoffeeScript doesn’t fix any of the fundamental problems of JavaScript
I think most developers who are well-versed with both JavaScript and CoffeeScript would disagree that CoffeeScript doesn't fix any of the problems with JavaScript. It certainly makes it easier to loop through object properties. It makes code more readable in a number of ways; post conditions, list comprehension-like syntax, simpler loops, the existential operator (`foo?`), and the maybe object-like syntax (`foo.bar?.baz?.quux`) are definitely improvements.
You can of course write bad code in any language, no matter how structured it is. I myself am about to embark on refactoring a massive, terribly-constructed Python system that processes millions of requests each day. The author didn't follow the strictures of the Python community at all. How is that any different from someone who exercises poor judgment when writing CoffeeScript? It's not.
- Macha 14y agoThe issue with the optional curly brackets is that for new users, or even experienced users reading through code quickly is that at first glance: if(something) doSomething(); And: if(something) doOneThing(); doAnotherThing(); Both look like they should execute the same way - running the indented code if the condition is true. The reason this is a problem in C and not in python is that in python, this code operates as it intuitively looks, while in C, it does not. (It can trip up experienced users if they're not paying enough attention and their mind just assumes the curly brackets are there.)
- artsrc 14y agoThe issue is that: * Humans use indentation * The Compiler ignores indentation * The indentation and the the compilers interpretation are different
- lmm 14y agoCan you give examples? I'd really like to see some unreadable python, and other than nested lambdas I can't see any real ways to screw it up at the basic syntax level. Even golf-style python tends to have a structure that's easy to follow (though what the code's actually doing can be another matter), and I feel it's significant that there's no obfuscated python contest.