coding-style

What is indirect object notation, why is it bad, and how does one avoid it?

孤者浪人 提交于 2019-12-17 16:56:11
问题 The title pretty much sums it up, but here's the long version anyway. After posting a small snippet of perl code, I was told to avoid indirect object notation, "as it has several side effects". The comment referenced this particular line: my $some_object = new Some::Module(FIELD => 'value'); As this is how I've always done it, in an effort to get with the times I therefore ask: What's so bad about it? (specifically) What are the potential (presumably negative) side effects? How should that

How To Hide An HTML Element With CSS? [closed]

蹲街弑〆低调 提交于 2019-12-17 16:50:42
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 6 years ago . I am trying to hide an HTML element with CSS. <select id="tinynav1" class="tinynav tinynav1"> but its very resilient, even with Google Inspect element I cannot change the styling Any ideas? Thank you :-) 回答1: It's simple, just set the display property to none in CSS: #tinynav1 { display:none }

C#: is calling an event handler explicitly really “a good thing to do”?

落花浮王杯 提交于 2019-12-17 16:28:30
问题 This question is related to C#, but may be applicable to other languages as well. I have a reservation against using code such as the following: using System.Windows.Forms; class MyForm : Form { private Timer myTimer; private Button myButton; public MyForm() { // Initialize the components, etc. myTimer.Tick += new EventHandler( myTimer_Tick ); myButton.Click += new EventHandler( myButton_Click ); myTimer.Start(); } private void myTimer_Tick( object sender, EventArgs eventArgs ) { myTimer.Stop

PHP IF statement for Boolean values: $var === true vs $var

拜拜、爱过 提交于 2019-12-17 16:27:20
问题 I know this question is not really important.. however I've been wondering: Which of the following IF statements is the best and fastest to use? <?php $variable = true; if($variable === true) { //Something } if($variable) { // Something } ?> I know === is to match exactly the boolean value. However is there really any improvement? 回答1: Using if ($var === true) or if ($var) is not a question of style but a question of correctness. Because if ($var) is the same as if ($var == true) . And ==

identity versus equality for None in Python

我怕爱的太早我们不能终老 提交于 2019-12-17 16:21:45
问题 Various Python guides say to use x is None instead of x == None . Why is that? Equality is used for comparing values, so it seems natural to ask if x has the value None , denoted with == and not is . Can someone explain why is is the preferred form and show an example where the two do not give the same answer? Thanks. 回答1: The reason people use is is because there is no advantage to using == . It is possible to write objects that compare equal to None , but it is uncommon. class A(object):

(When) should I use type hinting in PHP?

亡梦爱人 提交于 2019-12-17 16:12:40
问题 I can't understand the motivation of PHP authors to add the type hinting. I happily lived before it appeared. Then, as it was added to PHP 5, I started specifying types everywhere. Now I think it's a bad idea, as far as duck typing assures minimal coupling between the classes, and leverages the code modularization and reuse. It feels like type hints split the language into 2 dialects: some people write the code in static-language style, with the hints, and others stick to the good old dynamic

Advantages of using arrays instead of std::vector?

不羁的心 提交于 2019-12-17 16:10:33
问题 I'm currently seeing a lot of questions which are tagged C++ and are about handling arrays. There even are questions which ask about methods/features for arrays which a std::vector would provide without any magic. So I'm wondering why so much developers are chosing arrays over std::vector in C++? 回答1: In general, I strongly prefer using a vector over an array for non-trivial work; however, there are some advantages of arrays. arrays are slightly more compact: the size is implicit arrays are

Python “private” function coding convention

岁酱吖の 提交于 2019-12-17 15:59:17
问题 When writing a python module and functions in it, I have some "public" functions that are supposed to be exposed to outsiders, but some other "private" functions that are only supposed to be seen and used locally and internally. I understand in python there is no absolute private functions. But what is the best, most neat, or most used style to distinguish "public" functions and "private" functions? I list some of the styles I know: use __all__ in module file to indicate its "public"

Enum method overriding

耗尽温柔 提交于 2019-12-17 15:44:17
问题 I've found Enum s defined like the following: public Enum MyEnum { ONE { @Override public int getSomething() { return 1; } }, TWO { @Override public int getSomething() { return 2; } } int getSomething() { return 0; } } Somehow I feel some type of discomfort with this implementation because I would think that ideally a field should be defined for this purpose and the class should look something like: public Enum MyEnum{ ONE(1), TWO(2) private int theSomething; private MyEnum(int something) {

How many lines of code should a function/procedure/method have? [duplicate]

五迷三道 提交于 2019-12-17 15:27:08
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: When is a function too long? I've recently been given the unenviable task of reviewing poor code written by another developer and documenting the bad practices. (This is all for the purposes of getting out of paying for the developer's work rather than any altruistic reason, of course!) The reviewed code has several procedures that are many lines of code - the longest is almost 600 lines. A couple of problems