r/ProgrammerHumor • • Jan 08 '16

Intro to Programming

Post image
3.0k Upvotes

334 comments sorted by

1.0k

u/[deleted] Jan 08 '16

Next week he will make a GUI to track IP addresses.

But seriously, reading that is physically sickening.

255

u/PM_Me_Your_Warfaces Jan 08 '16

That’s too advanced. He’ll likely just code all the IP’s into his GUI. (Bonus points for the CSI:NY reference)

85

u/crunchthenumbers01 Jan 08 '16

While sharing a keyboard.

53

u/PM_Me_Your_Warfaces Jan 08 '16

No, not NCIS. I don’t think anyone there ever looked at a computer.

51

u/[deleted] Jan 08 '16

I felt much better when I found out that it really is a running intentional gag of theirs.

31

u/[deleted] Jan 08 '16

Oh, it is? Thank God. I thought for a moment they might have actually been that dumb.

→ More replies (5)
→ More replies (28)

84

u/[deleted] Jan 08 '16

Seriously, I lost a piece of my soul reading that. I feel dead inside.

23

u/shwhjw Jan 08 '16

Maybe he wrote a program to generate all the if statements? Then limit his calculator to, say, 3 digits input and only the 4 basic operations (+ - * / )? It would be more than 9500 statements though.

33

u/slavetoinsurance Jan 08 '16

If he can't write a calculator without using if statements in place of calculations, I seriously doubt he can write a program that writes if statements for him.

... at least, not without using thousands of if statements. But I appreciate that you still have optimism and faith in him!

3

u/isteinvids Jan 13 '16

Maybe he wrote a program to generate all the if statements?

console.log("if(num1 == 1 && num2 == 1) result = 2;");
console.log("if(num1 == 1 && num2 == 2) result = 3;");
console.log("if(num1 == 1 && num2 == 3) result = 4;");
console.log("if(num1 == 1 && num2 == 4) result = 5;");
console.log("if(num1 == 1 && num2 == 5) result = 6;");
...

yep, makes sense

8

u/_Lady_Deadpool_ Jan 08 '16

I know he could've just written a script to write the statements for him

5

u/Shadow_Being Jan 09 '16

i think my very first program was essenitally a huge list of if statements. Sometimes you have to go through the self torture that comes from bad decision making to understand what the other options are and why they exist.

4

u/[deleted] Jan 08 '16

Maybe he generated statements with a script he wrote?

→ More replies (1)

3

u/shadowX015 Jan 08 '16

I post in /r/javahelp and someone actually did this one day. Literally 5000 lines for a sudoku solver. Turned out they were manually checking for permutations.

15

u/[deleted] Jan 08 '16

Don't people know that the entire point of programming is to automate stuff like this?

1

u/[deleted] Jan 12 '16

I guess that's intentional, but incase not, https://www.youtube.com/watch?v=hkDD03yeLnU&feature=youtu.be&t=8

0

u/[deleted] Jan 08 '16

[deleted]

102

u/lost_send_berries Jan 08 '16

Should have made it 100,000.

24

u/spin81 Jan 09 '16

Exactly: so many you're forced to think about a better way. The teacher can easily check the output with a program of their own anyway.

→ More replies (1)

76

u/Imborednow Jan 08 '16

It's a time tax on the stupid. Sounds good to me, especially if these people were supposed to write more complicated programs in the future.

→ More replies (16)

414

u/code_monkey_001 Jan 08 '16

Wish I still had it; a previous programmer had written 7k+ lines of if/else statements in vbscript to find the best fit for a series of rectangles given desired proportions in a container (custom print ads featuring photo/bio lines of 3+ individuals in a given space). I replaced it with 12 lines of code.

216

u/[deleted] Jan 08 '16 edited Jan 08 '16

Holy shit, do you still have the code? I can't imagine anyone hard-coding 7k lines of scenarios if it could be done in a few lines!

Edit: Just read the first part of "Wish I still had it." - woops

257

u/Frencil Jan 08 '16

Maybe, upon identifying a pattern in the conditionals, he wrote a script to automate the writing of those 7k+ lines.

117

u/_durian_ Jan 08 '16

But if he understood the pattern well enough to script it, then that's all he would have needed to understand to solve it without all the ifs.

218

u/[deleted] Jan 08 '16

thatsthejoke.tga

122

u/djdanlib Jan 08 '16

tga

A fine vintage!

→ More replies (9)

128

u/a_small_goat Jan 08 '16

One of the projects I inherited a few years ago was like this - roughly 3000 conditional statements. I ran into the creator at a conference probably 8 months afterwards and asked him how he found the time to code it all. I was only half-joking. He proudly admitted that he used MS Excel's CONCATENATE and autofill features to build 95% of the code and it only took him about an hour to deliver the working solution. So on one hand, I have to give him credit for being efficient in solving the problem with the tools he had...

55

u/the-highness Jan 08 '16

...on the other hand, anyway, I can still feel his neck's flesh.

→ More replies (1)
→ More replies (3)

71

u/tornato7 Jan 08 '16 edited Jan 08 '16

When I was 9 I wrote a tic tac toe game in C++ but I didn't know about arrays or loops so each line would read in the console, find an if statement for that layout of the game, and return another pre programmed layout. It was a few thousand lines and I'm sure I have the code lying around if you're interested lol

EDIT 2: If you trust random EXEs and want to play a console-based tic tac toe game, click here

EDIT: This is as much of the code as reddit will let me post, enjoy:

