microsoft / alguidelines

Best Practices and Design Patterns for the AL Language
https://alguidelines.dev/
MIT License
129 stars 48 forks source link

Best Practice 'if-not-then-exit' #195

Closed sirhc101 closed 2 years ago

sirhc101 commented 2 years ago

I'm not sure you guys will like it, but I think it's at least good practice to do so and it helps to reduce complexity in source code and structuring your code.

Any hints or additions are very welcome.

JeremyVyska commented 2 years ago

Oh! That's an interesting inversion of long-standing practice. I might want to sit with that one a bit, but you're right that it does make the readability much higher. Tagging some other reviewers for thoughts.

sirhc101 commented 2 years ago

Just as an addition: Referring to this twitter thread https://twitter.com/waldo1001/status/1545455472693710848?s=21&t=biFnjpf0UdAUS0ne8kZ-KQ

It's also faster due to less code executed 😅

waldo1001 commented 2 years ago

I actually apply this quite a lot .. . I like the "test near" kind of approach.

I must say - I'm not going to reject any code if people don't do this.

So for me, it's a pass ;-).

TheDoubleH commented 2 years ago

I do this all the time. I have found it also increases readability - AND - make it much easier to add and remove conditions, should the need arise.