generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Naming Variables and Functions correctly

Previous Thread :: Next Thread 
Quenty is not online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
28 Mar 2012 06:56 PM
What should I do to _correctly_ name my variables and functions. Should I do..

function AllowSomething(something)

or

function Allow_Something(Something)

or

function allowSomething(SOMETHING)

or

function allow_something(something)

And what should I name variables?

Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
28 Mar 2012 06:57 PM
It's a matter of preference. I personally use

allowSomething()
Report Abuse
jode6543 is not online. jode6543
Joined: 16 Jun 2009
Total Posts: 5363
28 Mar 2012 07:06 PM
I do allowSomething() too. But that is only cause that is what I first got used to, and am therefore tricked (by myself) into thinking its cleaner. Even though they are both clean, PascalCase and camelCase. Just never use underscores, please.
Report Abuse
LocalChum is not online. LocalChum
Joined: 04 Mar 2011
Total Posts: 6906
28 Mar 2012 07:07 PM
AllowSomething() is the last ugly of all of them.
Report Abuse
Varp is not online. Varp
Joined: 18 Nov 2009
Total Posts: 5333
28 Mar 2012 07:07 PM
Be consistent within a project (so, if you're collaborating, you should probably work that out).
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
28 Mar 2012 07:08 PM
For me, something easy to type that looks moderately good is better than something harder to type that looks a little better.
Report Abuse
Flurite is not online. Flurite
Joined: 03 Apr 2011
Total Posts: 5386
28 Mar 2012 07:15 PM
I've heard of this naming idea called "Hungarian Notation", but that's not commonly used in Lua.. I think..
Report Abuse
MrNicNac is not online. MrNicNac
Joined: 29 Aug 2008
Total Posts: 26567
28 Mar 2012 07:20 PM
This is one of the main points of Lua. You are free to do it any way you please, it being a dynamic language and all. That's why the interpreter isn't so strict - or else naming them would be as well.

Pointless to worry much about it, unless you're just confusing yourself with names.
Report Abuse
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
28 Mar 2012 07:20 PM
I personally use allow_something.

But they're ALL preference and ALL of those you suggested are equal.
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
28 Mar 2012 07:21 PM
Standard Lua variable naming includes functions PascalCased and variables camelCased.

However, I do everything in camelCase.
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
28 Mar 2012 07:23 PM
Seems like standard Lua has everything lowercase:

getmetatable

string.find()
Report Abuse
Varp is not online. Varp
Joined: 18 Nov 2009
Total Posts: 5333
28 Mar 2012 07:26 PM
"I've heard of this naming idea called "Hungarian Notation", but that's not commonly used in Lua.. I think.."

Nah, Hungarian notation is most useful in languages without the notion of types. (Lua is dynamically typed)
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
28 Mar 2012 07:26 PM
string={
find=function() end
match=function() end
}

Variables :D

I'm also not talking about built in function, but rather user written code.
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
28 Mar 2012 07:27 PM
I was only going to show the string.find example, but then I added the string.match example and forgot a semicolin.
Report Abuse
Flurite is not online. Flurite
Joined: 03 Apr 2011
Total Posts: 5386
28 Mar 2012 07:32 PM
@Varp,

Oh yeah, very true.
Report Abuse
MrgamesNwatch is not online. MrgamesNwatch
Joined: 02 Feb 2009
Total Posts: 7729
28 Mar 2012 07:34 PM
i usually stick with pascalCase with variables unless its a more powerful sounding variable like:
TotalAnnihilation = "MOTHER OF GOD..."
totalValue = 1337

and functions are usually PascalCase.


~I happen to speak fluent Pokémon.
Report Abuse
MrgamesNwatch is not online. MrgamesNwatch
Joined: 02 Feb 2009
Total Posts: 7729
28 Mar 2012 07:35 PM
uh woops. "i usually stick with pascalCase with variables" i meant camelCase.

~I happen to speak fluent Pokémon.
Report Abuse
Legend26 is not online. Legend26
Joined: 08 Sep 2008
Total Posts: 10586
28 Mar 2012 07:36 PM
I find that since typing a '_' character takes a bit longer than anything else, I'm loath to use it if I can help it. For me, it just depends on the language. If it's in C++ I go with allowSomething, but if it's Lua, I use AllowSomething.
Report Abuse
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
28 Mar 2012 08:01 PM
"Standard Lua variable naming includes functions PascalCased and variables camelCased."

There is no standard Lua variable naming.

The only standard thing is that Lua's libraries are written in luacase, AKA: completely lowercase, no distinction between words.

"I find that since typing a '_' character takes a bit longer than anything else"

Not when your fingers are used to doing it, which is my case.

As long as you're used to typing it, the difference will be almost void.

I spend 50 000 times more time thinking about variable names and structuring the code than how much time I spend typing underscores.
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
28 Mar 2012 08:11 PM
"There is no standard Lua variable naming."

Wrong wording there. Often *
Report Abuse
NecroBumpist is not online. NecroBumpist
Joined: 12 Sep 2010
Total Posts: 4198
28 Mar 2012 08:18 PM
"Nah, Hungarian notation is most useful in languages without the notion of types. (Lua is dynamically typed)"

Ehh, I see it being useful to some extent in languages without strict type declarations.
It could help prevent the occasional type error.

Anyway, the format I asspire to use nowadays:

AnythingToDoWithClassesUsesPascal

CONSTANTS_USE_CRUISE_CONTROL_FOR_COOL (wish I would finish a preprocessor to eliminate this, oh well)

everything_else_uses_as_someone_else_described_luacase
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
28 Mar 2012 08:25 PM
[ Content Deleted ]
Report Abuse
nightname is not online. nightname
Joined: 10 Jun 2008
Total Posts: 8960
28 Mar 2012 08:27 PM
I follow the same style in Java, as I do in Lua.

For an example:

function doThis()

end

WIDTH = 600; -- Constant variables are capital

etc,
etc.
Report Abuse
NecroBumpist is not online. NecroBumpist
Joined: 12 Sep 2010
Total Posts: 4198
28 Mar 2012 09:00 PM
@Oysi,
"but I got so bored holding the shift button all the time, "

What if I told you that
Just above the left shift key, there's a Caps Lock key.
Report Abuse
LPGhatguy is not online. LPGhatguy
Forum Moderator
Joined: 27 Jun 2008
Total Posts: 4725
28 Mar 2012 09:08 PM
My really top-level core constants I write like THIS. My record for the amount of these in a script was one; it was called "RELEASE" and was a flag to determine whether the script was running in online mode or not.
i.e.

local RELEASE = false --Default release setting.

My functions and methods are usually PascalCase, along with my variables.
i.e.

function HelloWorld()
print("yes")
end

local Upvalue
do
local Foo = "Bar"
Upvalue = string.reverse(Foo)
end

My function arguments are usually either PascalCase or camelCase.
i.e.

function HelloWorld(why)
end

function GoodbyeWorld(Yes)
end


I typically keep luacase for Lua built-in functions, so if I'm adding to those libraries, I'll use luacase, of course.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image