crystal-lang / crystal

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

`crystal init` should allow UPPERCASE project name #10542

Open tonytangio opened 3 years ago

tonytangio commented 3 years ago

Discussion

What aspect of the language would you like to see improved?

Currently the crystal compiler's crystal init command does not accept any UPPERCASE characters within the name, raising an error during its name validation.

I believe that this validation step should be removed. If required, the generated project name could still be explicitly outputted as all-lowercase.

What are the reasons?

While I can understand if this is to promote an all-lowercase project directory name convention (not that I could find if this is actually a convention as per the conventions section of the crystal-lang reference), I believe that not allowing a project name with UPPERCASE:

  1. Creates minor contradictions with some conventions (see below); and
  2. Just appears to be unnecessarily restrictive.

Include practical examples to illustrate your points.

Contradictions Currently Enforced Convention Expected
Type Naming crystal init app foobar module Foobar crystal init app FooBar module FooBar
Acronyms crystal init app acmebar module Acmebar crystal init app ACMEBar module ACMEBar

Optionally add one (or more) proposals to improve the current situation.

  1. Remove the line of lowercase validation.

  2. Update the crystal-lang reference conventions to specify what project structures should look like.

  3. Optionally, explicitly output project root directory name as all lowercase if still desired.

tonytangio commented 3 years ago

I dug a bit further to understand if this was explicitly intended and found that the commit which introduced this validation referenced the specification for a shard name.

This explains which convention/specification that the validation is trying to maintain, but I still believe that the validation should not be done at this point. To reiterate my original points, we want to allow for an arbitrary level of capitalisation for the generated module/spec names (of course, assuming the best about users' awareness of convention here), and enforce all-lowercase at the point when it's actually needed (naming the project root dir according to shard name specification).

straight-shoota commented 3 years ago

Yes, the reason for those name restrictions is to enforce compatibility with the shard specification to avoid any surprises with unexpected project names.

However, I agree that an automatic transformation from PascalCased name could be a good enhancement. Currently it works the other way around in View#module_name which transforms snake_case to PascalCase for the module name. This direction is lossy though, because there's no way to accurately transform to PascalCased acronyms.

That being said, it's also easy to just change the spelling to your liking manually after running crystal init.