cap-js / ord

Open Resource Discovery (ORD) is a protocol that allows applications and services to self-describe their exposed resources and capabilities. This plugin enables generation of ORD document for CAP based applications.
Apache License 2.0
3 stars 3 forks source link

Variable name pattern #57

Open zongqichen opened 1 week ago

zongqichen commented 1 week ago

I notice there are some variables named with special pattern, e.g. fReadORDExtensions, aServices, aODMEntity, having prefix like f and a. I want to discuss that, where does this pattern coming from? Do we have chance to get rid of it? Or we have to use it because it meets the requirements of CAP framework?

I briefly look other repos under cap-js, such as cds-typer and cds-dbs, there is no such naming pattern. So I want to listen others opinion.

Fannon commented 1 week ago

I would be in favor of removing this "hungarian" notation. With an IDE and a compiler / language server, we already know what type a variable is. Adding types to variable names is therefore not needed and just adds noise, imho. I would therefore just go with the typical JavaScript conventions as most open source projects, which is variable names in lowerCaseCamelCase that express the meaning (not the technical type).

ductaily commented 1 week ago

Specifically fReadORDExtensions I would define functions using the function keyword. It is much more clear. If there is a reason why functions must be defined using const then it is a different story. But I am not aware of any. If anyone knows please correct me.

zongqichen commented 1 week ago

Specifically fReadORDExtensions I would define functions using the function keyword. It is much more clear. If there is a reason why functions must be defined using const then it is a different story. But I am not aware of any. If anyone knows please correct me.

I'm also confused about function creation in javascript, there are ways like statement, expression and arrow function. From my side, they are slightly different, but the purpose is same which is improving code readability and flexibility. Sometimes, expression and arrow functions are opposite, reduced the readability. I would propose that we use statement function as high priority but not strictly forbidden other ways to create function.

Fannon commented 1 week ago

https://dev.to/skinnypetethegiraffe/function-or-const-which-do-you-prefer-typescriptjavascript-apa

States it well. Reasons for going with function: