You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
// file: stdin.cpyprint"input 'q' to quit:";while(true){printf("> ");line=stdin.readline();line=line.strip().lower();if(line=='q'){print"bye.";break;}else{print'your input:',repr(line);}}
classes and functions
classA{publica=0;publicstatics=1;functioninit(a){this.a=a;print'A init',a;}functionf(a,b=1){returna+b;}}printA.s;// 1a=newA(1);// A init 1printa.f(1,2);// 3
Reusing Python codes
importtime;// Python's built-in time moduletime.sleep(1);
C-like vs Pythonic
Whitespace indentation to delimit block is bad
Python’s syntax is said to be clear and elegant. It is good for small piece of codes, but not good for more than 100 lines of codes. I usually mis-understand the number of indents when first glance at a more than 10 lines block of codes after an if.
And TAB vs SPACE is particularly annoying!
The curly braces are quit clear and elegant, most people feel comfortable at curly braces.
i++
i++ is very usefull.
"this" is that!
Python requires you to put an unnecessary “self” as the first argument of a function definition in a class, but to omit it when invoking that function. What’s the meaning of that? It’s total garbage.
Confusing expression of calling function in parent class
Couldn’t it be as simple as “parent.f()”? Why multi-inheritance?
Useless lambda expression
The lambda body can only be a single expression – useless! Ah-ha, now you are regret for discriminating curly braces, aren’t you? Look at the really ELEGANT syntax of JavaScript’s anonymous function.
Unwelcomed None/True/False
Just let those be: null, true, false. “i is None” is no more elegant than “i == null”.