I'm kind of confused what the use case of this would be.
So it's essentially saving you the trouble of having to put code into an "int main()" and putting declarations before it?
And then attempt to run the code after every line you type. Are there other examples of REPLs that work like this rather than all the state of execution being held in the REPL like I imagine Python does do it?
Can it Tab-complete identifiers I introduce in it? Actually, I suppose it's a single 115 LoC bash script, and I really don't mean to dunk on it, it's a neat little experiment. It just kinda made me wonder what REPLs are made for, for the first time. :D
Like I imagine a very basic "interactive" coding session (for any language) could also be achieved by having an editor open and saving after each line, or having that done automatically, and then in another terminal some script watches for those changes and compiles/interprets/runs it.
A REPL like python's is more like... having a debugger attached to your program, but it just sits at a breakpoint and let's you tell it what code to run next, and you can inspect variable contents and such.
Seems like languages that compile to machine code don't work all that well for REPLing, eh.
> like... having a debugger attached to your program
Maybe this answers your own question, it’s a great reason to use a REPL, and this is a good analogy.
One thing REPLs are good for is the ability to interactively work through syntax errors. Type a line, it has a problem, so just do it again. It doesn’t have to completely stop and start over like a compiler. Syntax errors are not a big deal for a small test file, but can be very annoying if you’re working in a big project with a big build system.
I’d say not having to save a file, not having to write the command line to compile it to another file, not having to write the command line to run it (while usually leads me to write a small makefile if I have to do it more than a few times), all in addition to not having to wrap the code in “int main()” all adds up to a nice convenient way to run small snippets of C/C++. It might be extra useful to optionally auto-include the most common headers, and perhaps offer some shortcuts for common things.
I test little snippets all the time like printing the bits in a floating point number, or checking the syntax for struct packing, or dumping a quick table of numbers run through a function, stuff like that. It’s a pretty common occurrence for me to want to run a small amount of C++ code without any workflow overhead.
I also use Python and JavaScript REPLs all the time too for quick tests, even though they also take files, and compile them.(!) All language compile to machine code, so I’m not sure I agree that has to do with how well a language works in a REPL. Python’s really not that great in a REPL, IMO: you can’t easily paste copied code into it because the indentation is usually wrong.
Julia compiles JIT to machine code, and I guess JS/TS and ruby too? All of those benefit from a repl for prototyping.
I think the biggest fail with most repls is the transition from the repl when you have that moment of "it worked" to having the working bits minus the stuff around it crammed into an idiomatic reusable thing. It is fairly easy in matlab, but I haven't found a workflow in Julia that does that well, tried dr. Doc strings, pluto, and vscode plugin. I'd welcome a rust repl too.
Developing the module functions with Revise.jl inside vscode and do REPL like things inside jupyterlab makes a pretty good workflow for me. And everytime I try some cpp REPL I end up using more Julia instead.
Its nothing earth shaking. I just type edit foo.m, select the lines from the history that worked and copy them to the new file, perhaps doing a quick namechange or two. It isn't anything a plugin could provide, and doctor doc strings tries to, but it is pretty clumsy, the name change refactoring thing isn't there, and more importantly, the idiomatic way to create a reusable module in julia is a lot heavier. I also run into issues of collisions between the new module and the lines I copied. I'm sure it is all resolvable, it just feels clunky out of the box after using it lightly for a year or so. I can use numpy the same way as matlab mostly, its just really slow. I haven't found a prototyping language other than matlab that I don't find myself thinking "might as well write it in rust as long as this is taking", as I know I'll end up doing that anyway.
what does Matlab provide wrt this? Does its editor have refactoring assistance now?
> the idiomatic way to create a reusable module in julia is a lot heavier
do you mean package creation?
> I also run into issues of collisions between the new module and the lines I copied.
what kind of collisions do you mean?
what would your ideal tool for this look like? you select parts of your REPL history, ask for some name changes in it, give it a package name, and have it generate a package? any other features or steps that come to mind as potentially helpful?
Matlab has some simple refactoring for names changes. Change a name and press shift+enter to change all other occurrences in the file.
Yes, package creation. The "right way" use create package.jl or whatever feels like a speedbump and requires setup.
When I import the newly created model, I have gotten name collisions with the playground remnants which you can't fully clear without restarting the repl.
That sounds like something I'd use, yeah. If you wanted to be fancy, you could make a function, putting uninitialized values into the argument list.
I guess the use case is to quickly try out some C/C++ code snippet. Typically I can think of checking binary arithmetic operations behavior.
Say you have some buffer that you need to align on 4K blocks, you could quickly try out your "& ~0x1000" in the REPL. It may not be a convincing example, but you get the gist, sometimes you just want to quickly see the result of some one liners.
I did what you described just yesterday. I couldn't remember offhand if the compiler I was using would automatically convert a uint8_t to an int (because I didn't want to have to add two levels of parentheses by explicitly casting the high byte and then shifting) and very quickly threw together a
// test if we need a<<8|b
// or (a<<8)|b
// or ((int)a<<8)|b
// or (((int)a)<<8)|b
#include <cstdio>
#include <cstdint>
int main() { uint8_t a = 2; uint8_t b = 38; printf("%d\n", a<<8|b); }
More than half of the time is the uninteresting parts: writing the includes, creating a temp file, exiting to compile, forgetting a parenthesis, reediting and resaving, compiling again, running, deleting...
In a REPL---particularly one with stdio/stdlib included by default---this would take 30 seconds but instead takes 3 or 4 minutes. It's not much, but tight feedback loops really, really keep you in a great mental state.
I'm gonna pick out one thing I'm always really curious about; what makes you trust a VPN provider more than an ISP? I've never quite understood this especially with how iffy and downright wrong VPN marketing (e.g. ad-reads on YT) can be.
- Why trust a VPN company more than your ISP? To me it seems like a commercial VPN could have equal or more incentive to do questionable things with your info.
- Is it somehow easier for an ISP to track my activity vs. a single VPN company whose servers I'd tunnel all my traffic through?
Sure, the ISP knows where I live and all that but it seems like a VPN could easily identify/know me to the same degree.
( - or is it like a self-hosted VPN sitting in the cloud, and would such a thing be practical/effective at all)
Obviously people have different reasons for using VPNs. But how I see it, between the ISP and a commercial VPN, which provider would you trust more with your internet activity?
The one with more PII data on you or the one with less? Noting that some VPNs even allow you to pay with Bitcoin.
My ISP knows where I live right to my doorstep. A VPN only knows roughly from which city I'm accessing the service from. And for mobile data, it is worse since the carrier I use has a copy of my govt issue ID (as mandated by law).
Between the two, do you trust the one whose core business is competitively providing privacy products? or .... the local private entity (some operating as a market monopoly) susceptible to government interference & anti-privacy laws .... and who basically answers to no one with regard to customer data/privacy?
Am sure all this PII data could be made to be used against you on a worst-case scenario basis but still...
I do have a self-hosted VPN tunnel that I use occasionally, but it's not as effective for privacy as a commercial VPN is if we put all device fingerprinting aside. And besides, the cloud provider still has my credit card so this route doesn't provide any greater privacy benefits than a VPN does.
I know you didn't write that poem, but I'm 99% certain the apostrophes in "I thought about my body. It's past. It's present." have no business being there :)
Might be intentional, simultaneously talking about the past and present of a body and also literally that it is past. It is present. It would not be weird to have that kind of wordplay in a poem.
But also this was from an early draft so it could be a mistake.
If I'm submitting a link, do I still get to add text here? I have to admit this is my first time submitting, and it's my own content.
I love finding interesting nerdy things and software/hardware deep-dives on HN.
A year ago I found Fabien Sanglard's post about Andrew Kensler's postcard pathtracer, and I was hooked. So I spent some weeks digging through the code further, and then set out to write about my findings.
Well, completing the series has taken me over a year. But I consider these four posts done now! So I just hope people will also find something of value within them.
PS: I also have a CUDA implementation going, but I only included a short video as a bonus at the end of post 3. I should get back on that. :)
So it's essentially saving you the trouble of having to put code into an "int main()" and putting declarations before it?
And then attempt to run the code after every line you type. Are there other examples of REPLs that work like this rather than all the state of execution being held in the REPL like I imagine Python does do it?
Can it Tab-complete identifiers I introduce in it? Actually, I suppose it's a single 115 LoC bash script, and I really don't mean to dunk on it, it's a neat little experiment. It just kinda made me wonder what REPLs are made for, for the first time. :D
Like I imagine a very basic "interactive" coding session (for any language) could also be achieved by having an editor open and saving after each line, or having that done automatically, and then in another terminal some script watches for those changes and compiles/interprets/runs it.
A REPL like python's is more like... having a debugger attached to your program, but it just sits at a breakpoint and let's you tell it what code to run next, and you can inspect variable contents and such.
Seems like languages that compile to machine code don't work all that well for REPLing, eh.