5 ms·
Also, as a Python programmer, you'll want to use "lodash.get" which is the equivalent of Python's dictionary.get() function which is incredibly useful. To inst
by andrewstuart 8y ago
Also, as a Python programmer, you'll want to use "lodash.get" which is the equivalent of Python's dictionary.get() function which is incredibly useful. To install it you do "yarn add lodash.get".
There's lots of ways to get variables from objects/dicts in JavaScript, and I almost always use:
let foo = {"kingName": "edward"}
get(foo, "kingName", null)
Thus you get a nice predictable null if there is no kingName.
Python does falesy well, JavaScript does not. In Python you rely on None alot, in JavaScript there are lots of inconsistent falsey values. Thus in Python I can do lots of code that is quite terse because it assumes a nice predictable falsey value, in JavaScript I tend to verbosely type out all my comparisons even if they are as simple as (variable === true) or (variable === false). By always consistently doing explicit comparisons (i.e. stating what I expect on both sides of the comparison) I can avoid alot of bugs arising from JavaScript's weird falsely behaviour. That's just my personal taste.
Broadly speaking I try to return null in JavaScript where I would have returned None in Python, and generally I'd rather be using lodash.get to force a null return. I prefer to avoid programming around "undefined" in JavaScript.
In Python you do alot of iterating dicts and lists. In JavaScript the equivalent is map/filter and find.
To answer the question of which framework to go with, it's a personal choice of course. I choose ReactJS over Vuejs. It strikes me that VueJS is easy to start with but that is because it lacks an overall architecture. Thus the tradeoff is that you learned it fast but maybe you'll pay for the lack of application architecture later. If you go with ReactJS you might find it harder up front to grasp the architecture, but you'll be in a good position when your application gets to the point of needing an architecture. If you are an experienced programmer then you should not be afraid to learn ReactJS. The other key difference IMO to VueJS and ReactJS is that ReactJS points in the direction of immutability with its one way data flow which I think is important. I must say my advice can be taken with a grain of salt though because I have not programmed VueJS so I'm biased.
As a Python programmer, you'll generally feel pain as you learn JavaScript because asynchronous programming pervades everything. At first I hated this but after many years of async programming I'm glad I understand it. Python is magnificently synchronous. For the Python programmer learning JavaScript I'd suggest making a real effort over time to learn all the JavaScript asynch programming techniques including callback, promises and async/await. Your head will spin but when it falls into place you'll realise the power of JavaScript's inherent async nature.
- meiraleal 8y ago> Broadly speaking I try to return null in JavaScript where I would have returned None in Python, and generally I'd rather be using lodash.get to force a null return. I prefer to avoid programming around "undefined" in JavaScript. Why not var kingName = foo["kingName"] || null ?
- baranovxyz 8y ago> var foo = { kingName: '' }; undefined > foo['kingName'] || null null
- meiraleal 8y ago'' defaults to null is a better default than '' been different than null (so you would have 2 different nulls).