123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|42|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> C/C++/C#/Other -> Code Hate! (C)

Sat, 28 Jan 2012, 10:51
HoboBen
Sometimes I hate C programmers. Your entire hashmap library is 100 % made up of preprocessor macros? Yeah, no, I am not going to read that.

-=-=-
blog | work | code | more code
Sat, 28 Jan 2012, 10:51
Afr0
I agree. Just because the syntax allows you to shorten boolean statements to if(X), doesn't mean it's a good idea to do it!

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Sat, 28 Jan 2012, 10:58
Afr0
Same thing goes for overusing typedefs... there's a reason these things were removed from C#!

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Sat, 28 Jan 2012, 11:13
HoboBen
Whaaaat? You can pry "if(X)" from my cold, dead hands.

-=-=-
blog | work | code | more code
Sat, 28 Jan 2012, 11:52
JL235
What is wrong with if statements?

I agree with macros though. D is meant to have very good features for running code at compile time.
Sat, 28 Jan 2012, 12:01
HoboBen
Some people like explicit conditions, like

"if (thing != NULL)", rather than "if (thing)"

Tabs vs spaces all over again.

Macros sometimes have their place though. For example, recently I wrote a function that needed to know the size and alignment of a structure that was passed to it with a pointer. To make this easy for the caller, I used a macro:



What I didn't do was write my entire bloody program as a macro.

-=-=-
blog | work | code | more code
Sat, 28 Jan 2012, 16:46
Afr0
Tabs vs spaces all over again.


No.
Implicit if-statements are OK when you're operating on a boolean, or checking whether or not a type is null. It's when you're operating on an integer value that stuff like "if(x)" is a crime.
First of all because it doesn't take into account whether or not something is null, and secondly because it is just downright confusing (especially when porting code). Especially if you do "if(x || y)", because then operator precedence comes into play.
Doing any of this stuff on integers implicitly is forbidden in C#, and AFAIK in Java too.

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Sat, 28 Jan 2012, 17:11
HoboBen
Ah, no argument there.

For integers, it can be very confusing unless you are explicit. "if (var > 0)" or "if (var != 0)" express much more, even if "if (var)" is legal C.

Some people extend this to explicit NULL checks on pointers. I call them heathens.

-=-=-
blog | work | code | more code
Sat, 28 Jan 2012, 17:23
JL235
I pretty much agree with Afr0 in this case. In a static language, I prefer conditions to have to be explicitly booleans, since it ensures that my conditions are valid.

In dynamic languages I don't mind 'if(x)', as long as only 'null', 'false' and 'undefined' evaluate to false.

0, empty strings and arrays (thanks to PHP) should all be true!
Sun, 29 Jan 2012, 05:02
Afr0
0, empty strings and arrays (thanks to PHP) should all be true!


What?
I always thought non-zero was true? o.O
Is this a difference between static and dynamic languages?

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Sun, 29 Jan 2012, 05:44
JL235
In Ruby they are all true; in PHP all of those are false, and many other dynamic languages are similar.

The idea is that 0 is a number, not a bit sequence. Why should zero be any less true then 1?