coding-style

javascript - using function calls in html - bad or good?

北战南征 提交于 2020-01-11 06:42:31
问题 Using angular brings lot of weird style of code. For example I always thought that this <button onclick="myFunction()">Click me</button> style I should not ever use, except when I would be lazy and want quick and dirty code. And I never used such style in projects and also I even thinked that this is bad. Now when I see angular here is the example: <div enter="loadMoreTweets()">Roll over to load more tweets</div> which is from there http://www.thinkster.io/pick/IgQdYAAt9V/angularjs-directives

Pro/con: Initializing a variable in a conditional statement

折月煮酒 提交于 2020-01-10 21:17:06
问题 In C++ you can initialize a variable in an if statement, like so: if (CThing* pThing = GetThing()) { } Why would one consider this bad or good style? What are the benefits and disadvantages? Personally i like this style because it limits the scope of the pThing variable, so it can never be used accidentally when it is NULL. However, i don't like that you can't do this: if (CThing* pThing = GetThing() && pThing->IsReallySomeThing()) { } If there's a way to make the above work, please post. But

Should I add a trailing comma after the last argument in a function call?

倖福魔咒の 提交于 2020-01-10 17:25:13
问题 What is better to do? self.call(1, True, "hi") or self.call(1, True, "hi",) And what in the following cases: self.call( 1, True, "hi" ) or self.call( 1, True, "hi", ) ? Reasons for adding a trailing comma in data structures are familiar to me, but what about function calls? 回答1: I think there's no technical reason to avoid trailing commas in function calls, but some people probably do find them distracting. Some may stop and say: "Hmmm, I wonder if that's really supposed to be there?" I

Is a variable named i unacceptable? [closed]

橙三吉。 提交于 2020-01-10 03:34:06
问题 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 4 years ago . As far as variable naming conventions go, should iterators be named i or something more semantic like count ? If you don't use i , why not? If you feel that i is acceptable, are there cases of iteration where it shouldn't be used? 回答1: Depends on the context I suppose. If you

Javascript: Configuration Pattern

≡放荡痞女 提交于 2020-01-10 03:02:10
问题 Problem : A Javascript function needs few parameters to work with: function kick(person, reason, amount) { // kick the *person* with the *amount*, based on the *reason* } As there's no way to do function overloading in JS like how you do in Java, if it needs to be designed for easy future improvement (parameters adding), it can be written as: /* Function Parameters pattern */ function kick() { // kick the person as in *arguments[0]*, with the amount as in *arguments[1]*, // based on the

Good or bad practice? Initializing objects in getter

只谈情不闲聊 提交于 2020-01-09 12:09:51
问题 I have a strange habit it seems... according to my co-worker at least. We've been working on a small project together. The way I wrote the classes is (simplified example): [Serializable()] public class Foo { public Foo() { } private Bar _bar; public Bar Bar { get { if (_bar == null) _bar = new Bar(); return _bar; } set { _bar = value; } } } So, basically, I only initialize any field when a getter is called and the field is still null. I figured this would reduce overload by not initializing

Good or bad practice? Initializing objects in getter

℡╲_俬逩灬. 提交于 2020-01-09 12:08:23
问题 I have a strange habit it seems... according to my co-worker at least. We've been working on a small project together. The way I wrote the classes is (simplified example): [Serializable()] public class Foo { public Foo() { } private Bar _bar; public Bar Bar { get { if (_bar == null) _bar = new Bar(); return _bar; } set { _bar = value; } } } So, basically, I only initialize any field when a getter is called and the field is still null. I figured this would reduce overload by not initializing

Should we declare a public constructor when the class is declared as package private?

假如想象 提交于 2020-01-09 07:42:12
问题 I think in this case there is no need to declare a public constructor since the class is not accessible outside the package anyway. But is there some hidden impact when the class has only package private constructor? 回答1: No, you don't have to declare the public constructor; package private constructors will be just as usable. Classes outside the package wouldn't be able to use the constructor anyway, since they can't see the class. 回答2: If your class is package private then the access levels

Cannot find reference 'xxx' in __init__.py - Python / Pycharm

匆匆过客 提交于 2020-01-09 03:07:04
问题 I have a project in Pycharm organized as follows: -- Sources |--__init__.py |--Calculators |--__init__.py |--Filters.py |--Controllers |--__init__.py |--FiltersController.py |--Viewers |--__init__.py |--DataVisualization.py |--Models |--__init__.py |--Data All of my __init__.py, except for the one right above Sources are blank files. I am receiving a lot of warnings of the kind: Cannot find reference 'xxx' in __init__.py For example, my FiltersController .py has this piece of code: import

Prefixing property names with an underscore in Objective C [duplicate]

不羁的心 提交于 2020-01-08 18:01:08
问题 This question already has answers here : Closed 7 years ago . I've previously avoided underscores in my variable names, perhaps a holdover from my college Java days. So when I define a property in Objective C this is what I naturally do. // In the header @interface Whatever { NSString *myStringProperty } @property (nonatomic, copy) NSString *myStringProperty; // In the implementation @synthesize myStringProperty; But in almost every example it is done like // In the header @interface Whatever