coding-style

Saving my PDO connection as a global variable [duplicate]

自作多情 提交于 2019-12-09 06:31:14
问题 This question already has answers here : How to properly set up a PDO connection (4 answers) Closed 6 years ago . While asking another questions about PDO queries, I've been told that saving my PDO connection object as global to use it in my various functions that call queries to my database is generally bad practice. Here is how I generally use my PDO object: function somefunction(){ global $pdo; $statement = $pdo->prepare("some query"); $statement->execute(); } The arguments I've read are

Why does Golang enforce curly bracket to not be on the next line?

最后都变了- 提交于 2019-12-09 05:02:27
问题 correct: if(true) { } incorrect: if(true) { } Why is this style enforced, does it have something to do with the language spec, or is it just because they prefer one style over another ? 回答1: Why are there braces but no semicolons? And why can't I put the opening brace on the next line? Go uses brace brackets for statement grouping, a syntax familiar to programmers who have worked with any language in the C family. Semicolons, however, are for parsers, not for people, and we wanted to

Where do you keep Constants used throughout your application?

左心房为你撑大大i 提交于 2019-12-09 04:37:11
问题 Is interface an acceptable place to store my public static final Foo bar Do you extrapolate them to be read from outside of the program? Do you make up a super class for it? How do you do it, when situation presents itself? 回答1: I'd put each constant into the class or interface it's most closely related to (e.g. because it will be use by its methods). A very seductive but ultimately very foolish idea is to have one "constants class" (or interface) that contains all constants used in the

What are the url parameters naming convention or standards to follow

末鹿安然 提交于 2019-12-09 04:08:30
问题 Are there any naming conventions or standards for Url parameters to be followed. I generally use camel casing like userId or itemNumber . As I am about to start off a new project, I was searching whether there is anything for this, and could not find anything. I am not looking at this from a perspective of language or framework but more as a general web standard. 回答1: I recommend reading Cool URI's Don't Change by Tim Berners-Lee for an insight into this question. If you're using parameters

Java convention on reference to methods and variables

旧街凉风 提交于 2019-12-09 03:38:59
问题 Section 10.2 of Java conventions recommends using class names instead of objects to use static variables or methods, i.e. MyClass.variable1 or MyClass.methodName1() instead of MyClass Obj1 = new MyClass(); Obj1.variable1; Obj1.methodName1(); There is no explanation of the rationale behind this, although I suspect this has something to do with memory use. It would be great if someone could explain this. 回答1: I guess you mean "for static methods and variables". There is no difference regarding

linq styling, chaining where clause vs and operator

随声附和 提交于 2019-12-09 02:35:00
问题 Is there a (logical/performance) difference to writing: ATable.Where(x=> condition1 && condition2 && condition3) or ATable.Where(x=>condition1).Where(x=>condition2).Where(x=>condition3) I've been using the former but realised that with the latter, I can read and copy parts of a query out to use somewhere else easier. Any thoughts? 回答1: Short answer You should do what you feel is more readable and maintainable in your application as both will evaluate to the same collection. Long answer quite

What are the conventions for __func functions?

我的未来我决定 提交于 2019-12-08 20:49:35
I've seen a bunch of functions in Linux code named __foo. What does the double underscore stand for and when should it be used? Hailei It means it's a reserved identifer. Both C++ 03 and C99 standard mentioned about this. C99: 7.1.3 Reserved identifiers All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use. All identifiers that begin with an underscore are always reserved for use as identifiers with file scope in both the ordinary and tag name spaces. C++ 03: Each name that contains a double underscore (_ _) or begins

where does the `where` clause come in handy in Haskell

允我心安 提交于 2019-12-08 20:38:41
问题 I find I quite seldom come across situations where I need to use the where clause. However, I do find that I have used it very occasionally in the past. When is the where clause used (i.e. what situations is it used in)? Under what circumstances should I use it? 回答1: There are two excellent answers to this question available on the Haskell Wiki as well: http://haskell.org/haskellwiki/Declaration_vs._expression_style http://haskell.org/haskellwiki/Let_vs._Where Both are used to create local

Indenting HTML tags on multiple lines

霸气de小男生 提交于 2019-12-08 20:37:46
问题 I can't find a guideline on how to indent HTML tags on multiple line, and the solution I am currently using doesn't really satisfy me. Imagine we have an extremely long div declaration, such as: <div data-something data-something-else data-is-html="true" class="html-class another-html-class yet-another-html-class a-class-that-makes-this-declaration-extremely-long" id="just-a-regular-id"> In order to avoid scrolling horizontally when I find these huge lines, I usually indent them in the

“using” directive in Java

让人想犯罪 __ 提交于 2019-12-08 20:33:13
问题 When the type name is too long, in C# i can create alias like this: using Dict = System.Collections.Generic.Dictionary<string, string>; And I can use it like this: Dict d = new Dict(); d.Add("key", "value"); Can I create an alias similar to this in Java? 回答1: You can't create an alias, but you can import packages (JLS 7.5 Import Declarations) so that you don't have to fully qualify class names in that package. import java.util.*; import java.lang.reflect.Field; .... Set<Field> s = ... // Set