How to write X in both Python 3 and JavaScript
71–80 of 84 posts
Re: How to write X in both Python 3 and JavaScript
#72How to write using X in both languages: Python: https://github.com/python-xlib/python-xlib Node.js: https://github.com/sidorares/node-x11
Haha, I also expected this. Now I'm kind of glad you responded in kind because I'd seen python-xlib but not the node one. That sounds like a bit of fun and punishment at the same time.
Re: How to write X in both Python 3 and JavaScript
#73Re: How to write X in both Python 3 and JavaScript
#74Earlier quoted context omitted.
Nice list. Perhabs just personal preference but I'd use for(let element of someList){ console.log(element); } instead of someList.forEach(element => { console.log(element) }) for...of is easier to read and recognize as a loop construct at first glance, and as far as I recall it's also faster nowadays since the body of the loop is inline, whereas forEach requires the runtime to deal with a function object.
Makes me wonder if maybe the syntax for mapping, folding and other collection operations should have a similar syntax to for instead of the current method-style syntax popular in most modern languages.
Re: How to write X in both Python 3 and JavaScript
#75As someone who is often switching languages, I find these sorts of cheatsheets useful. I know all the syntax in them but I'll be damned if I can ever remember which language uses which until I've settled back in to things.
Re: How to write X in both Python 3 and JavaScript
#76Earlier quoted context omitted.
Shouldn't that be `a < b`?
No, the compare function needs to be able to indicate when two values are equal, not just when one is smaller/larger than the other. Otherwise your sort function will return inconsistent results for compare(a, b) and compare(b, a) when both values are equal.
someList.sort((a,b) => a => b)
Would be better, because it produces a stable sort?`a - b` produces the same results, so equally valid?
Re: How to write X in both Python 3 and JavaScript
#77Sort example doesn't take into account Javascript does lexicographical sorting? javascript: someList = [ 40, 2, 1, 3, 7, 99] someList.sort() Array(6) [ 1, 2, 3, 40, 7, 99 ] python: someList = [ 40, 2, 1, 3, 7, 99] sorted(someList) [1, 2, 3, 7, 40, 99]
Re: How to write X in both Python 3 and JavaScript
#78Sort example doesn't take into account Javascript does lexicographical sorting? javascript: someList = [ 40, 2, 1, 3, 7, 99] someList.sort() Array(6) [ 1, 2, 3, 40, 7, 99 ] python: someList = [ 40, 2, 1, 3, 7, 99] sorted(someList) [1, 2, 3, 7, 40, 99]
Re: How to write X in both Python 3 and JavaScript
#79Earlier quoted context omitted.
No, the compare function needs to be able to indicate when two values are equal, not just when one is smaller/larger than the other. Otherwise your sort function will return inconsistent results for compare(a, b) and compare(b, a) when both values are equal.
So someList.sort((a,b) => a => b) Would be better, because it produces a stable sort? `a - b` produces the same results, so equally valid?
let arr = [
{number: 2, name: 'a'},
{number: 1, name: 'b'},
{number: 1, name: 'c'},
]
Now assume we want to sort arr with a compare function, and our sort function expects the compare function to return a boolean, not an integer. let compare = (a,b) => a.number => b.number
compare(arr[0], arr[1]) //=> true, so the object named 'a' comes after 'b'
compare(arr[1], arr[2]) //=> true, so the object named 'b' comes after 'c'?
See the problem?Re: How to write X in both Python 3 and JavaScript
#80How to write using X in both languages: Python: https://github.com/python-xlib/python-xlib Node.js: https://github.com/sidorares/node-x11
A couple more native X11 client implementations: Common Lisp: https://github.com/sharplispers/clx Go: https://github.com/BurntSushi/xgb Any others? (Looking for implementations of the X11 protocol in $LANGUAGE, not bindings to the C Xlib)
Emacs Lisp: https://github.com/ch11ng/xelb