conventions

Tabs versus spaces in Python programming

China☆狼群 提交于 2019-11-26 11:29:48
I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes. How does that make a difference? Are there other reasons why one would use spaces instead of tabs for Python? Or is it simply not true? Should I switch my editor to insert spaces instead of tabs right away or keep on going like I used to? Alexander Kojevnikov Because PEP-8 tells us to use spaces. yota Tired of chasing after indentation typos ( 8 spaces ? no, 7

Python import mechanics

梦想与她 提交于 2019-11-26 09:51:25
问题 I have two related Python \'import\' questions. They are easily testable, but I want answers that are language-defined and not implementation-specific, and I\'m also interested in style/convention, so I\'m asking here instead. 1) If module A imports module B, and module B imports module C, can code in module A reference module C without an explicit import? If so, am I correct in assuming this is bad practice? 2) If I import module A.B.C, does that import modules A and A.B as well? If so, is

JavaScript braces on new line or not? [closed]

喜夏-厌秋 提交于 2019-11-26 07:27:17
问题 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 9 years ago . At work, we place braces on the next line, but at home, I do the opposite. Which one do you prefer? (K&R vs OTBS) function something()

How to organize large R programs?

纵饮孤独 提交于 2019-11-26 06:51:15
问题 When I undertake an R project of any complexity, my scripts quickly get long and confusing. What are some practices I can adopt so that my code will always be a pleasure to work with? I\'m thinking about things like Placement of functions in source files When to break something out to another source file What should be in the master file Using functions as organizational units (whether this is worthwhile given that R makes it hard to access global state) Indentation / line break practices.

Is it pythonic to import inside functions?

我与影子孤独终老i 提交于 2019-11-26 06:30:03
问题 PEP 8 says: Imports are always put at the top of the file, just after any module comments and docstrings, and before module globals and constants. On occation, I violate PEP 8. Some times I import stuff inside functions. As a general rule, I do this if there is an import that is only used within a single function. Any opinions? EDIT (the reason I feel importing in functions can be a good idea): Main reason: It can make the code clearer. When looking at the code of a function I might ask

Are there any Java method ordering conventions? [closed]

你离开我真会死。 提交于 2019-11-26 06:04:32
问题 I\'ve got a large-ish class (40 or so methods) that is part of a package I will be submitting as course-work. Currently, the methods are pretty jumbled up in terms of utility public/private etc. and I want to order them in a sensible way. Is there a standard way of doing this? E.g. normally fields are listed before methods, the constructor(s) are listed before other methods, and getters/setters last; what about the remaining methods? 回答1: Some conventions list all the public methods first,

How do I pronounce “=>” as used in lambda expressions in .Net

谁说胖子不能爱 提交于 2019-11-26 04:36:48
问题 I very rarely meet any other programmers! My thought when I first saw the token was \"implies that\" since that\'s what it would read it as in a mathematical proof but that clearly isn\'t its sense. So how do I say or read \"=>\" as in:- IEnumerable<Person> Adults = people.Where(p => p.Age > 16) Or is there even an agreed way of saying it? 回答1: I usually say 'such that' when reading that operator. In your example, p => p.Age > 16 reads as "P, such that p.Age is greater than 16." In fact, I

Where is the JavaBean property naming convention defined?

二次信任 提交于 2019-11-26 03:59:24
问题 The Spring Framework API doc says: The convention used is to return the uncapitalized short name of the Class, according to JavaBeans property naming rules: So, com.myapp.Product becomes product; com.myapp.MyProduct becomes myProduct; com.myapp.UKProduct becomes UKProduct. I looked at Suns website to find a definition, but didn\'t find one. I wonder about a rule for names with more than one upper case character at the beginning. Is the rule that the first character is upper case if the second

Python __str__ versus __unicode__

廉价感情. 提交于 2019-11-26 03:47:49
问题 Is there a python convention for when you should implement __str__() versus __unicode__() . I\'ve seen classes override __unicode__() more frequently than __str__() but it doesn\'t appear to be consistent. Are there specific rules when it is better to implement one versus the other? Is it necessary/good practice to implement both? 回答1: __str__() is the old method -- it returns bytes. __unicode__() is the new, preferred method -- it returns characters. The names are a bit confusing, but in 2.x

Tabs versus spaces in Python programming

帅比萌擦擦* 提交于 2019-11-26 02:26:42
问题 I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes. How does that make a difference? Are there other reasons why one would use spaces instead of tabs for Python? Or is it simply not true? Should I switch my editor to insert spaces instead of tabs right away or keep on going like I used to? 回答1: Because PEP-8