naming

Best practice for parameter naming in Java constructors and simple setters

六月ゝ 毕业季﹏ 提交于 2019-11-27 21:47:58
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 C(Type foo) { this.foo = foo; } public void setFoo(Type foo) { this.foo = foo; } 3) Completely

Why do function prototypes include parameter names when they're not required?

不想你离开。 提交于 2019-11-27 20:50:13
I always thought that a function prototype must contain the parameters of the function and their names. However, I just tried this out: int add(int,int); int main() { std::cout << add(3,1) << std::endl; } int add(int x, int y) { return x + y; } And it worked! I even tried compiling with extreme over-caution: g++ -W -Wall -Werror -pedantic test.cpp And it still worked. So my question is, if you don't need parameter names in function prototypes, why is it so common to do so? Is there any purpose to this? Does it have something to do with the signature of the function? No, these are not necessary

What is the difference between a shim and a polyfill?

筅森魡賤 提交于 2019-11-27 19:40:19
问题 Both seem to be used in web development circles, see e.g. HTML5 Cross Browser Polyfills, which says: So here we're collecting all the shims, fallbacks, and polyfills... Or, there's the es5-shim project. In my current project we're using a number of these, and I want to stick them all in the same directory. So, what should I call this directory--- shims , or polyfills ? 回答1: A shim is any piece of code that performs interception of an API call and provides a layer of abstraction. It isn't

Name for HTTP Request+Response

怎甘沉沦 提交于 2019-11-27 17:11:18
问题 There's one thing I haven't found in rfc 2616 and that's a "canonical" name for a request/response pair. Is there such thing? 4.1 Message Types HTTP messages consist of requests from client to server and responses from server to client. HTTP-message = Request | Response ; HTTP/1.1 messages Taking this as a template, which word would you put in the following sentence? A single complete HTTP ... consists of one HTTP Request and one HTTP Response HTTP-... = Request Response roundtrip? cycle? 回答1

Can a DAO call DAO?

帅比萌擦擦* 提交于 2019-11-27 16:02:23
问题 I have component which needs to update the database for the customer and customer address (via JDBC). Is it appropriate to call the CustomerAddressDAO from the CustomerDAO? Or create a separate "CustomerDataManager" component which calls them separately? 回答1: You can do it, but that doesn't mean you should. In these cases, I like to use a Service ( CustomerService in this case) that has a method call that uses both DAOs. You can define the transaction around the service method, so if one call

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

谁说胖子不能爱 提交于 2019-11-27 13:15:32
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 variable names inside a macro in C++? -- Edit -- I mean unique but also random once I can use my macro twice

Naming Generic DataContracts in WCF

别等时光非礼了梦想. 提交于 2019-11-27 12:57:12
问题 I am using a Generic Class as a Response Data Contract. All is good and this is streamlining the design of my WCF service significantly. Each request is given a standard response object with the following signature: Status (Enum) Message (String) Result (T) Below is the Response Class: [DataContract] public class Response<T> { public Response() {} public Response(T result) { this.result = result; if (result != null) { this.status = Status.StatusEnum.Success; } else { this.status = Status

How to name variables

感情迁移 提交于 2019-11-27 11:33: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 function startEditing(){ if (user.canEdit(currentDocument)){ editorControl.setEditMode(true); setButtonDown(btnStartEditing); } } Should read like a narrative work. One rule I always follow is this: if a variable encodes a value that is in some particular units, then those units have to be part of the variable name. Example:

What are reserved filenames for various platforms?

六月ゝ 毕业季﹏ 提交于 2019-11-27 09:14:52
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? Jacob T. Nielsen 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 Windows Operating Systems using the FAT file system. Under Windows using the FAT file

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

冷暖自知 提交于 2019-11-27 08:49:05
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 Leh_func_begin0: pushq %rbp Ltmp0: movq %rsp, %rbp Ltmp1: movl $14, %edi callq _malloc ; Here movabsq