coding-style

acceptable fix for majority of signed/unsigned warnings?

烂漫一生 提交于 2019-12-04 00:32:01
问题 I myself am convinced that in a project I'm working on signed integers are the best choice in the majority of cases, even though the value contained within can never be negative. (Simpler reverse for loops, less chance for bugs, etc., in particular for integers which can only hold values between 0 and, say, 20, anyway.) The majority of the places where this goes wrong is a simple iteration of a std::vector, often this used to be an array in the past and has been changed to a std::vector later

PHP Interfaces: How are they usable in practice?

我们两清 提交于 2019-12-04 00:18:43
问题 I'll start by saying that I know how PHP interfaces work and how to "use" them. My question is rather; how do they become useful in real life applications? I've been writing PHP for over 3 years now and have never felt the need for an interface. I am writing interfaces more for good practice than for a particular purpose. 回答1: I'll provide an example where I've used interfaces in my own real-world experience. Interfaces are extremely useful when you need to define something like a plugin

Should you declare enums inside or outside a class? [closed]

一个人想着一个人 提交于 2019-12-04 00:14:51
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . Should you declare enums inside or outside a class if the said enums are only used in the class member functions? namespace nspace { // need to append OC, as this pollutes the current namespace enum OUTSIDE_CLASS {OC_POINTS, OC_LINES, OC

PSR-1 2.3 Side Effects Rule

99封情书 提交于 2019-12-04 00:03:29
I have a question Regarding PHP Basic Coding Standards PSR1. PSR 1 Rule 2.3 states: Rule 2.3 Side Effects A file SHOULD declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it SHOULD execute logic with side effects, but SHOULD NOT do both. The phrase "side effects" means execution of logic not directly related to declaring classes, functions, constants, etc., merely from including the file . "Side effects" include but are not limited to: generating output, explicit use of 'require' or 'include', connecting to external services, modifying ini settings,

Wrapping chained method calls on a separate line in Intellij for Java

别来无恙 提交于 2019-12-03 23:23:13
[Copied from]: Wrapping chained method calls on a separate line in eclipse for Java For example, I have this: someObject.A().B().C(); But I really want this: someObject.A() .B() .C(); I wanted to ask how to achieve that formatting in intellij. I was unable to achieve it. I want to use the same formatting given in this answer . Small disclaimer: this is IJ 14.4, it's possible that in later versions it may have been changed/renamed/etc, but it should be there somewhere nonetheless Go to Settings -> Editor -> Code style -> Java and select the Wrapping and Braces tab, then scroll to Chained method

Check Android Permissions in a Method

落花浮王杯 提交于 2019-12-03 22:43:15
here is my code and it works perfectly fine . if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { mMap.setMyLocationEnabled(true); } But I don't like such a big code on every check, and want to delegate it to a method in my utility class. if (Utils.hasMapLocationPermissions(getActivity())) { mMap.setMyLocationEnabled(true); } But setMyLocationEnabled has annotation @RequiresPermission And

What is the proper style for listing imports in Java?

对着背影说爱祢 提交于 2019-12-03 22:27:32
Is it better to list each individual piece of a package you're going to need (see #1) or is it better to just import everything from a package (see #2)? 1 import java.awt.image.ColorModel; import java.awt.image.ComponentColorModel; import java.awt.image.ColorConvertOp; 2 import java.awt.*; It's NOT simply a matter of style; import-on-demand can result in code that ceases to compile as new classes are added to existing packages. Basic idea (See http://javadude.com/articles/importondemandisevil.html for details.): import java.awt.*; import java.util.*; ... List list; worked in Java 1.1; as of

How to handle the pylint message: ID:W0612 Unused Variable

ぃ、小莉子 提交于 2019-12-03 22:19:36
I'm updating some code to PEP 8 standard using pylint. Part of the code is throwing the W0612 unused variable error but it's because it's using a module that returns (x,y) for example when only x is needed in this particular case, this is what's done. (var_1, var_2) = func() def func(): a="a" b="b" return (a,b) var_1 is then returned but var_2 is never used and therefore throws the error. How should I handle this? I'm thinking this var = func()[0] What is the best way to handle it? I believe that a, dummy = func() does the trick. Pylint allows (if I recall correctly) unused variables names

Show 80-character margin line in TextMate

一曲冷凌霜 提交于 2019-12-03 22:12:21
Is it possible to display a right-margin line at 80 characters in TextMate? (i.e. the right-margin line in eclipse, gedit, etc.) If so, how can I configure that? Figured it out: In the View menu, uncheck 'Soft Wrap'. Then, go to View -> Wrap Column -> Other... and select the column at 80 chars in your editor window. This will show the line at 80 characters, but won't force wrapping at 80 chars. (Turning 'Soft Wrap' back on will force wrapping.) What about Visual Ornaments/Show right margin indicator in Preferences? For TextMate 2 it looks like this has moved to View -> Show Wrap Column. So the

Assignment with “or” in python

廉价感情. 提交于 2019-12-03 22:08:17
Is it considered bad style to assign values to variables like this? x = "foobar" or None y = some_variable or None In the above example, x gets the value 'foobar'. No, it's a common practice. It's only considered bad style for expressions that are considerably longer than yours. The primary danger of doing something like this is the possibility that (in the second case) some_variable is False but not None (the integer 0 , for instance) and you don't want to end up with y equal to None in that case. I also feel a bit unconfortable using that kind of expressions. In Learning Python 4ed it is