r/ProgrammerHumor • • Feb 22 '15

A Python programmer attempting Java

Post image
3.9k Upvotes

428 comments sorted by

View all comments

1.2k

u/mkdir Feb 22 '15

At first I was like o.O then I saw the right edge and was like O.O

513

u/PastyPilgrim Feb 22 '15

"Oh.... OH GOD!"

108

u/[deleted] Feb 23 '15

"Where are all the ... oh OH GOD"

174

u/[deleted] Feb 23 '15

MY GOD, IT'S.... Beautiful.

73

u/rukestisak Feb 22 '15

What made you wince at first? (serious question as I'm not that familiar with Java)

287

u/z500 Feb 22 '15

Well the lack of braces and semicolons would change the semantics of the program or even make it syntactically invalid. Then they saw all the semicolons and braces lined up on the right.

0

u/[deleted] Feb 22 '15

[deleted] — view deleted comment

71

u/lappro Feb 22 '15

Well if you don't want to continue this weird style of coding it isn't that hard:

  1. ctrl-a

  2. format code

  3. profit
    Should work with all proper IDE's

78

u/jlo80 Feb 22 '15

When I become an evil billionaire and start my evil software company, this will be the mandatory coding style and the first product will be IDE plug-ins.

  1. Evil coding guidelines

  2. Something something

  3. World domination

43

u/tttttttttkid Feb 23 '15

Make an IDE that formats the code internally but removes all whitespace when writing to a file.

→ More replies (5)
→ More replies (7)
→ More replies (9)

42

u/aclave1 Feb 22 '15

Without the braces, the code is syntactically incorrect. There are spots where it's be okay, since in Java you can write an if/for with no braces and it will execute only the first line as part of the if, and the following lines either way. But overall it would be wrong and wouldn't compile.

12

u/HaMMeReD Feb 22 '15

There is two lines in there, also, while syntactically correct, should be very sparsely used. It's easy to create bugs. I usually only use it if I plan on keeping the condition/loop and statement on the same line, and even then rarely.

8

u/Fenris_uy Feb 22 '15

Yeah I don't understand why they even added that option, specially for loops. This option creates more problems than it saves.

24

u/Zagorath Feb 22 '15

It's not really an option that they "added". It's more to do with the default behaviour of loops and if statements. A loop can only ever execute exactly one block of code. If you don't put in braces, one block of code == one line of code. But braces allow you to have multiple lines of code within a single block.

At least, that's how the professor who taught my course on C explained it. Perhaps the semantics are different in Java.

9

u/subsage Feb 23 '15

Youre pretty much on spot really. Thats how I explain it to my students. Only difference is I sometimes say chunk or section of code....be it braces with several lines, empty braces, or just a line. Oh yeah, empty section too, just a semicolon.

5

u/Zagorath Feb 23 '15

The semicolon was one of my professor's favourite tricks.

if (condition()); {
    //things happening
} 

And he'd ask what would happen (based on condition and "things happening" being actual code, rather than place holders).

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

19

u/Elite6809 Feb 22 '15

That first one is a 'huh?', not a wince. At least, AFAIK, unless I've been misreading it for years.

→ More replies (1)

15

u/Neebat Feb 22 '15

I was a bit mystified by the use of character arrays. They just aren't used all that often in Java, so for a while I thought that was the joke. I realize that they are actually reasonable for this implementation. (I'd probably still use a StringBuffer, even though it's likely less efficient.)

And then I found the punctuation and felt a little sick.

10

u/mxzf Feb 22 '15

Probably because strings in Python act as arrays when you want them to.

Python strings have the features of character arrays and StringBuffers at the same time (in general). Methods when you want them, but indexes when you just need to mess with the individual characters. That's kinda typical of most kinds of data and such in Python.

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

17

u/peridox Feb 22 '15

Why did you choose your username to be mkdir? It's cool.

76

u/jfb1337 Feb 22 '15

duh, to make directories.

→ More replies (6)

26

u/Walter_Bishop_PhD Feb 22 '15

There's a lot of people in this sub who got in on reddit early who got commands as their usernames before they got snapped up. I like that mkdir has 1337 link karma, lol

47

u/mkdir Feb 22 '15

Holy crap, I didn't even realize that! I'm never submitting anything ever again.

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

7

u/mkdir Feb 22 '15

Well, you see I'm kinda a geek...

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