crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.46k stars 1.62k forks source link

Change `crystal init app` template to exclude "put your code inside module"? #6412

Open asterite opened 6 years ago

asterite commented 6 years ago

The default crystal init app foo template generates something like this:

require "./foo/*"

module Foo
  # TODO: put your code here
end

That's probably OK for a library, but for an app there's no need to put the main code inside the module. Well, you can do that, but it's not common, and then some people are confused by this (they might want to define methods inside the module and call them, but that doesn't work (you have to use def self.), or you might wonder why you have to put that code inside that module).

I propose we remove that module Foo declaration in that file for apps, and simply generate something like:

require "./foo/*"

# TODO: put your app code here
straight-shoota commented 6 years ago

I prefer to put app code in a module namespace as well, and only have a MyApp.run(ARGV) in the top level. This could also be provided by the template. But it doesn't really matter that much what the template produces, so I'm fine with this change.

jkthorne commented 6 years ago

The main project file now contains version after it was moved in Crystal#6317

This is what I get from a crystal init now

# TODO: Write documentation for `Foo`
module Foo
  VERSION = "0.1.0"

  # TODO: Put your code here
end

So the version constant has to go somewhere.

asterite commented 6 years ago

@wontruefree Yes, it can be this:

# TODO: Write documentation for `Foo`
module Foo
  VERSION = "0.1.0"
end

# TODO: Put your code here

Or simply:

# TODO: Put your code here

There's no need for a VERSION constant for an app... in fact, there's not even a need for a VERSION constant for a lib, not sure why we have that.

jkthorne commented 6 years ago

So I like what you are saying I would also say specs depend on the module sapce.

require "./spec_helper"

describe Foo do
  # TODO: Write tests

  it "works" do
    false.should eq(true)
  end
end

I like the idea of crystal init being very basic with flags to configure the setup. So the default generates shards, src, editorconfig, and gitignore. But you can build a project with flags for a test suite, shard dependencies, and CI.

crystal init app --test-suite=bacon --ci=travis