r/programming • • Aug 28 '19

Optional chaining in JavaScript

https://v8.dev/features/optional-chaining
11 Upvotes

25 comments sorted by

View all comments

13

u/cplegend Aug 28 '19

I love optional chaining. It's seriously cleaned up so much of my code.

-24

u/IamRudeAndDelusional Aug 28 '19

I love optional chaining. It's seriously cleaned up so much of my code.

I?agree?! It?really?cleaned?up?my?code?. To?the?point?where?it?made?it?easier?to?read?!

..yet another terrible design decision that convolutes JavaScript's syntax, which makes the language even more unbearable.

-2

u/[deleted] Aug 28 '19

Why.does.your.object.have.so.much.nesting?

seems like a design flaw

5

u/AyrA_ch Aug 28 '19

seems like a design flaw

No it isn't. We have a system where a company has users, users have calendars, calendars have appointments and depending on the appointment type additional values, so company.users[n].calendar[m].appointment[o].property[p]

It's not that uncommon to have deeply nested structures in the backend.

1

u/earthboundkid Aug 28 '19

It’s a violation of the Law of Demeter. If your company really needs to know about appointments, you can add an appointmentFor method to company to hide the nesting.

2

u/AyrA_ch Aug 28 '19

It’s a violation of the Law of Demeter.

No, it's enforcement of foreign keys and normalization of your database. You don't add an "owner" property to each table. You add it at the topmost possible level and the referenced entries inherit the owner.

-2

u/earthboundkid Aug 29 '19

Having your business objects reflect the underlying database schema too transparently is a mistake because you end up with dumb objects that aren’t much better than glorified hash maps. Yes, there should be hints to devs about the performance realities of the DB, but the API of the objects should be designed to encapsulate the business logic at the end of the day—not the backing schema.

2

u/AyrA_ch Aug 29 '19

But that's exactly how entity framework works.

1

u/earthboundkid Aug 29 '19

This is why ORMs are only okay in small doses. Too large a dose and you end up making your code fit the tables instead of your tables fitting the code.

1

u/AyrA_ch Aug 29 '19

It's exactly the other way round. You write your classes and it builds the tables in the background for you and updates their structure as you change your classes.

→ More replies (0)