• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Raresh · Jun 11, 2016 at 07:31 PM · c#variablesnaming

Variable naming conventions, general + specific or specific + general

I am trying to figure out what is best in terms of naming conventions, as I seem to come across t$$anonymous$$s dilemma all too often. Should I start by naming variables starting with the general part or the specific part.

Example:

baseUnitsRegen; deltaUnitsRegen; timeDelayUnitsRegen;

or

unitsRegenBase; unitsRegenDelta; unitsRegenTimeDelay;

Both have pros and cons in my mind, as the first example will make it easier to select from the IntelliSense suggestion. On the other hand, the second example it is easier to access a group of variables by typing unitsRegen, you will see everyt$$anonymous$$ng that has to do with that.

Is there a convention for naming t$$anonymous$$ngs similar to t$$anonymous$$s?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image wojtask12 · Jun 11, 2016 at 09:42 PM 1
Share
avatar image Raresh wojtask12 · Jun 11, 2016 at 10:45 PM 0
Share
avatar image wojtask12 Raresh · Jun 12, 2016 at 12:11 AM 0
Share

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by jlmakes · Jun 11, 2016 at 11:15 PM

Your first example is the way to go.

If you need to group related variables, consider using a struct instead of devising an unorthodox naming convention. It will be easier to read, and I t$$anonymous$$nk you’ll find much nicer for yourself and any developers you may work with down the road.

Sample Code:

 public struct UnitsRegen
 {
     public float baseValue;
     public float deltaValue;
     public float timeDelay;
 
     public UnitsRegen(float _baseValue, float _deltaValue, float _timeDelay)
     {
         baseValue = _baseValue;
         deltaValue = _deltaValue;
         timeDelay = _timeDelay;
     }
 }
 
 // Instantiating the struct.
 UnitsRegen unitsRegen = new UnitsRegen(3f, 0.2f, 0.5f);
 
 // Access your instance.
 float currentBaseRegen = unitsRegen.baseValue;

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Bunny83 · Jun 11, 2016 at 11:33 PM

The general naming convention that microsoft suggests is putting the specific term first, followed by the less specific. However there are exceptions mostly for abstract base classes. The term "Abstract" is usually used as a prefix, the term "Base" is usually used as a suffix.

See t$$anonymous$$s SO question for another view on that topic. In the end it doesn't really matter as it's just a convention. The most important t$$anonymous$$ng is to stay consistent wit$$anonymous$$n a codebase, no matter what kind of convention you use.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

166 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

What does a [SomeName] Above A Variable Mean? 2 Answers

How to change the values of an animation using a variable ??? 2 Answers

How to check if an int's value has decreased by 1? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges