coding-style

Visual Studio Extension for Code Alignment [closed]

非 Y 不嫁゛ 提交于 2019-12-08 18:48:27
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . Is there any free extension to perform code alignment, like Align Assignments with Productivity Power Tools but to align this code: public int ID; public string Title; public string Text; public decimal Factor; in that way, or something like that? public int ID; public string Title; public string Text; public

Brace placement after init list in C++

自古美人都是妖i 提交于 2019-12-08 18:21:23
For anyone who places braces thus: void f() { stuff(); } How do you prefer to place braces after long initializer lists? The same way? Object::Object() : foo(1) , bar(2) { stuff(); } Or make an exception so you actually see where the init list ends? Object::Object() : foo(1) , bar(2) { stuff(); } Or leave a blank line? Object::Object() : foo(1) , bar(2) { stuff(); } Or maybe make a weird hybrid? Object::Object() : foo(1) , bar(2) { stuff(); } Or abuse indentation Object::Object() : foo(1) , bar(2) { stuff(); } Object::Object() : foo(1) , bar(2) { stuff(); } In this small example all are pretty

Rationale for comment rules in MISRA

心已入冬 提交于 2019-12-08 18:11:23
问题 Rule 2.2 in MISRA states that "source code shall only use /* ... */ style comments". Does any one know what is the rationale for this rule? what is wrong with // style comments? 回答1: MISRA 1998 and 2004 only support the C90 standard ("ANSI C"). In that standard, // comments are not allowed and code containing them will not compile on C90 compilers. MISRA 2012 supports the C99 standard and // comments. 回答2: Further to Lundin 's reply, MISRA-C:2012 (which covers C99) DOES allow // style

how do you make a For loop when you don't need index in python?

為{幸葍}努か 提交于 2019-12-08 17:51:36
问题 if i need a for loop in python for i in range(1,42): print "spam" but don't use the "i" for anything pylint complains about the unused variable. How should i handle this? I know you can do this: for dummy_index in range(1,42): print "spam" but doing this seems quite strange to me, is there a better way? I'm quite new at python so forgive me if I'm missing something obvious. 回答1: There is no "natural" way to loop n times without a counter variable in Python, and you should not resort to ugly

Do you put a super() call a the beginning of your constructors?

风格不统一 提交于 2019-12-08 17:38:05
问题 This is a question about coding style and recommended practices: As explained in the answers to the question unnecessary to put super() in constructor?, if you write a constructor for a class that is supposed to use the default (no-arg) constructor from the superclass, you may call super() at the beginning of your constructor: public MyClass(int parm){ super(); // leaving this out makes no difference // do stuff... } but you can also omit the call; the compiler will in both cases act as if

Passing array of parameters vs. individual parameters to a function in PHP? [closed]

元气小坏坏 提交于 2019-12-08 17:37:47
问题 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 . When there is a function that requires a number of parameters to be passed, such as seven parameters, which is the better practice:

Why can't a designated initializer call a secondary initializer in its base class?

走远了吗. 提交于 2019-12-08 16:19:40
问题 According to the documentation, a class's designated initializer in Objective-C must call the designated initializer of its base class. Another rule is that secondary initializers must call the designated initializer of their own class. But if the second rule is followed, why can't a designated initializer call a secondary initializer in its base class? This base secondary initializer will ultimately call its own level's D.I., so the object will still be properly initialized, right? The

Should I use constants instead of strings even if the strings are only ever used once?

随声附和 提交于 2019-12-08 16:18:32
问题 I have a piece of code that parses some obscure text file. This text file can contain various keywords. At some point, there is some lengthy part that reads like this: void loadKeywords() { tmpString = getValueForKeyword("width"); if (tmpString != NULL) { /* do something for several lines */ } tmpString = getValueForKeyword("height"); if (tmpString != NULL) { /* do something for several lines */ } /* and so on a few dozen times */ } These strings "height" and "width" are only ever used in

Reformat code style in Eclipse

一曲冷凌霜 提交于 2019-12-08 16:03:13
问题 I'm looking for an automatic way in eclipse to reformat curly braces to K&R style, eliminating braces for single statements if, etc. Is there such a way? Thanks. 回答1: Before you reformat you need to customize the formatter settings in the Preferences Dialog Java/ Code Style / Formatter to your K&R settings if the default settings don't match your requirements. The Preferences Dialog is opened from Mainmenu / Window / Preferences You can even configure a save action Java / Editor / Save Action

How to represent regex number ranges (e.g. 1 to 12)?

拟墨画扇 提交于 2019-12-08 15:42:14
问题 I'm currently using ([1-9]|1[0-2]) to represent inputs from 1 to 12. (Leading zeros not allowed.) However it seems rather hacky , and on some days it looks outright dirty . ☞ Is there a proper in-built way to do it? ☞ What are some other ways to represent number ranges? 回答1: I tend to go with forms like [2-9]|1[0-2]? which avoids backtracking, though it makes little difference here. I've been conditioned by XML Schema to avoid such "ambiguities", even though regex can handle them fine. 回答2: