top | item 15055442

(no title)

srssays | 8 years ago

!! is an extremely common idiom, across multiple different programming languages.

Code should be written so that it is understandable by other professional programmers, not people who started programming two weeks ago.

discuss

order

WalterSear|8 years ago

As a professional programmer, I've come to prefer code written to be understood by someone who started two weeks ago.

joesb|8 years ago

In that case, don't write any code. Don't use function. Don't use React. Don't use lodash. Don't use third party library.

People who only start coding for two weeks can't understand any code.

People who start has enough experience to work, but only start in this project for two weeks, will understand "!!" idiom.

debaserab2|8 years ago

Then by that principle you'd want to use !! since casting via function or constructor differs more between languages.

prewett|8 years ago

I'm curious, which languages? I've never seen any of my colleagues write !!, ever, in C/C++, Java, Python, or Swift. I've also not seen it C# or Go, but my exposure is limited.

ashark|8 years ago

I've been paid to write code in Perl, PHP, Ruby, JS, Go, ObjC, and Java, plus a little C and Python, for going on 15 years. I'm pretty sure I've never written "!!" and I think I could count the times I've seen it used on one hand (maybe never in any codebase I've worked on, but I'm not entirely sure)

savanaly|8 years ago

It's one of the earliest things I can remember learning in my intro to programming classes in college. Those were in Java.

GordonS|8 years ago

What? I've been coding in multiple languages for multiple platforms for almost 30 years and have never come across it. It seems rather unlikely that it's 'extremely common'

slrz|8 years ago

It is very common in C code, where for most of its history you hadn't any explicit boolean data type but used int, following the rule that zero is false and anything else is true.

The '!!expr' is the idiom most people use whenever the need for a canonical 0/1 representation arises.