Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
And you let this go to production and the next guy finds it and comes on devRant to rant about it. ;)
-
There's something to be said for readability by using well chosen names and proper indentation.
But too often when people use the argument all I hear is "my brain can't handle complexity, please dumb it down" — leading to code which is less readable for those who are competent. -
Lightor7759y@apisarenco this is code to check if his primary contract is defined, yes. That is the convention. The you could throw a != undefined, but that's not even close to needed. As for asking questions, this is in a method called hasPrimaryContract? In the model which is giving you the ability to ask that question. Given the syntax and method name, functionality is very clear.
Just like .contacts should be a collection of contacts and if you used it in an if statement it would tell you if there were any or if it was an empty/undefined collection. That's how values behave when treated like a Boolean. Having a Boolean stored for all your record values to see if they've been set isn't feasible, you have to be able to make these determinations. -
Lightor7759y@apisarenco look in something like Angular for example, you check for null/undefined by calling the variable as a Boolean, it's very common convention.
I get what you're saying but it's a well established convention and practice. -
nicholai8499y@Lightor you don't call it as a Boolean, it's evaluates to truthy or falsy by coercion and yes, it's very common code to use to check if it has a non-empty property.
Related Rants
-
mephisto223
Manager: Why are you always refactoring?
Me: Refactoring keeps the codebase's entropy in check :)
Manager: m... -
xonya11I had a coworker used to write PHP pages in this way: <?php echo "<html>"; echo "<head>"; // 2000+ lines o... -
TheMaesterio3Aim to write simple code. Code that requires no skill to understand but mastery to write.

Code: if(customer.primaryContract)
Boss: "just using a variable as a boolean isn't very readable"
Me:
if(!(!customer.primaryContract != !true).toString() == 'false')
undefined
you happy now
explicit
critique
readability