Last active
September 25, 2015 22:48
-
-
Save datayja/997033 to your computer and use it in GitHub Desktop.
C++ vs. Ruby
This file contains hidden or 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
#ifdef __cplusplus | |
#include <iostream> | |
int main(int argc, const char **argv) { | |
for (unsigned int i = 0; i < 5; i++) { | |
std::cout << "Hello!" << std::endl; | |
} | |
} | |
#endif |
This file contains hidden or 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
5.times { puts "Hello!" } |
This file contains hidden or 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
#ifdef __cplusplus | |
#include <iostream> | |
#include <vector> | |
int main(int argc, const char **argv) { | |
std::vector<unsigned int> v; | |
v.push_back(1); | |
v.push_back(2); | |
v.push_back(3); | |
v.push_back(4); | |
v.push_back(5); | |
v.push_back(6); | |
v.push_back(7); | |
v.push_back(8); | |
v.push_back(9); | |
v.push_back(10); | |
typedef std::vector<unsigned int>::const_iterator iter; | |
iter it = v.begin(); | |
iter end = v.end(); | |
for ( ; it != end; ++it) { | |
std::cout << *it << std::endl; | |
} | |
} | |
#endif | |
// Just try to guess which language is more sexy. | |
// Well, yeah, I know, in C++ you could do it in less lines, but still not on a single one |
This file contains hidden or 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
# variant 1: | |
puts *1..10 | |
# variant 2: | |
p *1..10 | |
# variant 3 (more natural to programmers that came from other languages) | |
10.times { |i| puts i+1 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment