News for hackers. Stuff that matters.
Re:TypeScript 3.7 Beta by dtech on Wednesday October 02, 2019 @03:14AM (#21134042)
Really nice, I work in a project with a lot of nested optional values, and all the `a && a.b && a.b.c && a.b.c.d` checks really introduce a lot of noise.
Re:TypeScript 3.7 Beta by z3t4 on Wednesday October 02, 2019 @04:56AM (#21134516)
I don't think it's bad enough to warrant introduction of new syntax sugar to make it shorter.

The problem might be that we have most likely not yet handled the edge case situation where a.b and a.b.c doesn't exist. And just want to log out the value, and print undefined if it doesn't exist.

Re:TypeScript 3.7 Beta by gridlockd on Wednesday October 02, 2019 @05:24AM (#21134639)
I disagree. This is just an extreme example, but take it down one or two levels and it's extremely common.

Ruby has had this kind of syntax since forever and it's one of the things that people love about it.

> The problem might be that we have most likely not yet handled the edge case situation where a.b and a.b.c doesn't exist

That's not an edge case, that's an expected case. If it doesn't exist, nothing is supposed to happen.

Re:TypeScript 3.7 Beta by manojlds on Wednesday October 02, 2019 @03:32AM (#21134110)
Mostly it's a code smell though

https://en.m.wikipedia.org/wiki/Law_of_Demeter

Re:TypeScript 3.7 Beta by Vanit on Wednesday October 02, 2019 @03:50AM (#21134195)
4 chains is like reaching into an XHR response to pull out the success result, so I wouldn't say that's necessarily a smell.
Re:TypeScript 3.7 Beta by gridlockd on Wednesday October 02, 2019 @05:15AM (#21134595)
Programming is fundamentally about the transformation of data and sometimes data is in such a shape that inevitably requires such code. Most of the time, you don't get to decide what shape the data is in.

OOP just obfuscates this basic fact of programming life to the point where it's not obvious anymore. That is not a good thing, it's a huge waste of time. Favor plain data over "objects" and functions over methods. Favor plain SQL queries over ORM.

Re:TypeScript 3.7 Beta by zhirzh on Wednesday October 02, 2019 @04:53AM (#21134496)
I'd say it is a design smell and not necessarily code smell. Any API or data interface should try to keep "optional keys" at a minimum.

Depending on the language, `a.b && ...` could be checking either or both of the following:

- does `a` have key 'b'? - is `a.b` truthy?

Re:TypeScript 3.7 Beta by jiofih on Wednesday October 02, 2019 @02:44PM (#21139524)
Tell that to the team that created protocol buffers.
Re:TypeScript 3.7 Beta by mattmanser on Wednesday October 02, 2019 @04:33AM (#21134407)
Not really, especially when you're working with external APIs. That's when I find myself using a lot of this type of code.
Re:TypeScript 3.7 Beta by oliyoung on Wednesday October 02, 2019 @08:29PM (#21142339)
lodash's #get solves this for us now https://lodash.com/docs#get