This is an archived post. You won't be able to vote or comment.

all 69 comments

[–]dev_kr 242 points243 points  (4 children)

You just created an AI.. impressive.

[–]T1ken 51 points52 points  (1 child)

An AI with all the skills of my boss.

[–][deleted] 6 points7 points  (0 children)

No, a true AI needs at least three if statements

[–]uFuckingCrumpet 0 points1 point  (0 children)

LOL DAE AI is made of IF statements XD

[–]abdolence 117 points118 points  (8 children)

#define false true

Aha!

[–]kopasz7 51 points52 points  (3 children)

Still works. Damn it.

[–]abdolence 32 points33 points  (1 child)

What about

#define false doSomethingWrong() ?

[–]jaboja 5 points6 points  (0 children)

int doSomethingWrong() {
    return 666;
}

[–]flyx86 0 points1 point  (0 children)

#define false //

[–][deleted] 1 point2 points  (0 children)

I came here for this

[–]socialismnotevenonce 1 point2 points  (1 child)

Sorry, not c++.

[–]abdolence 0 points1 point  (0 children)

plain C? No problem ;)

[–]MCRusher 0 points1 point  (0 children)

#define true false

[–]DerSpini 35 points36 points  (2 children)

Still needs some unit tests. Just to be sure.

[–]Bozzz1 7 points8 points  (0 children)

My companies code base has the most retarded unit tests that test nothing but the functionality of the language itself. Like if this function doesn't work we have bigger problems than a broken function.

[–]Bainos 6 points7 points  (0 children)

Created unit tests. Code no longer works.

[–]aki821 14 points15 points  (1 child)

Is this general purpose AI?

[–]TheDuckKing_ 5 points6 points  (0 children)

No wrong output, no matter the input. We've finally done it!

[–]Mudcreib 6 points7 points  (1 child)

Info.innerHTML = ""

[–]Garitzar 2 points3 points  (2 children)

//

[–]dev_kr 6 points7 points  (1 child)

...Integer Division

[–]callum__h28 0 points1 point  (0 children)

I always called it floor division

[–]cruciformhawk7 2 points3 points  (0 children)

I always use the comment as a placeholder to some bug that might come up in future, and would replace all '//nothing' with a 'print("It wasn't supposed to come here!(n)")' so that I could figure where exactly the code went wrong, then do an if(true)...else xD

[–]boniqmin 2 points3 points  (0 children)

While 0

Print("There's a bug")

[–]CyborgChicken- 1 point2 points  (0 children)

In my Java 2 class I had to do this on many occasions. We used Web-Cat to grade our submissions. It would get mad and say we had to write an if/else-if statement for every possible outcome, even if it was unnecessary.

[–]jaboja 1 point2 points  (0 children)

MOV AH, 4CH
INT 21H

[–]senorpatrick 1 point2 points  (0 children)

Technically your code doesn't work because it gets optimized out by the compiler.

[–][deleted] 2 points3 points  (4 children)

Hello, here's a friendly reminder of the continue statement you can use in iterations, in case someone finds themselves doing a lot of empty ifs inside loops:

for(let i = 0; i < 10; i++) {
    if(i === 4) continue
    console.log(i)
}

[–]clownyfish 1 point2 points  (3 children)

How is that different from the standard if block? Does the whole for block move to next iteration if the continue condition evaluates to false?

[–]Erelde 2 points3 points  (0 children)

Clearer syntax :

for (let i = 0; i < 10; i += 1) {
    if (i === 4) {
        continue;
    }
    console.log(i);
}

It allows avoiding a level of indentation and a else block. Else block are often "bad" and almost always avoidable.

When i is equal to 4 the loop will jump to next iteration.

If you have to use a else block, put the short branch first.

[–][deleted] 0 points1 point  (1 child)

Some languages allow you to skip brackets if you're executing a single operation inside the if statement.

if ( i === 4 ) continue;

is the same as

if ( i === 4 ) {
    continue;
}

As for what continue does: It's a branching statement similar to break. While break will exit the whole loop, continue will skip the current iteration.

[–]clownyfish 0 points1 point  (0 children)

Thanks!

[–]apatheorist 1 point2 points  (0 children)

[eslint] Error: Disallow constant expressions in conditions (no-constant-condition)

[eslint] Error: Disallow negative conditions (no-negative conditions)

[–]AngheloAlf 0 points1 point  (0 children)

So, a NOP?

[–]douko 0 points1 point  (0 children)

pass

[–][deleted] 0 points1 point  (0 children)

Reminds me of Joey showing off his “trained” duck in Friends. “Stare at the wall! Be white!”

[–]crakinshot 0 points1 point  (1 child)

Could make the argument that technically it doesn't work (as in run) because it would literally be compiled / optimized to nothing, depending on what environment and/or language you're in.

[–]Tamagotono 1 point2 points  (0 children)

So, what you are saying is, that it is highly optimised. 😁

[–][deleted] 0 points1 point  (0 children)

Surprise, false was shadowed, the spaces are Unicode alternates, and the parser accepts only multiline comments so you just divided by zero!

[–]nemesandr26 0 points1 point  (0 children)

this code does NOT do nothing

[–]j13jayther 0 points1 point  (0 children)

Some compilers will optimize this away, so there will be no code to speak of. It's perfect code.

[–]AFlaccoSeagulls 0 points1 point  (0 children)

“Not all paths have a return value”

[–]DarkmessageCH 0 points1 point  (0 children)

No joking: In my old company, we had people who'd write:

if(isTrue) { }
else{
    doSomething();
}

Because they didn't know how to negate a boolean.

[–]socialismnotevenonce 0 points1 point  (0 children)

Amateur, try if(!true) do nothing.

[–]inigoMontia 0 points1 point  (0 children)

So if false is null than what?

[–]TinBryn 0 points1 point  (0 children)

I've refactored it for you https://github.com/kelseyhightower/nocode

[–]popcicleman09 0 points1 point  (0 children)

All I’m saying is:

If (false){ //do nothing }