coding-style

Is there a recommended maximum line length for HTML or JavaScript? [closed]

◇◆丶佛笑我妖孽 提交于 2021-02-06 06:33:37
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago . Improve this question Most style guidelines for most programming languages recommend a maximum line length, typically 80 characters. This seems impractically short for HTML and JavaScript (when it is embedded in HTML). Is there a consensus on a practical line length limit for

C++ style vs. performance?

霸气de小男生 提交于 2021-02-05 12:59:32
问题 C++ style vs. performance - is using C-style things, that are faster the some C++ equivalents, that bad practice ? For example: Don't use atoi() , itoa() , atol() , etc. ! Use std::stringstream <- probably sometimes it's better, but always? What's so bad using the C functions? Yep, C-style, not C++, but whatever? This is C++, we're looking for performance all the time.. Never use raw pointers, use smart pointers instead - OK, they're really useful, everyone knows that, I know that, I use the

Python multiple comparisons style?

杀马特。学长 韩版系。学妹 提交于 2021-02-04 12:27:22
问题 I am wondering if there is a way to do the following in a more compact style: if (text == "Text1" or text=="Text2" or text=="Text3" or text=="Text4"): do_something() The problem is i have more than just 4 comparisons in the if statement and it's starting to look rather long, ambiguous, and ugly. Any ideas? 回答1: How about this: if text in ( 'Text1', 'Text2', 'Text3', 'Text4' ): do_something() I've always found that simple and elegant. 回答2: The "if text in" answer is good, but you might also

Expand tabs to spaces in vim only in python files?

只谈情不闲聊 提交于 2021-02-04 09:57:25
问题 How do I have the tab key insert 4 spaces when I'm editing "*.py" files and not any other files? Following a recommendation from Vim and PEP 8 -- Style Guide for Python Code, I installed vim-flake8 (and vim-pathogen). This gives warnings when PEP8 style guidelines are violated. This is great, but I would for tabs to be expanded automatically in the first place when editing python files. I would like to have tab key actually insert tabs when editing other types of files. In other words, I want

Expand tabs to spaces in vim only in python files?

限于喜欢 提交于 2021-02-04 09:57:20
问题 How do I have the tab key insert 4 spaces when I'm editing "*.py" files and not any other files? Following a recommendation from Vim and PEP 8 -- Style Guide for Python Code, I installed vim-flake8 (and vim-pathogen). This gives warnings when PEP8 style guidelines are violated. This is great, but I would for tabs to be expanded automatically in the first place when editing python files. I would like to have tab key actually insert tabs when editing other types of files. In other words, I want

Pythonic alternative to dict-style setter?

♀尐吖头ヾ 提交于 2021-01-28 05:06:15
问题 People tend to consider getters and setters un-Pythonic, prefering to use @property instead. I'm currently trying to extend the functionality of a class that uses @property to support a dict: class OldMyClass(object): @property def foo(self): return self._foo @foo.setter def foo(self, value): self.side_effect(value) self._foo = value class NewMyClass(object): @property def foo(self, key): # Invalid Python return self._foo[key] @foo.setter def foo(self, key, value): # Invalid Python self.side

jQuery get elements without display=“none”

邮差的信 提交于 2021-01-20 17:51:26
问题 How can I get all tbody > tr that doesn't have this style attribute: display: none ? 回答1: $("tbody > tr:visible") Should do it, by using the :visible selector. 回答2: The accepted answer works, and is very useful, but not technically what the OP directly asked. I'm splitting hairs, admittedly, but I needed to find only tr elements which literally did not contain display: none within their style attribute, because the parent element might be hidden, thus returning no elements. So I wrote the

Code-style for indention of multi-line 'if' statement? [duplicate]

孤人 提交于 2020-12-27 08:19:13
问题 This question already has answers here : Styling multi-line conditions in 'if' statements? [closed] (30 answers) Closed 7 years ago . When indenting long if conditions, you usually do something like this (actually, PyDev indents like that): if (collResv.repeatability is None or collResv.somethingElse): collResv.rejected = True collResv.rejectCompletely() However, this puts the block started by the if statement on the same indentation level as the last part of the if condition which makes it

Code-style for indention of multi-line 'if' statement? [duplicate]

与世无争的帅哥 提交于 2020-12-27 08:18:30
问题 This question already has answers here : Styling multi-line conditions in 'if' statements? [closed] (30 answers) Closed 7 years ago . When indenting long if conditions, you usually do something like this (actually, PyDev indents like that): if (collResv.repeatability is None or collResv.somethingElse): collResv.rejected = True collResv.rejectCompletely() However, this puts the block started by the if statement on the same indentation level as the last part of the if condition which makes it

Is it acceptable for a submit button to have a name attribute?

…衆ロ難τιáo~ 提交于 2020-12-10 08:57:40
问题 Usually, a submit button works fine without a name attribute. However, there are occasions where there's a need to have two submit buttons for the same form, hence making use of the name attribute to identify which button was clicked on the server side. To clarify I am talking about: <input type="submit" name="foo"> 回答1: Yes, it is entirely acceptable. The specification has explicit rules for how to determine which submit button was successful, which would be useless if you couldn't give the