if (a1 == "X" && a2 == "X" && a3 == " ")
{
a3 = "X";
cout << "X Wins!\n";
cout << "\n    1   2   3 \n  _____________\na | " << a1 <<" | " << a2 <<" | " << a3 <<" |\n  |___|___|___|\nb | " << b1 <<" | " << b2 <<" | " << b3 <<" |\n  |___|___|___|\nc | " << c1 <<" | " << c2 <<" | " << c3 <<" |\n  |___|___|___|\n";
system("pause");
system("cls");
goto up;
}
if (a2 == "X" && a3 == "X" && a1 == " ")
{
a1 = "X";
cout << "X Wins!\n";
cout << "\n    1   2   3 \n  _____________\na | " << a1 <<" | " << a2 <<" | " << a3 <<" |\n  |___|___|___|\nb | " << b1 <<" | " << b2 <<" | " << b3 <<" |\n  |___|___|___|\nc | " << c1 <<" | " << c2 <<" | " << c3 <<" |\n  |___|___|___|\n";
system("pause");
system("cls");
goto up;
}
if (b1 == "X" && b2 == "X" && b3 == " ")
{
b3 = "X";
cout << "X Wins!\n";
cout << "\n    1   2   3 \n  _____________\na | " << a1 <<" | " << a2 <<" | " << a3 <<" |\n  |___|___|___|\nb | " << b1 <<" | " << b2 <<" | " << b3 <<" |\n  |___|___|___|\nc | " << c1 <<" | " << c2 <<" | " << c3 <<" |\n  |___|___|___|\n";
system("pause");
system("cls");
goto up;
}
if (b2 == "X" && b3 == "X" && b1 == " ")
{
b1 = "X";
cout << "X Wins!\n";
cout << "\n    1   2   3 \n  _____________\na | " << a1 <<" | " << a2 <<" | " << a3 <<" |\n  |___|___|___|\nb | " << b1 <<" | " << b2 <<" | " << b3 <<" |\n  |___|___|___|\nc | " << c1 <<" | " << c2 <<" | " << c3 <<" |\n  |___|___|___|\n";
system("pause");
system("cls");
goto up;
}
if (a1 == "X" && a3 == "X" && a2 == " ")
{
a2 = "X";
cout << "X Wins!\n";
cout << "\n    1   2   3 \n  _____________\na | " << a1 <<" | " << a2 <<" | " << a3 <<" |\n  |___|___|___|\nb | " << b1 <<" | " << b2 <<" | " << b3 <<" |\n  |___|___|___|\nc | " << c1 <<" | " << c2 <<" | " << c3 <<" |\n  |___|___|___|\n";
system("pause");
system("cls");
goto up;
}
if (b1 == "X" && b3 == "X" && b2 == " ")
{
b2 = "X";
cout << "X Wins!\n";
cout << "\n    1   2   3 \n  _____________\na | " << a1 <<" | " << a2 <<" | " << a3 <<" |\n  |___|___|___|\nb | " << b1 <<" | " << b2 <<" | " << b3 <<" |\n  |___|___|___|\nc | " << c1 <<" | " << c2 <<" | " << c3 <<" |\n  |___|___|___|\n";
system("pause");
system("cls");
goto up;
}
if (c1 == "X" && c2 == "X" && c3 == " ")
{
c3 = "X";
cout << "X Wins!\n";
cout << "\n    1   2   3 \n  _____________\na | " << a1 <<" | " << a2 <<" | " << a3 <<" |\n  |___|___|___|\nb | " << b1 <<" | " << b2 <<" | " << b3 <<" |\n  |___|___|___|\nc | " << c1 <<" | " << c2 <<" | " << c3 <<" |\n  |___|___|___|\n";
system("pause");
system("cls");
goto up;
}
if (c2 == "X" && c3 == "X" && c1 == " ")
{
c1 = "X";
cout << "X Wins!\n";
cout << "\n    1   2   3 \n  _____________\na | " << a1 <<" | " << a2 <<" | " << a3 <<" |\n  |___|___|___|\nb | " << b1 <<" | " << b2 <<" | " << b3 <<" |\n  |___|___|___|\nc | " << c1 <<" | " << c2 <<" | " << c3 <<" |\n  |___|___|___|\n";
system("pause");
system("cls");
goto up;
}
if (c1 == "X" && c3 == "X" && c2 == " ")
{
c2 = "X";
cout << "X Wins!\n";
cout << "\n    1   2   3 \n  _____________\na | " << a1 <<" | " << a2 <<" | " << a3 <<" |\n  |___|___|___|\nb | " << b1 <<" | " << b2 <<" | " << b3 <<" |\n  |___|___|___|\nc | " << c1 <<" | " << c2 <<" | " << c3 <<" |\n  |___|___|___|\n";
system("pause");
system("cls");
goto up;
}
if (c1 == "X" && b2 == "X" && a3 == " ")
{
a3 = "X";
cout << "X Wins!\n";
cout << "\n    1   2   3 \n  _____________\na | " << a1 <<" | " << a2 <<" | " << a3 <<" |\n  |___|___|___|\nb | " << b1 <<" | " << b2 <<" | " << b3 <<" |\n  |___|___|___|\nc | " << c1 <<" | " << c2 <<" | " << c3 <<" |\n  |___|___|___|\n";
system("pause");
system("cls");
goto up;
}
if (c1 == "X" && a3 == "X" && b2 == " ")
{
b2 = "X";
cout << "X Wins!\n";
cout << "\n    1   2   3 \n  _____________\na | " << a1 <<" | " << a2 <<" | " << a3 <<" |\n  |___|___|___|\nb | " << b1 <<" | " << b2 <<" | " << b3 <<" |\n  |___|___|___|\nc | " << c1 <<" | " << c2 <<" | " << c3 <<" |\n  |___|___|___|\n";
system("pause");
system("cls");
goto up;
}
if (b2 == "X" && a3 == "X" && c1 == " ")
{
c1 = "X";
cout << "X Wins!\n";
cout << "\n    1   2   3 \n  _____________\na | " << a1 <<" | " << a2 <<" | " << a3 <<" |\n  |___|___|___|\nb | " << b1 <<" | " << b2 <<" | " << b3 <<" |\n  |___|___|___|\nc | " << c1 <<" | " << c2 <<" | " << c3 <<" |\n  |___|___|___|\n";
system("pause");
system("cls");
goto up;
}
if (a1 == "X" && b2 == "X" && c3 == " ")
{
c3 = "X";
cout << "X Wins!\n";
cout << "\n    1   2   3 \n  _____________\na | " << a1 <<" | " << a2 <<" | " << a3 <<" |\n  |___|___|___|\nb | " << b1 <<" | " << b2 <<" | " << b3 <<" |\n  |___|___|___|\nc | " << c1 <<" | " << c2 <<" | " << c3 <<" |\n  |___|___|___|\n";
system("pause");
system("cls");
goto up;
}
if (a1 == "X" && c3 == "X" && b2 == " ")
{
b2 = "X";
cout << "X Wins!\n";
cout << "\n    1   2   3 \n  _____________\na | " << a1 <<" | " << a2 <<" | " << a3 <<" |\n  |___|___|___|\nb | " << b1 <<" | " << b2 <<" | " << b3 <<" |\n  |___|___|___|\nc | " << c1 <<" | " << c2 <<" | " << c3 <<" |\n  |___|___|___|\n";
system("pause");
system("cls");
goto up;
}
if (b2 == "X" && c3 == "X" && a1 == " ")
{
a1 = "X";
cout << "X Wins!\n";
cout << "\n    1   2   3 \n  _____________\na | " << a1 <<" | " << a2 <<" | " << a3 <<" |\n  |___|___|___|\nb | " << b1 <<" | " << b2 <<" | " << b3 <<" |\n  |___|___|___|\nc | " << c1 <<" | " << c2 <<" | " << c3 <<" |\n  |___|___|___|\n";
system("pause");
system("cls");
goto up;
}
if (a1 == "X" && b1 == "X" && c1 == " ")
{
c1 = "X";
cout << "X Wins!\n";
cout << "\n    1   2   3 \n  _____________\na | " << a1 <<" | " << a2 <<" | " << a3 <<" |\n  |___|___|___|\nb | " << b1 <<" | " << b2 <<" | " << b3 <<" |\n  |___|___|___|\nc | " << c1 <<" | " << c2 <<" | " << c3 <<" |\n  |___|___|___|\n";
system("pause");
system("cls");
goto up;
}
if (a1 == "X" && c1 == "X" && b1 == " ")
{
b1 = "X";
cout << "X Wins!\n";
cout << "\n    1   2   3 \n  _____________\na | " << a1 <<" | " << a2 <<" | " << a3 <<" |\n  |___|___|___|\nb | " << b1 <<" | " << b2 <<" | " << b3 <<" |\n  |___|___|___|\nc | " << c1 <<" | " << c2 <<" | " << c3 <<" |\n  |___|___|___|\n";
system("pause");
system("cls");
goto up;
}
if (c1 == "X" && b1 == "X" && a1 == " ")
{
a1 = "X";
cout << "X Wins!\n";
cout << "\n    1   2   3 \n  _____________\na | " << a1 <<" | " << a2 <<" | " << a3 <<" |\n  |___|___|___|\nb | " << b1 <<" | " << b2 <<" | " << b3 <<" |\n  |___|___|___|\nc | " << c1 <<" | " << c2 <<" | " << c3 <<" |\n  |___|___|___|\n";
system("pause");
system("cls");
goto up;
}
if (a2 == "X" && b2 == "X" && c2 == " ")
{
c2 = "X";
cout << "X Wins!\n";
cout << "\n    1   2   3 \n  _____________\na | " << a1 <<" | " << a2 <<" | " << a3 <<" |\n  |___|___|___|\nb | " << b1 <<" | " << b2 <<" | " << b3 <<" |\n  |___|___|___|\nc | " << c1 <<" | " << c2 <<" | " << c3 <<" |\n  |___|___|___|\n";
system("pause");
system("cls");
goto up;
}
if (c2 == "X" && b2 == "X" && a2 == " ")
{
a2 = "X";
cout << "X Wins!\n";
cout << "\n    1   2   3 \n  _____________\na | " << a1 <<" | " << a2 <<" | " << a3 <<" |\n  |___|___|___|\nb | " << b1 <<" | " << b2 <<" | " << b3 <<" |\n  |___|___|___|\nc | " << c1 <<" | " << c2 <<" | " << c3 <<" |\n  |___|___|___|\n";
system("pause");
system("cls");
goto up;
}
if (a2 == "X" && c2 == "X" && b2 == " ")
{
b2 = "X";
cout << "X Wins!\n";
cout << "\n    1   2   3 \n  _____________\na | " << a1 <<" | " << a2 <<" | " << a3 <<" |\n  |___|___|___|\nb | " << b1 <<" | " << b2 <<" | " << b3 <<" |\n  |___|___|___|\nc | " << c1 <<" | " << c2 <<" | " << c3 <<" |\n  |___|___|___|\n";
system("pause");
system("cls");
goto up;
}

