coding-style

C++ Coding Guideline 102

杀马特。学长 韩版系。学妹 提交于 2019-12-04 09:29:41
问题 If you were allowed to add another coding guideline to the 101 guidelines of the "C++ coding standards" (Herb Sutter and Andrei Alexandrescu), which would you add? 回答1: Write for a year later. 回答2: I vote for: " avoid considering goto , naming notation and indentation as being the subjects of coding rules " 回答3: Rule 102: Any change to expected functionality should result in a regression test that fails. 回答4: " Use RAII judiciously" 回答5: Prefer constructors to init()/setup() functions. Why

Delphi Coding Standards [duplicate]

守給你的承諾、 提交于 2019-12-04 09:11:24
This question already has answers here : What Delphi coding standards document(s) do you follow? [closed] (8 answers) Closed 4 years ago . I am in the process of writing (down) our companies coding standards for Delphi programming, so what would anyone suggest to have as a basis, anything that you would recommend to use / not use ? I used Delphi Language Coding Standards Document as a basis for an internal document. The Object Pascal Style Guide could probably be termed the "official" one, I think - as far as there is such a thing. lkessler Be careful not getting too anal about forcing

Why is it “easier to ask forgiveness than it is to get permission” in Python?

送分小仙女□ 提交于 2019-12-04 09:06:23
Why is "Easier to Ask Forgiveness than it is to get Permission" ( EAFP ) considered good practice in Python? As a programming novice I have the impression that using many try...except routines will rather lead to bloated and less readable code than compared to using other checks. What is the advantage of the EAFP approach? NB: I know there are similar questions here, but they mostly refer to some specific example, while I am more interested in the philosophy behind the principle. LBYL , the counter approach to EAFP doesn't have anything to do with assertions, it just means that you add a check

Gang of Four - Design Patterns - are those pattern samples coded in outdated way?

拥有回忆 提交于 2019-12-04 08:57:50
问题 So to clarify my question... each pattern in infamous GoF book - Design Patterns Elements of Reusable Object-Oriented Software - has its code samples in C++. Are those up to date? Or does nowadays code in C++ look very different? I'm asking that, because when I posted my code with my last question, lots of C++ devs told me that I should get rid of pointers, pointers that are widely used there... 回答1: They are a little out-dated, yes. But part of the point of those books is that these patterns

Python naming conventions in decorators

﹥>﹥吖頭↗ 提交于 2019-12-04 08:55:20
问题 Are there any "accepted" naming conventions for the innards of Python decorators? The style guide doesn't mention it, and this awesome entry about decorators is pretty consistent in using variants of "wrapped" for the ultimate function that is returned, but what about the names used when creating decorators that take arguments? def decorator_name(whatevs): def inner(function): def wrapped(*args, **kwargs): # sweet decorator goodness return wrapped return inner Specifically, what are the

null instead of ==

梦想的初衷 提交于 2019-12-04 08:50:15
问题 I have just started to learn Haskell out of interest. I follow learnyouahaskell.com. There I found this: null checks if a list is empty. If it is, it returns True , otherwise it returns False . Use this function instead of xs == [] (if you have a list called xs ) Why is that? Why should we use null instead of == when both produce the same result? Thanks. 回答1: Comparing the lists with == requires elements to be comparable (denoted as Eq a ). Prelude> :t (==[]) (==[]) :: (Eq a) => [a] -> Bool

An interesting detail about variable name

浪子不回头ぞ 提交于 2019-12-04 08:03:24
I have read tutorials all over the web with different kinds of tutorials specified on game (however, this turns out to be pretty general). Are there any reasons to why many developers name their variables like: mContext For me it is default to just name it "context" or something similar. Are there any reasons why the "m" are before? (I know that this is a matter of style, but I'm just curious what it stands for) The m will be to signify that the object is a member variable of the class in question. It's a common use of Hungarian Notation to prefix the name with clues to the variable's purpose

When should a C function return newly allocated memory?

こ雲淡風輕ζ 提交于 2019-12-04 07:48:03
问题 In a response elsewhere, I found the following snippet: In general it is nicer in C to have the caller allocate memory, not the callee - hence why strcpy is a "nicer" function, in my opinion, than strdup. I can see how this is a valid pattern, but why might it be considered nicer? Are there advantages to following this pattern? Or not? example Recently I've written a fair amount of code that looks something like: struct foo *a = foo_create(); // do something with a foo_destroy(a); If foo is a

Throw an exception or return null

房东的猫 提交于 2019-12-04 07:34:10
If I've got the function below, with two choices private MyObject findBlank() { for (int i = 0; i < pieces.length; i++) { if(pieces[i].isBlank()){ return pieces[i]; } } return null; } private MyObject findBlank() { for (int i = 0; i < pieces.length; i++) { if(pieces[i].isBlank()){ return pieces[i]; } } throw new NoSuchFieldError("No blank piece found!"); } From this method I know that it should always return an object one of the 'pieces' always is isBlank() == true , the return null at the end is just to please the compiler. Since this is the case and my code wouldn't work anyway if it

Fast input output function

偶尔善良 提交于 2019-12-04 07:25:10
#define getcx getchar_unlocked inline void inp( int &n )//fast input function { n=0; int ch=getcx();int sign=1; while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();} while( ch >= '0' && ch <= '9' ) n = (n<<3)+(n<<1) + ch-'0', ch=getcx(); n=n*sign; } Hi I have been using the above function for input in various coding contests but was never able to understand why is it fast. I know the logic but don't know the concept of it's fastness. For example what is this line doing "#define getcx getchar_unlocked" . Also I don't know any fast output function so is there any fast output function