0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

プログラミングにおける命名規則について

Posted at

普段、C#, Java, Python等の言語を使用しますが、私の場合は命名規則は一般的にその言語に使用されているパターンにならっております。
ご参考までに。

クラスの宣言

  • C#:Upper Camel Case (例 : MyClass)
  • Java:Upper Camel Case (例 : MyClass)
  • Python:Upper Camel Case (例 : MyClass)

プロパティ、メソッドの宣言

  • C#:Upper Camel Case (例 : FruitName)
  • Java:Lower Camel Case (例 : fruitName)
  • Python:Snake Case (例 : fruit_name)

定数

  • C#:Screaming Snake Case (例 : NAME_ORANGE)
  • Java:Screaming Snake Case (例 : NAME_ORANGE)
  • Python:Screaming Snake Case (例 : NAME_ORANGE)

これだけでは分かりづらいので、実際のコードで実例をご紹介いたします。

C#の場合

public class MyClass
{
    public readonly string NAME_ORANGE = "みかん";
    public readonly string NAME_APPLE = "りんご";

    private string FruitName { get; set; }
    private int FruitPrice { get; set; }

    public MyClass(string name, int price)
    {
        FruitName = name;
        FruitPrice = price;

    }

    public int Plus(int up)
    {
        FruitPrice += up;
    }
}

Javaの場合

public class MyClass
{
    public readonly string NAME_ORANGE = "みかん";
    public readonly string NAME_APPLE = "りんご";

    private string fruitName { get; set; }
    private int fruitPrice { get; set; }

    public MyClass(string name, int price)
    {
        fruitName = name;
        fruitPrice = price;

    }

    public int plus(int up)
    {
        fruitPrice += up;
    }
}

Pythonの場合

class MyClass:
     
    NAME_ORANGE = "みかん"
    NAME_APPLE = "りんご"

    def __init__(self, name, price):
        self.fruit_name = name
        self.fruit_price = price

    def plus(self, up):
        self.fruit_price += up
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?