Re: How to simplify nested ifs

2018-03-16 Thread Tony via Digitalmars-d-learn
On Tuesday, 13 March 2018 at 12:23:06 UTC, Ozan Süel wrote: if (source?pool?repository?directory?users) // do something That type of chain is sometimes referred to as a "train wreck" (see Law of Demeter). If this is a common lookup it could be: if (source && source.GotSomeUsers() )

Re: How to simplify nested ifs

2018-03-16 Thread bauss via Digitalmars-d-learn
On Tuesday, 13 March 2018 at 12:23:06 UTC, Ozan Süel wrote: Hi I have a construction like the following if (source) { if (source.pool) { if (source.pool.repository) { if (source.pool.repository.directory) { if (source.pool.repository.directory.users) { // do someth

Re: How to simplify nested ifs

2018-03-16 Thread bauss via Digitalmars-d-learn
On Friday, 16 March 2018 at 09:34:38 UTC, Satoshi wrote: null conditional operators are not implemented in D because, as a (I think Walter) said, D is not language designed to work with classes or advanced OOP stuff. Nobody uses it, so please, if you are using it, stop and use structs and meta

Re: How to simplify nested ifs

2018-03-16 Thread drug via Digitalmars-d-learn
On 16.03.2018 09:34, Satoshi wrote: On Tuesday, 13 March 2018 at 12:23:06 UTC, Ozan Süel wrote: Hi I have a construction like the following if (source) { if (source.pool) { if (source.pool.repository) { if (source.pool.repository.directory) { if (source.pool.repository.director

Re: How to simplify nested ifs

2018-03-16 Thread drug via Digitalmars-d-learn
On 16.03.2018 09:51, drug wrote: I think that null conditional operator is intended for OOP only. It's really useful if your data field may be nullable. May be start review about this? Oops. I mean *isn't intended for OOP only*

Re: How to simplify nested ifs

2018-03-16 Thread Satoshi via Digitalmars-d-learn
On Tuesday, 13 March 2018 at 12:23:06 UTC, Ozan Süel wrote: Hi I have a construction like the following if (source) { if (source.pool) { if (source.pool.repository) { if (source.pool.repository.directory) { if (source.pool.repository.directory.users) { // do someth

Re: How to simplify nested ifs

2018-03-13 Thread aliak via Digitalmars-d-learn
On Tuesday, 13 March 2018 at 13:13:07 UTC, rumbu wrote: On Tuesday, 13 March 2018 at 12:23:06 UTC, Ozan Süel wrote: Hi I have a construction like the following if (source) { if (source.pool) { if (source.pool.repository) { if (source.pool.repository.directory) { if (source.

Re: How to simplify nested ifs

2018-03-13 Thread rumbu via Digitalmars-d-learn
On Tuesday, 13 March 2018 at 12:23:06 UTC, Ozan Süel wrote: Hi I have a construction like the following if (source) { if (source.pool) { if (source.pool.repository) { if (source.pool.repository.directory) { if (source.pool.repository.directory.users) { // do someth

Re: How to simplify nested ifs

2018-03-13 Thread rikki cattermole via Digitalmars-d-learn
On 14/03/2018 1:23 AM, Ozan Süel wrote: Hi I have a construction like the following if (source) {   if (source.pool) {     if (source.pool.repository) {   if (source.pool.repository.directory) { if (source.pool.repository.directory.users) {   // do something Any chance to simp

How to simplify nested ifs

2018-03-13 Thread Ozan Süel via Digitalmars-d-learn
Hi I have a construction like the following if (source) { if (source.pool) { if (source.pool.repository) { if (source.pool.repository.directory) { if (source.pool.repository.directory.users) { // do something Any chance to simplify this nested ifs? I know some lang

How to simplify nested ifs

2018-03-13 Thread Ozan Süel via Digitalmars-d-learn
Hi I have a construction like the following if (source) { if (source.pool) { if (source.pool.repository) { if (source.pool.repository.directory) { if (source.pool.repository.directory.users) { return source.pool.repository.directory.users[ownerID];