coding-style

Why maintain traditional detailed ChangeLog in modern world (with SVN, Mercurial, Git)?

夙愿已清 提交于 2019-12-21 12:27:24
问题 Detailed ChangeLog entry usually tell who, when and what function changed and for why this change done. And this for every separate function in the source code tree! As I understand ChangeLog come from past when there were no good VCS. So traditional ChangeLog doesn't need at all as you can get it all from: $ svn log . $ hg log . $ git log . $ bzr log . Only one possible needs for ChangeLog for short summary between product versions and intended for user only (for example, when new version

root namespace coding convention in C++

牧云@^-^@ 提交于 2019-12-21 10:29:52
问题 Would you recommand prefixing global namespaces with :: ? (for instance ::std::cout instead of std::cout ) Why? Is it faster to parse for the C++ compiler? Thanks. 回答1: Only do this to disambiguate. I have a piece of code where this is necessary since I’m in a namespace X which has a function for a standard deviation – std . Whenever I want to access the std namespace, I need to use ::std because otherwise the compiler will think that I am referring to said function. Concrete example:

What exactly is the difference between My.Computer.FileSystem and System.IO.File

不问归期 提交于 2019-12-21 10:19:09
问题 There is a lot of duplication of functions in the My.Computer.FileSystem and System.IO.File namespaces. So what exactly is the difference between: My.Computer.FileSystem.CopyFile(source, dest, True) and: System.IO.File.Copy(source, dest, True) Is there a performance difference? What is everyone's opinion on which which has the edge on read-ability? I personally use the My.Computer Namespace but that is just habit now. 回答1: My.* is simply a set of facade-pattern classes implemented for VB.NET

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

痞子三分冷 提交于 2019-12-21 09:16:59
问题 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. 回答1: Future-proofing. Let's say in the future I do this: float blah = 1

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

不羁的心 提交于 2019-12-21 09:16:22
问题 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. 回答1: Future-proofing. Let's say in the future I do this: float blah = 1

Apply Different Style to Button When Pressed

蓝咒 提交于 2019-12-21 09:07:56
问题 Is there a way to apply a style to a button when the button is pressed? If I have a style in style.xml : <resources> <style name="test"> <item name="android:textStyle">bold</item> </style> </resources> a selector in button.xml : <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/test_pressed" style="@style/test" android:state_pressed="true"/> <item android:drawable="@drawable/test_focused" android:state_focused="true"/> <item android

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

微笑、不失礼 提交于 2019-12-21 07:14:15
问题 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

How to indent long conditionals for 'if' statements?

℡╲_俬逩灬. 提交于 2019-12-21 07:03:03
问题 My question relates to this previous question, but the solutions offered don't address the problem I have outlined below. After a google search I haven't found any code style guidelines that address the specific problem of long conditionals in an if statement like this. if( isNull(value1) || isToLong(value1) || hasBadFormat(valule1)){ doSomething(); }else{ doSomethingElse(); } OR: if( isNull(value1) || isToLong(value1) || hasBadFormat(valule1) ){ doSomething(); }else{ doSomethingElse(); } The

C++ override pure virtual method with pure virtual method

删除回忆录丶 提交于 2019-12-21 06:59:38
问题 Does it ever make sense to override a pure virtual method with another pure virtual method? Are there any functional differences or perhaps code style reasons to prefer one of the following options over the other? class Interface { public: virtual int method() = 0; }; class Abstract : public Interface { public: int method() override = 0; }; class Implementation : public Abstract { public: int method() override { return 42; } }; Versus: class Interface { public: virtual int method() = 0; };

Check Android Permissions in a Method

不羁岁月 提交于 2019-12-21 06:58:09
问题 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())