Fable: Extend rules for StringEnum

Created on 29 Jul 2016  ·  11Comments  ·  Source: fable-compiler/Fable

Consider the following:

 [<StringEnum>]
 type ItemAlignment =
 | [<CompiledName("flex-start")>] FlexStart
 | Center 
 | [<CompiledName("flex-end")>] FlexEnd
 | Strech

I think fable should generate these names with - automatically

feature revisit

Most helpful comment

Another option would be to specify the naming convention in the StringEnum attribute:

[<StringEnum(NamingConvention.SnakeCase)>]
type ItemAlignment =FlexStart | Center | FlexEnd | Strech

Though I wouldn't want to end up with the beauties of [<CompilationRepresentationAttribtue(CompilationRepresentationFlags.ModuleSuffix)>] :see_no_evil:

All 11 comments

I think like @forki, as in javascript people tend to use the snake case synthax.

And if we need to do it CamelCase we could used the CompiledName attribute.

It would be nice if a sigil or similar could be used rather than the longwinded attribute stuff.

I always try to keep a balance between expressiveness and cognitive load. CompiledName works like other cases and we shouldn't have to use it that often (especially if we add this rule).

Another option would be to specify the naming convention in the StringEnum attribute:

[<StringEnum(NamingConvention.SnakeCase)>]
type ItemAlignment =FlexStart | Center | FlexEnd | Strech

Though I wouldn't want to end up with the beauties of [<CompilationRepresentationAttribtue(CompilationRepresentationFlags.ModuleSuffix)>] :see_no_evil:

A bit more of work but I like that the translation rule is explicit in the code :+1:

Please make snake case the default ;-)

On Jul 29, 2016 16:46, "Alfonso Garcia-Caro" [email protected]
wrote:

A bit more of work but I like that the translation rule is explicit in the
code 👍


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/fsprojects/Fable/issues/302#issuecomment-236200331,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AADgNKdXJy-IjDU3RyJgjyAPNr8YOQKvks5qahJWgaJpZM4JYM49
.

I like being able to explicitly specify the NamingConvention, and I also like the idea of having one default naming convention. I do think that lisp-case should be the default for CSS stuff. But please don't use the name "snake case" for the hyphenated naming convention. Almost everywhere, snake_case means underscores, while lisp-case means hyphens. (It's also been called kebab-case and caterpillar-case, and there doesn't yet seem to be convention on what to call it -- but snake_case means underscores just about everywhere).

In case it isn't clear, I agree with @forki that the hyphenated-case should be the default for StringEnum. I'm only disagreeing with calling it "snake case". On the lisp-case vs. kebab-case vs. caterpillar-case, I have a slight preference for "lisp-case", due to my fondness for Clojure (which introduced me to functional programming), but I'd be happy with anything, and a bit of research does suggest that kebab-case is slightly more common than lisp-case as a name for the lowercase-with-hyphens style.

Thanks for the clarification @rmunn, I think you're absolutely right. I've also seen kebab-case more often so I guess to start we can add just two possibilities: NamingConvention.KebabCase and NamingConvention.None (meaning the case name will be used as is) and later add more if needed. If we don't want to break current bindings (though there're not that many) we should leave the argumentless constructor for StringEnumAttribute and then KebabCase should indeed be the default.

I suggest AsIs or Unchanged rather thanNone, so it doesn't look like an Option case. Other than that, :+1:.

Closing for now, will revisit.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

krauthaufen picture krauthaufen  ·  3Comments

alfonsogarciacaro picture alfonsogarciacaro  ·  3Comments

funlambda picture funlambda  ·  4Comments

ncave picture ncave  ·  3Comments

SirUppyPancakes picture SirUppyPancakes  ·  3Comments