IDE Tips for reading abstracted code
Sometimes you are reading model/tokenizers code that reuses some other model or tokenizers code, either through inheritance or composition, like:I usually (in Pycharm) just use cmd-b to jump to a function’s caller, but interested to know other people’s tricks!
2020-07-09T16:57:28Z
Goal: minimize cognitive burden when reading/tweaking python code.Hypothesis: Jumping to parent/helper fn definition is a start. Being able to read the implementation on hover is even better.PycharmPush Members DownWarning: This actually copies the implementation of methods to the child class.git checkout -b {code_reading}first orgit stashafter.Go to name of child class.Type meta-b to go to declaration of parent class.Right click → refactor → push members down. Check all the boxes that you want to read in your child’s file:820×645 84.9 KBResult:688×542 43.8 KB
2020-07-09T16:57:46Z
VSCode:Jump to parent, Peak References(jump to parent) In child’s signature, hover over parent. type f12 (or right click, to jump there.Then right click and select peak references to see child implementations in the same window with an overlay.1101×378 88.6 KB
2020-07-09T17:24:24Z
Thanks for the tips. Can you please also share for Vim?
2020-07-11T23:01:26Z
I am new to OOP , and beside I alwasys read Transformer source code directly from GitHub, so I am not 100% sure what’s going on hereI always go to the parent class straightforwardly too see the details(or maybe use GitHub search within Repo)But it’s great to see a pro trick here
2020-07-27T05:19:43Z
Surely, someone is working on a tool to expand the abstracted code into a flat code - obviously, controlling the level of expansion, i.e. expand functions only from a given list of libs/imports/projects.My other would-be-amazing-to-have-tool is a tool which records an execution path, like profilers do, and dumps just that code, removing any “branches” that didn’t get executed, so that it could be read and even executed. That would make understanding a complicated code a breeze. This would make debuging simple too in certain situations.I’m on emacs and there are quite a few different ways to jump around the code abstractions. I can share if there are emacs users here that need it.
2020-07-27T06:59:38Z
I’m a bit confused. Are you giving tips on how to write code or on how to read other code? Copying all methods into the child class seems redundant, so I assume that this is for making the code easier to read.As you say, I simply jump through the code in PyCharm (e.g. by ctrl+clicking a method name). After a while this may lead to a rabbit hole - but that in itselfmightbe a good sign that your code needs some refactoring and simplification.
2020-07-27T15:02:37Z
Yes, focused on reading!