Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
asterite opened this issue Jul 20, 2018 · 4 comments
Open

Comments

@asterite
Copy link
Member

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
Copy link
Member

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
Copy link
Contributor

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
Copy link
Member Author

@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
Copy link
Contributor

jkthorne commented Jul 20, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants