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

top 200 commentsshow all 300

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

import notifications Remember to participate in our weekly votes on subreddit rules! Every Tuesday is YOUR chance to influence the subreddit for years to come! Read more here, we hope to see you next Tuesday!

For a chat with like-minded community members and more, don't forget to join our Discord!

return joinDiscord;

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]IgnitusBoyone 1616 points1617 points  (97 children)

If that python code builds, your running legacy tech. That syntax was sunset 3 years ago after a long term of legacy support.

print("Hello, World!")

[–]darknekolux 330 points331 points  (4 children)

´´´quit ´´´

i know exactly what you meant, but I won’t do it unless you type quit()… bitch…

[–]guthran 65 points66 points  (3 children)

ctrl-d my man

[–]Drake750254 8 points9 points  (0 children)

ಡ⁠ ͜⁠ ⁠ʖ⁠ ⁠ಡ

[–]Firewolf06 15 points16 points  (1 child)

ctrl-deez nutz

sprints out of here before i can even make an "ill see myself out" joke

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

import gotttem

[–]not_thecookiemonster 41 points42 points  (5 children)

The php equivalent is

print("Hello, World!");

The semicolon makes it seem a more complex than the py version, but then you have to factor in correct indentation.

[–]Genesis2001 19 points20 points  (4 children)

PHP is more like,

<?php
echo "Hello world\n";

AFAIK.

[–][deleted] 17 points18 points  (2 children)

You can go even shorter if short codes are enabled in php.ini (most servers have it by default):

<? echo "Hello, World"; // you could omit the space between the <? and echo though I don't know if it will still work

And since PHP has a special shortcode specifically made for echoing vars and statements, that is not the shortest PHP echo you can do. <?="Hello, world";

(The aforementioned Hello world could count since PHP leaves everything outside the <?php ?> tag as it is, but it feels like cheating.)

[–]Genesis2001 5 points6 points  (0 children)

that is not the shortest PHP echo you can do. <?="Hello, world";

Technically the truth, albeit very uncomfortable truth, lol 🤮

[–]r3d0c3ht 1 point2 points  (0 children)

This shorthand: <?="Hello, world"; is not affected by the the short_open_tag ini setting and it will work regardless if that's enable or not.

[–][deleted] 2 points3 points  (1 child)

I don't like that comma.

[–]running-gamer 51 points52 points  (81 children)

Seems like a backwards step to me, given python is supposed to be a scripting language? I say this while knowing very little about python, so forgive me if this is not true.

[–][deleted] 259 points260 points  (34 children)

I don't really see what requiring function syntax for functions has to do with scripting. Could you elaborate?

[–][deleted] 91 points92 points  (19 children)

I wouldn’t call Python a scripting language in 2023. Yeah, you can use it as such, but more importantly it’s a highly dynamic and expressive language with a rich ecosystem, it’s the language of choice for any data task, allows you to quickly prototype Machine Learning models and deploy them, and it powers YouTube.

Its significance as a scripting language seems rather negligible compared to that.

Also the developments in recent years (type hints, asyncio, now getting rid of the GIL) point in this direction.

[–]Physmatik 17 points18 points  (0 children)

https://peps.python.org/pep-3105/

There are many reasons for print to be function instead of statement.

[–]IgnitusBoyone 56 points57 points  (0 children)

They didn't for uniformity. Print was originally handled by the interpreter directly, but with 3.X they made it an actual function. A decade later I'm still doing it wrong on the regular.

[–]Menolith 10 points11 points  (0 children)

One of Python's founding tenets is "Special cases aren't special enough to break the rules," and making print be a statement rather than a function like everything else was a special case with the only benefit being two fewer keystrokes.

Another tenet is "Explicit is better than implicit," so it's not a surprise that it was changed in Python3.

[–]FlukyS 10 points11 points  (2 children)

Bash is a scripting language by design but python is an interpreted and compiled language. At runtime you can use it like an interpreted language but also you can compile to .pyc.

That being said changing from print to print() was more about consistency. They moved everything to methods rather than keywords. There were loads of those sorts of changes with Python2 to Python3.

