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
-
Think about code portability and readability.
Someone from a strongly typed language like C# and Java won't immidiately understand the second one and can't just reuse that code without changing it. -
@MrCSharp if I'm not mistaken... That will work in everything but Java and Python whom both have no implicit cast from integer to Boolean. My C# is not fine-tuned, however. I know for a fact it works in c and c++, which are both strongly typed and static languages.
-
@AlgoRythm nope, got error CS0019 operator & & cannot be applied to operands of type imt and int
-
@MrCSharp Like I said, my c# is out of practice and the little things escape me. But I know it works with the rest of the c family!
-
@MrCSharp I knew Java is a bitch about it. Unfortunate amount of experience I have with Java.
here it is in c -
@AlgoRythm if you do & & in C with any value other than 0 or 1, it will error out during compilation
-
@MrCSharp If your compiler does that, it doesn't follow the c standard. True is defined as any number other than 0, and false is defined as 0.
Proof: -
@AlgoRythm I see. I was using an online repl tool running clang 7 on ubuntu
So maybe it is that but what you're saying about the c standard makes perfect sense 👌 -
@MrCSharp The internet is so fucking great for exchanging little blips of knowledge like this. Sometimes I almost even like the internet again.
-
@MrCSharp Oh, you probably wrote constants! There are special rules for those. You can't literally write 69 && 420.
((THIS DEPENDS ON COMPILER. It works with the tool I am using - common theme with c))
Programming is weird! -
@AlgoRythm yes, that's the one. Though I was using constants inside the if expression : if(1&&5)
Which is why it was failing.
Cheers brah 😅 -
I always compare with 0, '\0' or NULL, depending on the type, and use the "direct" form only for logical values. It's much easier to read because it gives an immediate hint what type of check is being done.
While I know I can save a few characters, I think that
if(username.length > 0 && password.length > 0)
looks a lot nicer than just
if(username.length && password.length)
However, I am so lazy that I will probably always use the uglier version just to save like 0.00001 seconds typing.
rant