naming

Best practice for parameter naming in Java constructors and simple setters

寵の児 提交于 2019-11-26 20:47:45
问题 Is there a standard acceptable convention for parameters in Java to straightforward constructors and setters? (I've seen the answer for C++, but practices are often different between the two communities) Suppose that I have a class C with a foo field. I have commonly seen the following three options: 1) Use the actual field name with an underscore: public C(Type foo_) { foo = foo_; } public void setFoo(Type foo_) { foo = foo_; } 2) Use the actual field name, just use "this" in setting: public

Reserved words as names or identifiers

你。 提交于 2019-11-26 19:06:08
Is there any tricky way to use Java reserved words as variable, method, class, interface, package, or enum constant names? No, there is no way. That's why they're labeled "reserved". Rob Kennedy This is a valid question. Such a thing is possible in other languages. In C#, prefix the identifier with @ ( as asked before ); in Delphi, prefix with & . But Java offers no such feature (partly because it doesn't really need to interact with identifiers defined by other languages the way the .Net world does). Most often this issue comes up for "class", in this case it is customary to write "clazz".

How to generate random variable names in C++ using macros?

大城市里の小女人 提交于 2019-11-26 18:15:01
问题 I'm creating a macro in C++ that declares a variable and assigns some value to it. Depending on how the macro is used, the second occurrence of the macro can override the value of the first variable. For instance: #define MY_MACRO int my_variable_[random-number-here] = getCurrentTime(); The other motivation to use that is to avoid selecting certain name to the variable so that it be the same as a name eventually chosen by the developer using the macro. Is there a way to generate random

Does the use of the “Async” suffix in a method name depend on whether the 'async' modifier is used?

戏子无情 提交于 2019-11-26 17:35:23
问题 What is the convention for suffixing method names with "Async"? Should the "Async" suffix be appended only to a method that is declared with the async modifier? public async Task<bool> ConnectAsync() Or is it enough that the method just returns Task<T> or Task ? public Task<bool> ConnectAsync() 回答1: I think the truth is ambiguous even from Microsoft documentation: In Visual Studio 2012 and the .NET Framework 4.5, any method that is attributed with the async keyword ( Async in Visual Basic) is

How to name variables

删除回忆录丶 提交于 2019-11-26 15:37:26
问题 What rules do you use to name your variables? Where are single letter vars allows? How much info do you put in the name? how about for example code? what are your preferred meaningless variable names? (after foo & bar) why are they spelled "foo" and "bar" rather than FUBAR 回答1: function startEditing(){ if (user.canEdit(currentDocument)){ editorControl.setEditMode(true); setButtonDown(btnStartEditing); } } Should read like a narrative work. 回答2: One rule I always follow is this: if a variable

Naming Classes - How to avoid calling everything a “<WhatEver>Manager”? [closed]

夙愿已清 提交于 2019-11-26 15:34:00
A long time ago I have read an article (I believe a blog entry) which put me on the "right" track on naming objects: Be very very scrupulous about naming things in your program. For example if my application was (as a typical business app) handling users, companies and addresses I'd have a User , a Company and an Address domain class - and probably somewhere a UserManager , a CompanyManager and an AddressManager would pop up that handles those things. So can you tell what those UserManager , CompanyManager and AddressManager do? No, because Manager is a very very generic term that fits to

Source control vs. Revision Control?

不打扰是莪最后的温柔 提交于 2019-11-26 15:12:53
Which is the correct name for a system which stores versions of source code, like SVN or TFS? I've always called it source control, but places like Wikipedia calls it revision control? To make this more complicated sites like this one have a tag for both? VonC Revision Control is the more generic term, used for source-control tools but also for other tools (Word, OpenOffice, ...). It references a version. Source Control offers revision control with branching and merging which are not always available in all revision tools (Word is not a Source Control, but offer revision control features)

What are reserved filenames for various platforms?

南笙酒味 提交于 2019-11-26 14:35:50
问题 I'm not asking about general syntactic rules for file names. I mean gotchas that jump out of nowhere and bite you. For example, trying to name a file "COM<n>" on Windows? 回答1: From: http://www.grouplogic.com/knowledge/index.cfm/fuseaction/view_Info/docID/111. The following characters are invalid as file or folder names on Windows using NTFS: / ? < > \ : * | " and any character you can type with the Ctrl key. In addition to the above illegal characters the caret ^ is also not permitted under

What is the reason function names are prefixed with an underscore by the compiler?

廉价感情. 提交于 2019-11-26 14:19:10
问题 When I see the assembly code of a C app, like this: emacs hello.c clang -S -O hello.c -o hello.s cat hello.s Function names are prefixed with an underscore (e.g. callq _printf ). Why is this done and what advantages does it have? Example: hello.c #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char *myString = malloc(strlen("Hello, World!") + 1); memcpy(myString, "Hello, World!", strlen("Hello, World!") + 1); printf("%s", myString); return 0; } hello.s _main: ; Here

What kind of prefix do you use for member variables?

假如想象 提交于 2019-11-26 13:03:39
问题 No doubt, it\'s essential for understanding code to give member variables a prefix so that they can easily be distinguished from \"normal\" variables. But what kind of prefix do you use? I have been working on projects where we used m_ as prefix, on other projects we used an underscore only (which I personally don\'t like, because an underscore only is not demonstrative enough). On another project we used a long prefix form, that also included the variable type. mul_ for example is the prefix