The next line of code in JavaScript isn't always going to be executed after the previous line is complete. This is unlike Python, which generally executes each line after the previous line is complete.
Hence all the callbacks, promises, async/awaits patterns to learn in JavaScript..
The next line in JS is guaranteed to execute immediately after the preceding one; except in the case of callbacks (including sugar, like promises), which are also executed sequentially, but deferred until they are explicitly called by whatever they're passed to. In fact, one of the biggest complaints about JavaScript (that it can block the main thread if it tries to do too much in one frame) is a consequence of this guarantee.
Granted, I've written primarily JavaScript for the last five years, but it's pretty straightforward to reason about. Any language that lets you respond to events, I/O, etc. is going to require that you reason about things over time - JavaScript is no outlier here.
The way you've written your remark, it sounds as if JavaScript executes lines out of order, or will wait an arbitrary amount of time to move from one line to the next. Obviously, neither of those is true.
You have things backwards. Python has threading, JavaScript does not. Potential breaks in execution are limited and explicit in JavaScript but almost ubiquitous in Python.
async/await is pretty easy to use... plus if you want your robot to be able to perform multiple actions at once (i.e. rotate a camera to stay focused on an object while moving) having asynchronous capabilities seems like it would make things easier.
That being said I have zero robotics experience, just a lot of JS experience lol :shrug:
bsimpson|7 years ago
The next line in JS is guaranteed to execute immediately after the preceding one; except in the case of callbacks (including sugar, like promises), which are also executed sequentially, but deferred until they are explicitly called by whatever they're passed to. In fact, one of the biggest complaints about JavaScript (that it can block the main thread if it tries to do too much in one frame) is a consequence of this guarantee.
Granted, I've written primarily JavaScript for the last five years, but it's pretty straightforward to reason about. Any language that lets you respond to events, I/O, etc. is going to require that you reason about things over time - JavaScript is no outlier here.
The way you've written your remark, it sounds as if JavaScript executes lines out of order, or will wait an arbitrary amount of time to move from one line to the next. Obviously, neither of those is true.
digitaLandscape|7 years ago
hartbeatnt|7 years ago
That being said I have zero robotics experience, just a lot of JS experience lol :shrug: