from Hacker News

How to write X in both Python 3 and JavaScript

by chibicode on 9/14/18, 2:12 PM with 78 comments

  • by alyandon on 9/14/18, 3:21 PM

    Sort 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]
  • by ChrisSD on 9/14/18, 2:46 PM

    As 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.

  • by aninteger on 9/14/18, 2:44 PM

    How to write using X in both languages:

    Python: https://github.com/python-xlib/python-xlib

    Node.js: https://github.com/sidorares/node-x11

  • by marsrover on 9/14/18, 2:44 PM

    When I read the headline I was expecting the X windowing system. When I clicked the article and saw “junior programmer” I thought this is about to be impressive.

    Cool site :P

  • by fabiomaia on 9/14/18, 2:45 PM

    Very cool! Reminds me of http://youmightnotneedjquery.com/

    I particularly enjoyed seeing that you used snake case in Python and camel case in JavaScript. Great attention to detail.

  • by sayazamurai on 9/14/18, 2:16 PM

    Creator here! Let me know if you have any suggestions.
  • by mvilim on 9/14/18, 2:45 PM

    http://hyperpolyglot.org/ is a great website with a similar idea.
  • by ramses0 on 9/14/18, 3:17 PM

  • by thomasfedb on 9/14/18, 2:43 PM

    A weird reference imo. Perhaps useful to build as a learning experience but I wouldn't expect who needs if/else included in a cheat sheet to be ready to learn to languages.
  • by dkonieczek on 9/14/18, 5:07 PM

    Do people actually use cheat sheets like this? IMO, the first stackoverflow result in google is generally what I'm looking for and quicker - especially for common things and common languages such as the things on this page. Even if you have the page bookmarked, you still need to find/search/scroll for the specific thing you're looking for. Also, with Alfred you can google anything even quicker by not having to cmd+tab to the browser.
  • by feniv on 9/14/18, 5:05 PM

    Reminds me of this OneLang HN post from several months ago - https://news.ycombinator.com/item?id=16415051

    It's an IDE that lets you code simultaneously in several different languages https://ide.onelang.io/

  • by tobiasz-cudnik on 9/14/18, 6:37 PM

    Reminds me of PLEAC - Perl Cookbook translated to >10 langs http://pleac.sourceforge.net
  • by nayuki on 9/14/18, 8:11 PM

    When I publish code about algorithms and data structures to my web site, I usually offer multiple language versions. Why? Because understanding the computer science theory and math proofs is a big effort. Writing and debugging my first implementation in any language is a big effort. But porting that code to a bunch of languages is comparatively easy and is almost a thoughtless mechanical process.
  • by basilgohar on 9/14/18, 3:30 PM

    I thought this was going to be a polyglot[1] demonstration of writing code for X Windows. However, I was not disappointed in what I found!

    [1] https://en.wikipedia.org/wiki/Polyglot_(computing)

  • by anticensor on 9/14/18, 7:07 PM

    I expected a Python/JS polyglot :)
  • by Too on 9/15/18, 6:53 AM

    Impressive to see almost all JS examples being as short as the python ones. Python is normally valued for being short and concise but modern JS is really catching up here.
  • by aavotins on 9/14/18, 5:27 PM

    I had such high hopes when I opened the arsenal. I anticipated it would an article of how to write code that's both JavaScript and Python syntactically correct.
  • by another-cuppa on 9/14/18, 8:54 PM

    What's the point of having print or console.log around everything? Just have one box with "print to standard output" and those two at the top.
  • by sheikheddy on 9/14/18, 3:06 PM

    I love it! Reminds me of https://www.interviewbit.com
  • by ingen0s on 9/14/18, 2:49 PM

    Excellent educational tool - will be passing this around to colleagues who need it. Thanks!
  • by undershirt on 9/14/18, 5:12 PM

    this is very good. i had it in my head that there was no "extend" function in JS, and didn't realize "push(...array)" was possible. thank you for the super detailed guide
  • by tracker1 on 9/14/18, 10:01 PM

    FizzBuzz example isn't correct
  • by enitihas on 9/14/18, 3:02 PM

    I was expecting to see a leftpad comparison too :D