Nested objects in real apps

In Modify an Object Nested Within an Object step we have this example:

let nestedObject = {
  id: 28802695164,
  date: 'December 31, 2016',
  data: {
    totalUsers: 99,
    online: 80,
    onlineStatus: {
      active: 67,
      away: 13,
      busy: 8

So my immediate question: how far this example from real implementations when we are dealing with some traffic statistics?

I imagine:

some new user goes online >>> something triggered(some function called??)

and some object similar to above example is modified

I mean, data is structured however is sensible in the context, there isn’t a special way it’s done, there isn’t a beginner example level of data structure and then an IRL level of data structure.

If this data structure was used in a real life context where it made sense then it would be a real implementation :man_shrugging:t3:

You normally store these kind of things in a database, then when you need the data out and usable in JS code you query for it in your code and depending how thing are set up out pops something like this

Totally makes sense.
I just have some bad learning experience when they throw at me bunch of theory/tutorials without any real-life context.
Sometimes I become little paranoid because of the above)

1 Like

Having seen a bit of real life data and how people store it, id say the example used here could be seen as simplified. The names are very intuitive and informative, the object nesting is not that deep and the values are not too complex. In real life, very often, you can encounter situations when data is structured in not very practical way, some variable names make no sense, or dont carry enough context and carry some business logic which can be very far from the developer. Especially when we talk about exchanging bigger data in api interactions, you can see some very deep nested objects.
I find the particular challenge example to be very fitting in describing how such nested objects can look in real life and its good exercise to see how you can access values from within. Keep in mind, in a normal project, where people made thigns consistent, you wont see stuff like myObj.someArr[2].checkSmh['data'].callFunc, even if the object you work with is that deep, accessing deeper levels would usually happen on several layers(you are likely to pass the object between several callbacks/sources, each time going a level or two deeper). Hope that makes sense

1 Like

I guess when many people working on complex things(plus with some deadlines), things can become a bit messy, that’s my understanding.

I hope if I’ll manage to develop some skill dealing with ‘not too deep stuff’, such fundamental will be scalable enough to deal with ‘more deep stuff’.

1 Like

Its true, when many people work on the same project, even when there are some set of rules and good practices, it still leaves space to how experienced a developer is, or his own personal preference and way of writing code. Ive already seen situations, when we ran out of good/descriptive names of variables, or you see something was just worked enough to work at the moment, but not structured well enough to be built on, yet you can be on a stage when you arenot confident and able enough to actually refactor it and implement a universal solution, so you built on top of it and it gets more complicated then it should be.
You are right, working with complex data objects can be scary at first, but once you get the hang of the basics, the scale dont matter that much and you will pretty much be able to deal with any set of data, it all comes to practice. All it takes is to know how to access a particular element of an array, or object data, then you can go deep as much as you need :slight_smile:

So this is real thing?)))
I’ve already run into naming issues dealing with simple exercises, but I thought it was just me lacking experience.

Good names is one of the canonically hard things about programming.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.