LoginSignup
0

More than 5 years have passed since last update.

false vs False 言語対決!

Last updated at Posted at 2018-06-07

備忘録の一種。

True,FalseといったBooleanな値を書くにはということの、言語差を感じた。

JavaScript

return_false.js
function return_false(){
    return false;
}

小文字のfalse、大文字Falseは未定義=変数代入できる、0と1はOK

Python(CPython 3.6)

return_false.py
def return_false():
    return False

こっちは逆で、大文字False、小文字falseは未定義=変数代入できる1

C

return_false.c
/* mainは省略 */
int return_false(void){
    return 0;
}

trueもTrueも通じない。

Ruby(追記 2018/07/07)

Rails開発を始めたので。
ruby:return_false.rb
def return_false
return false
end

小文字のfalseが通じる。FALSEは廃止だがRuby 2.5で使えた。
Falseはだめ。

結論

0と1が無難。

注釈


  1. Pythonの古いバージョンではTrueFalseも変数だった。 

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