Viewing a response to: @themarkymark/how-to-write-better-code-with-guard-clauses
Funny, I never knew this was called a *guard clause*. I seem to use them more often now than ever in this new era of love for weakly-typed languages. stuff like ~~~~ function whatever(value){ if (isNaN(value)) return false; ... ... return true; } ~~~~ I wish Javascript were more like this (at least optionally): ~~~~ private function whatever(value:Number):Boolean{ // Throws an error if passed value is not of type Number ... return true; } ~~~~ With languages like JS I spend most of my time trying to debug where the hell the issue is even coming from. I suppose some people like the flexibility of not declaring types, though. I know you can use something like TypeScript but it would be nice if one could [optionally static type](https://esdiscuss.org/topic/es8-proposal-optional-static-typing) and run it natively in the browser. But I digress... Nice to know what it's called a guard clause!
author | nuthman |
---|---|
permlink | re-themarkymark-q9s2aa |
category | technology |
json_metadata | {"tags":["technology"],"app":"peakd/2020.04.5"} |
created | 2020-05-03 22:54:12 |
last_update | 2020-05-03 22:54:12 |
depth | 1 |
children | 1 |
last_payout | 2020-05-10 22:54:12 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 915 |
author_reputation | 344,453,626,754,867 |
root_title | "How to write better code with Guard Clauses" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 97,168,527 |
net_rshares | 0 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
souris | 0 | 0 | 100% |
I have heard it termed as the happy path. Where as you work your way down the function you return out the "un-happy" steps.
author | souris |
---|---|
permlink | re-nuthman-qdmfyl |
category | technology |
json_metadata | {"tags":["technology"],"app":"peakd/2020.07.1"} |
created | 2020-07-17 16:18:24 |
last_update | 2020-07-17 16:18:24 |
depth | 2 |
children | 0 |
last_payout | 2020-07-24 16:18:24 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 HBD |
curator_payout_value | 0.000 HBD |
pending_payout_value | 0.000 HBD |
promoted | 0.000 HBD |
body_length | 124 |
author_reputation | 22,834,205,494 |
root_title | "How to write better code with Guard Clauses" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 HBD |
percent_hbd | 10,000 |
post_id | 98,572,797 |
net_rshares | 0 |