News for hackers. Stuff that matters.
Re:Why I'm not a React Native developer by sheetjs on Saturday August 19, 2017 @03:21PM (#15055088)
or

    this.setState({ isConnected: !!weAreConnected })
Re:Why I'm not a React Native developer by WalterSear on Saturday August 19, 2017 @03:37PM (#15055150)
I prefer boolean, easier to see what's going on. And,

   bo-tab(
is only two more characters :)
Re:Why I'm not a React Native developer by debaserab2 on Saturday August 19, 2017 @03:41PM (#15055173)
It's not any easier if you understand what !! does. Pretty common usage across many languages.
Re:Why I'm not a React Native developer by gruez on Saturday August 19, 2017 @03:47PM (#15055208)
>It's not any easier if you understand what !! does

which only applies if you're writing code for yourself. you can't expect everyone to know that idiom. same with using the + operator to cast to number, or an extreme case, the tadpole operator https://blogs.msdn.microsoft.com/oldnewthing/20150525-00/?p=...

Re:Why I'm not a React Native developer by srssays on Saturday August 19, 2017 @04:34PM (#15055442)
!! 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.

Re:Why I'm not a React Native developer by WalterSear on Saturday August 19, 2017 @05:36PM (#15055766)
As a professional programmer, I've come to prefer code written to be understood by someone who started two weeks ago.
Re:Why I'm not a React Native developer by joesb on Sunday August 20, 2017 @02:59AM (#15057293)
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.

Re:Why I'm not a React Native developer by debaserab2 on Saturday August 19, 2017 @06:05PM (#15055881)
Then by that principle you'd want to use !! since casting via function or constructor differs more between languages.
Re:Why I'm not a React Native developer by WalterSear on Saturday August 19, 2017 @06:22PM (#15055959)
What it looks like in other languages is only minorly relevant to its obviousness and readability.
Re:Why I'm not a React Native developer by debaserab2 on Saturday August 19, 2017 @06:48PM (#15056067)
I don't see the argument that Boolean(val) "reads easier" than !! as long as you know what !! does.
Re:Why I'm not a React Native developer by goatlover on Saturday August 19, 2017 @07:39PM (#15056223)
Wouldn't any programmer recognize that Boolean(val) is a cast to a True/False value that's most likely an object, given the uppercase?
Re:Why I'm not a React Native developer by inimino on Sunday August 20, 2017 @07:13PM (#15060713)
Perhaps, but it's a primitive, not an object.
Re:Why I'm not a React Native developer by prewett on Saturday August 19, 2017 @07:05PM (#15056116)
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.
Re:Why I'm not a React Native developer by ashark on Saturday August 19, 2017 @07:46PM (#15056243)
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)
Re:Why I'm not a React Native developer by oceanswave on Sunday August 20, 2017 @07:40PM (#15060842)
I feel sorry that they paid you then
Re:Why I'm not a React Native developer by xamuel on Sunday August 20, 2017 @01:05AM (#15057027)
Re:Why I'm not a React Native developer by savanaly on Saturday August 19, 2017 @07:31PM (#15056199)
It's one of the earliest things I can remember learning in my intro to programming classes in college. Those were in Java.
Re:Why I'm not a React Native developer by hirsin on Sunday August 20, 2017 @12:34AM (#15056969)
I spend chunks of every day looking at a C/C++ codebase and have never seen this. Taught Java for a year in college, I have never seen this. I would leave a note to a student for using this to be honest - too unclear, and (as this thread denotes) not well known enough to put in production worthy code.
Re:Why I'm not a React Native developer by debaserab2 on Sunday August 20, 2017 @02:56AM (#15057286)
I'm pretty surprised to hear this from someone who taught a programming course. It actually makes a ton of sense when you evaluate what is happening: it's the negative unary value and then the negative unary result of that value - there's no possible way it could be anything other than true or false. It's more of a side affect of the unary operator ! than it is a language feature, which I believe is why it sees such ubiquitous implementation.

> I would leave a note to a student for using this to be honest - too unclear, and (as this thread denotes) not well known enough to put in production worthy code.

You've done a total disservice to your students that understood negative unary operations then. Given how many upvotes my initial post on this thread has (currently 38) I don't think the thread denotes what you think it does at all.

Re:Why I'm not a React Native developer by empthought on Sunday August 20, 2017 @10:19AM (#15058481)
You're kidding, right? "!!foo" is a complete no-op in Java. It is never needed and never correct.
Re:Why I'm not a React Native developer by lomnakkus on Saturday August 26, 2017 @07:36PM (#15108074)
You're basically wrong on every single point. It's a syntactic hack in JS to get a guaranteed boolean coersion, but for anything else it's an absolutely pointless abomination. (Maybe PHP has a similar thing, but I haven't programmed in PHP, so I wouldn't know.)
Re:Why I'm not a React Native developer by lomnakkus on Sunday August 20, 2017 @08:15AM (#15058099)
In Java? What purpose would it serve there?
Re:Why I'm not a React Native developer by GordonS on Sunday August 20, 2017 @05:17AM (#15057637)
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'
Re:Why I'm not a React Native developer by slrz on Wednesday August 23, 2017 @05:39PM (#15085441)
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.

Re:Why I'm not a React Native developer by WalterSear on Saturday August 19, 2017 @05:35PM (#15055758)
Oh I understand, it, and used it for years. Boolean() is just easier to spot in unfamiliar code.