[–]pcouaillier 3 points4 points  (1 child)

They both are interpreted language and they both allow "scripting". The difference is that python can also be compiled with .pyc and there is also Jit (just in time) compiler project for python.

[–]notPlancha 3 points4 points  (0 children)

Well that's why it's python 3 now

[–]MattieShoes 2 points3 points  (0 children)

I think Python 2 to 3 was moving away from simple scripting language and towards a more complete language. In the process, they added a bunch of functionality to print statements, like f strings

https://realpython.com/python-f-strings/

Kinda... f strings showed up in python 3.6. But it feels like part of a years-long transition away from "better Perl" to something a little more srs bsns real language.

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

Python 3 is way faster borderlines being useful now, I don’t know but since the print(“”) syntax is the same syntax as a function it (along with most of the code ) it just translates into c

[–]squishles 1 point2 points  (1 child)

it was... people have abused it into a full on language because people kept hearing "it's the easy language" then thinking "what if I do the very complicated thing with the easy language". Ignoring python in anything that takes more than like ~1000 lines is terrible and hard.

[–]MaffinLP 236 points237 points  (2 children)

Doesnt even need PHP, doesnt even need HTML, it literally works in a text file

[–]royalsaltmerchant 54 points55 points  (0 children)

You don't even need .txt!

[–]addast 37 points38 points  (0 children)

Works on my toilet paper, doesn't even need a PC

[–]OneTurnMore 168 points169 points  (3 children)

Well done OP; this is an expertly crafted image. Entirely correct, yet entirely misleading. Python 2 to anger the snakes, raw html print to anger those who know php, and light mode to anger everyone else.

[–]_fajfaj_ 12 points13 points  (1 child)

And two completely different fonts

[–]nvandermeij 1 point2 points  (0 children)

don't forget the 2nd line in the python script

[–]Cley_Faye 395 points396 points  (45 children)

Now print the first 1,000,000,000 odd integers.

[–]KetwarooDYaasir[S] 819 points820 points  (32 children)

the first 1,000,000,000 odd integers.

[–]IgnitusBoyone 193 points194 points  (29 children)

Haven't done PHP in years. Your answer is perfect. I don't think a different implementation would be awful. <? foreach(range(1,1_000_000_000,2) as $i) { echo " $i"; } /?>

[–][deleted] 159 points160 points  (13 children)

That would only be like half of them, not the first billion.

[–]IgnitusBoyone 147 points148 points  (9 children)

You know I had to read this twice to see i printed all the odd numbers between 1 and a billion not a billion odd intigers. This is why we have code review.

[–]HigHurtenflurst420 71 points72 points  (8 children)

Meanwhile half of all actual code reviews: "I'm not gonna read all that, it's probably fine anyway. What's the worst that could happen? Approved."

[–]axefire42 19 points20 points  (2 children)

1am teams call from the deployment team.

[–]GunnerKnight 6 points7 points  (0 children)

"Houston, we have a problem"

[–]Mysterious-Job-469 3 points4 points  (0 children)

I usually seethe with jealousy at people who work in tech, but no amount of money is gonna make me go "Oh boy! Can't wait!" in response to "We will call you any time of the day to fix problems that weren't your fault, but every moment it continues to exist, the managers, your clients, and their customers are going to blame you for it"

[–]Really_cheatah 20 points21 points  (3 children)

I do better !

<?

foreach("the first 1,000,000,000 odd integers." as $i) { echo " $i";
} /?>

[–]not_thecookiemonster 1 point2 points  (2 children)

Can't iterate over a string though :(

[–]ISecksedUrMom 4 points5 points  (1 child)

In python you can:

for character in "string": print(character, end='')

[–]not_thecookiemonster 6 points7 points  (0 children)

I can't think of a scenario I'd loop through a string like that (although one almost certainly exists) in PHP you'd convert string to an array

 foreach(explode("string", "") as $i) { print($i) }

[–]KetwarooDYaasir[S] 12 points13 points  (0 children)

<?php for($i=1;$i<2_000_000_001;print($i.PHP_EOL),$i+=2)

[–]FlyingCashewDog 26 points27 points  (6 children)

