Tag Archives: code

Javascript Double Not-Operator(!!)

8 Oct

In javascript Falsy and Truthy values are used all over the place.

For example the following values are always falsy:

  • “” (empty string)
  • undefined
  • false
  • 0
  • null
  • NaN

And any other value is truthy.

Since undefined and empty string are falsy values then we could replace this code below:

if (typeof x !=== 'undefined' && x !=== '') {
  // not emtpy
}

 

with a falsy/truthy verification:

if (x) {
  // not emtpy
}

 

To set the result of falsy/thruthy verification to a variable is possible to use a double not-operator(!!) which will force a type casting to Boolean.

var xIsEmpty = !!x;

 

Actually !! is not an operator it is only the ! operator twice. The first ! will cast to boolean inverting the result. Then the second ! will invert again the value so it is the expected boolean value.

var x = 0;        // falsy
console.log(!x);  // true   (it is not what we want)
console.log(!!x); // false

 

Originally posted in blog.maxcnunes.net

4º Coding Dojo

30 Aug

Last monday occurred our 4º Coding Dojo here in Bravi. Maybe you are thinking “Coding Dojo? What is that?!”, so let me explain in short words.

Definition

A Coding Dojo is a meeting where a bunch of coders get together to work on a programming challenge. They are there have fun and to engage in DeliberatePractice in order to improve their skills.

Continue reading

Programmers and the Automated Build: A story of break-ups and love

18 Apr

If you are a software developer and work with automated build, you must admit: you have already broken the build at least once in your life. This is not something to be proud of, surely, but you have to keep in mind that breaking the build is crucial for your moral constitution. You certantly are a different person after breaking the build – at least more careful and attentive.

But if you are not a developer or have just started working with it, this post will try to explain you – through images – what is the sensation:

Continue reading

First Code Kata

28 Jan
734743_401155376635520_616232747_n
Last friday we had our first Code Kata in the office. The theme was about how to create a Tick Tack Toe using any language or approach.

SOLID Principles, as explained by a Zombie

26 Nov

One of the Zombies just wrote a nice article about SOLID principles, in Portuguese. But Google Translate can help with that, if you prefer to read it in English. Except the code, that is.

Check it out! And nice job, Max!

Image

Tips4Hackers: best ways to throw exceptions in .NET (if you must)

6 Sep

Do you know the difference between throw, throw ex and throw new Exception(), and how that impacts the information which is sent to the error log? Read on!

Throwing flowers, by Banksy

Continue reading

Tips4Hackers: TFS Shelvesets

26 Jul

One cool feature of TFS is the ability to shelve code, which lets us store code changes without performing a check-in. This can be very helpful not only as a backup mechanism, but also to quickly share and review code among colleagues.

Continue reading