-
Notifications
You must be signed in to change notification settings - Fork 173
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
Derived type naming convention #225
Comments
I lean towards option 3. It may be redundant, but it helps not clutter up the namespace. It would also be consistent with what I would think would be a decent convention for using the |
I would lean towards _t for derived types, but I don't like _m for modules.
…On Sun, Jul 26, 2020, at 2:48 PM, Brad Richardson wrote:
I lean towards option 3. It may be redundant, but it helps not clutter
up the namespace. It would also be consistent with what I would think
would be a decent convention for using the `_m` suffix for modules and
the `_i` suffix for abstract interfaces. I think there will be too many
instances where coming up with a second word for the type would be very
awkward/unnatural.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#225 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAAFAWFEBAKDEJOQYTHSODLR5SJATANCNFSM4PIEYLMA>.
|
This is a big pet peeve of mine. Mangling type and module names with something like PS: So I'm definitely in the option 1 camp. |
I prefer 1 for the same reason as Neil. |
I'm now at a keyboard so I'll elaborate more why 1. First, I do appreciate not wanting to clutter the namespace and I've had the same dilemma. However, in what scenarios would you want to name the type instance the same as the type itself? The only ones that come to mind are toy examples in tutorials or types intended to be used as singletons. However, in real-world code this is not common. Why call a string instance Second, does the value of giving the user more freedom in naming variables outweigh the cost of the ugliness of I assumed that use stdlib_string, only: string_t => string
type(string_t) :: string I think it's okay to make an exception to the rule when justified. If an appendage to the type name is necessary, then I think |
I'm not opposed to 1, and you're right that it is noise. I just think it does at least occasionally lead to name clashes due to the design of the language. For example, in a library for dealing with the composition of matter, I invariably have a type However, I will grant that this is not likely to be the majority case, and probably not likely to be a frequent occurrence in stdlib. Also, for the very generic use case of stdlib types, I agree with @milancurcic point about variable names with the same name as the type being unlikely. So, in that case I would be fine with option 1, and not bother worrying about the two word requirement for types. I will note however, that for @milancurcic example, had it not been for the stdlib namespace, he would have demonstrated exactly my point about the module name. |
Most C++ codes seem to follow the Python convention of using CamelCase for class names, and lower_case for variable names:
https://google.github.io/styleguide/cppguide.html#General_Naming_Rules
I like that convention also, it's just that it only works for Fortran if you have at least two words.
Do people prefer to use all lowercase for derived type, or CamelCase?
…On Sun, Jul 26, 2020, at 9:05 PM, septcolor wrote:
FWIW, I use Option 3 above in all my codes, partly by following the
convention used in C++, e.g.
https://docs.microsoft.com/en-us/cpp/cpp/char-wchar-t-char16-t-char32-t?view=vs-2019
so personally it does not appear very awkward to use `_t` as derived
type names.
(I noticed some people prefer `xxx_type` or `xxxType`. This could be an
alternative,
but in my case, I use `xxx_type` as a variable name... (because `_t` is
already "reserved"
for type names and there is no worry for name collision.)
As for modules, I had used `_mod` initially, but more recently tend to
use `_m` for brevity
(and following the above `_t` pattern). But I agree that this
convention is not so "popular"
in other languages and also find some people do not like it very much.
As for interfaces, I am still wondering what is a nice suffix... I
tried `_if` or `_intf` etc, but
not very nice. I have never used `_i` up to now, but if used
consistently, it may be useful
for brevity (if one gets used to it).
I noticed plural forms are sometimes used as some library names (e.g.,
`XyzLists`), but
I usually avoid it for type names because I use plural names to
distinguish scalars and
arrays (e.g., `word` and `words(:)`).
Anyway, in a line similar to @everythingfunctional
<https://github.com/everythingfunctional> (in the first post), I think
it is useful
and practically convenient if the naming convention eliminates name
collision (with user
variables) as automatically as possible, so reducing the need to care
about such collisions.
(Personally, I think that it is a (historical) design flaw in Fortran
to be not able to
distinguish upper and lowercase names in symbols... (maybe due to old
punched cards?),
and so I need to use some systematic workaround throughout my codes.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#225 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAAFAWDNTRXYPFXYGCEAVJ3R5TVHVANCNFSM4PIEYLMA>.
|
Definitely not CamelCase! We want Fortran style, not C++ or Python. In our code we are using option 3, so this looks very familiar to me. But I think it is just a matter of taste. |
Although we are using camel-case in some of our projects, I won't recommend it for stdlib for several reasons:
|
I agree: if someone wants to use CamelCase or judicially located upper case
characters, then let them, but we should not make that a convention. It may
force us to be slightly more inventive wrt names, but that is a minor
drawback. Using underscores to separate parts of a name happens in a lot of
places - think of ISO_FORTRAN_ENV for instance and the kinds and other
entities it defines.
Op ma 27 jul. 2020 om 10:10 schreef Bálint Aradi <[email protected]>:
… Although we are using camel-case in some of our projects, I won't
recommend it for stdlib for several reasons:
-
The one derived type already in the language type(c_ptr) uses the
lower-case + underscore convention. (Are there any other derived types
inthe standard?)
-
Since we have a case-insensitive language, people will start to use
the type names differently without being notified by the compiler e.g.
type(OSError), type(OsError), type(OSerror). I think, the safest
convention to ensure consistent usage for a case-insensitive language is to
consistently write everything lower cased. (The temptation to use
type(OS_error) instead of type(os_error) is hopefully smaller.)
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#225 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN6YR3JLH6SGUFW4TTBC2LR5UY5VANCNFSM4PIEYLMA>
.
|
Even though I agree with @milancurcic that naming variables after their type is bad style ( Somehow related to the question of naming conventions for variables is the naming convention for modules. For class-like types, it could be meaningful to have a module that contains one type only (see e.g. https://github.com/MarDiehl/quaternions). Would the module name in that case be the name of the type/class with some variation? Examples
Alternatively (multiple types/classes in one module):
There is also the point that a |
I agree with @MarDiehl. Just sharing my experience and my trial and errors on this topic: This is the design that I settled with, in my personal projects after several years of try and improve: module string_mod
type :: string_type
end type
end module string_mod program main
use string_mod, only: string_type
type(string_type) :: string
end In practice, I have found that I use the variable from string import String
string = String() But this is (, perhaps, fortunately) impossible in Fortran. An alternative that comes to my mind for Fortran is, module string_mod
type :: string
end type
end module string_mod program main
use string_mod, only: string_type => string
type(string_type) :: string
end But this would be highly inferior to the former method of suffixing types with In my opinion, there is nothing wrong with being expressive and clear in naming conventions, for example in choosing Regarding the If you are interested to see how this naming convention looks and feels in practice, take a look at this example module here: https://github.com/cdslaborg/paramonte/blob/master/src/ParaMonte/String_mod.f90 cheers |
For whatever it's worth, I too prefer "_t" suffix for derived types in Fortran; "_m" for modules; and "_sm" for submodules. I disagree with @milancurcic 's comment earlier, "in real-world code this is not common. Why call a string instance string, a datetime instance datetime, or a bitfield instance bitfield"
The teams I work with and I have found it to be tremendously helpful and productive to name an instance of a 'foo' type as foo itself which is accomplished by the simple So much so that some teams have carried that forward (or one can say brought back since |
I think this is worth the most--this thread asks what each of us prefers. Yes, TDD leads to some real-world code, and Considering a stronger preference so far for a suffix to type names, does anybody object to the suffix being |
I would opt for the option 3 (i.e., '_t' or '_type' as suffix). I would even prefer them as prefix, as typing e.g., I am quite opposed against plural nouns. There are probably some cases where using a plural noun would make no sense, and these situations could lead confusions.
@milancurcic Would you still be worried if this convention is mentioned clearly in the docs? |
@milancurcic I agree with you that |
Yes, we'd document any convention in the docs and style guide and this helps for sure. I'm concerned more about what happens in the first 0.5 s or so when your eyes read |
As for me, I am in favor of Fortunately, for modules we do not need any suffixes, as the namespace-prefix makes it highly unlikely that module names do not collide with type names or variable names. So, I think, if at all, we should suffix type names only. |
I like |
We always use |
Regarding |
I used Module suffixes don't pertain to stdlib because we prefix modules with |
@milancurcic since the community's opinion on the matter of naming convention appears to be fragmented, do you think a poll could resolve this issue of naming? perhaps a poll with an extra question on the years of experience of the participant with Fortran, so that the answers could be weighted based on experience. |
@septcolor the language was case insensitive because early computers used only six bits to represent characters . With only 64 character codes, 10 code points for digits, about 10 code points for special characters, and a few code points for control codes there weren't enough code points available for both upper and lower case. @aradi in addition to |
To repeat already opinions:
|
I don't think experience years should count. We want to advocate new comers to the language on an equal footing (they are the inheriting use base!). :) |
FWIW I agree with @certik that with the |
Thank you @wclodius2 for this information. |
Just like with the indentation convention, let's simply document the most viable approaches here, so that people can choose from it. Let's not enforce any particular approach right now, as it is too early for multiple reasons: our community is very young, and we are still in early stages of developing Let's start with modules: the convention for Regarding derived types, the options are to append nothing, |
Yes, and I think we already have a decent poll in this thread--a separate poll could break the flow we have here. I don't agree with weighing votes by experience. I think everybody's input should count equally, newcomers and old-timers alike. |
FWIW in regards to type naming, I am now of the opinion that is the type name is long or otherwise inconvenient to be used as a variable name it should not have a suffix, but if likely to be used as a variable name it should have the _t suffix. |
Several PRs (#201, #221, #224) wishes to introduce derived types into stdlib. We need a name convention for them. The conventions I have met in Fortran code so far, are the following ones:
Singular noun, such as
type(os_error)
,type(bitfield)
. Pro: compatible with Fortrans naming convention (e.g.type(c_ptr)
). Con: You reserve a name, which would be also very natural for an instance variable, e.g.type(bitfield) :: bitfield
does not work.Plural noun, such as
type(os_errors)
andtype(bitfields)
as suggested for example in API for a bitset data type #221. Pro: You can give the corresponding singular name to the instance variable:type(bitfields) :: bitfield
. Con: All languages I know use singular for type/class names, so it may feel strange an unnatural for stdlib-newcomers.Singular noun with a
_t
suffix, such as:type(os_error_t)
,type(bitfield_t)
. Pro: You can use the noun without the suffix as instance variable, e.g.type(bitfield_t) :: bitfield
. Con: The extra_t
is redundant.I am tending towards option 1. with the additional restriction, that derived type should always contain at least two nouns (connected by underscores). Then, the corresponding variable instance name could be still exactly the same, but without the connecting underscore, e.g.
type(bit_field) :: bitfield
ortype(os_error) :: oserror
.Any opinions on this?
The text was updated successfully, but these errors were encountered: