Closed filipux closed 5 years ago
notice that we have multiple backends
(otherwise it sounds good to me as well as a default action)
I don't know, it may lead to beginners keep recompiling the same program over and over in order to execute it without realizing that an executable was generated.
This sounds like a potential security issue to me, honestly. Although I suppose in the grander scheme of things, we already have staticExec
, which makes compilation inherently "risky"
Also this would probably break tests and require a pretty hefty source change for what would be effectively a minor convenience; unless you're suggesting that nim c xyz.nim
not implicitly perform --run
, only nim xyz.nim
does.
I don't know, it may lead to beginners keep recompiling the same program over and over in order to execute it without realizing that an executable was generated.
We already cache it. Nothing is recompiled really when you do multiple nim c -r foo.nim
commands.
How about we ship a simple script/program called nime
(or similar) to do that?
For beginners every extra step like this can be a big hurdle.
how is typing c -r
even an issue?
How about we ship a simple script/program called nime (or similar) to do that?
Why not just add runc
, runcpp
, etc targets in a default config.nims
shipped by Nim? I do that in my config (ref).
@filipux You simply need to add these to your global config.nims
:
task runc, "Run equivalent of 'nim c -r ..'":
switch("run")
setCommand("c")
task runcpp, "Run equivalent of 'nim cpp -r ..'":
switch("run")
setCommand("cpp")
Then you can do nim runc foo.nim
or nim runcpp foo.nim
. You can name those NimScript tasks anyhow you like as long as they don't overlap with existing nim
subcommands (like c
, cpp
, etc).
I think the OP's point is misunderstood : runc
etc don't really help, as it's about new user expecations: many languages run files when you type lang <file>
Otherwise those commands are useful @kaushalmodi, i have to add them to my config!
I do believe a solution like this would make Nim more user-friendly for beginners, but it seems like it would go against the expectations of more experienced developers. I got the discussion I wanted from it so I'm closing this issue now. Thanks!
Problem
Today you always have to provide the c parameter to compile a nim file but that seems like an unnecessary step. You almost always want to compile. For beginners every extra step like this can be a big hurdle.
Proposed solution
I propose that running "nim mycode.nim" should compile the passed file and then run the built executable, i.e. making both c and --run default parameters for Nim. This would lower the bar for beginners and approach the usability of Node from the JavaScript world.