Multi-line String
Python3.6
print("""string text line 1
string text line 2""")
Enter fullscreen mode
Exit fullscr...
For further actions, you may consider blocking this person and/or reporting abuse
I just really want indentation instead of brackets for code blocks! Then JavaScript will officially be fully Pythonic.
You've just described CoffeeScript.
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.
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.
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 😄
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!
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.
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 😅
I totally agree with Evan You (who wrote Vue) on this one slides.com/evanyou/semicolons#/
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.
To add to the Getter & Setter examples: You can use
this
in Python instead ofself
. It is just a convention, that people refer to the current instance asself
. Also, instead ofsqrt
in both languages, you can write**0.5
. With both modifications, that codes look even more similar.About the classes example: They might look similar, but they are not.
__init__
is not a constructor.__init__
is an initializer. The constructor in Python is called__new__
. Also, usually you override__repr__
to get a representation of the object instead of__str__
.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.
No need to be that categorical in your judgement, your
'' + 2
code 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” ;)
There's a method for that:
Or as an alternative,
String(x)
, which does exactly the same thing, except ifx
is null or undefined, then it produces'null'
or'undefined'
instead of throwing an error.Javascript cannot be Pythonic until it has Python's rules of dynamic typing, mutability/immutability, and equivalence. It would also need to iterate in the same manner. See Facts and myths about Python names and values and Loop Like a Native by Ned Batchelder for excellent explanations.
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 takes more than a few specific capabilities to be "Pythonic".
PEP-20 for example is pretty core to Python: python.org/dev/peps/pep-0020/
I find it unlikely that JS's poor organization will ever reach a level where they could be considered Pythonic, even though they do make (often sloppy) copies of features from (among other things) Python.
:( Kinda gutted that JS extends syntax looked a lot cleaner.
I have to fight to not use braces if I switch between Python & JS, even though they waste space and the language doesn't enforce (eslint is a tool, it's not language enforced like python).
Here's my tweet response twitter.com/LewisCowles1/status/10...
I noticed these similarities when working with Django. So often I accidentally code with Python syntax in JS or vice versa
Very interesting comparison, thanks for the nice clear examples.. :)
Yeah, I've noticed this some time ago.
Don't forget that you also can omit semicolons in JS as well :)
Looks a lot more like C# to me. If ES2017 had access modifiers it'd be nearly identical.
Just have a look on the TypeScript :)
I was worried that the variable declaration of the sample code is
var
though using ES2017.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.
Great that's what I just needed ;)
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'd say it's even more like Ruby, but everyone already says that Ruby and Python are similar.
Just waiting for ES202? == Python, you might as well...
It looks more like C#. if you consider Typescript instead of JavaScript is uncanny similar
Wow didn't know JavaScript became cool😁