开发者

Length of member names

开发者 https://www.devze.com 2023-01-17 15:18 出处:网络
What is the maximum number of characters (roughly) for a member (variable,property,method) namebeyond which the descriptive ability of the name i开发者_开发技巧sn\'t just worth it ? Any rules of thumb

What is the maximum number of characters (roughly) for a member (variable,property,method) name beyond which the descriptive ability of the name i开发者_开发技巧sn't just worth it ? Any rules of thumb ?


My rule of thumb is: If this variable name was a URL, would people not want to type it in to go to my website? If the answer is yes, then it's too long.


There is no hard rule of thumb. 8 Characters is just someone's opinion. I say:

If the member name is hard to read then it's too long. Example:

foo.TemperatureWhenInitializedAndAllocated = 56.7;

If it's easy to read, then it's better.

foo.Temperature = 56.7 // put the extra description in comments... When initialized and allocated

But most of all the member variable names must make sense, be concise, easy to read, and not cryptic or mysterious.


Visual Studio will accept user defined types with a length no more than 512 characters. Even though it's possible, please don't.

The ECMA standard does not mention a limit.

http://www.ecma-international.org/publications/standards/Ecma-335.htm (More specifically Partition II, section 22)

This is the maximum variable name that will compile in Visual Studio 2008:

public class Program
    {
        static void Main()
        {
            var
                oqqdidqhcklcipgkafunpkhibulewkmwzwdtwhqsmgrbjvsdkqtvctskkucuuvduhmoshvnmtlujflogqlmlmawperuqqrblmubosgpxatbzlngtpgnrofsrybeivctnvyuszwdyzpdqvjptdvxtahxqcjxxkjuloywtqjavhjodocipbhstwfmmpobiinfgqwjrrthpzyjnrrliiqwpcalfmpoqqoaxdpflbaygblotedyyavkhrsuutnlvilfmzgldwdyunudxbmulbxhxqgmgjhrxjgtxftaradjeiabxhsavmwpjzsoojziwuxrfvezbnadlndkuxuqbgrgtraautnirpkzjukijltgpcdcoxtqeljhyufwwnyrjuvqldobnsjupbzdehpzezyrbggbvrglyjcsjwoeojwrnjspraitaxkmabfqrekokhgdezmqmkgyhbikbdxwuetqxhapjblbsphxvmfmgumpydupiqjikwyepwsxyijyxhfc
                    = "foo";
        }
    }


From code complete book the author says a good length would be 8 characters. Idea is its easier to type even if you don't have an intellicence IDE.


My rule: one (precise) word is best, two is good, three is acceptable, four is too much.

0

精彩评论

暂无评论...
验证码 换一张
取 消