views:

408

answers:

5

Hi,

  • Is there an "official" naming / casing convention for F#?

I'm always in doubt of using C# style or not:

Class.MyFunctionName or Module.my_function_name

In F# you're meant to mix BCL classes and F# library ones: they have different casing and the code looks very ugly.

Thanks

+1  A: 

From what I've seen from hubfs.com and other sources, its a mix from .net and OCaml.

I hope they switch to either one and not have two different conventions and being Microsoft i am sure they will go with the dot net style.

masfenix
+3  A: 

Anything official: I think "not quite yet", but whenever VS 2010 reaches Beta1 you'll probably see the F# library in its nearly-final form, and there will be a number of renamings relative to the CTP. F# will probably always be a little more schizophrenic than its older .NET cousins, given its history.

Brian
Hi Brian, what do you mean by "F# will probably always be a little more schizophrenic than its older .NET cousins, given its history"? Thanks.
Joan Venge
History: F# is derived from OCaml, and F# still retains a core that is very largely source-compatible with OCaml. But OCaml has different naming convention than .Net. So F# is pulled in two different directions.
Brian
A: 

Not sure there is any real solution. It seems that perhaps OCaml-ish code might retain some of its naming, i.e., lowercase module methods, whereas OO members will go .NET style.

MichaelGG
+1  A: 

My understanding and current usage is that module/static functions have lower case, and 'instance' functions have upper case.

Edit not an answer to this question, but related: F# Formatting conventions by Don Syme

Benjol
+3  A: 

Yes, there is confusion, because F# has morphed from OCaml to .Net over the years. Basically, the naming conventions are a "breaking change" - old code is inconsistent with new code.

However, the May 2009 CTP has settled the issue.

The Release Notes say...

Standard Library Naming Conventions

The naming conventions adopted for the F# library are as follows:

o All .NET and F# OO code uses PascalCase according to existing .NET guidelines

o The F# functional programming operators such as List.map are for use in F# internal implementation code. This kind of code uses camelCase for operator names

o Underscores should not be used.

So, your question...

Class.MyFunctionName or Module.my_function_name

The answer is

Class.MyFunctionName and Module.MyFunctionName

(applying rule 1 above).

There is still some confusion by comparision with the F# programming operators (eg. List.averageBy), but production F# code should use CamelCase, and thus look like everyone else's .Net code. If in doubt, check the sample code for the CTP.

(I personally like_the_caml_style, but I'll have to GetOverThat)

Javaman59
Update - in the latest release, the to_type functions have been dropped in favour of toType
Benjol
Thanks. To keep it simple, I removed the text which mentions them.
Javaman59