Skip to content
loading...

From Javascript to Python

Avery Berkowitz on December 01, 2019

So you know javascript but you get this amazing offer to work at this great company in the perfect city and JS is nowhere to be found in their tech... [Read Full]
markdown guide
 

One thing that could be added is that when updating a global variable from a function, the variable needs to be declared as global in the function.

outerVar = "not assigned"

def assign():
   global outerVar
   outervar = "Assigned"
 

Good hint, but in my opinion it doesn't belong to this kind of introduction to python, because it is (in most cases) bad practise. The "normal" case should be to use parameters and return a value.

 

Well, he introduced variables and functions, so I think it's worth mentioning because should they want to use it, they may think they are used the same way as many other languages and wonder why the variable is not updated.

Since this is geared to people coming from Javascript, I'm assuming they already know when or when not use a global variable.

Okay, good points, thanks. The argument, that people should already know what they are doing, convinced me. So maybe, yes, it is worth to mention it.

 

we use classes [...] to allow our programs to represent things in the Real World.

Sorry, but I could not resist. I think as developers we must be very careful with this statement.

I've explained why in my two part series

 

Well, it's much better than moving the other way around like I'm doing: less node_modules 'black holes' since you can do basic things like deep-copying objects out of the box and the language works without transpiling the heck out of it... 😂
I guess you'll still have much JS on the frontend that uses Django to access APIs created with Django REST Framework.
I'm curious, do you use any "DRY" approach/library so that you don't have to write the same checks in both Python and JavaScript?

 

You gotta try out pnpm! Its like npm but it doesnt install things more than once per machine:)

 

I believe it's not "touples" but "tuples".

I recently started using python (even though that was the language that introduced me to programming) from a javascript and C# background.
I somehow found it disconcerting at first and I had to do basically what you wrote. I had to check how things work in python.
I think a post like this can be useful so thanks for writing it!

 

yes, definitely tuples. thanks for the catch

 

Very cool to see an inverse perspective to mine. I started in Python before moving to JavaScript. Thanks for sharing.

 

I started in Python2 before moving to CoffeeScript for JavaScript.
Then back to Python3, then CoffeeScript kinda fading away slowly,
then tried TypeScript but didnt like it and wont work for me.
Then learned Nim which covers JavaScript and WebAssembly now.

JavaScript does not really feel like a pure Functional language tho.
Good post, keep it up.

 
 

This is the equivalent of javascripts typeOf().

Should be typeof operator or typeof(...) (lowercase o) function.

Useful article though.

 

thanks for the catch. moving too fast today!

code of conduct - report abuse