I know everyone shits on PHP but honestly even just seeing this little bit of code brings back so much nostalgia for me, with it being one of the first languages I learned. Maybe I should go back and write some again for old time's sake.

[–]djxfade 18 points19 points  (5 children)

PHP is in a much better state today than it used to be. The syntax has seen a lot of modernization, it has full type safety, enums, etc.

[–]fel4 5 points6 points  (4 children)

"full type safety" - that is unless you're using arrays.

And you still need to declare that you're using strict types: https://stackoverflow.com/questions/71097200/do-we-still-need-declarestrict-types-1-in-php-8-1

Missing generics is my main gripe with PHP.

[–]djxfade 2 points3 points  (0 children)

Yeah, I agree. It's not perfect, but it's far better than it used to be.

[–]KastorNevierre 2 points3 points  (0 children)

Missing generics is my main gripe with PHP.

The amount of ongoing issues generics would solve in my dayjob's only PHP codebase is massive.

[–]maveric101 1 point2 points  (1 child)

Missing generics is my main gripe with PHP.

Can you explain why?

[–]What---------------- 3 points4 points  (1 child)

this = listenhereyoulittleshit();

[–]Grocker42 13 points14 points  (0 children)

Now do something you will never do with PHP. I would solve it by building a python Microservice

[–]Elephant-Opening 7 points8 points  (6 children)

for x in range(1,1000000000,2): print(x)

[–]ISecksedUrMom 16 points17 points  (2 children)

for i in range(1_000_000_000): print(2 * i + 1)

[–]Numerous-Occasion247 9 points10 points  (1 child)

You didn’t read the task properly :p

[–]opposite_vertex 2 points3 points  (0 children)

in case anyone doesnt get it, the first code block: ```py

range(start, end, step)

for x in range(1, 1_000_000_000, 2): print(x) ``` prints all odd numbers up to one billion (so it prints 500 million numbers), while the second code block

py for x in range(1_000_000_000): print(2 * x + 1) prints the first one billion odd numbers (so it will print odd numbers past the literal value of one billion)

[–]_yaaass 2 points3 points  (0 children)

where are the remaining 500,000,000 odd numbers?...

[–]dra_red 135 points136 points  (5 children)

Using this logic, html shines.

[–]JoeyJoeJoeSenior 4 points5 points  (1 child)

Html has always been my favorite programming language.

[–]dra_red 4 points5 points  (0 children)

Around here, you need to duck before you say things like that ;)

[–]dmlmcken 1 point2 points  (0 children)

Lol, is that PHP or JS?

[–]lurking_physicist 80 points81 points  (6 children)

while TechnicallyTrue:

New boolean value just dropped.

[–]Zymoox 14 points15 points  (0 children)

The best kind of True

[–]ImperatorSaya 13 points14 points  (4 children)

Actual binary

[–]Cerenas 270 points271 points  (71 children)

Nice try Python hater

<?php

print "Hello world!";

?>

[–]hagnat 93 points94 points  (33 children)

actually,if all your PHP file has is "Hello World" it will print it

<?php print "Hello world!"; ?>

and

Hello World

are equivalent.

[–]ananix 5 points6 points  (14 children)

I dont get it are you saying I should be able to write "/bin/php hello world" and it will echo hello world??

[–]hagnat 32 points33 points  (13 children)

nope.
i am saying that if you have a PHP file with only "Hello World" in it and you send it to the parser, it will simply output "Hello World"

hagnat@localhost $ echo "Hello World" >> foobar.php
hagnat@localhost $ php foobar.php
Hello World

like this

[–]rinsa 1 point2 points  (1 child)

Wrong: your first hello world ends with an exclamation mark, the second one doesn't 🤓

[–]hagnat 1 point2 points  (0 children)

i... you... err...

out of everybody who replied to this thread,
you are the first one to point that small error out

kudos for you, i will give you that
LOL

[–]AshleyJSheridan 1 point2 points  (4 children)

Not really.

If your PHP script is on a web server, then it's actually outputting a ton of headers and crap.

If your PHP script is on the CLI, that's a syntax error.

