Created
June 20, 2011 23:41
-
-
Save garindra/1036886 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Garindra Prahandono | |
#These are basic and most-used operations when I program. | |
##Super Simple If Boolean Statement | |
#Perl | |
if($awesome) | |
{ | |
dance(); | |
sleep(); | |
} | |
#Python | |
if awesome: | |
dance() | |
sleep() | |
#Comments : Look at the absence of braces and semicolons. Coming from C & PHP background, the first time I saw this I thought this was magic. | |
##Simple Loop | |
#Perl | |
for($i = 0; $i < 100; $i++) | |
{ | |
do_something($i); | |
do_another_thing($i); | |
} | |
#Python | |
for i in range(100): | |
do_something(i) | |
do_another_thing(i) | |
#Comments : I can't see why you need three different loop statements, braces, and semicolons just to run a simple loop... | |
## Multiple If Conditions | |
#Perl | |
if($seat != 'front_seat' && $today == 'friday') | |
{ | |
get_down(); | |
} | |
#Python | |
if seat not 'front_seat' and today is 'friday': | |
get_down() | |
#Comments : Wow. Look how much English is there. I like. | |
##If Within If Within If statements (IFCEPTION) | |
#Python | |
if condition_one: | |
do_first_thing() | |
if condition_two: | |
do_second_thing() | |
if condition_three: | |
do_third_thing() | |
#Comments : Simple and to-the-point. | |
#Perl | |
if($condition_one) | |
{ | |
do_first_thing(); | |
if($condition_two) | |
{ | |
do_second_thing(); | |
if($condition_three) | |
{ | |
do_third_thing(); | |
} | |
} | |
} | |
#Comments : Look at all of these closing brackets and semicolons I have to take care of! How is this not extraneous? | |
#It seemed natural to me when I didn't know Python yet, | |
#but now when I compare both of them, | |
#this is totally extraneous. | |
#Usually when your code gets too deep like this, it's best to refactor it anyway. | |
#But Python definitely makes it more bearable for me at times like this. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment