Week 40/2017 - Python on Hacker News

PUBLISHED ON OCT 9, 2017 — PYTHON

The 5 most popular Python related submissions from 2017-10-02 to 2017-10-08.

  • Sieve of Eratosthenes in Python (2015)
    • The classic problem from math class solved and optimized in Python
    • I like the animation on the Wikipedia page
    • Comments
  • Livepython: Visually trace your Python code in real time
    • JavaScript/Electron/React based app that allows you to watch your Python code during (slowed down) execution
    • Very early in development (0.0.3)
    • Comments
  • Rubyist makes some Python code 5x Faster
    • Guy with 10 years of Ruby experience writes Python now
    • His tips are:
      • Don’t Repeat Your (logic): One of the most basic of optimizations is to not duplicate work.
      • Prefer Logic over Objects: In scripting languages object creation takes memory and CPU cycles. Lists and dicts are much more expensive to make than strings. Likewise integers are cheaper than strings.
      • Careful how you Serialize: How is that object being manipulated after it has been allocated? It is MUCH faster to pass in the decomposed values instead of a tuple.
      • Careful with literals in loops: Something like valid_moves = [] allocates a very expensive array. Just because a function doesn’t have a for or a while right above it, doesn’t mean that it’s not inside of a loop.
      • Don’t look, just leap: There is no code faster than “no code”. If you KNOW for a fact that a certain scenario can never happen, then you don’t need to check for it.
      • No Methods no Problem: Method calls (function calls in Python) are not free.
      • Bench your code: When it comes to any performance code you must ALWAYS benchmark. Before, and after and in-between.
      • Sometimes break all the rules: Sometimes more objects are better. We can trade CPU for memory by caching.
    • Using Numpy is probably still faster
    • Comments
  • Show HN: Weekly Python Exercise
    • Service that sends you a 30min Python exercise for $15 every Tuesday
    • Focus on developers who used Python less than one year
    • Comments
  • Using Python Flask framework to quickly create a REST based file server
    • For purely educational purposes I hope
    • With GraphQL becoming more and more popular it seems the days of the REST API are numbered anyways
    • Comments

All submissions via HN search.