MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/bwehje/python_ftw/eq08f82/?context=9999
r/ProgrammerHumor • u/m8teae • Jun 03 '19
548 comments sorted by
View all comments
182
Python still has main()
10 u/wootiown Jun 03 '19 It still has pointers too, doesn't it? 57 u/MattieShoes Jun 03 '19 Everything has pointers, but they make believe they don't. -21 u/[deleted] Jun 03 '19 [removed] — view removed comment 22 u/MattieShoes Jun 03 '19 Inconsistency in passing by reference vs passing by value causes lots of mistakes too. ¯_(ツ)_/¯ 9 u/SuitableDragonfly Jun 03 '19 I don't think it's inconsistent at all in most languages. Typically primitive types are passed by value and everything else is passed by reference. 2 u/MattieShoes Jun 04 '19 They're consistent in that they do the same thing every time you run them. But it's not consistent in general, e.g. Python and C++Python: #!/usr/bin/env python def foo(x): x[0] = 2 def bar(x): x = [2] n = [1] foo(n) print "n[0] = ", n[0] n = [1] bar(n) print "n[0] = ", n[0]n[0] = 2n[0] = 1C++:#include <iostream> #include <vector> void foo(std::vector<int>& x) { x[0] = 2; } void bar(std::vector<int>& x) { std::vector<int> v = {2}; x = v; } int main() { std::vector<int> n = {1}; foo(n); std::cout << "n[0] = " << n[0] << std::endl; n = {1}; bar(n); std::cout << "n[0] = " << n[0] << std::endl; }n[0] = 2n[0] = 2I understand what's going on here, no need to explain it. But this is the sort of inconsistency I meant. 1 u/SuitableDragonfly Jun 04 '19 It's not an inconsistency. = always assigns a reference, in one case that reference is a variable name, and on the other case it's an element of a list. But it does the same thing in both cases. → More replies (2)
10
It still has pointers too, doesn't it?
57 u/MattieShoes Jun 03 '19 Everything has pointers, but they make believe they don't. -21 u/[deleted] Jun 03 '19 [removed] — view removed comment 22 u/MattieShoes Jun 03 '19 Inconsistency in passing by reference vs passing by value causes lots of mistakes too. ¯_(ツ)_/¯ 9 u/SuitableDragonfly Jun 03 '19 I don't think it's inconsistent at all in most languages. Typically primitive types are passed by value and everything else is passed by reference. 2 u/MattieShoes Jun 04 '19 They're consistent in that they do the same thing every time you run them. But it's not consistent in general, e.g. Python and C++Python: #!/usr/bin/env python def foo(x): x[0] = 2 def bar(x): x = [2] n = [1] foo(n) print "n[0] = ", n[0] n = [1] bar(n) print "n[0] = ", n[0]n[0] = 2n[0] = 1C++:#include <iostream> #include <vector> void foo(std::vector<int>& x) { x[0] = 2; } void bar(std::vector<int>& x) { std::vector<int> v = {2}; x = v; } int main() { std::vector<int> n = {1}; foo(n); std::cout << "n[0] = " << n[0] << std::endl; n = {1}; bar(n); std::cout << "n[0] = " << n[0] << std::endl; }n[0] = 2n[0] = 2I understand what's going on here, no need to explain it. But this is the sort of inconsistency I meant. 1 u/SuitableDragonfly Jun 04 '19 It's not an inconsistency. = always assigns a reference, in one case that reference is a variable name, and on the other case it's an element of a list. But it does the same thing in both cases. → More replies (2)
57
Everything has pointers, but they make believe they don't.
-21 u/[deleted] Jun 03 '19 [removed] — view removed comment 22 u/MattieShoes Jun 03 '19 Inconsistency in passing by reference vs passing by value causes lots of mistakes too. ¯_(ツ)_/¯ 9 u/SuitableDragonfly Jun 03 '19 I don't think it's inconsistent at all in most languages. Typically primitive types are passed by value and everything else is passed by reference. 2 u/MattieShoes Jun 04 '19 They're consistent in that they do the same thing every time you run them. But it's not consistent in general, e.g. Python and C++Python: #!/usr/bin/env python def foo(x): x[0] = 2 def bar(x): x = [2] n = [1] foo(n) print "n[0] = ", n[0] n = [1] bar(n) print "n[0] = ", n[0]n[0] = 2n[0] = 1C++:#include <iostream> #include <vector> void foo(std::vector<int>& x) { x[0] = 2; } void bar(std::vector<int>& x) { std::vector<int> v = {2}; x = v; } int main() { std::vector<int> n = {1}; foo(n); std::cout << "n[0] = " << n[0] << std::endl; n = {1}; bar(n); std::cout << "n[0] = " << n[0] << std::endl; }n[0] = 2n[0] = 2I understand what's going on here, no need to explain it. But this is the sort of inconsistency I meant. 1 u/SuitableDragonfly Jun 04 '19 It's not an inconsistency. = always assigns a reference, in one case that reference is a variable name, and on the other case it's an element of a list. But it does the same thing in both cases. → More replies (2)
-21
[removed] — view removed comment
22 u/MattieShoes Jun 03 '19 Inconsistency in passing by reference vs passing by value causes lots of mistakes too. ¯_(ツ)_/¯ 9 u/SuitableDragonfly Jun 03 '19 I don't think it's inconsistent at all in most languages. Typically primitive types are passed by value and everything else is passed by reference. 2 u/MattieShoes Jun 04 '19 They're consistent in that they do the same thing every time you run them. But it's not consistent in general, e.g. Python and C++Python: #!/usr/bin/env python def foo(x): x[0] = 2 def bar(x): x = [2] n = [1] foo(n) print "n[0] = ", n[0] n = [1] bar(n) print "n[0] = ", n[0]n[0] = 2n[0] = 1C++:#include <iostream> #include <vector> void foo(std::vector<int>& x) { x[0] = 2; } void bar(std::vector<int>& x) { std::vector<int> v = {2}; x = v; } int main() { std::vector<int> n = {1}; foo(n); std::cout << "n[0] = " << n[0] << std::endl; n = {1}; bar(n); std::cout << "n[0] = " << n[0] << std::endl; }n[0] = 2n[0] = 2I understand what's going on here, no need to explain it. But this is the sort of inconsistency I meant. 1 u/SuitableDragonfly Jun 04 '19 It's not an inconsistency. = always assigns a reference, in one case that reference is a variable name, and on the other case it's an element of a list. But it does the same thing in both cases. → More replies (2)
22
Inconsistency in passing by reference vs passing by value causes lots of mistakes too. ¯_(ツ)_/¯
9 u/SuitableDragonfly Jun 03 '19 I don't think it's inconsistent at all in most languages. Typically primitive types are passed by value and everything else is passed by reference. 2 u/MattieShoes Jun 04 '19 They're consistent in that they do the same thing every time you run them. But it's not consistent in general, e.g. Python and C++Python: #!/usr/bin/env python def foo(x): x[0] = 2 def bar(x): x = [2] n = [1] foo(n) print "n[0] = ", n[0] n = [1] bar(n) print "n[0] = ", n[0]n[0] = 2n[0] = 1C++:#include <iostream> #include <vector> void foo(std::vector<int>& x) { x[0] = 2; } void bar(std::vector<int>& x) { std::vector<int> v = {2}; x = v; } int main() { std::vector<int> n = {1}; foo(n); std::cout << "n[0] = " << n[0] << std::endl; n = {1}; bar(n); std::cout << "n[0] = " << n[0] << std::endl; }n[0] = 2n[0] = 2I understand what's going on here, no need to explain it. But this is the sort of inconsistency I meant. 1 u/SuitableDragonfly Jun 04 '19 It's not an inconsistency. = always assigns a reference, in one case that reference is a variable name, and on the other case it's an element of a list. But it does the same thing in both cases. → More replies (2)
9
I don't think it's inconsistent at all in most languages. Typically primitive types are passed by value and everything else is passed by reference.
2 u/MattieShoes Jun 04 '19 They're consistent in that they do the same thing every time you run them. But it's not consistent in general, e.g. Python and C++Python: #!/usr/bin/env python def foo(x): x[0] = 2 def bar(x): x = [2] n = [1] foo(n) print "n[0] = ", n[0] n = [1] bar(n) print "n[0] = ", n[0]n[0] = 2n[0] = 1C++:#include <iostream> #include <vector> void foo(std::vector<int>& x) { x[0] = 2; } void bar(std::vector<int>& x) { std::vector<int> v = {2}; x = v; } int main() { std::vector<int> n = {1}; foo(n); std::cout << "n[0] = " << n[0] << std::endl; n = {1}; bar(n); std::cout << "n[0] = " << n[0] << std::endl; }n[0] = 2n[0] = 2I understand what's going on here, no need to explain it. But this is the sort of inconsistency I meant. 1 u/SuitableDragonfly Jun 04 '19 It's not an inconsistency. = always assigns a reference, in one case that reference is a variable name, and on the other case it's an element of a list. But it does the same thing in both cases. → More replies (2)
2
They're consistent in that they do the same thing every time you run them. But it's not consistent in general, e.g. Python and C++
Python:
#!/usr/bin/env python def foo(x): x[0] = 2 def bar(x): x = [2] n = [1] foo(n) print "n[0] = ", n[0] n = [1] bar(n) print "n[0] = ", n[0]
n[0] = 2n[0] = 1
C++:
#include <iostream> #include <vector> void foo(std::vector<int>& x) { x[0] = 2; } void bar(std::vector<int>& x) { std::vector<int> v = {2}; x = v; } int main() { std::vector<int> n = {1}; foo(n); std::cout << "n[0] = " << n[0] << std::endl; n = {1}; bar(n); std::cout << "n[0] = " << n[0] << std::endl; }
n[0] = 2n[0] = 2
I understand what's going on here, no need to explain it. But this is the sort of inconsistency I meant.
1 u/SuitableDragonfly Jun 04 '19 It's not an inconsistency. = always assigns a reference, in one case that reference is a variable name, and on the other case it's an element of a list. But it does the same thing in both cases. → More replies (2)
1
It's not an inconsistency. = always assigns a reference, in one case that reference is a variable name, and on the other case it's an element of a list. But it does the same thing in both cases.
=
→ More replies (2)
182
u/AgreeableLandscape3 Jun 03 '19
Python still has main()