Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor for better cleanliness #6

Open
arrowtype opened this issue Nov 8, 2019 · 0 comments
Open

refactor for better cleanliness #6

arrowtype opened this issue Nov 8, 2019 · 0 comments

Comments

@arrowtype
Copy link
Owner

arrowtype commented Nov 8, 2019

Today, I was lucky enough to talk with Ned Batchelder about ways to improve the code quality in this script. Here are my notes from this, so I can refer to them later as I improve this script further.


Computational complexity

  • Linear vs quadratic, etc (how do more outputs increase time)

Are there big things you’re doing “wrong”? Not really.

One thing to improve: put functions at the start, then calls at the end

  • The “doing lines” could be moved into functions.
  • “Only using something once” isn’t a reason to not make a function. It creates a concept for someone reading the code

Classes

  • Become useful if you’re dealing with similar kinds of data alongside each other a lot
  • e.g. a list of fonts, plus a list of other things to go with the font
  • Another sign: many functions that take the same input. e.g. many functions that just take a font object
  • Another thing: repeated lines for “full name”
    • The class could define “fontName” once, and then the methods could just call self.fontName

Complexity in report:

  • each time you append to a string, you are actually creating a new string (because strings are immutable)
  • Opportunity for class: “report”
    • Could have a method “addLine”
    • Could be a list of strings
    • And at the save point, you just join the list with newlines

Opening fonts in a list

  • “Classic time-space tradeoff”
  • Opening fonts takes a bit of time – not the opening, but the reading

Python memory vs disk memory

  • Not really equal
  • 20gb of data might not fit into your 32gb system RAM
  • You can somewhat see the measurement of python in activity monitor

Is robofont giving you anything special?

  • Not really. You could make this a command line tool

conference talk to watch, by Ned: PyCon Computational Complexity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant