coding-style

Best way to get rid of hungarian notation?

人盡茶涼 提交于 2019-12-19 19:41:11
问题 Let's say you've inherited a C# codebase that uses one class with 200 static methods to provide core functionality (such as database lookups). Of the many nightmares in that class, there's copious use of Hungarian notation (the bad kind). Would you refactor the variable names to remove the Hungarian notation, or would you leave them alone? If you chose to change all the variables to remove Hungarian notation, what would be your method? 回答1: Refactor -- I find Hungarian notation on that scale

What is benefit of this constructor definition [duplicate]

 ̄綄美尐妖づ 提交于 2019-12-19 19:38:09
问题 This question already has answers here : In this specific case, is there a difference between using a member initializer list and assigning values in a constructor? (12 answers) Closed 6 years ago . I was just going through random pages on Cprogramming.com and noticed the Constructors and Destructors tutorial/example page. They have used the following method of defining a constructor: class String { private: char *str; int size; public: String() : str(NULL), size(0) { } // <- This statement

C++ rely on implicit conversion to bool in conditions?

拈花ヽ惹草 提交于 2019-12-19 18:56:39
问题 I found the following rule in a coding standards sheet : Do not rely on implicit conversion to bool in conditions. if (ptr) // wrong if (ptr != NULL) // ok How reasonable/usefull is this rule? How much overload on the compiled code? 回答1: In the strictest sense, you can rely on implicit conversions to bool. Backwards compatibility with C demands it. Thus it becomes a question of code readability. Often the purpose of code standards is to enforce a sameness to the code style, whether you agree

Is this idiom pythonic? (someBool and “True Result” or “False Result”)

梦想的初衷 提交于 2019-12-19 17:35:11
问题 I just came across this idiom in some open-source Python, and I choked on my drink. Rather than: if isUp: return "Up" else: return "Down" or even: return "Up" if isUp else "Down" the code read: return isUp and "Up" or "Down" I can see this is the same result, but is this a typical idiom in Python? If so, is it some performance hack that runs fast? Or is it just a once-off that needs a code review? 回答1: The "a and b or c" idiom was the canonical way to express the ternary arithmetic if in

When should I use Perl's AUTOLOAD?

放肆的年华 提交于 2019-12-19 16:53:45
问题 In "Perl Best Practices" the very first line in the section on AUTOLOAD is: Don't use AUTOLOAD However all the cases he describes are dealing with OO or Modules. I have a stand alone script in which some command line switches control which versions of particular functions get defined. Now I know I could just take the conditionals and the evals and stick them naked at the top of my file before everything else, but I find it convenient and cleaner to put them in AUTOLOAD at the end of the file.

File open: Is this bad Python style?

本秂侑毒 提交于 2019-12-19 16:39:50
问题 To read contents of a file: data = open(filename, "r").read() The open file immediately stops being referenced anywhere, so the file object will eventually close... and it shouldn't affect other programs using it, since the file is only open for reading, not writing. EDIT: This has actually bitten me in a project I wrote - it prompted me to ask this question. File objects are cleaned up only when you run out of memory, not when you run out of file handles. So if you do this too often, you

$(document).ready() or $(function()) — Which to use?

自古美人都是妖i 提交于 2019-12-19 12:27:43
问题 I saw there is an answered question about whether there is a difference between using $(document).ready(function(){}) and $(function(){}) (there isn't), but my question is which is the preferred syntax and why. I've been using jQuery for about a year and have always used the $(document).ready() syntax; but lately on SO and in some other places, I've seen the $(function()) syntax used more and more. Is there a preferred syntax that you use and why do you use it? Do you use the shorter syntax

Constant abuse?

Deadly 提交于 2019-12-19 12:25:33
问题 I have run across a bunch of code in a few C# projects that have the following constants: const int ZERO_RECORDS = 0; const int FIRST_ROW = 0; const int DEFAULT_INDEX = 0; const int STRINGS_ARE_EQUAL = 0; Has anyone ever seen anything like this? Is there any way to rationalize using constants to represent language constructs? IE: C#'s first index in an array is at position 0. I would think that if a developer needs to depend on a constant to tell them that the language is 0 based, there is a

Constant abuse?

天涯浪子 提交于 2019-12-19 12:25:12
问题 I have run across a bunch of code in a few C# projects that have the following constants: const int ZERO_RECORDS = 0; const int FIRST_ROW = 0; const int DEFAULT_INDEX = 0; const int STRINGS_ARE_EQUAL = 0; Has anyone ever seen anything like this? Is there any way to rationalize using constants to represent language constructs? IE: C#'s first index in an array is at position 0. I would think that if a developer needs to depend on a constant to tell them that the language is 0 based, there is a

Make ReSharper respect your preference for code order

强颜欢笑 提交于 2019-12-19 10:54:10
问题 Related to my other question: What's the best way to layout a C# class? Is there a way in ReSharper to define the order you want your members to be in, so that ReSharper will maintain it? 回答1: From this answer: Check under Type Members Layout in Options (under the C# node). It's not simple, but it is possible to change the layout order. 来源: https://stackoverflow.com/questions/603805/make-resharper-respect-your-preference-for-code-order