Hacker News new | ask | show | jobs
by specialist 999 days ago
Neat. Will check it out.

I recently spotted a (new to me) foreach / else construct in a templating language (sorry, forget which one); else is invoked if the list is empty. Nice sugar for common outputs like "no items found".

I appreciate modest syntactic sugar.

For instance, my #1 sugar wish is for Java's foreach is to do nothing when the list reference is null. Versus tossing a NPE.

Eliminates an unnecessary null check and makes the world a little bit more null-safe.

1 comments

> else is invoked if the list is empty.

for / else should do that too …