coding-style

Should Java member enum types be capitalized?

。_饼干妹妹 提交于 2019-12-04 02:59:50
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 conventions doc, but didn't see this issue referenced. no pun intended If they are their own class start

Should I really use static_cast every single time I want to convert between primitive types?

好久不见. 提交于 2019-12-04 02:52:41
What makes this long l = 1; char c = static_cast<char>(l); float f = 1.0f; int i = static_cast<int>(f); better than this long l = 1; char c = (char)l; float f = 1.0f; int i = (int)f; when casting one primitive data type to another? I've got much of legacy code that uses the second style for type casting in similar situations, so this is also a question about should I or may I not perform full-scale revision of that code. R. Martinho Fernandes Future-proofing. Let's say in the future I do this: float blah = 1.0f; float* f = &blah; Now, int i = static_cast<int>(f); stops compiling, but int i =

C# Action/Delegate Style Question

我们两清 提交于 2019-12-04 02:52:36
What is considered better style for an event definition: public event Action<object, double> OnNumberChanged; or public delegate void DNumberChanged(object sender, double number); public event DNumberChanged OnNumberChanged; The first takes less typing, but the delegate one gives names to the parameters. As I type this, I think number 2 is the winner, but I could be wrong. Edit: A different (third) approach is the winner. Read below. Neither 1 or 2. A third option is the winner public event EventHandler<NumberChangedEventArgs> NumberChanged; You're breaking a number of style guidelines for

How to cleanly keep below 80-char width with long strings?

扶醉桌前 提交于 2019-12-04 02:47:02
问题 I'm attempting to keep my code to 80 chars or less nowadays as I think it looks more aesthetically pleasing, for the most part. Sometimes, though, the code ends up looking worse if I have to put line breaks in weird places. One thing I haven't figured out how to handle very nicely yet is long strings. For example: #0.........1........2........3........4.........5.........6.........7.........8xxxxxxxxx9xxxxxx def foo(): if conditional(): logger.info("<Conditional's meaning> happened, so we're

Should I test if equal to 1 or not equal to 0?

拈花ヽ惹草 提交于 2019-12-04 02:11:30
I was coding here the other day, writing a couple of if statements with integers that are always either 0 or 1 (practically acting as bool s). I asked myself: When testing for positive result, which is better; testing for int == 1 or int != 0 ? For example, given an int n , if I want to test if it's true , should I use n == 1 or n != 0 ? Is there any difference at all in regards to speed, processing power, etc? Please ignore the fact that the int may being more/less than 1 / 0 , it is irrelevant and does not occur. Human's brain better process statements that don't contain negations, which

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

岁酱吖の 提交于 2019-12-04 01:57:12
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 wondering if anyone has a recommendation on how to do this cleanly in C#? This might make things a bit

Premature optimization in Java: when to use “x = foo.getX()” vs simply “foo.getX()”

送分小仙女□ 提交于 2019-12-04 01:53:13
When I find myself calling the same getter method multiple times, should this be considered a problem? Is it better to [always] assign to a local variable and call only once? I'm sure the answer of course is "it depends". I'm more concerned about the simpler case where the getter is simply a "pass-along-the-value-of-a-private-variable" type method. i.e. there's no expensive computation involved, no database connections being consumed, etc. My question of "is it better" pertains to both code readability (style) and also performance. i.e. is it that much of a performance hit to have: SomeMethod1

Java performance vs. code-style: Making multiple method calls from the same line of code

半腔热情 提交于 2019-12-04 01:18:54
问题 I am curious whether packing multiple and/or nested method calls within the same line of code is better for performance and that is why some developers do it, at the cost of making their code less readable. E.g. //like Set<String> jobParamKeySet = jobParams.keySet(); Iterator<String> jobParamItrtr = jobParamKeySet.iterator(); Could be also written as //dislike Iterator<String> jobParamItrtr = jobParams.keySet().iterator(); Personally, I hate the latter because it does multiple evaluations in

Objective-C Class Prefixes [closed]

痞子三分冷 提交于 2019-12-04 00:48:37
Closed . This question is opinion-based. It is not currently accepting answers. Learn more . Want to improve this question? Update the question so it can be answered with facts and citations by editing this post . Closed 5 years ago . What's your preference with naming ObjC classes? I'm a little uncertain what would be the most reasonable approach on this so it would be nice to hear some other opinions. Apple recommends prefixing cocoa classes, because ObjC doesn't support namespaces. The Google ObjC styleguide (which i mostly aim for) does away with them, unless you're extending (category,

Too many imports spamming my code

江枫思渺然 提交于 2019-12-04 00:33:31
In my project I have a shapes package which has shapes I designed for my graphics program e.g Rectangle, Circle. I also have one or two more packages that have the same names as java.awt classes. Now, since I do not want to rename every class in my code-base, to show my source files which class I mean when I , say, declare a new Rectangle, I need to either: 1- import the rectangle class explicitly, i.e import shapes.Rectangle OR 2- import only the java.awt classes I need and not import java.awt.* which automatically includes the awt.Rectangle Now the problem is that both ways result in a lot