nim-lang / Nim

Nim is a statically typed compiled systems programming language. It combines successful concepts from mature languages like Python, Ada and Modula. Its design focuses on efficiency, expressiveness, and elegance (in that order of priority).
https://nim-lang.org
Other
16.55k stars 1.47k forks source link

Make compile and --run default parameters for nim #12248

Closed filipux closed 5 years ago

filipux commented 5 years ago

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.

alehander92 commented 5 years ago

notice that we have multiple backends

alehander92 commented 5 years ago

(otherwise it sounds good to me as well as a default action)

andreaferretti commented 5 years ago

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.

juancarlospaco commented 5 years ago
awr1 commented 5 years ago

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"

awr1 commented 5 years ago

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.

Araq commented 5 years ago

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.

Araq commented 5 years ago

How about we ship a simple script/program called nime (or similar) to do that?

SolitudeSF commented 5 years ago

For beginners every extra step like this can be a big hurdle.

how is typing c -r even an issue?

kaushalmodi commented 5 years ago

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).

See https://nim-lang.github.io/Nim/nims.

alehander92 commented 5 years ago

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!

filipux commented 5 years ago

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!