Skip to content

Instantly share code, notes, and snippets.

@datayja
Last active September 25, 2015 22:48
Show Gist options
  • Save datayja/997033 to your computer and use it in GitHub Desktop.
Save datayja/997033 to your computer and use it in GitHub Desktop.
C++ vs. Ruby
#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
5.times { puts "Hello!" }
#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
# 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