3 ms·
Data structures are largely universal concepts, but how you access and organize data structures differs by language. There are a lot of good books about reason
by austincheney 6y ago
Data structures are largely universal concepts, but how you access and organize data structures differs by language. There are a lot of good books about reasoning data in an abstract way.
I am a JavaScript developer and here is an overview of what I know from writing in this language:
* objects (hash maps) are a list of key value pair. The keys are always strings and the values are of any data types. Keys must be unique. Just like hash maps in C, C++, Java, and other C-like languages keys are accessed randomly from memory until the requested key is retrieved. Knowing this opens the potential for low level performance hacks. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guid...
* arrays are a list. Unlike most strongly typed languages arrays in JavaScript are not bound to a fixed length or data type. Arrays of a single data type do execute much faster though due to improvements in the JIT compilers. A requested array index is retrieved from memory in index order, which is typically faster than accessing an object property by name, but not always. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
* Maps are a key/value pair similar to objects except the key does not have to be a string data type. The key name could be another object. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
* Sets are a list of values where each value is unique according to its data type and actual value. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
* Weak Map - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
* Weak Set - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
---
The biggest problem I have seen through my career with people's approach to data structures is to treat the data as a value set, like something retrieved from a database query, instead of a structure like a program class or function. That distinction is huge and will change how you perceive programming. The difference is that you will see a structure is an abstract set of relations to walk where a data value is something to blindly throw code at until you get the answer you want.
For example file systems are data structures. You can blindly search a file system for something, but that is lazy and slow. Instead if you have a general idea of what you are looking for you can walk there with a bit more effort in a fraction of the time.
JSON is a common data reference scheme based upon JavaScript's objects and arrays.