coding-style

Resolving how to give an attribute in a class in Python

自闭症网瘾萝莉.ら 提交于 2020-01-04 15:54:08
问题 I have the following class: class Point(object): __slots__= ("x","y","z","data","classification") def __init__(self,x,y,z,n=None): self.x = float(x) self.y = float(y) self.z = float(z) self.data = [self.x,self.y,self.z] def set_classification(self,n): self.classification = n p = Point(10,20,30) p.data [10.0, 20.0, 30.0] p.set_classification(0) p.data [10.0, 20.0, 30.0] I have the following questions: First, the parameters to create the Point object are x,y , and z . Classification is an

Is there a convention for naming initializer method in objective-c?

好久不见. 提交于 2020-01-04 04:22:07
问题 In an objective-c class that can be initialized through different init... methods, it is common sense to collect initialization code that is common to all initializers into one common method that is called from the other init* methods (or also sometimes from awakeFromNib). Is there a convention for how this method should be named? initializer ? initCommon ? ...? 回答1: According to Apple, initializer methods should always begin with the word 'init,' followed by name components that describe the

Using the name “function” for a variable in Python code

强颜欢笑 提交于 2020-01-03 17:22:26
问题 Is using the word function for the name of an argument considered bad style in Python code? def conjunction_junction(function): pass # do something and call function in here This pattern occurs all the time, especially in decorators. You see func , fn and f used all of the time but I prefer to avoid abbreviations when possible. Is the fact that it's the name of a type enough to warrant abbreviating it? >> type(conjunction_junction).__name__ 'function' 回答1: It's not a reserved keyword, so I

"How to impress interviewers with my coding? What practices can I adopt in the code I've written for the question stated to impress interviewers?

↘锁芯ラ 提交于 2020-01-03 15:39:11
问题 Say there is a vector of int. Now we want to merge such that , we select 2 adjacent element v[I] and v[I+1] ( for each valid I ) and do v[I] = v[I+1] + v[I] . And erase v[I+1]. Keep on doing this until you're just left with one element in the vector.(Note I=0 & I=v.size()-1 are also considered as adjacent ). so we need to try all such possible combination(i.e which pair we took first and merged matters if further clarification required please let me know in the comment) where every time we

"How to impress interviewers with my coding? What practices can I adopt in the code I've written for the question stated to impress interviewers?

时光总嘲笑我的痴心妄想 提交于 2020-01-03 15:38:07
问题 Say there is a vector of int. Now we want to merge such that , we select 2 adjacent element v[I] and v[I+1] ( for each valid I ) and do v[I] = v[I+1] + v[I] . And erase v[I+1]. Keep on doing this until you're just left with one element in the vector.(Note I=0 & I=v.size()-1 are also considered as adjacent ). so we need to try all such possible combination(i.e which pair we took first and merged matters if further clarification required please let me know in the comment) where every time we

Is fully qualified naming vs the using directive simply a matter of opinion?

ぃ、小莉子 提交于 2020-01-03 12:30:52
问题 I find now that I work in a mostly solo environment that I actually type fully qualified methods calls more and more, instead of make use of the using directive. Previously, I just stayed consistent with the most prominent coding practice on the team. Personally, I find it easier to read verbose code at a glance, I type fast especially with autocompletion and I find myself using Google more often as my source of documentation, which a fully qualified name returns a much narrower results set.

Is fully qualified naming vs the using directive simply a matter of opinion?

元气小坏坏 提交于 2020-01-03 12:30:42
问题 I find now that I work in a mostly solo environment that I actually type fully qualified methods calls more and more, instead of make use of the using directive. Previously, I just stayed consistent with the most prominent coding practice on the team. Personally, I find it easier to read verbose code at a glance, I type fast especially with autocompletion and I find myself using Google more often as my source of documentation, which a fully qualified name returns a much narrower results set.

GWT Themes and Component Libraries

自作多情 提交于 2020-01-03 10:18:12
问题 Are there any good themes or component libraries for GWT? The built-in themes are rather plain for my purposes. I've seen gwt-ext and smartgwt, but those aren't that great looking. Are there any others that have a real nice look? I know of vaadin an I really really like the look, but from what I understand that just an entirely new framework. 回答1: The first thing to be careful of is that there are two frameworks which use EXT and GWT: GWT-Ext Ext GWT Both are based on the Ext JS component

int i vs int index etc. Which one is better? [duplicate]

心不动则不痛 提交于 2020-01-03 08:08:35
问题 This question already has answers here : Closed 9 years ago . Possible Duplicates: Is a variable named i unacceptable? What is an ideal variable naming convention for loop variables? Coming from a C background I've always used int i for generic loop variables. Of course in big nested loops or other complex things I may use a descriptive name but which one had you rather see? int i; for(i=0;i<Controls.Count;i++){ DoStuff(Controls[i]); } or int index; for(index=0;index<Controls.Count;index++){

int i vs int index etc. Which one is better? [duplicate]

牧云@^-^@ 提交于 2020-01-03 08:08:10
问题 This question already has answers here : Closed 9 years ago . Possible Duplicates: Is a variable named i unacceptable? What is an ideal variable naming convention for loop variables? Coming from a C background I've always used int i for generic loop variables. Of course in big nested loops or other complex things I may use a descriptive name but which one had you rather see? int i; for(i=0;i<Controls.Count;i++){ DoStuff(Controls[i]); } or int index; for(index=0;index<Controls.Count;index++){