conventions

JavaScript braces on new line or not? [closed]

家住魔仙堡 提交于 2019-11-26 19:55:02
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() { // ... } function something() { // ... } A lot of JavaScript libraries seem to use the OTBS (one true brace style). I'd like to follow them for consistence among other JavaScript projects, but doesn't K&R style look more readable? Note: We know the problem with return and braces in JavaScript, that will always be an exception. However, that is only a single case. This is a Holy War to which you will never get a usable answer! Just stick with whatever everyone

Is it pythonic to import inside functions?

徘徊边缘 提交于 2019-11-26 19:54:34
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 myself: "What is function/class xxx?" (xxx being used inside the function). If I have all my imports at the

Are there any Java method ordering conventions? [closed]

血红的双手。 提交于 2019-11-26 17:05:40
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? Some conventions list all the public methods first, and then all the private ones - that means it's easy to separate the API from the implementation, even when

Java: Infinite Loop Convention [closed]

♀尐吖头ヾ 提交于 2019-11-26 16:30:47
问题 What is the convention for an infinite loop in Java? Should I write while(true) or for(;;) ? I personally would use while(true) because I use while loops less often. 回答1: There is no difference in bytecode between while(true) and for(;;) but I prefer while(true) since it is less confusing (especially for someone new to Java). You can check it with this code example void test1(){ for (;;){ System.out.println("hello"); } } void test2(){ while(true){ System.out.println("world"); } } When you use

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

亡梦爱人 提交于 2019-11-26 15:47:26
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? 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 asked this very question on the official linq pre-release forums, and Anders Hejlsberg responded by saying I usually

Where is the JavaBean property naming convention defined?

此生再无相见时 提交于 2019-11-26 15:27:48
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 character is upper case too? The background is, that I want to generate variable names automatically

What are common conventions for using namespaces in Clojure?

旧时模样 提交于 2019-11-26 15:25:50
问题 I'm having trouble finding good advice and common practices for the use of namespaces in Clojure. I realize that namespaces are not the same as Java packages so I'm trying to tease out the conventions in Clojure, which seem surprisingly hard to determine. I think I have a pretty good idea how to split functions into clj files and even roughly how I'd want to organize those files into directories. But beyond that I'm having trouble finding the mechanics for my dev environment. Some inter

Python: using 4 spaces for indentation. Why? [closed]

末鹿安然 提交于 2019-11-26 15:25:17
问题 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 5 years ago . While coding python I'm using only 2 spaces to indent, sure PEP-8 really recommend to have 4 spaces, but historically for me it's unusual. So, can anyone convince me to use 4 spaces instead of 2? What pros and cons? P.S. And finally, what's easy way to convert all existing

Python __str__ versus __unicode__

China☆狼群 提交于 2019-11-26 14:05:16
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? __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 we're stuck with them for compatibility reasons. Generally, you should put all your string formatting in _

AS3: cast or “as”?

半城伤御伤魂 提交于 2019-11-26 12:46:40
问题 Is there any difference of use, efficiency or background technique between var mc:MovieClip = MovieClip(getChildByName(\"mc\")); and var mc:MovieClip = getChildByName(\"mc\") as MovieClip; ? The choice is just matter of convention, preference or are there cases where you can\'t use one? 回答1: This article describes the differences well: A key difference between casting and the as operator is the behavior on failure. When a cast fails in ActionScript 2, null is returned. When a cast fails in