3 ms·
Question by someone who never used interacted development before: How do you save the results of your work? How do you ensure the state of your program is what
by xg15 6y ago
Question by someone who never used interacted development before: How do you save the results of your work? How do you ensure the state of your program is what you think it is.
E.g.: Imagine you're in a breakloop as described in the article. You find that local variable X is 5 when it really should be 4, so you quickly set it to 4. You find function foo() is not defined, so you define it. You continue and your program works. Great!
At the end of the day, you quit your environment and shut down. How do you ensure your interactive work is not lost and the environment is still what you expect it to be when you start again the next day. How would you compile such a program?
Is there some command that dumps the whole environment to a file as source code? Would you save your REPL history? Would you manually copy/paste relevant bits to s code file?
Also, if significant parts of the source code are written inside the REPL, wouldn't the lack of modern IDE features be a hassle? No syntax highlighting, no code completion, no code inspections etc. Or are there tools that offer those?
- nlitened 6y agoThe way I do it with Clojure, you never really write any code in REPL prompt directly. You write it in your source code file, then send a piece of code to the REPL to update the “in-memory” state of your running program. So any modifications you make stay in your files, just like you would normally do with any other language. But you write your program while it’s running, and you grow/change it piece-by-piece, until it’s done (by that time, your source code is exactly your finished program). If you want to re-start your REPL session, you just run your current file in the REPL as a whole, and maybe run some “Rich comments” (from the same file) to set up a limited test environment (to isolate the piece of program you’re working on). This way, you make use of syntax highlighting and all the IDE features. Edit: I’ve re-read your example with breakloop — I don’t really have experience with this style of REPLing. I agree that it raises a lot of questions, but thankfully functional nature of Clojure discourages this kind of programming.
- Jtsummers 6y agoYou can edit the source file and send it to the listener. Suppose I'm in my REPL and I do this: > (foo 'bar) I get dropped into the debugger because foo doesn't exist. So I switch over to my .lisp file in another buffer and I type: (defun foo (symbol) (format t "Baz ~A~%" symbol)) ;; this will print "Baz BAR" in the example With the cursor anywhere within that function definition I type C-c C-c, go to the debugger and restart it. It works now. My source file and my Lisp image are both synchronized. In the case of changing a variable. Say I'm somewhere deep in some code and this tries to run: ;; in context x = 0 (/ y x) I'm dropped into the debugger. I know x was supposed to have a minimum of 1. I can do a couple things: 1. Examine the back trace in the debugger to see if I can locate where x got an incorrect value (maybe it was the line above, maybe 10 functions earlier). I make a note of what to fix, maybe I fix it now. 2. Change x to its proper minimum value and resume. If I was able to trace how x got a wrong value, it's fixed already. If not, I'll have to explore more. But I don't have to restart way earlier, I can just restart at this point (assuming nothing else was broken by x having the wrong value here) and still get the result of my program (assuming x being wrong didn't break a lot of other things). Or I can quit back to the REPL and start exploring the problem.
- proverbialbunny 6y agoIt depends what kind of environment you're using. Eg, notebooks like Jupyter are a kind of REPL environment, which is how data scientists typically write code. You prototype in a cell that is the source code that gets saved. If you've finalized the function or piece you're working on, you go to another cell. The reason data scientists do it this way is load times are gruesome for data science work. Sometimes it takes days to process something. Imagine every time you change a line of code having to wait days to see if there is a bug in code or what the output is. Instead we run it in an environment that loads it once and keeps it in ram (a REPL), so when working on code below what is already loaded there are no load times. There are other kinds of environments though. Sometimes video game devs develop on a REPL where the game is running, they pause it, update some code, and then go back into the game with the updates automatically put in. No load times.
- nsm 6y ago> At the end of the day, you quit your environment and shut down. How do you ensure your interactive work is not lost and the environment is still what you expect it to be when you start again the next day. How would you compile such a program? Modern Smalltalks have solved this problem. Smalltalk has the concept of Packages just like Java, and as you go along building your environment, even though you are modifying the Smalltalk image, you can export these packages to plain-text files, and put them in Git, just like any other language. The environment itself supports Git integration (called Iceberg in Pharo). > Also, if significant parts of the source code are written inside the REPL, wouldn't the lack of modern IDE features be a hassle? No syntax highlighting, no code completion, no code inspections etc. Or are there tools that offer those? The command-line REPLs that other languages have are NOT what you get in Smalltalk. I believe the author means the entire interactive environment, and the "style" of development is REPL, not the actual UI. The Smalltalk "IDE" is just as powerful as any other IDE, including code completion, automatic generation of certain getters/setters, renaming methods/classes, finding uses, jumping to declarations and even refactoring within methods. The difference between a normal IDE for Java is that this "IDE" is pervasively available, including in breakloops and the debugger. Since the system is live, there is no separate notion of debugging, the debugger is always there, and you can use all the editor IDE features when stopped in a debugger. You no longer have to deal with a crippled debugging environment way different from your authoring environment. It truly is mind-blowing! I highly recommend giving Pharo Smalltalk a spin (by following their MOOC or similar). This video is also worth a watch - https://www.youtube.com/watch/baxtyeFVn3w https://www.youtube.com/watch/baxtyeFVn3w I did most of this year's Advent Of Code in Smalltalk and saved it in Git just like any other language. Someone else can then import it into their image. https://github.com/nikhilm/AdventOfCode2020 https://github.com/nikhilm/AdventOfCode2020. Note that the source code looks very verbose, but you never actually interact with the source like that. The source is just a serialization. Your actual environment only ever shows you UI elements and entire IDE windows describing your classes and individual methods. The only thing I miss in Pharo is that it doesn't have Vim keybindings :) Apart from that there is a significant lack of OS integration and polish, but these are due to the small community and priorities than fundamental deficiencies.
- mikelevins 6y ago