Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript - Use PascalCasing or camelCasing for module names?

I'm wondering if I should use PascalCasing or camelCasing for my modules names, so far I've always used PascalCasing, i.e: Ayolan.Engine.Rendering instead of Ayolan.engine.rendering (I keep PascalCasing for the container, since I want the global object name to be Ayolan and not ayolan).

I haven't found any headline on this, found that thread from 3 years ago but not really useful.

I'm wondering because I'm working with Java developpers and to them it makes more sense to use camelCasing, but that's not what I've seen so far with TS.

like image 549
Vadorequest Avatar asked Apr 13 '15 09:04

Vadorequest


People also ask

Does TypeScript use CamelCase?

In TypeScript & JavaScript, the camel case convention is used to signify that a token is a variable, function, method, parameter, or property.

Is snake case or camel case better?

Screaming snake case is used for variables. Scripting languages, as demonstrated in the Python style guide, recommend snake case in the instances where C-based languages use camel case.

What is the difference between camel case and Pascal case?

Camel case and Pascal case are similar. Both demand variables made from compound words and have the first letter of each appended word written with an uppercase letter. The difference is that Pascal case requires the first letter to be uppercase as well, while camel case does not.

What is Pascal case used for?

PascalCase is a naming convention in which the first letter of each word in a compound word is capitalized. Software developers often use PascalCase when writing source code to name functions, classes, and other objects. PascalCase is similar to camelCase, except the first letter in PascalCase is always capitalized.


1 Answers

In TypeScript, we use the same standards as JavaScript, because we are working with many JavaScript libraries (and potentially being consumed by JavaScript code too).

So we prefer PascalCase for modules and classes, with members being camelCase.

module ExampleModule {
    export class ExampleClass {
        public exampleProperty: string;

        public exampleMethod() {

        }
    }
}

The only other style rule I can think of is that constants are ALL_UPPER.

You will notice that this blends in nicely with the following code:

Math.ceil(Math.PI);

Most importantly of all - keep consistent with the style you use as the style can imply meaning, so if you aren't consistent it will cause confusion.

like image 122
Fenton Avatar answered Sep 28 '22 08:09

Fenton