CamelCasing a Constant: Acceptable Practice?
#9
Ruby is very dynamic even allowing idiocity like this:
Code:
def true.hello_world
  p "Hello World!"
end

def true.==(other)
  true
end

true.hello_world
p true == false

There can easily be situations where it makes sense to break the convention.
Lemme show you one percularity of using methods which starts with an upper case:
Code:
def Hello?
  p 'Hi'
end

def DIE!
  p 'dies'
end

def Happy(ans = true)
  p ans ? 'good for you' : "d'awww"
end

def SomeMethod
  p 'Yeah!'
end
  
Hello?
DIE!
Happy(true)
Happy(false)
self.SomeMethod
SomeMethod #=> NameError - uninitialized constant

I would heavily advice against having CamelCase methods unless they return a class since it would be the root of confusion.
I would call it a practice which in general leads to less managable code with higher chance of errors being present.

While your Math.PI method is useless if it stands alone it will make perfect sense if you could control the accuracy. I.e. how many decimals you want to get. Of course it won't really be a constant anymore, but conceptually keeping it as a constant may not be so bad an idea.
Thanks for mentioning the opportunities anyway. I may not have known them ^_^

*hugs*
Reply }


Messages In This Thread
CamelCasing a Constant: Acceptable Practice? - by Zeriab - 02-19-2010, 12:02 PM



Users browsing this thread: 1 Guest(s)