coding-style

What is the preferred way to check for a Null pointer in C++?

家住魔仙堡 提交于 2019-12-05 19:23:52
Options A: if (NULL == pSomethingColumn) // Yes, we use Yoda conditions if (NULL != pSomethingColumn) Or if (pSomethingColumn) if (!pSomethingColumn) I am looking for references explaining the reasoning as well. I have heard some people say that technically NULL does not have to be defined as 0 , but come on! if that was the case, then the sucker (our app) would crash in -2147483648 different ways. So, if NULL != 0 , then we will have big problems. Please help me settle a pointless syntax debate. I am not particularly attached to either way; just looking for the official way. Thanks. P.S. We

JavaScript style/optimization: String.indexOf() v. Regex.test()

前提是你 提交于 2019-12-05 18:58:46
问题 I've recently come across this piece of JavaScript code: if (",>=,<=,<>,".indexOf("," + sCompOp + ",") != -1) I was intrigued, because to write this test I would have done: if (/(>=|<=|<>)/.test(sCompOp)) Is this just a stylistic difference, or does the author of the other code know something about optimization that I don't? Or perhaps there is a different good reason to do this, or to not use regexes...? It seems to me that using String.indexOf() for this is a little more difficult to read

Why is “lower-case with dashes” the standard for HTML classes? [duplicate]

人盡茶涼 提交于 2019-12-05 18:23:01
This question already has answers here : Closed 7 years ago . Possible Duplicate: Why are dashes preferred for CSS selectors / HTML attributes? Personally I use "lower-case with dashes" to format my HTML classes, which seems to be the standard these days. Using something like camel case seems more reserved for JavaScript in my eyes, but I realise that's just my opinion. I'm trying to improve front-end code consistency at my workplace and part of that will be coding guidelines. Rather than just saying "we should do it this way" I'm keen to hear some valid reasons behind this common trend. So

C# Equivalent for C++ Macros and using Auto<> Properties

ぐ巨炮叔叔 提交于 2019-12-05 17:51:28
问题 I have some auto-instantiation code which I would like to apply to about 15 properties in a fairly big class. The code is similar to the following but the type is different for each instance: protected ComplexType _propertyName; public ComplexType PropertyName { get { if (_propertyName == null) { _propertyName = new ComplexType(); } return _propertyName; } } To repeat this in C++ (as there are ~15 instances), I would have used a preprocessor macro but I notice C# doesn't support them. I am

Should Java member enum types be capitalized?

好久不见. 提交于 2019-12-05 17:14:04
问题 Anal question here: we have Java enums which are their own classes, and enums which are members of a class: public enum reportType { ... Every time I see this it jars me* because when I see it used in a declaration, it's a type, and types should be capitalized. But when I try to capitalize it, Eclipse warns me that I shouldn't capitalize field names. I figure Eclipse probably knows the official Java conventions better than I do, but it just doesn't seem right. Even flipped through the Java

JSLint says new keyword is missing [duplicate]

落花浮王杯 提交于 2019-12-05 17:09:23
This question already has an answer here: How to fix JSLint “missing new” error 2 answers Let's say I have some JavaScript that looks like this: function A() { var MyVar, SomeParameter; // do work MyVar = FunctionB(SomeParameter); } JsLint says I'm Missing 'new'. at the line MyVar = FunctionB(SomeParameter); Why should I rewrite as MyVar = new FunctionB(SomeParameter); Is there going to be any benefit? It is the convention that constructors (eg: Array , Object ) are starting with a capital. JSLint complains, because it thinks that you're trying to use a constructor, without new keyword. To fix

Is there a way to make eclipse report a general “catch (Exception e)” as an error/warning (in java)?

一世执手 提交于 2019-12-05 16:58:52
I'm trying to encourage a best practice of not catching general exceptions in Java code. eg: try { ... } catch (Exception e) { // bad! ... } Is there a way to flag this as an error/warning in Eclipse? I know PMD picks this up, but I'd rather avoid integrating it into everyone's build environment at the moment. You can use Checkstyle eclipse plugin to do the same. Check 'IllegalCatch' section at documentation FindBugs can report this: REC : Exception is caught when Exception is not thrown ( REC_CATCH_EXCEPTION ) This method uses a try-catch block that catches Exception objects, but Exception is

Try/Catch Use Convention(s)

浪子不回头ぞ 提交于 2019-12-05 16:43:37
What is the convention for Try/Catch outside of obviously needed locations(such as getting specific user input)? While code re-use is an important idea behind OOP, is it expected that each (example) array access should have a try/catch? Is it primarily the designer's decision of what can throw an exception, and those parts of the program that should be well regulated enough to never throw an exception? Ex. An array of playing cards is, and should always be, 52 cards. No try/catch is necessary. Or since an array out of bounds exception could cause a run-time error, and the deck could be used at

Are there issues using Dim foo As Foo in VB.NET?

做~自己de王妃 提交于 2019-12-05 14:34:54
In a recent VB.NET project I adopted the naming conventions I'm used to using in C#. Namely, often calling a variable the same name as the class it references, only with a different case, e.g. Foo foo = new Foo(); // C# Dim foo As New Foo() ' VB.NET I find this is often the clearest way to write code, especially for small methods. This coding style obviously works fine in C#, being case sensitive, and because of the syntax highlighting provided by Visual Studio, it is very easy to see that the class name and the variable name are different. However, to my surprise, this also worked fine nearly

Stop PhpStorm from adding a new line after function declaration when arguments split across multiple lines

余生长醉 提交于 2019-12-05 14:24:26
In my PhpStorm 8.0.3 code style, I have set it to add a new line after a function declaration, which works fine. Problem is now I'm in a new project that follows the PSR-2 Standards , which say that the opening brace of a function MUST be placed in the same line that the closing parenthesis of the function arguments when these split across multiple lines, as you can see here . I want this when arguments split across multiple lines... public function myMethod( MyClass $arg1, $arg2 = null ) { // method body } ...and this when they are all in the same line... public function myMethod(MyClass