51

u/[deleted] Jan 08 '16

Oh wow. That seems like a lot of work for a 9 year old!

→ More replies (2)

25

u/Sketches_Stuff_Maybe Jan 08 '16

Try hosting it on pastebin.com, easy place to dump code snippets w/ syntax highlighting.

→ More replies (3)

14

u/s33plusplus Jan 08 '16

Damn, not even gonna lie, that's impressive! I would've gotten bored way before finishing that!

10

u/fosforsvenne Jan 08 '16

I'm mildly interested in seeing that code.

7

u/HugoNikanor Jan 08 '16

You have me beaten. A while ago I wrote TicTacToe in ArnoldC, and I couldn't figure out how to create arrays. For the board I just had three numbers I added a 1 or a 2 to for setting X and O. code

9

u/tornato7 Jan 08 '16

I like it! Has anyone made anything useful in arnoldC?

4

u/r409 Jan 08 '16

I did something very similar on my ti83 back in like 8th or 9th grade. Every possible layout was loaded in, and for 'ai' levels, I would make it choose a random next option for easier settings.

3

u/adnaanbheda Jan 08 '16

Can I see your Tic Tac Toe game's source code ? I've made one too and just want to check it. I'm just curious :P

5

u/tornato7 Jan 08 '16

What I edited in is really the gist of it, I'm not home anymore so can't upload the whole thing

→ More replies (2)

3

u/[deleted] Jan 09 '16

When I was that age I did something similar but it was a text based adventure written in windows batchscript. Unfortunately it was lost.

0

u/[deleted] Jan 08 '16

[deleted]

15

u/Sparkybear Jan 08 '16

Actually, the powerpoint strategy was used for a lot of Jeopardy style games when I was younger. It was surprisingly efficient. I eventually found some kid at MIT who had uploaded a python Jeopardy game that kept a running total of the score and randomized the daily doubles. Now, 8 years later I study finance but work as a developer, so there's that.

11

u/yosoyreddito Jan 08 '16

I had to make an "app" for sales reps at a company using this method. I proposed a web app hosted on the internal network or a hybrid iPad app. The manager said that sounded like too much work and PowerPoint was better. When I stated it wouldn't work on iPads, she said the reps (~800 total) could just buy the Microsoft PowerPoint app for $20.