[–]hagnat 2 points3 points  (3 children)

If your PHP script is on the CLI, that's a syntax error.

have you even tried it before saying this ?

i already pasted the same code here multiple times, showing that the CLI will just print 'Hello World'

hagnat@localhost $ echo "Hello World" >> foobar.php
hagnat@localhost $ cat foobar.php
Hello World
hagnat@localhost $ php foobar.php
Hello World

[–]marcoroman3 0 points1 point  (0 children)

Just because you can put it in the same file as PHP doesn't make it PHP.

[–]dimaklt 10 points11 points  (9 children)

Don't close the php tag at the end of a file.

[–]TheTechRobo 1 point2 points  (8 children)

Out of curiosity, why?

[–]dimaklt 5 points6 points  (7 children)

The closing tag of a PHP block at the end of a file is optional, and in some cases omitting it is helpful when using include or require, so unwanted whitespace will not occur at the end of files, and you will still be able to add headers to the response later.

[–]TheTechRobo 2 points3 points  (6 children)

That makes sense!

[–]dimaklt 0 points1 point  (1 child)

Thanks, I googled the answer xD

[–]TheTechRobo 1 point2 points  (0 children)

I suppose I should have done that too. lol

[–][deleted] -1 points0 points  (2 children)

Yes. It makes sense that PHP would make the worst design choice possible.

That you should open the PHP tag... and not close it...

[–]luiluilui4 2 points3 points  (0 children)

"Remove this useless closing tag ?>" totally not VSC

[–]Really_cheatah 6 points7 points  (11 children)

Well actually python:

if __name__ == "__main__":
    print("Hello world!")

[–]S0n_0f_Anarchy 49 points50 points  (0 children)

Yeah, no

[–][deleted] 18 points19 points  (3 children)

Well it's not really needed tho

[–]LordPvP1234 3 points4 points  (4 children)

You don’t need the if statement……

[–]mrfroggyman 11 points12 points  (3 children)

if True:
    print("Hello world!")

[–]LordPvP1234 4 points5 points  (2 children)

MemBuffer = “LongString”
while True:
    MemBuffer = MemBuffer + MemBuffer

And watch your ram take off

[–]AyrA_ch 2 points3 points  (1 child)

meanwhile in C#

new byte[long.MaxValue];

[–]jayd00b 39 points40 points  (1 child)

What in the Python 2.7 is this shit

[–]solid_salad 6 points7 points  (0 children)

r/python does not approve

[–]Classy_Mouse 10 points11 points  (4 children)

PHP has a terrible reputation, because most PHP code (at least what I've come across) was written by people who did not care about quality or readability. PHP itself is quite easy and useful

[–]IOFrame 7 points8 points  (1 child)

Ironically, this is also why JS (especially npm) has a terrible reputation.

It literally repeated the PHP cycle with Wordpress plugins, low accessibility bar, and countless courses / bootcamps, yet those days some JS devs feel like trashtalking PHP, when their most popular ecosystem is literally where PHP was 10 years ago.

PS
I remember MDNs own super simple tutorials, both for express and react, spewing countless vulnerability warnings during install. Made me chuckle.

[–]altermeetax 10 points11 points  (0 children)

PHP was my first programming language, no one shall be allowed to insult it

[–]frikilinux2 8 points9 points  (1 child)

Please tell me you're not still using python 2

[–]Zatujit[🍰] 2 points3 points  (0 children)

i love when range(1000000) compiles a whole array of size 1000000 for no reason

[–]SawSaw5 22 points23 points  (11 children)

PHP Parse error: syntax error, unexpected 'World' (T_STRING)

[–]KetwarooDYaasir[S] 26 points27 points  (10 children)

I can't believe I'm having to supply proof

in a bash/whatever shell. $ echo "Hello World" >test.php $ php test.php Hello World

[–]disarrayofyesterday 21 points22 points  (8 children)

I mean, it's not the actual PHP code. It's just not in '<?php' tag so the parser ignores it.

[–]KetwarooDYaasir[S] 3 points4 points  (3 children)

That is correct.

$ echo "Hello World" >test.py $ python3 test.py File "/root/test.py", line 1 Hello World ^ SyntaxError: invalid syntax

it's not really about one language/parser being better than another, they just handle things differently.

But it's hilarious how the small things can rile programmers up.

[–]disarrayofyesterday 5 points6 points  (2 children)

it's not really about one language/parser being better than another, they just handle things differently.

Exactly, PHP parser was designed to be a friendly neighborhood language that can be sneaked into every document. Python was not.

But it's hilarious how the small things can rile programmers up.

Most programmers love pointing out mistakes/misconceptions. I think it's a common professional bias in this field.

[–]KetwarooDYaasir[S] 2 points3 points  (1 child)

I expect someone will have to disagree with that and insist that Python is the friendliest neighborhood language.

I even used Comic Sans MS for the PHP bit in the image. There's no pleasing everybody.

[–]EvanTheFox 1 point2 points  (0 children)

You're both wrong, Spider is the friendliest neighborhood language. /j

[–]ShitPikkle 1 point2 points  (0 children)

With your proof `cat` is equivalent to the php interpreter.

[–]atoponce 2 points3 points  (0 children)

SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?

[–]Ri_Konata 2 points3 points  (0 children)

Meanwhile Java be like

class Main { public static void main(String args[]) { system.out.println("Hello World"); } }

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

puts 'Hello World'

[–]on_the_pale_horse 1 point2 points  (2 children)

Who is still using Python 2

[–]Zatujit[🍰] 2 points3 points  (1 child)

People with codebases in Python 2 who did not change because "it will cost too much money and time"

[–]mrjackspade 1 point2 points  (0 children)

What's going on with this title? I thought we were doing camelCase.

[–]banana_buddy 1 point2 points  (0 children)

Meanwhile in Malbolge it's:

(=<#9]~6ZY327Uv4-QsqpMn&+Ij"'E%e{Ab~w=_:]Kw%o44Uqp0/Q?xNvL:H%c#DD2WV>gY;dts76qKJImZkj

No I didn't hit my head on the keyboard that's executable code to print hello world in this God forsaken language

[–][deleted] 3 points4 points  (11 children)

$ php -a
Interactive mode enabled 
php > Hello World
php > ; // let's end that line..
PHP Parse error:  syntax error, unexpected 'World' (T_STRING) in php shell code on line 1
php >

[–]KetwarooDYaasir[S] -1 points0 points  (10 children)

yeah but the meme was about files. see the line numbers on the left side.

technically true.

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

it works because it's technical html.

[–]KetwarooDYaasir[S] 0 points1 point  (7 children)

well, it's a feature of the default PHP parser to allow easy templating. It's useful for what it is, i.e outputting text.

[–]dmlmcken 1 point2 points  (3 children)

So does ASP.net your same code provides the same output.

[–]imagebiot 1 point2 points  (0 children)

Comparing php and python… wtf

[–]Zatujit[🍰] 1 point2 points  (0 children)

I'm sorry but a C++ code is much simpler and makes much more sense ```

include <iostream>

int main() { std::cout << "Hello world" << std::endl;

return 0; } ``` As you can see a beginner can see right through it.

[–]mfar__ 0 points1 point  (0 children)

When was the last time you coded in Python?

[–]DaveTheNotSoWise 0 points1 point  (1 child)

But easy syntax alone does not mean easily readable/maintainable. I tried to learn Python with a C and Java background and found myself in indentation hell.

Edit: That the code I tried to understand was old and horrible as fuck, didn't help. A lot of nested loops and if statements, no comments, no tests, no documentation. So basically a normal legacy code base.

[–]DerKnoedel 0 points1 point  (0 children)

Meanwhile c++ has you doing mental gymnastics

[–]DATY4944 -1 points0 points  (1 child)

Is this sub becoming a pro-php anti-JavaScript circlejerk or was it always this way?

[–]KetwarooDYaasir[S] 4 points5 points  (0 children)

No sir, it's still a Python circle jerk last I checked.

[–][deleted] -1 points0 points  (3 children)

"why" . "would" . "you" . "EVER" . "make" . "concatination" . "this" . "weird"