If ( isTrue() ){ goDo(something);}//vs if ( isTrue() ){ goDo(something);}//vsif ( isTrue() ) goDo(something);

if ( isTrue() ){ goDo(something);}//vs if ( isTrue() ){ goDo(something);}//vsif ( isTrue() ) goDo(something);

Clearly the first one is superior because your worth is judged by the number of lines of code you wright and it results in an extra line, the last one is just pants on head retarded.

Other urls found in this thread:

gnu.org/licenses/>.if
en.wikipedia.org/wiki/C_standard_library#Buffer_overflow_vulnerabilities
twitter.com/NSFWRedditVideo

if ( isTrue() ) goDo(something);
masterrace

Ideally,
if isTrue(): goDo(something)
But if that's not an option
if (isTrue()) goDo(something);

while( isTrue() ){ goDo(something); break;}

:^)

for (int x = isTrue(); x; goDo(something), x = 0);

Have any of you read The C Programming Language, written by the guys who made the damn language? The only option is if (istrue()) goDo(something);

get on my level
isTrue() && goDo(something);

!isTrue() ? : goDo(something);

switch(isTrue()){ case true: goDo(something); case false: default: break;};

if (!isTrue()) goto isNotTrue;goDo(something);isNotTrue:;

:^)

void run_if_true(int tester(void), void doer(void *), void *arg) { if (tester()) doer(arg);}[...]run_if_true(isTrue, goDo, &something);

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see gnu.org/licenses/>.if ( isTrue() ){ goDo(something);}

smh tbh fam

Something about function pointers or a jump table but I'm far too lazy to actually do it.

Switch ( isTrue() ){ case true: goDo(something); break; case false: break; default: break;}

Second is better for general work because you aren't wasting an extra line. You don't have to scroll as much, and you can see more code on one page.
Third is for quick stuff, especially if you aren't held to a code standard. if you're using Perl you can go even further with
goDo(something) if isTrue();

And for meme-tier here's a dispatch table
my %dispatch;$dispatch{true} = \&goDo;$dispatch{false} = "no";$dispatch{isTrue()}->(something);

goDo(something);
fixed your dead code
t. gcc

Anyone care to rig up a test harness and tell us which version is slowest?

laughingsegfaults.jpg

Do you want error prone code? Because that's how you get error prone code. The guys who made the language are not gods. They chose to use in band signalling for string length, for fucks sake.

Real men use this:
if Is_True then Go_Do (Something);end if;

Fuck you. BRB inserting null characters in a password field.

Never write a single-line if without brackets, lest you want another goto fail fail. It will also consume you more time if you want to expand said if later on, whereas by writing it from the start you can let your editor autocomplete the brackets aulutomatically.


Segfaults are actually good. It's a sign your OS is actually working as intended. Problem is when your program DOESN'T segfault, then you are all sorts of fucked.

C still not having a native string "long long int + char array" struct because "muh overhead not everybody may use" in the era of GB-sized memory is retarded, though. We could have prevented so many fuckups this way it's not even fun. Not deprecating strcpy is even worse; these people just don't fucking learn.

I feel compelled to write some ANSI C code that use strcpy now. At least then it will work on 80's machine (the only ones worth caring about).

Couldn't one simply use
struct string { size_t length; char *content;}
And wrap that up in a typedef and some constructor and accessor functions? Or is there more to strings than that?

Function pointers and switch tables masterrace.
typedef (*void)(int) action;void goDo(int i);void noAction(int i);action action_table[2] { [0] = &noAction; [1] = &goDo;};action_table[isTrue()](something);

I have no idea if I nailed the syntax, function pointer syntax in C is one thing I can never remember correctly and there is no way I'm actually going to compile this abomination

Close, and yeah, function pointer syntax is weird.
typedef return_type (*typedef_name)(argument_list);
In this case it'd be
typedef void (*action)(int);

The first is fucking retarded, the second is ok for most cases, and the third is ok for a short piece of code.

1 is the best, its just a standard of orderliness that pretty much every coder agrees to use for the sake of the coders that come after.

however, if your if statement is just a single line of code, then 3 is good, 1 is more for when your IF leads to a chunk of code that is 2+ lines long.

2 is batshit retarded, holy shit i want to kill anyone who uses it.

if (!isGNU()) { interjectFor(aMoment); }

:^)
while(isTrue()==true){goDo(something);break;}

You could; you'd need to write wrappers for all of the clib string functions as well. It's probably more trouble than it's worth though; if there are code hotspots where e.g. scanning forward to find the end of a string is a bottleneck, you'd be better off hand-optimizing.

Have fun with those buffer overflows, pal

Honestly? Yes, it's as simple as that. There are two main problems to that thing, though. First, implementing this in your code is extra work many programmers don't want to do because char arrays are "good enough" (they aren't) and will proceed to fuck up every time, so it would have to be included into the standard, but here comes the second problem: C is designed to include only "what every C programmer may need", but the "C masters" who are in charge of defining new versions of the standard have some very inconsistent guidelines. For example, according to them, every C programmer will use complex numbers (complex.h) in their programs, but of course they won't use sane strings. The C community would probably reject this absolutely crazy idea because 64 bits waste a lot of resources that could very well just be 8 bits or 1 null byte, nevermind this would maybe waste resources but save us several millions in security failures.

en.wikipedia.org/wiki/C_standard_library#Buffer_overflow_vulnerabilities

Level up your portable assembly and use C++ for christ's sake.

So you want the standard to hand hold? Why not try another language.

Wee

Get the fuck off java pajeets and bsdtards.


End your life faggot

...

Bump for requesting someone to test these and let us know which one is slowest.

it's the one that sends the most bytes in the compiler's parser obviously. so that would 1 and 2 by ex-aequo.
But more precisely it would have to be 1, because it adds one more optional newline, a specially handled character in the C preprocessor.

THIS TBH

Where did this shit meme come from? The official Java code guidelines don't use Allman, but K&R. Although my Java book does come with Allman so you might have a point

doIfTrue();

I bet you have the nerve to call others Pajeets in this very board.

Yes, you are. Look closer.

(if (is-true) (something!))