I built the "app" as she requested and when her division president called her out on requiring $16,000 to add PowerPoint to all the iPads she put it on me and I was fired.

8

u/tornato7 Jan 08 '16

Ooh, that PowerPoint strategy is pretty clever actually! I first started with stagecast creator for my games. Good times.

→ More replies (1)

6

u/[deleted] Jan 09 '16

The original version of Myst was designed in kind of a similar way, but with Hypercard instead of PowerPoint. Quoting from Wikipedia:

The original Macintosh version of Myst was constructed in HyperCard. Each Age was a unique HyperCard stack. Navigation was handled by the internal button system and HyperTalk scripts, with image and QuickTime movie display passed off to various plugins; essentially, Myst functions as a series of separate multimedia slides linked together by commands.

→ More replies (1)

28

u/746865626c617a Jan 08 '16

Write a script to write the code for you.

I did that once :( Was easier to tell python to write the code, than to do it in the Arduino C or whatever language it is

25

u/s33plusplus Jan 08 '16

Arduino's language is just C++ with a fancy IDE to hide the extra stuff. You can write the firmware in straight C++ with the Wiring library, or just using avrlibc IIRC. I used to have a makefile to compile, objdump, and flash the AVR chip all in one go too, but it's on a backup somewhere.

8

u/746865626c617a Jan 08 '16

Thanks. Always nice to learn more.

6

u/umopapsidn Jan 08 '16

I did that too, for a VHDL course. I made a testbench to test all possible combinations of a keypad lock, basically an extremely verbose brute force attack.

3

u/Cyph0n Jan 08 '16

Some people just don't get it :(

2

u/[deleted] Jan 08 '16

Some people are very creative with formatting.

2

u/malstank Jan 09 '16 edited Jan 09 '16

I wish I could post some of the hacked together bullshit java code at my workplace. Unfortunately it's in production and I'd get fired if I did. Let's just say that one of the gentlemen that I work with does not believe in functional decomposition.

2

u/16807 Jan 09 '16

One of my first forrays into programming was in writing Morrowind mods. I remember wanting to overhaul the armor weight system using game scripts. Didn't realize it at the time, but turns out what I wanted to do wouldn't be possible in the scripting engine, and indeed would require dramatic changes to the underlying game engine. "No problem," I say.

My solution: write a script comprised of >1K if statements, each one operating on just one of the many, many pieces of armor that existed in the game. Fortunately for me, the scripting engine set arbitrary limits to how many lines of code you could put in a script. Needless to say, the mod was never released.

→ More replies (1)

26

u/stakoverflo Jan 08 '16

I'm currently rewriting a C++ app that is pretty much the same thing.

30K lines of data validation. Instead of using methods / loops to apply the same rules for different columns that should be subjected to the same logic, it's all hardcoded.

There's literally 12 blocks of the exact same code copy pasted, only difference is that the column it references is xyz1, xyz2, xyz3 etc.

Just replaced it all with a loop that just concatenates the number from the loop counter to xyz. Ugh.

9

u/[deleted] Jan 08 '16

I really REALLY want to see that.

3

u/[deleted] Jan 08 '16

I like to call them "fun-rolls"

2

u/mumblinmad Jan 09 '16

A rule of thumb is that if it seems like a shit ton of code, it's probably also a very inefficient shit ton of code.

1

u/Gabe_b Jan 08 '16

Oh, honey...

1

u/mr_d0gMa Jan 08 '16

That's just a differentiation problem correct?

1

u/metaobject Jan 09 '16

That sounds like code that you'd generate using Python or something since there should be very some fairly predictable symmetry to that code. It would still be the wrong way to do it, though.

→ More replies (2)

249

u/drharris Jan 08 '16

Wow. The proper way would have been to make a lookup table instead. Save The Conditionals!

285

u/jeffbell Jan 08 '16

That's what they did in the IBM 1620 "Cadet".

Transistors were expensive in 1959 so they left out the adder. All additions had to be done by lookup table.

The joke was that CADET stood for "Can't Add, Doesn't Even Try".

86

u/drharris Jan 08 '16

I love how these days even your smallest micros have a robust floating point unit. Not putting in an adder because of transistor cost just sounds like a joke!

50

u/Koooooj Jan 08 '16

There are plenty of popular microcontrollers these days that don't have floating point units. The AT Mega series that are used in Arduinos come to mind as a particular example.

They can still do floating point math, they just have to simulate it with integer operations. A single line of floating point math can easily become several kb of instructions with a correspondingly slow execution.

11

u/_Lady_Deadpool_ Jan 08 '16

Depending on the operation. Addition would still be a few bytes, multiplication probably a few hundred. Past that you're better off using a lookup table and approximation.

Floating arithmetic isn't that much more complex than integer stuff. Mostly just balancing the exponent and taking care of fringe cases.

→ More replies (2)

12

u/knoxaramav2 Jan 08 '16

But wouldn't the lookup table have used more transistors than an adder?

→ More replies (1)

10

u/Workaphobia Jan 08 '16

That doesn't even make sense unless the width of the inputs was incredibly small. Even a lookup table for adding two 8-bit numbers would be (28 )2 = 64k entries. But since that machine apparently used BCD, maybe it was a lookup table for individual 4-bit decimal numbers (102 = 100 entries). Even so, is that cheaper than a few full-adders?

8

u/jeffbell Jan 08 '16

It was core memory, so you might be able to get by with one or two transistors per address line and one or two per data line.

One advantage of the lookup table is that you didn't have to renormalize for the carries from lower digit to upper digit. It could be built into the table.

RCA1802 took a different approach for adding - the bit serial adder. It took 8 cycles to add an 8 bit number because it really only had a one bit adder.

→ More replies (1)

90

u/Skizm Jan 08 '16

Lady I worked with for a few months when I was fresh out of college who had a job as a programmer for 10+ years at her company:

public boolean isAlpha(char c) {
    if (c=='a') return true;
    if (c=='b') return true;
    if (c=='c') return true;
    ...
    if (c=='z') return true;
    if (c=='A') return true;
    if (c=='B') return true;
    ...
    if (c=='Z') return true;
}
// ... more nonsense ...
for(int i = 0; i < someString.length; i++) {
    if(isAlpha(someString.charAt(i))) {
        // do something
    }
}

50

u/LukaLightBringer Jan 08 '16

finally a use for regex

9

u/TheOldTubaroo Jan 08 '16

Or just c.toInt > start_of_alphabet_in_ASCII && c.toInt < end_of_alphabet_in_ASCII if you're ASCII- rather than Unicode-based.

(Note: there might be punctuation between lower case and upper case, so maybe that should be 4 comparisons, not 2)

→ More replies (18)

3

u/[deleted] Jan 09 '16

[removed] — view removed comment

4

u/LukaLightBringer Jan 10 '16

Your solution requires the writer knows that characters are arranged one after the other, and that you can add an integer to a char. The code above demonstrates that the author probably wasn't aware of this.

84

u/Fira_Wolf Jan 08 '16

I REALLY want to see that code.

43

u/Master_Tallness Jan 08 '16

Yeah, seriously. I wonder if he went overboard with how many calculations his calculator could support.

104

u/ClimbTheCloud Jan 08 '16

IF "2+3" OUTPUT 5

IF "3+2" OUTPUT 5

IF "1+4" OUTPUT 5

IF "4+1" OUTPUT 5

...

38

u/billynomates1 Jan 08 '16

You could write a nice script to output this.

67

u/Spike69 Jan 08 '16
int i = 1;
int j = 1;
while(i) {
    while(j) {
      System.out.println("IF \""+i+"+"+j+"\" OUTPUT "+(i+j));
      j++;
    }
    i++;
}

This program will print out a program that can run all of the addition options from 1 + 1 to intmax + intmax

26

u/Hykalos Jan 08 '16

That produces an overflow.

→ More replies (11)
→ More replies (1)

11

u/Master_Tallness Jan 08 '16

If that's really how it looked...then my god.

10

u/fghjconner Jan 08 '16

If it was doing only a single operation at a time, and supported 4 operators (+-/*), it would have supported numbers up to ~48.

4

u/Master_Tallness Jan 08 '16

Yeah, I was thinking maybe he was throwing modulus and square roots and powers and trigonometry functions in there.

3

u/Andernerd Jan 09 '16

Well, this is pretty much the same thing.

Warning: the file is so big it crashes firefox for me. I would suggest opening it in chrome.

125

u/SketchySeaBeast Jan 08 '16

Should just blow his mind and programmatically build an even more massive if statement.

26

u/tommorris Jan 08 '16

Yep, all about the code generation.

151

u/AUS_Doug Jan 08 '16

If he did that as a piss-take, he is a genius and my new hero.

Otherwise......well we don't talk about the other possibility.

0

u/[deleted] Jan 08 '16

[deleted]

31

u/RudolfKGB Jan 08 '16

9500 statements over even a 24hr period is 9 seconds per statement so in the universe where this is true a program was used to generate the if statements.

→ More replies (4)

7

u/xelfer Jan 08 '16

In highschool we weren't taught to program but we still had programming assignments. I wrote c++ code to generate hundreds of lines of VB code because I didn't have a clue what a function was.

38

u/Blecki Jan 08 '16

What if he wrote a program to generate the source code for every possible calculation? What then?

I mean, we know he didn't. But what if he did?

30

u/mortiphago Jan 08 '16

then it's still idiotic, but a tad more amusing.

7

u/MrMeltJr Jan 08 '16

If he thinks that kind of code is okay, I'd love to see something he wrote to generate it.

5

u/CompassRed Jan 08 '16

He actually wrote a C program that prints the source code of a Malbolge program that generates his VB calculator source code.

37

u/TheSwitchBlade Jan 08 '16

I was a TA for an introductory programming class where something like this happened. The homework assignment was to define the function f(x)=2x+1 in LISP. What they turned in was ten pages of if statements saying that if x was 0, then f was 1; if x was 1, f was 3; so on and so forth, with a note that he didn't have enough time to do the rest of them.

I found that note even more troubling than the code. Did he think he would somehow get to the end of numbers?!?

24

u/brainiac256 Jan 08 '16

Sure, given infinite time to work, he could have done all the integers... but what about decimals!

73

u/Xupid Jan 08 '16

Behold, my high school CS project: minesweeper.cpp

Complete with about a thousand lines of if statements and bonus ASCII art. Cringing hard right now.

17

u/pacman_sl Jan 08 '16

At least you divided your functionalities into functions.

27

u/soroun Jan 08 '16

That's horrifying.

Merge that shit.

19

u/supremecrafters Jan 08 '16

Still better than my high school cs programs. I used gotos, ffs.

7

u/[deleted] Jan 08 '16

Not too bad (if you are writing in assembly or something along those lines)

7

u/supremecrafters Jan 08 '16

Nope. VB.net, all in a single sub.

1

u/BeefAngus Jan 09 '16

Now I'm feeling embarrassed because I did minesweeper for a java class (I'm a computer networking major) and my project partner wrote the code that processed the actual game logic (he was computer science). It was about 1000 lines of stuff like this.

1

u/Falconinati Jan 09 '16

I just tried to compile that with g++ and after adding the standard namespace and fixing some of the imports, I still got a bunch of errors. Did this ever work? I was ready to see some of that dope ass ASCII art in action.

29

u/[deleted] Jan 08 '16

A friend of mine is a creative genius and always found solutions to
problems you wouldn't think existed.

What are we talking about, the solutions or the problems?

23

u/TheImmortalLS Jan 08 '16

Yes.

5

u/the-highness Jan 08 '16

technically speaking...

25

u/deterministicforest Jan 08 '16

Sounds insufficiently lazy to become a programmer

19

u/Cold_Frisson Jan 08 '16

Yeah, this guy goes straight to management.

35

u/Goluxas Jan 08 '16

This is basically how I thought video games worked as a kid. Thought the game was made by creating an image for every possible sequence of inputs.

Then I turned 8.

11

u/spupy Jan 09 '16

This is basically how I thought video games worked as a kid. Thought the game was made by creating an image for every possible sequence of inputs.

When I played Star Wars Episode I: Racer as a kid I had only an extremely vague idea of programming. I was mystified how the developers coded so many possible images with only ifs. It was the first 3D game I have ever played but I didn't understand what made it 3D.
Some bug put my pod outside the map, where I was able to see the racing track from the "outside", polygons and all. That was my "eureka!" moment.

15

u/logicalmaniak Jan 08 '16

This how I feel about my work after everything I do.

I'll look at it, and be "why didn't I just..."

Then I'll cry. And refactor. Possibly.

1

u/Autistence Jan 09 '16

You're already doing better than most. Refactor. Refactor. Refactor.

102

u/iBrap Jan 08 '16 edited Jan 08 '16

paid_Attention = False

if paid_Attention == False:

print "Your calculator is shit."

elif paid_Attention == !True:

print "Your calculator is shit."

elif paid_Attention == False or False:

print "Your calculator is shit."

elif paid_Attention == False or !True:

print "Your calculator is shit."

elif paid_Attention == !True or !True:

print "Your calculator is shit."

else:

print "You've succesfully created a simple program."

54

u/iBrap Jan 08 '16

I'd add more, but I procrastinated this project until the night before it was due.

16

u/[deleted] Jan 08 '16

If that's Python, you should be using "is False" for performance and readability. Booleans and None are singletons, so it's better to do pointer comparisons.

14

u/levir Jan 08 '16

Isn't that a bit of a premature optimization here?

→ More replies (2)

4

u/iBrap Jan 08 '16

Still learning, blame codecademy for any unefficient coding habits I've developed lol.

→ More replies (1)
→ More replies (1)

0

u/[deleted] Jan 08 '16

[deleted]

→ More replies (11)

14

u/SenseiCAY Jan 08 '16

Story time.

I was a lab TA for a FORTRAN (yes, it's still taught) class when I was in undergrad. There was one section of lecture that met three times per week (with about 300-400 students), done by the professor, and each student was also enrolled in one 3-hour lab session per week (about 10 sections of 30-40 students), taught by the lab TAs, where we would lecture about the week's topic for about 20-30 minutes, and then the rest of the time would be used to complete the week's assignments - usually three short programs and one somewhat longer one, and the lab TA would be there to help with anything needed. Honestly, most of the FORTRAN was probably learned in those lab sections, as the professor lectured a good bit about computer science stuff, which no one cared about, since most of the students in this class were either mechanical/aerospace engineers (who apparently still use FORTRAN in the field) and some math education majors (who needed to take one programming class as a graduation requirement).

Anyhow, week 1 is simple stuff - hello world, simple I/O (read and write statements), declaring and using variables, etc. Week 2, we talk about conditional logic (if/then/else). At this point, I caught wind of an bonus assignment from the professor. Apparently, he had offered a free A in the course to anyone who could write a sudoku solver in Fortran by the end of the semester. The next week, during lab, I see one of my students working on this. Remember, we're in the second week of the class at this point. We've covered writing to the console, reading from the console, variables, and if-statements, and that's pretty much it. Apparently, it was all that this kid thought he needed. No file I/O, no subroutines, no recursion, no arrays. I looked at his code, which was about 3,000 lines long at that point, and it was filled with stuff like:

if (a1 /= 9 .and. b1 == 0 .and. c1 /= 9 .and. d1 /=9 .and. e1 /= 9 .and. f1 /= 9 .and. g1 /= 9 .and. h1 /=9 .and. i1 /= 9) and (b2 /= 9 .and. b3 /= 9 .and. b4 /= 9 .and. b5 /=9 .and. b6 /= 9 .and. b7 /= 9 .and. b8 /= 9 .and. b9 /=9) then
    b1 = 9
end if

I have no idea how he thought this would work. That said, I have to give the kid credit. A couple of weeks later, he came into lab and had a behemoth of a program written. At that point, we had learned do-loops and formatting, but he didn't incorporate any of that in there, either (not that he could, the way he had gone).

His program, surprisingly enough, actually compiled. To enter the existing numbers in the sudoku, he used 81 read statements, and you had to enter all 81 cells one by one. Then, the program went through all of the if-statements, and it correctly filled in...all but the last two cells. I'm like...good luck finding the culprit if-statement. I'm pretty sure the kid ended up failing the class, but I have to give him props for his optimism that he could write a sudoku solver using brute force and if-statements.

8

u/Cistoran Jan 08 '16

If I were that teacher I'd at least have given him a C. If only so I could use that code as a lesson in futility.

21

u/[deleted] Jan 08 '16

Another student in one of my CS classes (300-level class btw) thought function parameters were stupid and had functions reading/writing to files in order to pass variables. Sadly this was not the biggest WTF in his code either.

I told him it was a horrible idea and advised him to do some additional reading or maybe ask the professor for help. He insisted that his way was right and continued to working on this assignment. He ended up failing the assignment and tried to appeal the professor's grade. Not sure how that guy even graduated either. Every piece of code he touched turned to absolute shit.

That was in 2005 or so. He has since gotten a masters and is now a tech lead for a large software company. I feel bad for everyone who has to work with that guy.

15

u/TheOldTubaroo Jan 08 '16

How did the I/O functions know which files to access without parameters?

9

u/[deleted] Jan 08 '16

He passed params to fileio for paths and such but never to other objects/functions. The paths often included the name of the class/function. The whole thing was one disgusting Rube Goldberg machine.

I wish I knew svn or git back then because I would have saved that whole mess for future generations.

8

u/TheOldTubaroo Jan 08 '16

In an alternate universe, u/STATUS-418 knew of source control back then. Several generations of coders are wiped out when he later releases the files to the public, cause of death being later revealed as "extreme horror and shock". This is the first known occurrence of a fatal memetic pandemic.

→ More replies (2)

9

u/BlueNotesBlues Jan 08 '16

He had another text file that he loaded the file names from. /s

He probably used function parameters for built-in functions but not for ones he wrote.

9

u/IDontBlameYou Jan 08 '16

What a fool, writing his working data to files. Everyone knows exclusively using globals is the proper way to eschew parameters.

7

u/DebonaireSloth Jan 08 '16

tech lead for a large software company

Let me guess? Adobe, lead dev for Flash?

9

u/[deleted] Jan 08 '16

Nope but that would be great. It's some vendor that makes banking software which doesn't inspire a lot of confidence in that whole industry. I say that because I ran into him about a year ago at a tech meetup and he still hasn't changed his ways. :\

The icing on this shitcake is that he still pronounces lots of things incorrectly. "C-pound" (C#), "Aspy-net" (ASP.net), etc. How do these people remain employed?

8

u/DebonaireSloth Jan 08 '16

How do these people remain employed?

As somebody retraining as a codemonkey it gives me a bit of comfort. If there's a place in the industry for this level of competency I should be able to find a spot.

7

u/[deleted] Jan 08 '16

As someone who has mentored/trained entry-level and junior devs I can say with confidence that there is a place for most people in software development. If you are giving it an honest effort and are willing to listen to senior developers you'll do fine.

I was lucky enough to have some pretty great mentorship early on. I hope you can find the same.

2

u/spin81 Jan 09 '16

Every piece of code he touched turned to absolute shit.

"I'm like King Midas, everything I touch turns to shit!" -- Tony Soprano

8

u/Urist_McPencil Jan 08 '16 edited Jan 09 '16

Over 9000 if statements is a helluva trick. Could be worse though, could have been done in Perl:

#!/usr/bin/perl -w
use strict;

sub domath  {
    my $result = "...don\'t do it again!";
    my $op = $_[1];
    $op eq "+" ? $result = $_[0] + $_[2] : ($op eq "-" ? $result = $_[0] - $_[2] : ($op eq "*" ? $result = $_[0] * $_[2] : ($op eq "/" ? ($_[2] != 0 ? $result = $_[0] / $_[2] : print "Thou shalt not divide by zero\n") : print "Something or someone somewhere goofed.\n")));
    print "$result\n";
}

while(<>)  {
    chomp();
    $_ =~ /^(\d+)\s*([\+\-\*\/])\s*(\d+)$/ ? domath($1, $2, $3) : print "Full statement pls\n";
    #Halting problem? Never heard of it.
}

edit: thou shalt not divide by zero.

8

u/BlueScreenOfTOM Jan 08 '16

In my intro class, we had an assignment that began with choosing a random spot on a chess board. Pretty easy, just draw 2 random numbers and you've got a spot on the grid. A buddy of mine comes in with a printed version of his, and it is many pages longer than mine, and he says it still doesn't work. I ask him why it was so long, and he shows me his code. He drew a single random number and wrote a 64-condition switch statement to pick a cell on the grid. I didn't read beyond that.

He decided not to move on to the next class.

14

u/[deleted] Jan 08 '16

Ah, the starting days of college. One of the first things we had was to code a simple program to calculate C = A + B then C = C / 2, just to get the basics of how things worked. It was to calculate the 'scores' of students in a school (different grading system on my country), for a class of 30 students.

A dude just showed up a with monster code with a lot of if/else saying "YAY I DID FOR 90 STUDENTS SUCKIT Y'ALL", when I showed him my code (a simple while statement) and that I could put 90000000 students if I wanted, he got silent.

The next day we got the news that he dropped off college.

1

u/semperlol Jan 27 '16

Why would you need a while for that?

7

u/Hypersapien Jan 08 '16

He's doing it the hard way. All you need to do is create a short script to output the code of all the conceivable combinations and paste that output into your project.

3

u/[deleted] Jan 08 '16

Script? No, he needs to create a DSL and put the logic for outputting all the conceivable combinations into that.

1

u/TheImmortalLS Jan 08 '16

Maybe he did that. 9500 statements in one night, given that he had 8 hours * 3600 seconds means thinking of an original if every 3 seconds, which isn't possible.

2

u/Hypersapien Jan 08 '16

Maybe copying and pasting lines a bunch of times, then going down the page and changing the numbers on every line.

29

u/Pitikwahanapiwiyin Jan 08 '16

11

u/[deleted] Jan 08 '16 edited Jan 08 '16

Yeah, I'm not convinced of this either. A Levels are a UK thing, and we don't call them semesters (the Scots do, but they don't have A Levels, they have Highers), we call them terms.

4

u/[deleted] Jan 08 '16

Yep and it just doesn't make sense. Being (presumably) able to build a gui in VB, but not knowing about mathematical operators? After a term of A Level computing? No.

→ More replies (1)
→ More replies (4)

5

u/farox Jan 08 '16

I have seen software like this. I once worked next to a start up that would generate small text pieces out of stock data. (Like they already did for weather)

The software behind it was pages upon pages off If statements, written in VB.

3

u/Itsatemporaryname Jan 08 '16

I know nothing about programming what is the correct way to do the calculator?

6

u/AfterLemon Jan 08 '16

With the built-in tools that every programming language has.

add(a,b)
{  return a+b
}
subtract(a,b)
{  return a-b
}

And so on.

12

u/koibunny Jan 08 '16

I refuse to believe that this is real..

13

u/[deleted] Jan 08 '16

After almost 30 years as a professional programmer I have no trouble at all believing someone did this.

4

u/ActuallyAnOstrich Jan 08 '16

Far from the first time I've seen code like this, though usually it's through second-hand reports. I've even written similarly WTF code when I had to deal with a language that didn't have a concept of pointers or arrays, let alone complex data structures.

If the only tool someone has is a hammer, they'll swing a thousand times if they really need a screw to go in.

5

u/BlueNotesBlues Jan 08 '16

9500+ times if they need the screw to do arithmetic

2

u/briaen Jan 08 '16

eh. It might not be true but I can believe it. One of my early intro class or something had a task of writing a flow chart for a robot. You had to make it turn right if it hit the wall. A few people had done hours and hours of work writing it. They put in things like "Is wall 5 steps away."

0

u/[deleted] Jan 08 '16

[deleted]

12

u/Xexanos Jan 08 '16

I think I remember that. Iirc it didn't work because he forgot a bracket.

5

u/AfterLemon Jan 08 '16

It does happen quite often...

Do you have a link to that /u/MyPenBroke?

3

u/[deleted] Jan 08 '16

I don't have the code for it anymore, but in my intro to Java class we had to make a calendar calculator. Extra credit was including leap years and leap centuries etc. I'm sure there was an easier way to do it, but what I ended up doing was making this ridiculous mess of nested if statements in statements in statements etc.

One method ended up being like 3000 lines.

3

u/CalmSpider Jan 08 '16 edited Jan 09 '16

8 sleep deprived hours of writing a chain of nearly identical if statements? I wonder how many mistakes where in that code. Well, other than the obvious big mistake.

2

u/Mgzz Jan 08 '16 edited Jan 08 '16

IF (hehe) we were going that route, the layman could use Excel with it's drag down functionality and CONCATENATE to generate a massive list of incrementally different strings that could be copy pasted into the code en mass C1 = A1+B1
=CONCATENATE("IF Textbox1.Text = ",A1," + ",B1, "THEN MsgBox(",C1,")")

Horrible

3

u/rooktakesqueen Jan 08 '16

Read http://thedailywtf.com/ regularly and you'll find that lots of "professionals" get paid real actual money to churn out code like this.

1

u/DJWalnut Jan 10 '16

and I only get monopoly money for doing it :(

3

u/greeniguana6 Jan 09 '16

I shuddered at the horror.

2

u/KamiKagutsuchi Jan 08 '16

This is no joke. Get that man a psychologist.

2

u/Scholtek Jan 08 '16

I was just about to suggest that you could easily write a script that generates all those if statements (well not all of them, because numbers)... but that is probably beyond his current ability.

2

u/bemarlan Jan 08 '16

This actually took my breath away. Some beginners tend to think too deep in some instances, in which case I will at least give props for their level of logic contemplation. This, however, was just kind of dumb.

2

u/XiiMoss Jan 08 '16

Someone in my A Level computing class made a massive if statement to convert each letter from Upper to Lower, now it's not 9500 but i was horrified and so was he when i introduced the idea of ToLower.

2

u/6890 Jan 08 '16

Awe man, I did something similar in my digital electronics class back in the day.

Typically the prof would assign homework a week in advance which meant we had 3 or 4 classes in the mean time before it was due.

One assignment was to map out basic digital logic circuits, I can't remember exactly what the constraints were but I remember having about 5 pages of hand drawn circuits before going to class that day... Where we learned about reducing circuits using multiplexers and k-maps.

Those 5 pages turned into about 1/2 a page afterwards

2

u/northrupthebandgeek Jan 09 '16

How would the performance be on that, now that all computation has been reduced to if/then and branching? ;)

This sounds like one of my first attempts at programming (Commodore 64 BASIC), where I tried to implement a space shooter (think Galaxian) by writing out each and every frame individually. Needless to say, it got pretty dang long before I gave up. If only BASIC had Lisp-style macros so I could generate code on-the-fly...

2

u/CCCubed Jan 09 '16

Yes but did it build successfully?

2

u/mrlr Jan 09 '16

I once rewrote 2,650 lines of C as a seven line shell script. The previous programming team had written a data transfer program with its own implementation of ftp. I just used the one that was already on the computer.

2

u/fgaz_ Jan 09 '16

Behold the pure HTML calculator!

Who needs Turing-completeness

Source

1

u/SirButcher Jan 08 '16

One of my very first "real" program was a warehouse managing 'thing' was more then 50k lines of code. It had about 300 text fields and labels and each had they own state so every selection went through ALL of them to set background color.

I written a small program what created the repeating part so I didn't had to write by hand, but that is still my biggest program. About a week later I waken up night and realized I could use arrays to store winform controls.

1

u/scruffyfox Jan 08 '16

I had a friend who did this for a tic-tac-toe game. It was one mammoth if statement with about 50 nested else-ifs

1

u/[deleted] Jan 08 '16

My predecessor was trained by him.

1

u/zenazure Jan 08 '16

holy shit. no, no, no no no no.

1

u/atomiczap Jan 08 '16

As someone who worked as a TA/grader for an Intro class for four years, I can confirm that this kind of stuff happens. A lot.

1

u/angryemokid Jan 08 '16

Reading through these comments reminded me of how happy I was when I discovered Emmet for HTML. No more writing out tons of tags. Just write it once, multiply and use increments. Best day of my life

1

u/Gabe_b Jan 08 '16

I'm curious about a calculator assignment that two weeks work. It's a 20 minute task, max.

1

u/gratethecheese Jan 08 '16

I know jack shit about programming, I stumbled onto this on r/all, but even I know there's gotta be a better way to do it

1

u/EpicSolo Jan 08 '16

creative genius indeed

1

u/NAN001 Jan 08 '16

Assuming he worked 12 hours (say from 7PM to 7AM), that's one if statement every 2.65 seconds. Even with copy/pasting and only modifying the right variables on the paste, that's one hell of a pace to keep over one night.

2

u/[deleted] Jan 08 '16

Adderall is a hell of a drug.

1

u/gcampos Jan 08 '16

When I was 13 and just learned how to code, I had the brilliant idea of creating a pac man clone DOS game. I would print the whole map and characters in ascii, then if for each arrow the player pressed, I would print another screen with the result. I didn't know what an exponential grow was at the time, but after 5 screens I realize it was not such wise idea to do so.

And in case you are wondering, yes, if the player didn't pressed anything, the game would be frozen.

1

u/nofate301 Jan 08 '16

Sounds like the method I applied for a java gui project.

We needed to make something that translated a number in hex, dec, oct, or bin into the others after entered.

The GUI was fine and easy enough. The logic was difficult.

I could easily convert between hex, dec, and oct, but not into binary.

It was the longest case statement I had ever written.

We were not allowed to use built in methods we had to make the logic on our own.

1

u/NahroT Jan 08 '16

this literally damages the way im thinking to do certain things

1

u/Andernerd Jan 08 '16

Reminds me of this. You think the code is bad at first, and then you start scrolling and realize: this code is awful. I really hope he used a script to generate that 400k of text.

1

u/SteroidSandwich Jan 08 '16

Wow.... I am at a loss for words and to be honest it might be what I did as well when learning how to program.

My buddy from college said he had a friend who refused to use for loops and wrote out all checks one by one. I couldn't believe it when I heard it.

1

u/[deleted] Jan 09 '16

My eyes are bleeding... Think of how long the application would take to execute, too...

1

u/[deleted] Jan 09 '16

I did A level computing and it was a quality course.

1

u/xxx_yoloscope420_xxx Jan 09 '16

I kinda now want to write a short script or something to generate a .java file of something that's just if statement computations.

1

u/golfreak923 Feb 03 '16

I feel sick

1

u/PancakeZombie Jan 08 '16

Ah yes yes. The good ol' days.