classColorPoint(Point):def__init__(self,x,y,color):super().__init__(x,y)self.color=colordef__str__(self):return"{} in color {}".format(super().__str__(),self.color)
ES2017
classColorPointextendsPoint{constructor(x,y,color){super(x,y)this.color=color}toString(){return`${super.toString()} in ${this.color}`}}
“As much as I’d love our code to be fully compliant with the great programming practices of this world, I’d rather have it working — if possible before the heat death of the Universe.”
Or as an alternative, String(x), which does exactly the same thing, except if x is null or undefined, then it produces 'null' or 'undefined' instead of throwing an error.
“As much as I’d love our code to be fully compliant with the great programming practices of this world, I’d rather have it working — if possible before the heat death of the Universe.”
No need to be that categorical in your judgement, your '' + 2 code sample has always been outdated, as String(2) or (2).toString() have been allowed since the 1997 standard (source).
It’s possible to do awful code in a lot of languages, Python included, finding the worst in a tech is not a proof of it “sucking” ;)
True, this is kind of half joke, half dream scenario. You would probably need automatic bracket insertion similar to the automatic semi-colon insertion that exists now!
Yep, CoffeeScript is a good idea except that this kind of syntax-driven transpiling never seems to be worth it. Maybe pre-ES2015 but I can't imagine CoffeeScript living much longer besides legacy.
I disagree. If you have to use a build step to convert JavaScript into older JavaScript to get all of it's best features using another syntax is just as okay. Use Elm use ClojureScript use CoffeeScript use whatever you're comfortable with.
I agree with you, but what I was trying to say is that with JS's improvements, CoffeeScript isn't offering as much. A lot of the benefits are now native, so the CoffeeScript community shrinks and the tradeoffs of fewer people understanding it are no longer worth the trouble.
Elm and ClojureScript bring more than syntactic sugar to the table. Same with TypeScript.
Use CoffeeScript if that's what you like, but I think the benefits have faded of late.
I haven't really used it myself but the community seems to have some really dedicated people. I believe they just released a new version to put it more in line with modern js.
So I'd hate to stop a potential user from trying it because they read this and didn't think it was worth a glance.
The JS comminity owes them a lot cause es6 wouldn't be what it is without coffeescript so hopefully they keep doing innovative stuff that ends up coming over to us.
The JS comminity owes them a lot cause es6 wouldn't be what it is without coffeescript so hopefully they keep doing innovative stuff that ends up coming over to us.
I think this is a little off the mark. This thread was discussed the influencing factors for coffeescript and this post showed how js is similar to a coffeescript influence (python). Personally, I think it's more accurate to thank python for doing innovative stuff that "ends up coming over to us". Repositories like this highlight how cs is waning.
According to wikipedia: "CoffeeScript is a programming language that transcompiles to JavaScript. It adds syntactic sugar inspired by Ruby, Python and Haskell in an effort to enhance JavaScript's brevity and readability."
I'm a Sr. Software Engineer at Flashpoint. I specialize in Python and Go, building functional, practical, and maintainable web systems leveraging Kubernetes and the cloud. Blog opinions are my own.
Array comprehensions existed briefly but didn't receive enough support to become standardized so they were dropped. I expect they may come back in the future.
It kinda seems like languages are all becoming each other, haha. I can draw a lot of similarities here to Dart. I'm sure some folks would find that a lot of the same features listed here are also in other languages like Kotlin and Swift.
I interned at NASA, working on statistical modeling and machine learning projects. Now I'm at Ferguson Enterprise, working on applying UX principles to internal tooling!
The best thing that happened to me was when I presented some working python code and the guy on the front row asked me when I was going to implement the pseudocode example.
It sure makes JS more usable. Still, the "insides" keep on being messy, there is many holes around and so on. But yup it's moving towards a direction that I like.
Oldest comments (49)
Hmm... Good comparaison, JS is definitely getting better, but still.
Quick thougts:
Everything is an Object in JS (including arrays), there isn't any proper equivalent of python's magic functions (add for example).
One thing that horrifies me: how to convert a integer to string:
'' + 2.I think JS' ecosystem is awesome, but JS in itself absolutely sucks. Pretty much the opposite of Python.
There's a method for that:
Or as an alternative,
String(x), which does exactly the same thing, except ifxis null or undefined, then it produces'null'or'undefined'instead of throwing an error.No need to be that categorical in your judgement, your
'' + 2code sample has always been outdated, asString(2)or(2).toString()have been allowed since the 1997 standard (source).It’s possible to do awful code in a lot of languages, Python included, finding the worst in a tech is not a proof of it “sucking” ;)
I just really want indentation instead of brackets for code blocks! Then JavaScript will officially be fully Pythonic.
That will be a problem for minimizers
True, this is kind of half joke, half dream scenario. You would probably need automatic bracket insertion similar to the automatic semi-colon insertion that exists now!
You've just described CoffeeScript.
Yep, CoffeeScript is a good idea except that this kind of syntax-driven transpiling never seems to be worth it. Maybe pre-ES2015 but I can't imagine CoffeeScript living much longer besides legacy.
I disagree. If you have to use a build step to convert JavaScript into older JavaScript to get all of it's best features using another syntax is just as okay. Use Elm use ClojureScript use CoffeeScript use whatever you're comfortable with.
I agree with you, but what I was trying to say is that with JS's improvements, CoffeeScript isn't offering as much. A lot of the benefits are now native, so the CoffeeScript community shrinks and the tradeoffs of fewer people understanding it are no longer worth the trouble.
Elm and ClojureScript bring more than syntactic sugar to the table. Same with TypeScript.
Use CoffeeScript if that's what you like, but I think the benefits have faded of late.
I haven't really used it myself but the community seems to have some really dedicated people. I believe they just released a new version to put it more in line with modern js.
So I'd hate to stop a potential user from trying it because they read this and didn't think it was worth a glance.
The JS comminity owes them a lot cause es6 wouldn't be what it is without coffeescript so hopefully they keep doing innovative stuff that ends up coming over to us.
I think this is a little off the mark. This thread was discussed the influencing factors for coffeescript and this post showed how js is similar to a coffeescript influence (python). Personally, I think it's more accurate to thank python for doing innovative stuff that "ends up coming over to us". Repositories like this highlight how cs is waning.
True, CoffeeScript is heavily influenced by Python! I do think it usually causes more pain than its worth to add something like that in though.
Isn't CoffeeScript influenced by Ruby?
According to wikipedia: "CoffeeScript is a programming language that transcompiles to JavaScript. It adds syntactic sugar inspired by Ruby, Python and Haskell in an effort to enhance JavaScript's brevity and readability."
The indentation is definitely Pythonic.
How about BuckleScript, a OCaml compiler back-end that eats OCaml and spits out JavaScript?
Looks pretty Pythonic to me:
woah that looks super Elm-ish to me
They actually share roots! OCaml and Elm are both in the ML family of programming languages.
I had a better time learning Reason and BuckleScript than learning Elm though LOL but hey as long as it's functional I'm all for it
Yeah plus all the types and all the goodness 😄
no way 😂 i hate indentation
Do you know if JavaScript has anything approaching comprehension syntax? That would be extra pythonic!
From your "Arrow Function" section:
Generally (and you probably know this), you see this in Python as:
Array comprehensions existed briefly but didn't receive enough support to become standardized so they were dropped. I expect they may come back in the future.
Yeah, I don't think the syntax was quite as clean as Python's but I love that feature in Python and hope it comes back to JavaScript.
You can get rid of the semicolons as well. I use prettier in VS Code and it automatically does it for you.
I totally agree with Evan You (who wrote Vue) on this one slides.com/evanyou/semicolons#/
Newbie question, what is the performance hit for auto insertion?
I mean when the interpreter does it, "live"
lh3.googleusercontent.com/hX39h-wD...
If it's a large app, this seems like a lot 😅
It kinda seems like languages are all becoming each other, haha. I can draw a lot of similarities here to Dart. I'm sure some folks would find that a lot of the same features listed here are also in other languages like Kotlin and Swift.
Almost all of these C# can do.
Cool! Also, closure works the same in Python and Javascript.
The best thing that happened to me was when I presented some working python code and the guy on the front row asked me when I was going to implement the pseudocode example.
I noticed these similarities when working with Django. So often I accidentally code with Python syntax in JS or vice versa
I'd say it's even more like Ruby, but everyone already says that Ruby and Python are similar.
I'd better keep apart semantics and tinkering with lang:
JS:
Python:
But, JS:
and Python:
Thus historically JS is much more ad-hoc with all the consequences.
It sure makes JS more usable. Still, the "insides" keep on being messy, there is many holes around and so on. But yup it's moving towards a direction that I like.