5 ms·
>What I ended up using heavily was REPL to file integration, which gave me the ability to write a function normally, evaluate it in the attached REPL session, a
by xkeysc0re 6y ago
>What I ended up using heavily was REPL to file integration, which gave me the ability to write a function normally, evaluate it in the attached REPL session, and then play around with it in the REPL. This is far short of the “REPL driven development” that’s commonly discussed, and frankly something that’s probably possible with the Python REPL if they wanted to.
I mean, yeah. You just import the Python module you're writing and you can call any function or inspect any object you want. iPython even has hot reload
- Folcon 6y agoI'm personally of the opinion that this isn't the same thing and I'm saying this as someone who wants to do this in python. Unless you've figured it out? In which case please say, because I want to code python like this. Specifically I write code in my editor, hit a keystroke and all the code at the cursor gets sent to my running python and evaluated. The editor needs to be aware of python's indenting rules so it can do this, but once again if you've worked out a nice way to do this please say. Minimal keystrokes required would be great =)... I'm not really requiring that the evaluated output gets sent to the editor, though of course that would be ideal, because in the worst case I can side-by-side the editor and the terminal. From my perspective jupyter notebooks get kind of close, but I'm not coding in a file, so it's not quite ideal.
- Izkata 6y ago> Specifically I write code in my editor, hit a keystroke and all the code at the cursor gets sent to my running python and evaluated. The editor needs to be aware of python's indenting rules so it can do this, but once again if you've worked out a nice way to do this please say. Minimal keystrokes required would be great =)... ...I call this "copy/paste". And since I use X clipboard and a tiled window manager, it's only a couple keystrokes and no mouse. Highlight the code in the editor, "super+<direction>" to switch windows, "shift+insert" to paste.
- Folcon 6y agoI don't quite agree, that might work for your specific workflow, but you can flub that sort of thing. There's a reason I'm specifying specific actions, I can easily see increasing the cognitive burden breaking the ease of that workflow. You can't tell me that putting your cursor to a code block and hitting a key is the same as selection, copy, swap to console, paste... I've certainly had situations where I've done what you're describing and then still taken the extra time to setup the workflow I've described above because it's worthwhile when you're trying to debug a knotty problem.
- mattmein 6y agoOne thing that has tripped me up with this workflow in the past is that you lose context - the code you copy/paste and execute in the repl is not evaluated in its module/namespace, so any other code calling it is not updated. Is there a shortcut to evaluate the code in the correct module/namespace for Python? Maybe to switch the namespace in which the Python REPL evaluates the code you paste in?
- hirple 6y agoorg-babel might work here. There are also repl keybindings in python mode in emacs.
- petemc_ 6y agoNot a keystroke and I'm probably being captain obvious, but I use pythons execfile for this.
- rdrey 6y agoVSCode's Interactive mode does this quite well. Docs: https://code.visualstudio.com/docs/python/jupyter-support-py https://code.visualstudio.com/docs/python/jupyter-support-py A short demo on YouTube: https://www.youtube.com/watch?v=lwN4-W1WR84 https://www.youtube.com/watch?v=lwN4-W1WR84
- kernelsanderz 6y agoI use a vim plugin called slimux to send code from vim into a REPL running in another tmux pane. It works really well. Here's the fork that I'm currently using https://github.com/grusky/slimux https://github.com/grusky/slimux I use it with python and node.is and MySQL and psql It's great because it can work with any REPL. I used to use jupyter notebooks but almost exclusively use slimux now unless I need to some data visualisation or computer vision. VS code's ipython REPL is quite good and has support for images and graphs. I will say that the main thing that triggered a REPL driven workflow was dealing with large state. When you do machine learning and you have to deal with large models and datasets, loading them each time you save your code and triggering a unit test really gets tedious. You can definitely do it with caching and reducing the dataset size, but it only gets you so far IMO. There's nothing like being to inspect the state of your environment. Particularly when it takes a long time to create that state.
- sfsys 6y agoI've been doing exactly this for a while now using Emacs built-in python mode and I think it's its quite nice. With just a few keystrokes I can send any part of the code I'm working on into a running python process and see the results in a separate repl buffer. The built-in python-mode already has a good selection of possible selections to send and I've written two extra ones working with indent levels dependent on where the cursor currently is. [1] It's nice to be able to, for example, run the if statement you're currently writing without running the while loop that if statement is in. One important thing to keep in mind though is that it is not as dynamic as Lisp, so things like re-evaluating a class definition does not update existing objects. I end up restarting the python process and evaluating the buffers I'm working on often enough that I've bound it to its own key. [1] https://pastebin.com/ctz5erD4 https://pastebin.com/ctz5erD4
- Folcon 6y agoThanks for the definitions =)... I've not used emacs for python, but could give it a spin for this! Bit unfortunate that you need to restart the process for re-evaluating classes though.
- sfsys 6y agoYeah. There are a quite few niggles like that. Even though you can get quite close by (automatically) sending code to the repl, Python is simply not set up for interactive development. It's one of the main reasons why I love Common Lisp so much. Still, it's not too bad and IMO a lot better then restarting the process on every single change