coding-style

Java: Clean way of avoiding NullPointerException in equals checks

丶灬走出姿态 提交于 2019-12-21 03:17:08
问题 I have an address object that I want to create an equals method for. I could have made this quite simple by doing something like the following (shortened a bit): public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Address other = (Address) obj; return this.getStreet().equals(other.getStreet()) && this.getStreetNumber().equals(other.getStreetNumber()) && this.getStreetLetter().equals(other

How can I simplify C# code that sets multiple properties of an object?

可紊 提交于 2019-12-20 17:17:25
问题 I have code that looks like this: itemView.Question.AnswersJSON = itemView.Answer.ToJSONString(); itemView.Question.Modified = DateTime.Now; itemView.Question.ModifiedBy = User.Identity.Name plus many more lines where I set values for the Question class that is inside the itemView . I think the answer is "not possible" but just putting it out as a question in case anyone knows a way. What I would like to do is to find a way to simplify this code without repeating itemView.Question in every

To foo bar, or not to foo bar: that is the question

大城市里の小女人 提交于 2019-12-20 16:22:54
问题 This was something originally discussed during a presentation given by Charles Brian Quinn of the Big Nerd Ranch at acts_as_conference. He was discussing what he had learned from instructing a Ruby on Rails Bootcamp to many people both new to programming and new to Rails. One particular slide that stood out was along the lines of never using foo and bar as examples when trying to teach someone to program . His reasoning was very simple. Which is easier to understand? baz = foo + bar or answer

Well written C++ examples [closed]

馋奶兔 提交于 2019-12-20 15:12:24
问题 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 8 years ago . I'm currently learning C++ and would like to start reading others sourcecode to pick up tips. I was wondering if anyone has examples

Matlab code formatting similar to AStyle? [closed]

旧街凉风 提交于 2019-12-20 14:12:50
问题 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 8 years ago . Is there any tool similar to AStyle to format matlab code in m-files? 回答1: In recent versions of MATLAB, you can use the "Smart Indent

Are there any tools out there to refactor the coding-style of a java code base?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-20 12:39:11
问题 Normally, when doing some work on an existing project, I would just go with whatever style is already established in the code base. But our team has to maintain multiple small to medium sized projects which all differ slightly in coding style. It would be more efficient and less confusing if we could cleanup these differences. So I'm looking for a tool that allows me to refactor the existing style. Lots of features are already provided by standard code formatting tools, like changing the

JavaScript Space After Function [closed]

半城伤御伤魂 提交于 2019-12-20 12:38:27
问题 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 . I know that white space is irrelevant in JavaScript, but I am curious about style. When defining a function like: function Foo(a, b, c

Using $this, self::, parent:: for code readability

风流意气都作罢 提交于 2019-12-20 12:34:07
问题 I would like to know if it is acceptable/preferred to use self::method() and parent::method() when working in php classes. You can use $this->method() but $this-> can also refer to a class variable, a parent class variable, or a method from the parent class. There is no ambiguity in self:: Is self:: depreciated and/or are there any caveats or cons to using this style? I understand that self:: and parent:: refer to a static instance of the class, but in kohana, unless you specifically define a

Should I make my private class methods static?

偶尔善良 提交于 2019-12-20 12:32:14
问题 Is there a best practice for making private methods in classes static? I have a class with a few methods. Some of these can easily be made static, since they simply process data. Should I make them static or just leave them as is? Is this more of a style issue? Are there performance considerations? Edit: Method can be made static, but should it? 回答1: If the methods don't access any of the type's state then they should be static. Static method calls provide a performance gain over instance

Is Iterator initialization inside for loop considered bad style, and why?

◇◆丶佛笑我妖孽 提交于 2019-12-20 12:22:04
问题 Typically you will find STL code like this: for (SomeClass::SomeContainer::iterator Iter = m_SomeMemberContainerVar.begin(); Iter != m_SomeMemberContainerVar.end(); ++Iter) { } But we actually have the recommendation to write it like this: SomeClass::SomeContainer::iterator Iter = m_SomeMemberContainerVar.begin(); SomeClass::SomeContainer::iterator IterEnd = m_SomeMemberContainerVar.end(); for (; Iter != IterEnd; ++Iter) { } If you're worried about scoping, add enclosing braces: { SomeClass: